diff --git a/llvm/lib/Analysis/DataStructure/BottomUpClosure.cpp b/llvm/lib/Analysis/DataStructure/BottomUpClosure.cpp index fceb1ded59a1..2125064030ee 100644 --- a/llvm/lib/Analysis/DataStructure/BottomUpClosure.cpp +++ b/llvm/lib/Analysis/DataStructure/BottomUpClosure.cpp @@ -57,23 +57,6 @@ bool BUDataStructures::run(Module &M) { NumCallEdges += ActualCallees.size(); - - // At the end of the BU phase, clone the BU graph for main into the globals - // graph to make sure it has everything. - if (MainFunc) { - DSGraph &MainGraph = getOrCreateGraph(MainFunc); - DSScalarMap &MainSM = MainGraph.getScalarMap(); - ReachabilityCloner RC(*GlobalsGraph, MainGraph, DSGraph::StripAllocaBit); - - // Clone everything reachable from globals in the "main" graph into the - // globals graph. - for (DSScalarMap::global_iterator I = MainSM.global_begin(), - E = MainSM.global_end(); I != E; ++I) - RC.getClonedNH(MainSM[*I]); - - - } - // At the end of the bottom-up pass, the globals graph becomes complete. // FIXME: This is not the right way to do this, but it is sorta better than // nothing! In particular, externally visible globals and unresolvable call @@ -329,5 +312,16 @@ void BUDataStructures::calculateGraph(DSGraph &Graph) { // reach live nodes as live. Graph.removeDeadNodes(DSGraph::KeepUnreachableGlobals); + // When this graph is finalized, clone the globals in the graph into the + // globals graph to make sure it has everything, from all graphs. + DSScalarMap &MainSM = Graph.getScalarMap(); + ReachabilityCloner RC(*GlobalsGraph, Graph, DSGraph::StripAllocaBit); + + // Clone everything reachable from globals in the "main" graph into the + // globals graph. + for (DSScalarMap::global_iterator I = MainSM.global_begin(), + E = MainSM.global_end(); I != E; ++I) + RC.getClonedNH(MainSM[*I]); + //Graph.writeGraphToFile(std::cerr, "bu_" + F.getName()); }