Skip to content

Commit 38e28b8

Browse files
angelomatni1copybara-github
authored andcommitted
Ensure folding graph nodes and edges are ordered
PiperOrigin-RevId: 815858502
1 parent c47faff commit 38e28b8

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

xls/passes/resource_sharing_pass.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,6 +2757,16 @@ FoldingGraph::FoldingGraph(
27572757
// Allocate the graph
27582758
graph_ = std::make_unique<Graph>();
27592759

2760+
// Ensure deterministic construction of FoldingGraph
2761+
std::sort(foldable_actions.begin(), foldable_actions.end(),
2762+
[](const std::unique_ptr<BinaryFoldingAction>& a,
2763+
const std::unique_ptr<BinaryFoldingAction>& b) {
2764+
if (a->GetFrom()->id() == b->GetFrom()->id()) {
2765+
return a->GetTo()->id() < b->GetTo()->id();
2766+
}
2767+
return a->GetFrom()->id() < b->GetFrom()->id();
2768+
});
2769+
27602770
// Add the nodes
27612771
AddNodes(foldable_actions);
27622772

0 commit comments

Comments
 (0)