building on the new CallGraphSCC abstraction, teach CallGraphSCCPassManager
authorChris Lattner <sabre@nondot.org>
Fri, 16 Apr 2010 23:04:30 +0000 (23:04 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 16 Apr 2010 23:04:30 +0000 (23:04 +0000)
to keep the node entries in scc_iterator up to date instead of dangling as
the SCC mutates.

This is a really terrible problem which was causing -g to affect codegen
because it would permute the memory image of the compiler process.

Thanks to Dale for expertly hunting it down.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101565 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/SCCIterator.h
lib/Analysis/IPA/CallGraphSCCPass.cpp

index 315940643d1481e1464c8397ae258165f4ed68c5..80eb8c55b22f64fa26a4c5bdae07d13b4bdfe90f 100644 (file)
@@ -183,6 +183,15 @@ public:
         return true;
     return false;
   }
+                           
+  /// ReplaceNode - This informs the scc_iterator that the specified Old node
+  /// has been deleted, and New is to be used in its place.
+  void ReplaceNode(NodeType *Old, NodeType *New) {
+    assert(!nodeVisitNumbers.count(New) && "New already in scc_iterator?");
+    assert(nodeVisitNumbers.count(Old) && "Old not in scc_iterator?");
+    nodeVisitNumbers[New] = nodeVisitNumbers[Old];
+    nodeVisitNumbers.erase(Old);
+  }
 };
 
 
index f5d24f005f594369e6c4268bd2afcc50a4bdcc23..7b73c5dffce5590e3c8b52270d6e4e2c33041786 100644 (file)
@@ -417,6 +417,11 @@ void CallGraphSCC::ReplaceNode(CallGraphNode *Old, CallGraphNode *New) {
     Nodes[i] = New;
     break;
   }
+  
+  // Update the active scc_iterator so that it doesn't contain dangling
+  // pointers to the old CallGraphNode.
+  scc_iterator<CallGraph*> *CGI = (scc_iterator<CallGraph*>*)Context;
+  CGI->ReplaceNode(Old, New);
 }