diff options
author | Chris Lattner <sabre@nondot.org> | 2005-04-25 19:16:31 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-04-25 19:16:31 +0000 |
commit | a1198b52545b8e08a17e78835c8519824d3515c3 (patch) | |
tree | 853a1bf2363c4c1ee76f314cc29df7232b5a6628 /lib/Analysis/DataStructure/BottomUpClosure.cpp | |
parent | 63320cc84106b32afcec479275d1eca8599896a6 (diff) |
Correctly handle global-argument aliases induced in main
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21537 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/DataStructure/BottomUpClosure.cpp')
-rw-r--r-- | lib/Analysis/DataStructure/BottomUpClosure.cpp | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/Analysis/DataStructure/BottomUpClosure.cpp b/lib/Analysis/DataStructure/BottomUpClosure.cpp index aa5144437d..21ca2dc037 100644 --- a/lib/Analysis/DataStructure/BottomUpClosure.cpp +++ b/lib/Analysis/DataStructure/BottomUpClosure.cpp @@ -434,14 +434,42 @@ DSGraph &BUDataStructures::CreateGraphForExternalFunction(const Function &Fn) { void BUDataStructures::calculateGraph(DSGraph &Graph) { + // If this graph contains the main function, clone the globals graph into this + // graph before we inline callees and other fun stuff. + bool ContainsMain = false; + DSGraph::ReturnNodesTy &ReturnNodes = Graph.getReturnNodes(); + + for (DSGraph::ReturnNodesTy::iterator I = ReturnNodes.begin(), + E = ReturnNodes.end(); I != E; ++I) + if (I->first->hasExternalLinkage() && I->first->getName() == "main") { + ContainsMain = true; + break; + } + + // If this graph contains main, copy the contents of the globals graph over. + // Note that this is *required* for correctness. If a callee contains a use + // of a global, we have to make sure to link up nodes due to global-argument + // bindings. + if (ContainsMain) { + const DSGraph &GG = *Graph.getGlobalsGraph(); + ReachabilityCloner RC(Graph, GG, + DSGraph::DontCloneCallNodes | + DSGraph::DontCloneAuxCallNodes); + + // Clone the global nodes into this graph. + for (DSScalarMap::global_iterator I = GG.getScalarMap().global_begin(), + E = GG.getScalarMap().global_end(); I != E; ++I) + if (isa<GlobalVariable>(*I)) + RC.getClonedNH(GG.getNodeForValue(*I)); + } + + // Move our call site list into TempFCs so that inline call sites go into the // new call site list and doesn't invalidate our iterators! std::list<DSCallSite> TempFCs; std::list<DSCallSite> &AuxCallsList = Graph.getAuxFunctionCalls(); TempFCs.swap(AuxCallsList); - DSGraph::ReturnNodesTy &ReturnNodes = Graph.getReturnNodes(); - bool Printed = false; std::vector<Function*> CalledFuncs; while (!TempFCs.empty()) { |