[PATCH] D120670: [SCCIterator] Fix a non-determinism in scc_member_iterator
Hongtao Yu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 28 11:28:57 PST 2022
hoy created this revision.
Herald added subscribers: dexonsmith, modimo, wenlei, mgrang.
hoy requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Prevoiusly we initialzed a queue with MST roots based on NodeInfoMap which is an unordered map. This could cause a non-determinism. I'm fixing this by initializing the queue based on SortedEdges.
This should be a no-diff change in terms of code quality. However this helps debugging.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D120670
Files:
llvm/include/llvm/ADT/SCCIterator.h
Index: llvm/include/llvm/ADT/SCCIterator.h
===================================================================
--- llvm/include/llvm/ADT/SCCIterator.h
+++ llvm/include/llvm/ADT/SCCIterator.h
@@ -348,9 +348,14 @@
NodeInfoMap[Edge->Target].Visited = false;
std::queue<NodeType *> Queue;
- for (auto &Node : NodeInfoMap)
- if (Node.second.Visited)
- Queue.push(Node.first);
+ // Initialze the queue with MST roots. Note that walking through SortedEdges
+ // instead of NodeInfoMap ensures an ordered deterministic push.
+ for (auto *Edge : SortedEdges) {
+ if (NodeInfoMap[Edge->Source].Visited) {
+ Queue.push(Edge->Source);
+ NodeInfoMap[Edge->Source].Visited = false;
+ }
+ }
while (!Queue.empty()) {
auto *Node = Queue.front();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120670.411854.patch
Type: text/x-patch
Size: 778 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220228/4ec86527/attachment.bin>
More information about the llvm-commits
mailing list