[llvm-commits] [poolalloc] r56934 - in /poolalloc/trunk: include/dsa/DSGraph.h include/dsa/DataStructure.h lib/DSA/BottomUpClosure.cpp lib/DSA/DataStructure.cpp lib/DSA/TopDownClosure.cpp

Andrew Lenharth alenhar2 at cs.uiuc.edu
Wed Oct 1 15:53:18 PDT 2008


Author: alenhar2
Date: Wed Oct  1 17:53:17 2008
New Revision: 56934

URL: http://llvm.org/viewvc/llvm-project?rev=56934&view=rev
Log:
Resolve some calls sometimes and clean up globals graph afterwards

Modified:
    poolalloc/trunk/include/dsa/DSGraph.h
    poolalloc/trunk/include/dsa/DataStructure.h
    poolalloc/trunk/lib/DSA/BottomUpClosure.cpp
    poolalloc/trunk/lib/DSA/DataStructure.cpp
    poolalloc/trunk/lib/DSA/TopDownClosure.cpp

Modified: poolalloc/trunk/include/dsa/DSGraph.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DSGraph.h?rev=56934&r1=56933&r2=56934&view=diff

==============================================================================
--- poolalloc/trunk/include/dsa/DSGraph.h (original)
+++ poolalloc/trunk/include/dsa/DSGraph.h Wed Oct  1 17:53:17 2008
@@ -152,6 +152,17 @@
     ValueMap.erase(I);
   }
 
+  void clear_scalars() {
+    for(iterator ii = begin(); ii != end(); )
+      if (isa<GlobalValue>(ii->first))
+        ++ii;
+      else {
+        iterator next = ii;
+        ++ii;
+        erase(next);
+      }
+  }
+
   void clear() {
     ValueMap.clear();
     GlobalSet.clear();
@@ -542,7 +553,7 @@
   /// merged with other nodes in the graph.  This is used as the first step of
   /// removeDeadNodes.
   ///
-  void removeTriviallyDeadNodes();
+  void removeTriviallyDeadNodes(bool updateForwarders = false);
 };
 
 

Modified: poolalloc/trunk/include/dsa/DataStructure.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DataStructure.h?rev=56934&r1=56933&r2=56934&view=diff

==============================================================================
--- poolalloc/trunk/include/dsa/DataStructure.h (original)
+++ poolalloc/trunk/include/dsa/DataStructure.h Wed Oct  1 17:53:17 2008
@@ -179,7 +179,7 @@
 
   // This map is only maintained during construction of BU Graphs
   std::map<std::vector<Function*>,
-           std::pair<DSGraph*, std::vector<DSNodeHandle> > > *IndCallGraphMap;
+           std::pair<DSGraph*, std::vector<DSNodeHandle> > > IndCallGraphMap;
 
   std::set<Function*> InlinedSomewhere;
 
@@ -233,6 +233,7 @@
 
 
   void CloneAuxIntoGlobal(DSGraph& G);
+  void finalizeGlobals(void);
 };
 
 

Modified: poolalloc/trunk/lib/DSA/BottomUpClosure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/BottomUpClosure.cpp?rev=56934&r1=56933&r2=56934&view=diff

==============================================================================
--- poolalloc/trunk/lib/DSA/BottomUpClosure.cpp (original)
+++ poolalloc/trunk/lib/DSA/BottomUpClosure.cpp Wed Oct  1 17:53:17 2008
@@ -49,9 +49,6 @@
   GlobalsGraph = new DSGraph(LocalDSA.getGlobalsGraph(), GlobalECs);
   GlobalsGraph->setPrintAuxCalls();
 
-  IndCallGraphMap = new std::map<std::vector<Function*>,
-                           std::pair<DSGraph*, std::vector<DSNodeHandle> > >();
-
   std::vector<Function*> Stack;
   hash_map<Function*, unsigned> ValMap;
   unsigned NextID = 1;
@@ -81,11 +78,11 @@
   // If we computed any temporary indcallgraphs, free them now.
   for (std::map<std::vector<Function*>,
          std::pair<DSGraph*, std::vector<DSNodeHandle> > >::iterator I =
-         IndCallGraphMap->begin(), E = IndCallGraphMap->end(); I != E; ++I) {
+         IndCallGraphMap.begin(), E = IndCallGraphMap.end(); I != E; ++I) {
     I->second.second.clear();  // Drop arg refs into the graph.
     delete I->second.first;
   }
-  delete IndCallGraphMap;
+  IndCallGraphMap.clear();
 
   // 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
@@ -93,7 +90,10 @@
   // nodes at the end of the BU phase should make things that they point to
   // incomplete in the globals graph.
   //
-  GlobalsGraph->removeTriviallyDeadNodes();
+
+  finalizeGlobals();
+
+  GlobalsGraph->removeTriviallyDeadNodes(true);
   GlobalsGraph->maskIncompleteMarkers();
 
   // Mark external globals incomplete.
@@ -127,6 +127,43 @@
   return false;
 }
 
+static inline bool nodeContainsExternalFunction(const DSNode *N) {
+  std::vector<Function*> Funcs;
+  N->addFullFunctionList(Funcs);
+  for (unsigned i = 0, e = Funcs.size(); i != e; ++i)
+    if (Funcs[i]->isDeclaration()) return true;
+  return false;
+}
+
+void BUDataStructures::finalizeGlobals(void) {
+  // Any unresolved call can be removed (resolved) if it does not contain
+  // external functions and it is not reachable from any call that does
+  // contain external functions
+  std::set<DSCallSite> GoodCalls, BadCalls;
+  for (DSGraph::afc_iterator ii = GlobalsGraph->afc_begin(), 
+         ee = GlobalsGraph->afc_end(); ii != ee; ++ii)
+    if (ii->isDirectCall() ||
+        nodeContainsExternalFunction(ii->getCalleeNode()))
+      BadCalls.insert(*ii);
+    else
+      GoodCalls.insert(*ii);
+  hash_set<const DSNode*> reachable;
+  for (std::set<DSCallSite>::iterator ii = BadCalls.begin(),
+         ee = BadCalls.end(); ii != ee; ++ii) {
+    ii->getRetVal().getNode()->markReachableNodes(reachable);
+    for (unsigned x = 0; x < ii->getNumPtrArgs(); ++x)
+      ii->getPtrArg(x).getNode()->markReachableNodes(reachable);
+  }
+  for (std::set<DSCallSite>::iterator ii = GoodCalls.begin(),
+         ee = GoodCalls.end(); ii != ee; ++ii)
+    if (reachable.find(ii->getCalleeNode()) == reachable.end())
+      GlobalsGraph->getAuxFunctionCalls()
+        .erase(std::find(GlobalsGraph->getAuxFunctionCalls().begin(),
+                         GlobalsGraph->getAuxFunctionCalls().end(),
+                         *ii));
+  GlobalsGraph->getScalarMap().clear_scalars();
+}
+
 static void GetAllCallees(const DSCallSite &CS,
                           std::vector<Function*> &Callees) {
   if (CS.isDirectCall()) {
@@ -447,7 +484,7 @@
       // See if we already computed a graph for this set of callees.
       std::sort(CalledFuncs.begin(), CalledFuncs.end());
       std::pair<DSGraph*, std::vector<DSNodeHandle> > &IndCallGraph =
-        (*IndCallGraphMap)[CalledFuncs];
+        IndCallGraphMap[CalledFuncs];
       
       if (IndCallGraph.first == 0) {
         std::vector<Function*>::iterator I = CalledFuncs.begin(),

Modified: poolalloc/trunk/lib/DSA/DataStructure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/DataStructure.cpp?rev=56934&r1=56933&r2=56934&view=diff

==============================================================================
--- poolalloc/trunk/lib/DSA/DataStructure.cpp (original)
+++ poolalloc/trunk/lib/DSA/DataStructure.cpp Wed Oct  1 17:53:17 2008
@@ -2000,6 +2000,7 @@
            E = AuxFunctionCalls.end(); I != E; ++I)
       markIncomplete(*I);
 
+#if 0
   // Mark stuff passed into external functions as being incomplete.
   // External functions may not appear in Aux during td, so process
   // them specially
@@ -2007,6 +2008,7 @@
          E = FunctionCalls.end(); I != E; ++I)
     if(I->isDirectCall() && I->getCalleeFunc()->isDeclaration())
       markIncomplete(*I);
+#endif
 
   // Mark all global nodes as incomplete.
   for (DSScalarMap::global_iterator I = ScalarMap.global_begin(),
@@ -2191,38 +2193,39 @@
 // other nodes in the graph.  These nodes will all be trivially unreachable, so
 // we don't have to perform any non-trivial analysis here.
 //
-void DSGraph::removeTriviallyDeadNodes() {
+void DSGraph::removeTriviallyDeadNodes(bool updateForwarders) {
   TIME_REGION(X, "removeTriviallyDeadNodes");
 
-#if 0
-  /// NOTE: This code is disabled.  This slows down DSA on 177.mesa
-  /// substantially!
-
-  // Loop over all of the nodes in the graph, calling getNode on each field.
-  // This will cause all nodes to update their forwarding edges, causing
-  // forwarded nodes to be delete-able.
-  { TIME_REGION(X, "removeTriviallyDeadNodes:node_iterate");
-  for (node_iterator NI = node_begin(), E = node_end(); NI != E; ++NI) {
-    DSNode &N = *NI;
-    for (unsigned l = 0, e = N.getNumLinks(); l != e; ++l)
-      N.getLink(l*N.getPointerSize()).getNode();
-  }
+  if (updateForwarders) {
+    /// NOTE: This code is disabled.  This slows down DSA on 177.mesa
+    /// substantially!
+    
+    // Loop over all of the nodes in the graph, calling getNode on each field.
+    // This will cause all nodes to update their forwarding edges, causing
+    // forwarded nodes to be delete-able.
+    { TIME_REGION(X, "removeTriviallyDeadNodes:node_iterate");
+      for (node_iterator NI = node_begin(), E = node_end(); NI != E; ++NI) {
+        DSNode &N = *NI;
+        for (unsigned l = 0, e = N.getNumLinks(); l != e; ++l)
+          N.getLink(l*N.getPointerSize()).getNode();
+      }
+    }
+    
+    // NOTE: This code is disabled.  Though it should, in theory, allow us to
+    // remove more nodes down below, the scan of the scalar map is incredibly
+    // expensive for certain programs (with large SCCs).  In the future, if we can
+    // make the scalar map scan more efficient, then we can reenable this.
+    { TIME_REGION(X, "removeTriviallyDeadNodes:scalarmap");
+      
+      // Likewise, forward any edges from the scalar nodes.  While we are at it,
+      // clean house a bit.
+      for (DSScalarMap::iterator I = ScalarMap.begin(),E = ScalarMap.end();I != E;){
+        I->second.getNode();
+        ++I;
+      }
+    }
   }
 
-  // NOTE: This code is disabled.  Though it should, in theory, allow us to
-  // remove more nodes down below, the scan of the scalar map is incredibly
-  // expensive for certain programs (with large SCCs).  In the future, if we can
-  // make the scalar map scan more efficient, then we can reenable this.
-  { TIME_REGION(X, "removeTriviallyDeadNodes:scalarmap");
-
-  // Likewise, forward any edges from the scalar nodes.  While we are at it,
-  // clean house a bit.
-  for (DSScalarMap::iterator I = ScalarMap.begin(),E = ScalarMap.end();I != E;){
-    I->second.getNode();
-    ++I;
-  }
-  }
-#endif
   bool isGlobalsGraph = !GlobalsGraph;
 
   for (NodeListTy::iterator NI = Nodes.begin(), E = Nodes.end(); NI != E; ) {
@@ -2262,7 +2265,8 @@
       }
     }
 
-    if (Node.getNodeFlags() == 0 && Node.hasNoReferrers()) {
+    if ((Node.getNodeFlags() == 0 && Node.hasNoReferrers())
+        || (isGlobalsGraph && Node.hasNoReferrers() && !Node.isGlobalNode())){
       // This node is dead!
       NI = Nodes.erase(NI);    // Erase & remove from node list.
       ++NumTrivialDNE;

Modified: poolalloc/trunk/lib/DSA/TopDownClosure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/TopDownClosure.cpp?rev=56934&r1=56933&r2=56934&view=diff

==============================================================================
--- poolalloc/trunk/lib/DSA/TopDownClosure.cpp (original)
+++ poolalloc/trunk/lib/DSA/TopDownClosure.cpp Wed Oct  1 17:53:17 2008
@@ -93,6 +93,10 @@
                                                  Visited);
   Visited.clear();
 
+  // Clear Aux of Globals Graph to be refilled in later by post-TD unresolved 
+  // functions
+  GlobalsGraph->getAuxFunctionCalls().clear();
+
   // Functions without internal linkage also have unknown incoming arguments!
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
     if (!I->isDeclaration() && !I->hasInternalLinkage())
@@ -103,18 +107,6 @@
   hash_set<DSGraph*> VisitedGraph;
   std::vector<DSGraph*> PostOrder;
 
-#if 0
-{TIME_REGION(XXX, "td:Copy graphs");
-
-  // Visit each of the graphs in reverse post-order now!
-  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
-    if (!I->isDeclaration(*I)
-        getOrCreateGraph(*I);
-  return false;
-}
-#endif
-
-
 {TIME_REGION(XXX, "td:Compute postorder");
 
   // Calculate top-down from main...





More information about the llvm-commits mailing list