After finishing BU analysis, move all global variables from the globals
authorChris Lattner <sabre@nondot.org>
Sun, 13 Mar 2005 20:15:06 +0000 (20:15 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 13 Mar 2005 20:15:06 +0000 (20:15 +0000)
graph into main and mark them complete.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@20583 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/DataStructure/BottomUpClosure.cpp
lib/Analysis/DataStructure/CompleteBottomUp.cpp
lib/Analysis/DataStructure/EquivClassGraphs.cpp

index 6d3c4b0a1a4d33de4a4d47bc66069404f711db4d..ba559bb0e6723009a6804459190fc1ec980cf52e 100644 (file)
@@ -81,6 +81,27 @@ bool BUDataStructures::runOnModule(Module &M) {
   // 
   GlobalsGraph->removeTriviallyDeadNodes();
   GlobalsGraph->maskIncompleteMarkers();
+
+  // Merge the globals variables (not the calls) from the globals graph back
+  // into the main function's graph so that the main function contains all of
+  // the information about global pools and GV usage in the program.
+  if (MainFunc) {
+    DSGraph &MainGraph = getOrCreateGraph(MainFunc);
+    const DSGraph &GG = *MainGraph.getGlobalsGraph();
+    ReachabilityCloner RC(MainGraph, 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));
+
+    MainGraph.markIncompleteNodes(DSGraph::MarkFormalArgs | 
+                                  DSGraph::IgnoreGlobals);
+  }
+
   return false;
 }
 
index 1c9e3299d02945205e8a09d200ed38e557658893..77a5f32fa59bc249bc4abf9d2d501cdf1247e558 100644 (file)
@@ -76,9 +76,10 @@ bool CompleteBUDataStructures::runOnModule(Module &M) {
   hash_map<DSGraph*, unsigned> ValMap;
   unsigned NextID = 1;
 
-  if (Function *Main = M.getMainFunction()) {
-    if (!Main->isExternal())
-      calculateSCCGraphs(getOrCreateGraph(*Main), Stack, NextID, ValMap);
+  Function *MainFunc = M.getMainFunction();
+  if (MainFunc) {
+    if (!MainFunc->isExternal())
+      calculateSCCGraphs(getOrCreateGraph(*MainFunc), Stack, NextID, ValMap);
   } else {
     std::cerr << "CBU-DSA: No 'main' function found!\n";
   }
@@ -88,6 +89,28 @@ bool CompleteBUDataStructures::runOnModule(Module &M) {
       calculateSCCGraphs(getOrCreateGraph(*I), Stack, NextID, ValMap);
 
   GlobalsGraph->removeTriviallyDeadNodes();
+
+
+  // Merge the globals variables (not the calls) from the globals graph back
+  // into the main function's graph so that the main function contains all of
+  // the information about global pools and GV usage in the program.
+  if (MainFunc) {
+    DSGraph &MainGraph = getOrCreateGraph(*MainFunc);
+    const DSGraph &GG = *MainGraph.getGlobalsGraph();
+    ReachabilityCloner RC(MainGraph, 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));
+
+    MainGraph.markIncompleteNodes(DSGraph::MarkFormalArgs | 
+                                  DSGraph::IgnoreGlobals);
+  }
+
   return false;
 }
 
index a16d40fbe0f3a6e02767ea74b55692f7030e4bee..8dc2064810436489dba38fc7ef34728aa00780c5 100644 (file)
@@ -89,9 +89,9 @@ bool EquivClassGraphs::runOnModule(Module &M) {
   std::map<DSGraph*, unsigned> ValMap;
   unsigned NextID = 1;
 
-  if (Function *Main = M.getMainFunction()) {
-    if (!Main->isExternal())
-      processSCC(getOrCreateGraph(*Main), Stack, NextID, ValMap);
+  Function *MainFunc = M.getMainFunction();
+  if (MainFunc && !MainFunc->isExternal()) {
+    processSCC(getOrCreateGraph(*MainFunc), Stack, NextID, ValMap);
   } else {
     std::cerr << "Fold Graphs: No 'main' function found!\n";
   }
@@ -103,6 +103,27 @@ bool EquivClassGraphs::runOnModule(Module &M) {
   DEBUG(CheckAllGraphs(&M, *this));
 
   getGlobalsGraph().removeTriviallyDeadNodes();
+
+  // Merge the globals variables (not the calls) from the globals graph back
+  // into the main function's graph so that the main function contains all of
+  // the information about global pools and GV usage in the program.
+  if (MainFunc) {
+    DSGraph &MainGraph = getOrCreateGraph(*MainFunc);
+    const DSGraph &GG = *MainGraph.getGlobalsGraph();
+    ReachabilityCloner RC(MainGraph, 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));
+
+    MainGraph.markIncompleteNodes(DSGraph::MarkFormalArgs | 
+                                  DSGraph::IgnoreGlobals);
+  }
+
   return false;
 }