[llvm-commits] CVS: poolalloc/lib/PoolAllocate/PoolAllocate.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Nov 6 21:23:57 PST 2004



Changes in directory poolalloc/lib/PoolAllocate:

PoolAllocate.cpp updated: 1.83 -> 1.84

---
Log message:

Add support for a new Heuristic, AllInOneGlobalPool.  This heuristic allows
us to quantify how much of a different our pool allocator runtime library
makes over using the system malloc.


---
Diffs of the changes:  (+41 -3)

Index: poolalloc/lib/PoolAllocate/PoolAllocate.cpp
diff -u poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.83 poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.84
--- poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.83	Sat Nov  6 13:41:49 2004
+++ poolalloc/lib/PoolAllocate/PoolAllocate.cpp	Sat Nov  6 23:23:47 2004
@@ -67,6 +67,7 @@
     NoNodes,
     CyclicNodes,
     SmartCoallesceNodes,
+    AllInOneGlobalPool,
     OnlyOverhead,
   };
   cl::opt<PoolAllocHeuristic>
@@ -75,6 +76,7 @@
             cl::values(clEnumVal(AllNodes, "  Pool allocate all nodes"),
                        clEnumVal(CyclicNodes, "  Pool allocate nodes with cycles"),
                        clEnumVal(SmartCoallesceNodes, "  Use the smart node merging heuristic"),
+                       clEnumVal(AllInOneGlobalPool, "  Use pool library as replacement for malloc/free"),
                        clEnumVal(OnlyOverhead, "  Do not pool allocate anything, but induce all overhead from it"),
                        clEnumVal(NoNodes, "  Do not pool allocate anything"),
                        clEnumValEnd),
@@ -86,6 +88,11 @@
   cl::opt<bool>
   DisablePoolFreeOpt("poolalloc-force-all-poolfrees",
                      cl::desc("Do not try to elide poolfree's where possible"));
+
+
+  // TheGlobalPD - This global pool is the one and only one used when running
+  // with Heuristic=AllInOneGlobalPool.
+  GlobalVariable *TheGlobalPD = 0;
 }
 
 void PoolAllocate::getAnalysisUsage(AnalysisUsage &AU) const {
@@ -334,6 +341,7 @@
   // a heuristic to filter out nodes which are not profitable to pool allocate.
   switch (Heuristic) {
   default:
+  case AllInOneGlobalPool:
   case OnlyOverhead:
   case AllNodes: return true;
   case NoNodes: return false;
@@ -359,8 +367,6 @@
   Order.push_back(N);
 }
 
-
-
 // SetupGlobalPools - Create global pools for all DSNodes in the globals graph
 // which contain heap objects.  If a global variable points to a piece of memory
 // allocated from the heap, this pool gets a global lifetime.  This is
@@ -389,7 +395,8 @@
   }
   
   // If we don't need to create any global pools, exit now.
-  if (GlobalHeapNodes.empty()) return false;
+  if (GlobalHeapNodes.empty() ||
+      Heuristic == AllInOneGlobalPool) return false;
 
   // Otherwise get the main function to insert the poolinit calls.
   Function *MainFunc = M.getMainFunction();
@@ -408,6 +415,28 @@
   std::cerr << "Pool allocating " << GlobalHeapNodes.size()
             << " global nodes!\n";
 
+  // If we are putting everything into a single global pool, create it now and
+  // put all globals pool descriptors into it.
+  if (Heuristic == AllInOneGlobalPool) {
+    // Create the global pool descriptor.
+    TheGlobalPD = 
+      new GlobalVariable(PoolDescType, false, GlobalValue::InternalLinkage, 
+                         Constant::getNullValue(PoolDescType), "GlobalPool",&M);
+      
+    // Initialize it on entry to main.
+    Value *ElSize = ConstantUInt::get(Type::UIntTy, 0);
+    new CallInst(PoolInit, make_vector((Value*)TheGlobalPD, ElSize, 0),
+                 "", InsertPt);
+
+    for (hash_set<DSNode*>::iterator I = GlobalHeapNodes.begin(),
+           E = GlobalHeapNodes.end(); I != E; ++I)
+      GlobalNodes[*I] = TheGlobalPD;
+
+    ++NumPools;  // We have one pool.
+    return false;
+  }
+
+
   // Loop over all of the pools, creating a new global pool descriptor,
   // inserting a new entry in GlobalNodes, and inserting a call to poolinit in
   // main.
@@ -415,6 +444,7 @@
          E = GlobalHeapNodes.end(); I != E; ++I) {
     bool ShouldPoolAlloc = true;
     switch (Heuristic) {
+    case AllInOneGlobalPool: assert(0 && "Case handled above!");
     case OnlyOverhead:
     case AllNodes: break;
     case NoNodes: ShouldPoolAlloc = false; break;
@@ -493,6 +523,10 @@
       }
     }
     break;
+  case AllInOneGlobalPool:
+    for (unsigned i = 0, e = NodesToPA.size(); i != e; ++i)
+      PoolDescriptors[NodesToPA[i]] = TheGlobalPD;
+    break;
 
   case SmartCoallesceNodes: {
     std::set<DSNode*> NodesToPASet(NodesToPA.begin(), NodesToPA.end());
@@ -782,6 +816,10 @@
   // Insert all of the poolinit/destroy calls into the function.
   for (unsigned i = 0, e = NodesToPA.size(); i != e; ++i) {
     DSNode *Node = NodesToPA[i];
+
+    if (isa<GlobalVariable>(PoolDescriptors[Node]))
+      continue;
+
     assert(isa<AllocaInst>(PoolDescriptors[Node]) && "Why pool allocate this?");
     AllocaInst *PD = cast<AllocaInst>(PoolDescriptors[Node]);
     





More information about the llvm-commits mailing list