From de023a3c1d1946db496055695e7d1fde421c409f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Fri, 16 Apr 2010 23:04:30 +0000 Subject: [PATCH] building on the new CallGraphSCC abstraction, teach CallGraphSCCPassManager 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. llvm-svn: 101565 --- llvm/include/llvm/ADT/SCCIterator.h | 9 +++++++++ llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/llvm/include/llvm/ADT/SCCIterator.h b/llvm/include/llvm/ADT/SCCIterator.h index 315940643d14..80eb8c55b22f 100644 --- a/llvm/include/llvm/ADT/SCCIterator.h +++ b/llvm/include/llvm/ADT/SCCIterator.h @@ -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); + } }; diff --git a/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp b/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp index f5d24f005f59..7b73c5dffce5 100644 --- a/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp +++ b/llvm/lib/Analysis/IPA/CallGraphSCCPass.cpp @@ -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 *CGI = (scc_iterator*)Context; + CGI->ReplaceNode(Old, New); }