[llvm-commits] [poolalloc] r45267 - in /poolalloc/trunk/lib/PoolAllocate: AccessTrace.cpp Heuristic.cpp PointerCompress.cpp PoolAllocate.cpp PoolOptimize.cpp TransformFunctionBody.cpp

John Criswell criswell at uiuc.edu
Thu Dec 20 11:56:51 PST 2007


Author: criswell
Date: Thu Dec 20 13:56:51 2007
New Revision: 45267

URL: http://llvm.org/viewvc/llvm-project?rev=45267&view=rev
Log:
Updated code to use PointerType::getUnqual() to get pointer types.
Disabled the dependence of the ConvertUnsafeAllocas pass; this appears to be
a performance hack that is not strictly needed and should be implemented
within the SAFECode passes.

Modified:
    poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp
    poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp
    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/PoolAllocate/AccessTrace.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp?rev=45267&r1=45266&r2=45267&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/AccessTrace.cpp Thu Dec 20 13:56:51 2007
@@ -63,7 +63,7 @@
 }
 
 void PoolAccessTrace::InitializeLibraryFunctions(Module &M) {
-  VoidPtrTy = PointerType::get(Type::Int8Ty);
+  VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
 
   AccessTraceInitFn = M.getOrInsertFunction("poolaccesstraceinit",
                                             Type::VoidTy,NULL);

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

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/Heuristic.cpp Thu Dec 20 13:56:51 2007
@@ -311,7 +311,7 @@
         } else if (N->isArray() && !N->isNodeCompletelyFolded()) {
           // We never pool allocate array nodes.
           PoolDescriptors[N] =
-            Constant::getNullValue(PointerType::get(PoolDescType));
+            Constant::getNullValue(PointerType::getUnqual(PoolDescType));
           ++NumNonprofit;
 #endif
         } else {
@@ -349,7 +349,7 @@
             // If this node has predecessors that are in different pools, don't
             // pool allocate this node.
             PoolDescriptors[N] =
-              Constant::getNullValue(PointerType::get(PoolDescType));
+              Constant::getNullValue(PointerType::getUnqual(PoolDescType));
             ++NumNonprofit;
           } else if (PredPool) {
             // If all of the predecessors of this node are already in a pool,
@@ -370,7 +370,7 @@
             // reason to pool allocate it, don't.
             assert(PredPool == 0);
              PoolDescriptors[N] =
-              Constant::getNullValue(PointerType::get(PoolDescType));
+              Constant::getNullValue(PointerType::getUnqual(PoolDescType));
             ++NumNonprofit;
           }
         }

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

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PointerCompress.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PointerCompress.cpp Thu Dec 20 13:56:51 2007
@@ -690,7 +690,7 @@
 
   // The compressed type for the pool.  FIXME: NOTE: This only works if 'Val'
   // pointed to the start of a node!
-  const Type *NTy = PointerType::get(PI->getNewType());
+  const Type *NTy = PointerType::getUnqual(PI->getNewType());
 
   //Check if we have a pointer to an array of Original Types this happens if
   //you do a malloc of [n x OrigTy] for a pool of Type OrigTy
@@ -699,7 +699,7 @@
       cast<PointerType>(GEPI.getOperand(0)->getType())->getElementType();
     if(isa<ArrayType>(PT)) {
       if (cast<ArrayType>(PT)->getElementType() == PI->getNode()->getType())
-        NTy = PointerType::get(ArrayType::get(PI->getNewType(),
+        NTy = PointerType::getUnqual(ArrayType::get(PI->getNewType(),
                                               cast<ArrayType>(PT)->getNumElements()));
     }
   }
@@ -776,7 +776,7 @@
   Value *SrcPtr = new GetElementPtrInst(BasePtr, Ops,
                                         LI.getOperand(0)->getName()+".pp", &LI);
   const Type *DestTy = LoadingCompressedPtr ? MEMUINTTYPE : LI.getType();
-  SrcPtr = CastInst::createPointerCast(SrcPtr, PointerType::get(DestTy),
+  SrcPtr = CastInst::createPointerCast(SrcPtr, PointerType::getUnqual(DestTy),
                                       SrcPtr->getName(), &LI);
   std::string OldName = LI.getName(); LI.setName("");
   Value *NewLoad = new LoadInst(SrcPtr, OldName, &LI);
@@ -843,7 +843,7 @@
                                          SI.getOperand(1)->getName()+".pp",
                                          &SI);
   DestPtr = CastInst::createPointerCast(DestPtr,
-                                        PointerType::get(SrcVal->getType()),
+                                        PointerType::getUnqual(SrcVal->getType()),
                                         DestPtr->getName(), &SI);
   new StoreInst(SrcVal, DestPtr, &SI);
 
@@ -1498,8 +1498,8 @@
 /// InitializePoolLibraryFunctions - Create the function prototypes for pointer
 /// compress runtime library functions.
 void PointerCompress::InitializePoolLibraryFunctions(Module &M) {
-  const Type *VoidPtrTy = PointerType::get(Type::Int8Ty);
-  const Type *PoolDescPtrTy = PointerType::get(ArrayType::get(VoidPtrTy, 16));
+  const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+  const Type *PoolDescPtrTy = PointerType::getUnqual(ArrayType::get(VoidPtrTy, 16));
 
   PoolInitPC = M.getOrInsertFunction("poolinit_pc", VoidPtrTy, PoolDescPtrTy, 
                                      Type::Int32Ty, Type::Int32Ty, NULL);

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

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolAllocate.cpp Thu Dec 20 13:56:51 2007
@@ -88,19 +88,16 @@
 }
 
 void PoolAllocate::getAnalysisUsage(AnalysisUsage &AU) const {
-#ifdef SAFECODE
-  AU.addRequired<ConvertUnsafeAllocas>();
-#endif  
-  AU.addRequired<EquivClassGraphs>();
+  AU.addRequiredTransitive<EquivClassGraphs>();
   AU.addPreserved<EquivClassGraphs>();
 #ifdef SAFECODE  
   //Dinakar for preserving the pool information across passes
   AU.setPreservesAll();
 #endif  
-#ifdef BOUNDS_CHECK  
+#ifdef BOUNDS_CHECK
   //Dinakar hack for preserving the pool information across passes
   AU.setPreservesAll();
-#endif  
+#endif
   AU.addRequired<TargetData>();
   if (UseTDResolve)
     AU.addRequired<CallTargetFinder>();
@@ -109,7 +106,9 @@
 bool PoolAllocate::runOnModule(Module &M) {
   if (M.begin() == M.end()) return false;
 #ifdef SAFECODE  
+#if 0
   CUAPass = &getAnalysis<ConvertUnsafeAllocas>();
+#endif
 #endif  
   CurModule = &M;
   ECGraphs = &getAnalysis<EquivClassGraphs>();   // folded inlined CBU graphs
@@ -183,13 +182,13 @@
 void PoolAllocate::AddPoolPrototypes() {
   if (VoidPtrTy == 0) {
     // NOTE: If these are changed, make sure to update PoolOptimize.cpp as well!
-    VoidPtrTy = PointerType::get(Type::Int8Ty);
+    VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
 #ifdef SAFECODE    
     PoolDescType = ArrayType::get(VoidPtrTy, 50);
 #else
     PoolDescType = ArrayType::get(VoidPtrTy, 16);
 #endif    
-    PoolDescPtrTy = PointerType::get(PoolDescType);
+    PoolDescPtrTy = PointerType::getUnqual(PoolDescType);
   }
 
   CurModule->addTypeName("PoolDescriptor", PoolDescType);
@@ -514,7 +513,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] = Constant::getNullValue(PointerType::get(PoolDescType));
+    GlobalNodes[*I] = Constant::getNullValue(PointerType::getUnqual(PoolDescType));
     ++NumNonprofit;
   }
   
@@ -617,7 +616,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] =Constant::getNullValue(PointerType::get(PoolDescType));
+    PoolDescriptors[*I] =Constant::getNullValue(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=45267&r1=45266&r2=45267&view=diff

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PoolOptimize.cpp Thu Dec 20 13:56:51 2007
@@ -50,8 +50,8 @@
 }
 
 bool PoolOptimize::runOnModule(Module &M) {
-  const Type *VoidPtrTy = PointerType::get(Type::Int8Ty);
-  const Type *PoolDescPtrTy = PointerType::get(ArrayType::get(VoidPtrTy, 16));
+  const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
+  const Type *PoolDescPtrTy = PointerType::getUnqual(ArrayType::get(VoidPtrTy, 16));
 
 
   // Get poolinit function.

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

==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/TransformFunctionBody.cpp Thu Dec 20 13:56:51 2007
@@ -203,7 +203,18 @@
   if (MI.isArrayAllocation())
     AllocSize = BinaryOperator::create(Instruction::Mul, AllocSize,
                                        MI.getOperand(0), "sizetmp", &MI);
+//
+// NOTE:
+//  The code below used to be used by SAFECode.  However, it requires
+//  Pool Allocation to depend upon SAFECode passes, which is messy.
+//
+//  I believe the code below is an unneeded optimization.  Basically, when
+//  SAFECode promotes a stack allocation to the heap, this makes it a stack
+//  allocation again if the DSNode has no heap allocations.  This seems to be
+//  a performance optimization and unnecessary for the first prototype.
+//
 #ifdef SAFECODE
+#if 0
   const MallocInst *originalMalloc = &MI;
   if (FI.NewToOldValueMap.count(&MI)) {
     originalMalloc = cast<MallocInst>(FI.NewToOldValueMap[&MI]);
@@ -218,8 +229,8 @@
     MI.getParent()->getInstList().erase(&MI);
     Value *Casted = AI;
     Instruction *aiNext = AI->getNext();
-    if (AI->getType() != PointerType::get(Type::Int8Ty))
-      Casted = CastInst::createPointerCast(AI, PointerType::get(Type::Int8Ty),
+    if (AI->getType() != PointerType::getUnqual(Type::Int8Ty))
+      Casted = CastInst::createPointerCast(AI, PointerType::getUnqual(Type::Int8Ty),
 			      AI->getName()+".casted",aiNext);
     
     Instruction *V = new CallInst(PAInfo.PoolRegister,
@@ -229,6 +240,9 @@
 #else
   TransformAllocationInstr(&MI, AllocSize);  
 #endif
+#else
+  TransformAllocationInstr(&MI, AllocSize);  
+#endif
 }
 
 void FuncTransform::visitAllocaInst(AllocaInst &MI) {
@@ -247,7 +261,7 @@
 					 MI.getOperand(0), "sizetmp", &MI);
     
     //  TransformAllocationInstr(&MI, AllocSize);
-    Instruction *Casted = CastInst::createPointerCast(&MI, PointerType::get(Type::Int8Ty),
+    Instruction *Casted = CastInst::createPointerCast(&MI, PointerType::getUnqual(Type::Int8Ty),
 				       MI.getName()+".casted", MI.getNext());
     Instruction *V = new CallInst(PAInfo.PoolRegister,
 				  make_vector(PH, Casted, AllocSize, 0), "", Casted->getNext());
@@ -263,8 +277,8 @@
 
   // Insert a cast and a call to poolfree...
   Value *Casted = Arg;
-  if (Arg->getType() != PointerType::get(Type::Int8Ty)) {
-    Casted = CastInst::createPointerCast(Arg, PointerType::get(Type::Int8Ty),
+  if (Arg->getType() != PointerType::getUnqual(Type::Int8Ty)) {
+    Casted = CastInst::createPointerCast(Arg, PointerType::getUnqual(Type::Int8Ty),
 				 Arg->getName()+".casted", Where);
     G.getScalarMap()[Casted] = G.getScalarMap()[Arg];
   }
@@ -296,7 +310,7 @@
 
 void FuncTransform::visitCallocCall(CallSite CS) {
   TargetData& TD = PAInfo.getAnalysis<TargetData>();
-  bool useLong = TD.getABITypeSize(PointerType::get(Type::Int8Ty)) != 4;
+  bool useLong = TD.getABITypeSize(PointerType::getUnqual(Type::Int8Ty)) != 4;
   
   Module *M = CS.getInstruction()->getParent()->getParent()->getParent();
   assert(CS.arg_end()-CS.arg_begin() == 2 && "calloc takes two arguments!");
@@ -320,12 +334,12 @@
   // finish calloc, we need to zero out the memory.
   Constant *MemSet =  M->getOrInsertFunction((useLong ? "llvm.memset.i64" : "llvm.memset.i32"),
                                              Type::VoidTy,
-                                             PointerType::get(Type::Int8Ty),
+                                             PointerType::getUnqual(Type::Int8Ty),
                                              Type::Int8Ty, (useLong ? Type::Int64Ty : Type::Int32Ty),
                                              Type::Int32Ty, NULL);
 
-  if (Ptr->getType() != PointerType::get(Type::Int8Ty))
-    Ptr = CastInst::createPointerCast(Ptr, PointerType::get(Type::Int8Ty), Ptr->getName(),
+  if (Ptr->getType() != PointerType::getUnqual(Type::Int8Ty))
+    Ptr = CastInst::createPointerCast(Ptr, PointerType::getUnqual(Type::Int8Ty), Ptr->getName(),
                        BBI);
   
   // We know that the memory returned by poolalloc is at least 4 byte aligned.
@@ -345,7 +359,7 @@
   if (Size->getType() != Type::Int32Ty)
     Size = CastInst::createIntegerCast(Size, Type::Int32Ty, false, Size->getName(), I);
 
-  static Type *VoidPtrTy = PointerType::get(Type::Int8Ty);
+  static Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
   if (OldPtr->getType() != VoidPtrTy)
     OldPtr = CastInst::createPointerCast(OldPtr, VoidPtrTy, OldPtr->getName(), I);
 
@@ -407,7 +421,7 @@
     Value *RetVal = Constant::getNullValue(I->getType());
     I->replaceAllUsesWith(RetVal);
 
-    static const Type *PtrPtr=PointerType::get(PointerType::get(Type::Int8Ty));
+    static const Type *PtrPtr=PointerType::getUnqual(PointerType::getUnqual(Type::Int8Ty));
     if (ResultDest->getType() != PtrPtr)
       ResultDest = CastInst::createPointerCast(ResultDest, PtrPtr, ResultDest->getName(), I);
   }
@@ -601,7 +615,7 @@
       ArgTys.push_back((*I)->getType());
     
     FunctionType *FTy = FunctionType::get(TheCall->getType(), ArgTys, false);
-    PointerType *PFTy = PointerType::get(FTy);
+    PointerType *PFTy = PointerType::getUnqual(FTy);
     
     // If there are any pool arguments cast the func ptr to the right type.
     NewCallee = CastInst::createPointerCast(CS.getCalledValue(), PFTy, "tmp", TheCall);
@@ -650,7 +664,7 @@
 	if (!isa<InvokeInst>(TheCall)) {
 	  //Dinakar we need pooldescriptors for allocas in the callee if it escapes
 	  BasicBlock::iterator InsertPt = TheCall->getParent()->getParent()->front().begin();
-	  Type *VoidPtrTy = PointerType::get(Type::Int8Ty);
+	  Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
 	  ArgVal =  new AllocaInst(ArrayType::get(VoidPtrTy, 16), 0, "PD", InsertPt);
 	  Value *ElSize = ConstantInt::get(Type::Int32Ty,0);
 	  Value *Align  = ConstantInt::get(Type::Int32Ty,0);





More information about the llvm-commits mailing list