* Make the DSGraph cloner automatically merge global nodes
authorChris Lattner <sabre@nondot.org>
Thu, 17 Oct 2002 20:09:52 +0000 (20:09 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 17 Oct 2002 20:09:52 +0000 (20:09 +0000)
 * BUClosure doesn't have to worry about global nodes
 * TDClosure now works with global nodes
 * Reenable DNE on TD pass, now that globals work right

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

lib/Analysis/DataStructure/BottomUpClosure.cpp
lib/Analysis/DataStructure/DataStructure.cpp
lib/Analysis/DataStructure/TopDownClosure.cpp

index 7601524dd2d2621c1020d442ea95039e850c0306..acb90a27bb4cdef5ca42492f15dd993dd2812dd7 100644 (file)
@@ -71,35 +71,6 @@ static void ResolveArguments(std::vector<DSNodeHandle> &Call, Function &F,
   }
 }
 
-// MergeGlobalNodes - Merge all existing global nodes with globals
-// inlined from the callee or with globals from the GlobalsGraph.
-//
-static void MergeGlobalNodes(DSGraph &Graph,
-                             map<Value*, DSNodeHandle> &OldValMap) {
-  map<Value*, DSNodeHandle> &ValMap = Graph.getValueMap();
-  for (map<Value*, DSNodeHandle>::iterator I = ValMap.begin(), E = ValMap.end();
-       I != E; ++I)
-    if (GlobalValue *GV = dyn_cast<GlobalValue>(I->first)) {
-      map<Value*, DSNodeHandle>::iterator NHI = OldValMap.find(GV);
-      if (NHI != OldValMap.end())       // was it inlined from the callee?
-        I->second.mergeWith(NHI->second);
-#if 0
-      else                              // get it from the GlobalsGraph
-        I->second.mergeWith(Graph.cloneGlobalInto(GV));
-#endif
-    }
-
-  // Add unused inlined global nodes into the value map
-  for (map<Value*, DSNodeHandle>::iterator I = OldValMap.begin(),
-         E = OldValMap.end(); I != E; ++I)
-    if (isa<GlobalValue>(I->first)) {
-      DSNodeHandle &NH = ValMap[I->first];  // If global is not in ValMap...
-      if (NH.getNode() == 0)
-        NH = I->second;                     // Add the one just inlined.
-    }
-
-}
-
 DSGraph &BUDataStructures::calculateGraph(Function &F) {
   // Make sure this graph has not already been calculated, or that we don't get
   // into an infinite loop with mutually recursive functions.
@@ -191,11 +162,6 @@ DSGraph &BUDataStructures::calculateGraph(Function &F) {
             if (Call[0].getNode())  // Handle the return value if present
               RetVal.mergeWith(Call[0]);
 
-            // Merge global value nodes in the inlined graph with the global
-            // value nodes in the current graph if there are duplicates.
-            //
-            MergeGlobalNodes(*Graph, OldValMap);
-
             // Erase the entry in the Callees vector
             Callees.erase(Callees.begin()+c--);
 
index 2418b0c65725ee3553535c49fd30d025382ba9ce..2313cd09e8724bc6b657e35fce0e9ee98e2993e0 100644 (file)
@@ -439,14 +439,25 @@ DSNodeHandle DSGraph::cloneInto(const DSGraph &G,
     for (unsigned i = FN, e = Nodes.size(); i != e; ++i)
       Nodes[i]->NodeType &= ~StripBits;
 
-  // Copy the value map...
+  // Copy the value map... and merge all of the global nodes...
   for (std::map<Value*, DSNodeHandle>::const_iterator I = G.ValueMap.begin(),
-         E = G.ValueMap.end(); I != E; ++I)
-    OldValMap[I->first] = DSNodeHandle(OldNodeMap[I->second.getNode()],
-                                       I->second.getOffset());
+         E = G.ValueMap.end(); I != E; ++I) {
+    DSNodeHandle &H = OldValMap[I->first];
+    H = DSNodeHandle(OldNodeMap[I->second.getNode()], I->second.getOffset());
+
+    if (isa<GlobalValue>(I->first)) {  // Is this a global?
+      std::map<Value*, DSNodeHandle>::iterator GVI = ValueMap.find(I->first);
+      if (GVI != ValueMap.end()) {   // Is the global value in this fun already?
+        GVI->second.mergeWith(H);
+      } else {
+        ValueMap[I->first] = H;      // Add global pointer to this graph
+      }
+    }
+  }
   // Copy the function calls list...
   CopyFunctionCallsList(G.FunctionCalls, FunctionCalls, OldNodeMap);
 
+
   // Return the returned node pointer...
   return DSNodeHandle(OldNodeMap[G.RetNode.getNode()], G.RetNode.getOffset());
 }
index 8d4b93a294eac1c2da4a87e943d366e324fe8df3..5312bba198d199b0233c109eae16cfc119b5bc33 100644 (file)
@@ -165,13 +165,6 @@ DSGraph &TDDataStructures::calculateGraph(Function &F) {
       }
 
       ResolveCallSite(*Graph, CallSite);
-
-#if 0
-      // If its not a self-recursive call, merge global nodes in the inlined
-      // graph with the corresponding global nodes in the current graph
-      if (&caller != &callee)
-        MergeGlobalNodes(calleeGraph, OldValMap);
-#endif
     }
   }
   
@@ -180,9 +173,7 @@ DSGraph &TDDataStructures::calculateGraph(Function &F) {
   Graph->maskIncompleteMarkers();
   Graph->markIncompleteNodes(/*markFormals*/ !F.hasInternalLinkage()
                              /*&& FIXME: NEED TO CHECK IF ALL CALLERS FOUND!*/);
-#if 0
   Graph->removeDeadNodes(/*KeepAllGlobals*/ false, /*KeepCalls*/ false);
-#endif
 
   DEBUG(std::cerr << "  [TD] Done inlining callers for: " << F.getName() << " ["
         << Graph->getGraphSize() << "+" << Graph->getFunctionCalls().size()