Internals: Refactor MT scheduling (#8012)

Prep for fixing test added in #7913.

This is a large scale no functional change refactor, however, MT output
is perturbed as tied scores will be broken differently due to ordering
changes (still deterministic).

Split multi-threaded scheduling out of the monolithic
V3OrderParallel.cpp, into relatively independent parts, simplify the
data structures, and drop redundant or unused code.

New translation units:
- V3OrderMTaskGraph.h/.cpp: OrderMTaskGraph, the graph of LogicMTask
  vertices and MTaskEdge edges. LogicMTask and MTaskEdge no longer
  depend on the coarsening algorithm's merge candidate types;
  per-algorithm auxiliary data is attached externally via the vertex and
  edge user pointers.
- V3OrderMTaskFixHazards.cpp: data hazard fixup, was FixDataHazards.
- V3OrderMTaskContraction.cpp: graph coarsening, was Partitioner
  together with PropagateCp and the merge candidate types.
- V3OrderParallel.cpp: now just the partitioning driver and ExecMTask
  graph construction.

Data structure changes:
- Delete V3Scoreboard.h/.cpp. The generic template had a single user, now
  a file-local MergeCandidateScoreboard in V3OrderMTaskContraction.cpp.
- Merge candidates are now MergeCandidate/SiblingMC/EdgeMC, distinguished
  by a bit in the candidate id rather than by a vtable, and allocated by
  the scoreboard, which owns their lifetime. This removes the multiple
  inheritance previously used by MTaskEdge.

Move `hashGraphDebug` which prints the hash of a graph's shape for debugging
to generic `V3Graph::hashGraphDebug`.

Removed (can be added back later):
- Unnecesasry self tests that force special data stucture requirements.
- Per stage --stats output under --debug. (Final figures still reported.)
- Various debug dumps
This commit is contained in:
Geza Lore
2026-07-31 15:03:26 +01:00
committed by GitHub
parent 40323cc02c
commit 781f6d90bf
19 changed files with 2400 additions and 2597 deletions
+15
View File
@@ -388,3 +388,18 @@ void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) const {
cout << "dot -Tpdf -o ~/a.pdf " << filename << "\n";
}
void V3Graph::hashGraphDebug(const char* debugName) const {
// Disabled when there are no nondeterminism issues in flight.
if (!v3Global.opt.debugNondeterminism()) return;
// Assign a unique ID to each vertex for pointer stability, then hash
uint32_t id = 1;
std::unordered_map<const V3GraphVertex*, uint32_t> vx2Id;
for (const V3GraphVertex& vtx : vertices()) vx2Id[&vtx] = ++id;
V3Hash hash;
for (const V3GraphVertex& vtx : vertices()) {
for (const V3GraphEdge& edge : vtx.outEdges()) hash += vx2Id[edge.top()];
}
UINFO(0, "Hash of shape (not contents) of " << debugName << " = " << cvtToHex(hash.value()));
}