[llvm] 50bc945 - [CSSPGO][SCCIterator] Fix a non-determinism in scc_member_iterator

Hongtao Yu via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 8 09:08:53 PST 2022


Author: Hongtao Yu
Date: 2022-03-08T09:08:47-08:00
New Revision: 50bc945a8fc539894fdbf618ace28085c1e19534

URL: https://github.com/llvm/llvm-project/commit/50bc945a8fc539894fdbf618ace28085c1e19534
DIFF: https://github.com/llvm/llvm-project/commit/50bc945a8fc539894fdbf618ace28085c1e19534.diff

LOG: [CSSPGO][SCCIterator] Fix a non-determinism in scc_member_iterator

Previously we initialed the work 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.

I don't see any performance move with this change. However this helps debugging.

Reviewed By: wenlei

Differential Revision: https://reviews.llvm.org/D120670

Added: 
    

Modified: 
    llvm/include/llvm/ADT/SCCIterator.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/SCCIterator.h b/llvm/include/llvm/ADT/SCCIterator.h
index ad35e09f0f74a..e4035a02b5f50 100644
--- a/llvm/include/llvm/ADT/SCCIterator.h
+++ b/llvm/include/llvm/ADT/SCCIterator.h
@@ -348,9 +348,14 @@ scc_member_iterator<GraphT, GT>::scc_member_iterator(
     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();


        


More information about the llvm-commits mailing list