Move the getAnalysisUsage method from the header file
[oota-llvm.git] / lib / Analysis / DataStructure / DataStructure.cpp
index a3fecec69ccb7edd69217ce8ef2f81d067e7f406..241c2a9e35485a339b852cda1845254ddbd36e0a 100644 (file)
@@ -10,6 +10,7 @@
 #include "llvm/DerivedTypes.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Assembly/Writer.h"
+#include "Support/Debug.h"
 #include "Support/STLExtras.h"
 #include "Support/Statistic.h"
 #include "Support/Timer.h"
@@ -1581,3 +1582,31 @@ void DSGraph::AssertGraphOK() const {
   AssertAuxCallNodesInGraph();
 }
 
+/// mergeInGlobalsGraph - This method is useful for clients to incorporate the
+/// globals graph into the DS, BU or TD graph for a function.  This code retains
+/// all globals, i.e., does not delete unreachable globals after they are
+/// inlined.
+///
+void DSGraph::mergeInGlobalsGraph() {
+  NodeMapTy GlobalNodeMap;
+  ScalarMapTy OldValMap;
+  ReturnNodesTy OldRetNodes;
+  cloneInto(*GlobalsGraph, OldValMap, OldRetNodes, GlobalNodeMap,
+            DSGraph::KeepAllocaBit | DSGraph::DontCloneCallNodes |
+            DSGraph::DontCloneAuxCallNodes);
+  
+  // Now merge existing global nodes in the GlobalsGraph with their copies
+  for (ScalarMapTy::iterator I = ScalarMap.begin(), E = ScalarMap.end(); 
+       I != E; ++I)
+    if (isa<GlobalValue>(I->first)) {             // Found a global node
+      DSNodeHandle &GH = I->second;
+      DSNodeHandle &GGNodeH = GlobalsGraph->getScalarMap()[I->first];
+      GH.mergeWith(GlobalNodeMap[GGNodeH.getNode()]);
+    }
+  
+  // Merging leaves behind unused nodes: get rid of them now.
+  GlobalNodeMap.clear();
+  OldValMap.clear();
+  OldRetNodes.clear();
+  removeTriviallyDeadNodes();
+}