[llvm-commits] [poolalloc] r115069 - in /poolalloc/trunk: include/poolalloc/Heuristic.h include/poolalloc/PoolAllocate.h lib/PoolAllocate/Heuristic.cpp lib/PoolAllocate/PoolAllocate.cpp

John Criswell criswell at uiuc.edu
Wed Sep 29 12:11:28 PDT 2010


Author: criswell
Date: Wed Sep 29 14:11:28 2010
New Revision: 115069

URL: http://llvm.org/viewvc/llvm-project?rev=115069&view=rev
Log:
Moved the code that determines which DSNodes should be pool allocated to the
Heuristic classes.
Removed the BoundsCheckEnabled option as it is no longer needed.

Modified:
    poolalloc/trunk/include/poolalloc/Heuristic.h
    poolalloc/trunk/include/poolalloc/PoolAllocate.h
    poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp
    poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp

Modified: poolalloc/trunk/include/poolalloc/Heuristic.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc/Heuristic.h?rev=115069&r1=115068&r2=115069&view=diff
==============================================================================
--- poolalloc/trunk/include/poolalloc/Heuristic.h (original)
+++ poolalloc/trunk/include/poolalloc/Heuristic.h Wed Sep 29 14:11:28 2010
@@ -22,6 +22,7 @@
 
 #include <vector>
 #include <map>
+#include <set>
 
 namespace llvm {
   class Value;
@@ -36,6 +37,7 @@
 namespace PA {
   // Type for a container of DSNodes
   typedef std::vector<const DSNode*> DSNodeList_t;
+  typedef std::set<const DSNode*>    DSNodeSet_t;
 
   //
   // Class: Heuristic
@@ -50,6 +52,12 @@
     PoolAllocate *PA;
     DataStructures *Graphs;
 
+    // DSNodes reachable from a global variable and that require a global pool
+    std::set<const DSNode *> GlobalPoolNodes;
+
+    /// Find globally reachable DSNodes that need a pool
+    virtual void findGlobalPoolNodes (DSNodeSet_t & Nodes);
+
   public:
     // Virtual Destructor
     virtual ~Heuristic() {}
@@ -95,7 +103,10 @@
     };
 
     /// Find globally reachable DSNodes that need a pool
-    virtual void findGlobalPoolNodes (std::vector<const DSNode *> & Nodes);
+    virtual void getGlobalPoolNodes (std::vector<const DSNode *> & Nodes);
+
+    /// Find DSNodes local to a function that need a pool
+    virtual void getLocalPoolNodes (const Function & F, DSNodeList_t & Nodes);
 
     /// AssignToPools - Partition NodesToPA into a set of disjoint pools,
     /// returning the result in ResultPools.  If this is a function being pool

Modified: poolalloc/trunk/include/poolalloc/PoolAllocate.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc/PoolAllocate.h?rev=115069&r1=115068&r2=115069&view=diff
==============================================================================
--- poolalloc/trunk/include/poolalloc/PoolAllocate.h (original)
+++ poolalloc/trunk/include/poolalloc/PoolAllocate.h Wed Sep 29 14:11:28 2010
@@ -150,7 +150,6 @@
 
   // FIXME: We want to remove SAFECode specified flags.
   bool SAFECodeEnabled;
-  bool BoundsChecksEnabled;
 
   enum LIE_TYPE {LIE_NONE, LIE_PRESERVE_DSA, LIE_PRESERVE_ALL, LIE_PRESERVE_DEFAULT};
   // FIXME: Try to minimize lying
@@ -237,7 +236,7 @@
     : PoolAllocateGroup ((intptr_t)IDp),
       PassAllArguments(passAllArguments)
       {
-		  SAFECodeEnabled = BoundsChecksEnabled = SAFECode |  PA::PA_SAFECODE;
+		  SAFECodeEnabled = SAFECode |  PA::PA_SAFECODE;
 		  lie_preserve_passes = SAFECodeEnabled ? LIE_PRESERVE_ALL : LIE_PRESERVE_DSA;
 		  dsa_pass_to_use = SAFECodeEnabled ? PASS_EQTD : PASS_BUEQ;
       }
@@ -251,7 +250,7 @@
       : PoolAllocateGroup ((intptr_t)IDp),
         PassAllArguments(passAllArguments)
         {
-  		  SAFECodeEnabled = BoundsChecksEnabled = SAFECode |  PA::PA_SAFECODE;
+  		  SAFECodeEnabled = SAFECode |  PA::PA_SAFECODE;
 
   		  if(lie_preserve_passes_ == LIE_PRESERVE_DEFAULT)
   			  lie_preserve_passes = SAFECodeEnabled ? LIE_PRESERVE_ALL : LIE_PRESERVE_DSA;

Modified: poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp?rev=115069&r1=115068&r2=115069&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp Wed Sep 29 14:11:28 2010
@@ -292,7 +292,7 @@
 //          have global pools will be *added* to this container.
 //
 void
-Heuristic::findGlobalPoolNodes (std::vector<const DSNode *> & Nodes) {
+Heuristic::findGlobalPoolNodes (DSNodeSet_t & Nodes) {
   // Get the globals graph for the program.
   DSGraph* GG = Graphs->getGlobalsGraph();
 
@@ -357,7 +357,95 @@
   //
   for (DenseSet<const DSNode*>::iterator I = GlobalHeapNodes.begin(),
          E = GlobalHeapNodes.end(); I != E; ++I) {
-    Nodes.push_back (*I);
+    Nodes.insert (*I);
+  }
+
+  return;
+}
+
+//
+// Method: getGlobalPoolNodes()
+//
+// Description:
+//  This method returns DSNodes that are reachable from globals and that need a
+//  pool.  The Automatic Pool Allocation transform will use the returned
+//  information to build global pools for the DSNodes in question.
+//
+//  Note that this method does not assign DSNodes to pools; it merely decides
+//  which DSNodes are reachable from globals and will need a pool of global
+//  scope.
+//
+// Outputs:
+//  Nodes - The DSNodes that are both reachable from globals and which should
+//          have global pools will be *added* to this container.
+//
+// Preconditions:
+//  This method assumes that the findGlobalPoolNodes() has been called to find
+//  all of the global DSNodes needing a pool.
+//
+void
+Heuristic::getGlobalPoolNodes (std::vector<const DSNode *> & Nodes) {
+  //
+  // Copy the DSNodes which are globally reachable and need a global pool into
+  // the set of DSNodes given to us by the caller.
+  //
+  Nodes.insert (Nodes.end(), GlobalPoolNodes.begin(), GlobalPoolNodes.end());
+  return;
+}
+
+//
+// Method: getLocalPoolNodes()
+//
+// Description:
+//  For a given function, determine which DSNodes for that function should have
+//  local pools created for them.
+//
+void
+Heuristic::getLocalPoolNodes (const Function & F, DSNodeList_t & Nodes) {
+  //
+  // Get the DSGraph of the specified function.  If the DSGraph has no nodes,
+  // then there is nothing we need to do.
+  //
+  DSGraph* G = Graphs->getDSGraph(F);
+  if (G->node_begin() == G->node_end()) return;
+
+  //
+  // Calculate which DSNodes are reachable from globals.  If a node is reachable
+  // from a global, we will create a global pool for it, so no argument passage
+  // is required.
+  Graphs->getGlobalsGraph();
+
+  // Map all node reachable from this global to the corresponding nodes in
+  // the globals graph.
+  DSGraph::NodeMapTy GlobalsGraphNodeMapping;
+  G->computeGToGGMapping(GlobalsGraphNodeMapping);
+
+  //
+  // Loop over all of the nodes which are non-escaping, adding pool-allocatable
+  // ones to the NodesToPA vector.  In other words, scan over the DSGraph and
+  // find nodes for which a new pool must be created within this function.
+  //
+  for (DSGraph::node_iterator I = G->node_begin(), E = G->node_end();
+       I != E;
+       ++I){
+    // Get the DSNode and, if applicable, its mirror in the globals graph
+    DSNode * N   = I;
+    DSNode * GGN = GlobalsGraphNodeMapping[N].getNode();
+
+    //
+    // Only the following nodes are pool allocated:
+    //  1) Local Heap nodes
+    //  2) Nodes which are mirrored in the globals graph and, in the globals
+    //     graph, are heap nodes.
+    //
+    if ((N->isHeapNode()) || (GGN && GGN->isHeapNode())) {
+      if (!(GlobalPoolNodes.count (N) || GlobalPoolNodes.count (GGN))) {
+        // Otherwise, if it was not passed in from outside the function, it must
+        // be a local pool!
+        assert(!N->isGlobalNode() && "Should be in global mapping!");
+        Nodes.push_back (N);
+      }
+    }
   }
 
   return;
@@ -381,6 +469,12 @@
   Graphs = &getAnalysis<EQTDDataStructures>();   
   assert (Graphs && "No DSGraphs!\n");
 
+  //
+  // Find DSNodes which are reachable from globals and should be pool
+  // allocated.
+  //
+  findGlobalPoolNodes (GlobalPoolNodes);
+
   // We never modify anything in this pass
   return false;
 }
@@ -412,6 +506,12 @@
   //
   Graphs = &getAnalysis<EQTDDataStructures>();   
 
+  //
+  // Find DSNodes which are reachable from globals and should be pool
+  // allocated.
+  //
+  findGlobalPoolNodes (GlobalPoolNodes);
+
   // We never modify anything in this pass
   return false;
 }
@@ -480,6 +580,12 @@
   //
   Graphs = &getAnalysis<EQTDDataStructures>();   
 
+  //
+  // Find DSNodes which are reachable from globals and should be pool
+  // allocated.
+  //
+  findGlobalPoolNodes (GlobalPoolNodes);
+
   // We never modify anything in this pass
   return false;
 }
@@ -517,6 +623,12 @@
   //
   Graphs = &getAnalysis<EQTDDataStructures>();   
 
+  //
+  // Find DSNodes which are reachable from globals and should be pool
+  // allocated.
+  //
+  findGlobalPoolNodes (GlobalPoolNodes);
+
   // We never modify anything in this pass
   return false;
 }
@@ -708,6 +820,12 @@
   //
   Graphs = &getAnalysis<EQTDDataStructures>();   
 
+  //
+  // Find DSNodes which are reachable from globals and should be pool
+  // allocated.
+  //
+  findGlobalPoolNodes (GlobalPoolNodes);
+
   // We never modify anything in this pass
   return false;
 }
@@ -745,6 +863,12 @@
   //
   Graphs = &getAnalysis<EQTDDataStructures>();   
 
+  //
+  // Find DSNodes which are reachable from globals and should be pool
+  // allocated.
+  //
+  findGlobalPoolNodes (GlobalPoolNodes);
+
   // We never modify anything in this pass
   return false;
 }

Modified: poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp?rev=115069&r1=115068&r2=115069&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp Wed Sep 29 14:11:28 2010
@@ -868,7 +868,7 @@
   // pools.
   //
   std::vector<const DSNode*> NodesToPA;
-  CurHeuristic->findGlobalPoolNodes (NodesToPA);
+  CurHeuristic->getGlobalPoolNodes (NodesToPA);
 
   // Otherwise get the main function to insert the poolinit calls.
   Function *MainFunc = M.getFunction("main");
@@ -1036,84 +1036,21 @@
   }
 }
 
-// processFunction - Pool allocate any data structures which are contained in
-// the specified function.
 //
-void PoolAllocate::ProcessFunctionBody(Function &F, Function &NewF) {
+// Method: processFunction()
+//
+// Description:
+//  Pool allocate any data structures which are contained in the specified
+//  function.
+//
+void
+PoolAllocate::ProcessFunctionBody(Function &F, Function &NewF) {
+  //
+  // Ask the heuristic for the list of DSNodes which should get local pools.
+  //
   DSGraph* G = Graphs->getDSGraph(F);
-
-  if (G->node_begin() == G->node_end()) return;  // Quick exit if nothing to do.
-  
-  FuncInfo &FI = *getFuncInfo(F);
-  DenseSet<const DSNode*> &MarkedNodes = FI.MarkedNodes;
-
-  // Calculate which DSNodes are reachable from globals.  If a node is reachable
-  // from a global, we will create a global pool for it, so no argument passage
-  // is required.
-  Graphs->getGlobalsGraph();
-
-  // Map all node reachable from this global to the corresponding nodes in
-  // the globals graph.
-  DSGraph::NodeMapTy GlobalsGraphNodeMapping;
-  G->computeGToGGMapping(GlobalsGraphNodeMapping);
-
-  //
-  // Loop over all of the nodes which are non-escaping, adding pool-allocatable
-  // ones to the NodesToPA vector.  In other words, scan over the DSGraph and
-  // find nodes for which a new pool must be created within this function.
-  //
-  for (DSGraph::node_iterator I = G->node_begin(), E = G->node_end();
-       I != E;
-       ++I){
-    //
-    // FIXME: Don't do SAFECode specific behavior here; follow the heuristic.
-    // FIXME: Are there nodes which don't have the heap flag localally but have
-    //        it set in the globals graph?
-    //
-    // Only the following nodes are pool allocated:
-    //  1) Heap nodes
-    //  2) Array nodes when bounds checking is enabled.
-    //  3) Nodes which are mirrored in the globals graph and are heap nodes.
-    //
-    DSNode *N = I;
-#if 0
-    if ((N->isHeapNode()) || (BoundsChecksEnabled && (N->isArrayNode())) ||
-    	(GlobalsGraphNodeMapping.count(N) &&
-       GlobalsGraphNodeMapping[N].getNode()->isHeapNode())) {
-      if (GlobalsGraphNodeMapping.count(N)) {
-        // If it is a global pool, set up the pool descriptor appropriately.
-        DSNode *GGN = GlobalsGraphNodeMapping[N].getNode();
-        assert(GGN && GlobalNodes[GGN] && "No global node found??");
-        FI.PoolDescriptors[N] = GlobalNodes[GGN];
-      } else if (!MarkedNodes.count(N)) {
-        // Otherwise, if it was not passed in from outside the function, it must
-        // be a local pool!
-        assert(!N->isGlobalNode() && "Should be in global mapping!");
-        FI.NodesToPA.push_back(N);
-      }
-    }
-#else
-    //
-    // FIXME: This is not correct for SAFECode; all DSNodes will need to be
-    //        poolallocated.
-    //
-    if ((N->isHeapNode()) ||
-    	(GlobalsGraphNodeMapping.count(N) &&
-       GlobalsGraphNodeMapping[N].getNode()->isHeapNode())) {
-      DSNode *GGN = GlobalsGraphNodeMapping[N].getNode();
-      if (GlobalNodes[N]) {
-        FI.PoolDescriptors[N] = GlobalNodes[N];
-      } else if (GlobalNodes[GGN]) {
-        FI.PoolDescriptors[N] = GlobalNodes[GGN];
-      } else if (!MarkedNodes.count(N)) {
-        // Otherwise, if it was not passed in from outside the function, it must
-        // be a local pool!
-        assert(!N->isGlobalNode() && "Should be in global mapping!");
-        FI.NodesToPA.push_back(N);
-      }
-    }
-#endif
-  }
+  FuncInfo & FI = *getFuncInfo(F);
+  CurHeuristic->getLocalPoolNodes (F, FI.NodesToPA);
 
   //
   // Add code to create the pools that are local to this function.
@@ -1125,7 +1062,7 @@
   } else {
     DEBUG(errs() << "[" << F.getNameStr() << "] transforming body.\n");
   }
-  
+
   // Transform the body of the function now... collecting information about uses
   // of the pools.
   std::multimap<AllocaInst*, Instruction*> PoolUses;





More information about the llvm-commits mailing list