[llvm-commits] [poolalloc] r75470 - in /poolalloc/trunk/lib: DSA/DataStructureOpt.cpp PoolAllocate/AccessTrace.cpp PoolAllocate/Makefile PoolAllocate/PointerCompress.cpp PoolAllocate/PoolAllocate.cpp PoolAllocate/PoolOptimize.cpp PoolAllocate/TransformFunctionBody.cpp

John Criswell criswell at uiuc.edu
Mon Jul 13 09:11:04 PDT 2009


Author: criswell
Date: Mon Jul 13 11:11:04 2009
New Revision: 75470

URL: http://llvm.org/viewvc/llvm-project?rev=75470&view=rev
Log:
Fixed code so that it calls ConstantPointerNull::get() or
ConstantAggregateZero()::get() depending upon which type of zero constant it
needs to produce.
Build pool allocation as a shared library so that it can be used in bugpoint
and opt.

Modified:
    poolalloc/trunk/lib/DSA/DataStructureOpt.cpp
    poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp
    poolalloc/trunk/lib/PoolAllocate/Makefile
    poolalloc/trunk/lib/PoolAllocate/PointerCompress.cpp
    poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
    poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp
    poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp

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

==============================================================================
--- poolalloc/trunk/lib/DSA/DataStructureOpt.cpp (original)
+++ poolalloc/trunk/lib/DSA/DataStructureOpt.cpp Mon Jul 13 11:11:04 2009
@@ -79,8 +79,7 @@
         // remove anything that references the global: later passes will take
         // care of nuking it.
         if (!I->use_empty()) {
-          Type * Ty = (Type *) I->getType();
-          I->replaceAllUsesWith(ConstantAggregateZero::get(Ty));
+          I->replaceAllUsesWith(ConstantPointerNull::get(I->getType()));
           ++NumGlobalsIsolated;
         }
       } else if (GNode && GNode->isCompleteNode()) {
@@ -89,8 +88,7 @@
         // visible, kill any references to it so it can be DCE'd.
         if (!GNode->isModifiedNode() && !GNode->isReadNode() &&I->hasInternalLinkage()){
           if (!I->use_empty()) {
-            Type * Ty = (Type *) I->getType();
-            I->replaceAllUsesWith(ConstantAggregateZero::get(Ty));
+            I->replaceAllUsesWith(ConstantPointerNull::get(I->getType()));
             ++NumGlobalsIsolated;
           }
         }

Modified: poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp?rev=75470&r1=75469&r2=75470&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp Mon Jul 13 11:11:04 2009
@@ -29,7 +29,7 @@
     PoolAllocate *PoolAlloc;
     DataStructures *G;
     Constant *AccessTraceInitFn, *PoolAccessTraceFn;
-    const Type *VoidPtrTy;
+    const PointerType *VoidPtrTy;
   public:
 
     PoolAccessTrace() : ModulePass((intptr_t)&ID) {}
@@ -91,7 +91,7 @@
   if (PD)
     PD = CastInst::CreatePointerCast (PD, VoidPtrTy, PD->getName(), I);
   else
-    PD = ConstantAggregateZero::get(VoidPtrTy);
+    PD = ConstantPointerNull::get(VoidPtrTy);
 
   // Insert the trace call.
   Value *Opts[2] = {Ptr, PD};

Modified: poolalloc/trunk/lib/PoolAllocate/Makefile
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/Makefile?rev=75470&r1=75469&r2=75470&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/Makefile (original)
+++ poolalloc/trunk/lib/PoolAllocate/Makefile Mon Jul 13 11:11:04 2009
@@ -7,6 +7,7 @@
 # Give the name of a library.  This will build a dynamic version.
 #
 BUILD_RELINKED=1
+SHARED_LIBRARY=1
 LIBRARYNAME=poolalloc
 
 #

Modified: poolalloc/trunk/lib/PoolAllocate/PointerCompress.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PointerCompress.cpp?rev=75470&r1=75469&r2=75470&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PointerCompress.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PointerCompress.cpp Mon Jul 13 11:11:04 2009
@@ -287,7 +287,7 @@
     assert(PoolBase == 0 && "Mixing and matching optimized vs not!");
     
     // Get the pool base pointer.
-    Constant *Zero = ConstantAggregateZero::get(Type::Int32Ty);
+    Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
     Value *Opts[2] = {Zero, Zero};
     Value *BasePtrPtr = GetElementPtrInst::Create(getPoolDesc(), Opts, Opts + 2,
                                               "poolbaseptrptr", &I);
@@ -299,7 +299,7 @@
                           isa<GlobalVariable>(PoolDesc))) {
       BasicBlock::iterator IP = I.getParent()->getParent()->begin()->begin();
       while (isa<AllocaInst>(IP)) ++IP;
-      Constant *Zero = ConstantAggregateZero::get(Type::Int32Ty);
+      Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
       Value *Opts[2] = {Zero, Zero};
       Value *BasePtrPtr = GetElementPtrInst::Create(getPoolDesc(), Opts, Opts + 2,
                                                 "poolbaseptrptr", IP);
@@ -383,7 +383,7 @@
     /// value, creating a new forward ref value as needed.
     Value *getTransformedValue(Value *V) {
       if (isa<ConstantPointerNull>(V))                // null -> uint 0
-        return ConstantAggregateZero::get(SCALARUINTTYPE);
+        return ConstantInt::get(SCALARUINTTYPE, 0);
       if (isa<UndefValue>(V))                // undef -> uint undef
         return UndefValue::get(SCALARUINTTYPE);
 
@@ -828,7 +828,7 @@
     }
   } else {
     // FIXME: This assumes that all null pointers are compressed!
-    SrcVal = ConstantAggregateZero::get(MEMUINTTYPE);
+    SrcVal = ConstantInt::get(MEMUINTTYPE, 0);
   }
   
   // Get the pool base pointer.

Modified: poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp?rev=75470&r1=75469&r2=75470&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp Mon Jul 13 11:11:04 2009
@@ -587,7 +587,7 @@
   // Any unallocated DSNodes get null pool descriptor pointers.
   for (hash_set<const DSNode*>::iterator I = GlobalHeapNodes.begin(),
          E = GlobalHeapNodes.end(); I != E; ++I) {
-    GlobalNodes[*I] = ConstantAggregateZero::get(PointerType::getUnqual(PoolDescType));
+    GlobalNodes[*I] = ConstantPointerNull::get(PointerType::getUnqual(PoolDescType));
     ++NumNonprofit;
   }
   
@@ -686,7 +686,7 @@
   // Any unallocated DSNodes get null pool descriptor pointers.
   for (std::set<const DSNode*>::iterator I = UnallocatedNodes.begin(),
          E = UnallocatedNodes.end(); I != E; ++I) {
-    PoolDescriptors[*I] =ConstantAggregateZero::get(PointerType::getUnqual(PoolDescType));
+    PoolDescriptors[*I] = ConstantPointerNull::get(PointerType::getUnqual(PoolDescType));
     ++NumNonprofit;
   }
 }

Modified: poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp?rev=75470&r1=75469&r2=75470&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp Mon Jul 13 11:11:04 2009
@@ -130,7 +130,9 @@
       // poolrealloc(PD, X, 0) -> poolfree(PD, X)
       Value* Opts[2] = {CI->getOperand(1), CI->getOperand(2)};
       CallInst::Create(PoolFree, Opts, Opts + 2, "", CI);
-      CI->replaceAllUsesWith(ConstantAggregateZero::get(CI->getType()));
+      const PointerType * PT = dyn_cast<PointerType>(CI->getType());
+      assert (PT && "poolrealloc call does not return a pointer!\n");
+      CI->replaceAllUsesWith(ConstantPointerNull::get(PT));
       CI->eraseFromParent();
     } else if (isa<ConstantPointerNull>(CI->getOperand(1))) {
       // poolrealloc(null, X, Y) -> realloc(X, Y)

Modified: poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp?rev=75470&r1=75469&r2=75470&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp Mon Jul 13 11:11:04 2009
@@ -446,7 +446,9 @@
     PH = getPoolHandle(I);
 
     // Return success always.
-    Value *RetVal = ConstantAggregateZero::get(I->getType());
+    const PointerType * PT = dyn_cast<PointerType>(I->getType());
+    assert (PT && "memalign() does not return pointer type!\n");
+    Value *RetVal = ConstantPointerNull::get(PT);
     I->replaceAllUsesWith(RetVal);
 
     static const Type *PtrPtr=PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty));





More information about the llvm-commits mailing list