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

Chris Lattner lattner at cs.uiuc.edu
Wed Mar 2 08:21:54 PST 2005



Changes in directory llvm-poolalloc/lib/PoolAllocate:

PointerCompress.cpp updated: 1.36 -> 1.37
---
Log message:

implement the pool base optimization, where we only load a pool base on entry
to a function or right after poolinit (instead of at every load/store to the
pool).


---
Diffs of the changes:  (+46 -11)

 PointerCompress.cpp |   57 +++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 46 insertions(+), 11 deletions(-)


Index: llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp
diff -u llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.36 llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.37
--- llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.36	Wed Mar  2 01:04:52 2005
+++ llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp	Wed Mar  2 10:21:41 2005
@@ -40,6 +40,9 @@
   SmallIntCompress("compress-to-16-bits",
                    cl::desc("Pointer compress data structures to 16 bit "
                             "integers instead of 32-bit integers"));
+  cl::opt<bool>
+  DisablePoolBaseASR("disable-ptrcomp-poolbase-aggregation",
+                     cl::desc("Don't optimize pool base loads"));
 
   Statistic<> NumCompressed("pointercompress",
                             "Number of pools pointer compressed");
@@ -152,9 +155,10 @@
     Value *PoolDesc;
     const Type *NewTy;
     unsigned NewSize;
+    mutable Value *PoolBase;
   public:
     CompressedPoolInfo(const DSNode *N, Value *PD)
-      : Pool(N), PoolDesc(PD), NewTy(0) {}
+      : Pool(N), PoolDesc(PD), NewTy(0), PoolBase(0) {}
     
     /// Initialize - When we know all of the pools in a function that are going
     /// to be compressed, initialize our state based on that data.
@@ -174,13 +178,8 @@
 
     /// EmitPoolBaseLoad - Emit code to load the pool base value for this pool
     /// before the specified instruction.
-    Value *EmitPoolBaseLoad(Instruction &I) const {
-      // Get the pool base pointer.
-      Constant *Zero = Constant::getNullValue(Type::UIntTy);
-      Value *BasePtrPtr = new GetElementPtrInst(getPoolDesc(), Zero, Zero,
-                                                "poolbaseptrptr", &I);
-      return new LoadInst(BasePtrPtr, "poolbaseptr", &I);
-    }
+    Value *EmitPoolBaseLoad(Instruction &I) const;
+    void setPoolBase(Value *PB) const { PoolBase = PB; }
 
     // dump - Emit a debugging dump of this pool info.
     void dump() const;
@@ -235,6 +234,36 @@
   }
 }
 
+/// EmitPoolBaseLoad - Emit code to load the pool base value for this pool
+/// before the specified instruction.
+Value *CompressedPoolInfo::EmitPoolBaseLoad(Instruction &I) const {
+  if (DisablePoolBaseASR) {
+    assert(PoolBase == 0 && "Mixing and matching optimized vs not!");
+    
+    // Get the pool base pointer.
+    Constant *Zero = Constant::getNullValue(Type::UIntTy);
+    Value *BasePtrPtr = new GetElementPtrInst(getPoolDesc(), Zero, Zero,
+                                              "poolbaseptrptr", &I);
+    return new LoadInst(BasePtrPtr, "poolbaseptr", &I);
+  } else {
+    // If this is a pool descriptor passed into the function, and this is the
+    // first use, emit a load of the pool base into the entry of the function.
+    if (PoolBase == 0 && (isa<Argument>(PoolDesc) || 
+                          isa<GlobalVariable>(PoolDesc))) {
+      BasicBlock::iterator IP = I.getParent()->getParent()->begin()->begin();
+      while (isa<AllocaInst>(IP)) ++IP;
+      Constant *Zero = Constant::getNullValue(Type::UIntTy);
+      Value *BasePtrPtr = new GetElementPtrInst(getPoolDesc(), Zero, Zero,
+                                                "poolbaseptrptr", &I);
+      PoolBase = new LoadInst(BasePtrPtr, "poolbaseptr", &I);
+    }
+    
+    assert(PoolBase && "Mixing and matching optimized vs not!");
+    return PoolBase;
+  }
+}
+
+
 /// dump - Emit a debugging dump for this pool info.
 ///
 void CompressedPoolInfo::dump() const {
@@ -778,7 +807,14 @@
   Ops.push_back(ConstantUInt::get(Type::UIntTy, PI->getNewSize()));
   Ops.push_back(CI.getOperand(3));
   // TODO: Compression could reduce the alignment restriction for the pool!
-  new CallInst(PtrComp.PoolInitPC, Ops, "", &CI);
+  Value *PB = new CallInst(PtrComp.PoolInitPC, Ops, "", &CI);
+
+  if (!DisablePoolBaseASR) { // Load the pool base immediately.
+    PB->setName(CI.getOperand(1)->getName()+".poolbase");
+    // Remember the pool base for this pool.
+    PI->setPoolBase(PB);
+  }
+
   CI.eraseFromParent();
 }
 
@@ -1206,8 +1242,7 @@
   const Type *VoidPtrTy = PointerType::get(Type::SByteTy);
   const Type *PoolDescPtrTy = PointerType::get(ArrayType::get(VoidPtrTy, 16));
 
-  PoolInitPC = M.getOrInsertFunction("poolinit_pc", Type::VoidTy,
-                                     PoolDescPtrTy, 
+  PoolInitPC = M.getOrInsertFunction("poolinit_pc", VoidPtrTy, PoolDescPtrTy, 
                                      Type::UIntTy, Type::UIntTy, 0);
   PoolDestroyPC = M.getOrInsertFunction("pooldestroy_pc", Type::VoidTy,
                                         PoolDescPtrTy, 0);






More information about the llvm-commits mailing list