Fix for PR341
[oota-llvm.git] / lib / Analysis / DataStructure / TopDownClosure.cpp
index 67ea400dced7e6324ccc839838cc92cc21b41ad1..4635787a041304053c4f680a2c5c9363b550484f 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
-#include "llvm/Analysis/DataStructure.h"
+#include "llvm/Analysis/DataStructure/DataStructure.h"
 #include "llvm/Module.h"
 #include "llvm/DerivedTypes.h"
-#include "llvm/Analysis/DSGraph.h"
+#include "llvm/Analysis/DataStructure/DSGraph.h"
 #include "Support/Debug.h"
 #include "Support/Statistic.h"
 using namespace llvm;
@@ -60,11 +60,12 @@ bool TDDataStructures::run(Module &M) {
   // they are accessible outside this compilation unit.  Currently, these
   // arguments are functions which are reachable by global variables in the
   // globals graph.
-  const DSGraph::ScalarMapTy &GGSM = GlobalsGraph->getScalarMap();
+  const DSScalarMap &GGSM = GlobalsGraph->getScalarMap();
   hash_set<DSNode*> Visited;
-  for (DSScalarMap::global_iterator I = GGSM.global_begin(), E = GGSM.global_end();
+  for (DSScalarMap::global_iterator I=GGSM.global_begin(), E=GGSM.global_end();
        I != E; ++I)
-    markReachableFunctionsExternallyAccessible(GGSM.find(*I)->second.getNode(), Visited);
+    markReachableFunctionsExternallyAccessible(GGSM.find(*I)->second.getNode(),
+                                               Visited);
 
   // Loop over unresolved call nodes.  Any functions passed into (but not
   // returned!) from unresolvable call nodes may be invoked outside of the
@@ -107,6 +108,8 @@ bool TDDataStructures::run(Module &M) {
   }
 
   ArgsRemainIncomplete.clear();
+  GlobalsGraph->removeTriviallyDeadNodes();
+
   return false;
 }
 
@@ -175,7 +178,6 @@ void TDDataStructures::releaseMyMemory() {
 
 void TDDataStructures::inlineGraphIntoCallees(DSGraph &Graph) {
   // Recompute the Incomplete markers and eliminate unreachable nodes.
-  Graph.removeTriviallyDeadNodes();
   Graph.maskIncompleteMarkers();
 
   // If any of the functions has incomplete incoming arguments, don't mark any
@@ -260,14 +262,13 @@ void TDDataStructures::inlineGraphIntoCallees(DSGraph &Graph) {
     ReachabilityCloner RC(CalleeGraph, Graph, DSGraph::StripModRefBits);
 
     // Clone over any global nodes that appear in both graphs.
-    for (DSGraph::ScalarMapTy::const_iterator
-           SI = CalleeGraph.getScalarMap().begin(),
-           SE = CalleeGraph.getScalarMap().end(); SI != SE; ++SI)
-      if (GlobalValue *GV = dyn_cast<GlobalValue>(SI->first)) {
-        DSGraph::ScalarMapTy::const_iterator GI = Graph.getScalarMap().find(GV);
-        if (GI != Graph.getScalarMap().end())
-          RC.merge(SI->second, GI->second);
-      }
+    for (DSScalarMap::global_iterator
+           SI = CalleeGraph.getScalarMap().global_begin(),
+           SE = CalleeGraph.getScalarMap().global_end(); SI != SE; ++SI) {
+      DSScalarMap::const_iterator GI = Graph.getScalarMap().find(*SI);
+      if (GI != Graph.getScalarMap().end())
+        RC.merge(CalleeGraph.getNodeForValue(*SI), GI->second);
+    }
 
     // Loop over all of the distinct call sites in the caller of the callee.
     for (; CSI != CallSites.end() && CSI->first == &CalleeGraph; ++CSI) {