Changes in directory llvm-poolalloc/lib/PoolAllocate:
AccessTrace.cpp updated: 1.6 -> 1.7 PointerCompress.cpp updated: 1.72 -> 1.73 PoolAllocate.cpp updated: 1.127 -> 1.128 PoolOptimize.cpp updated: 1.8 -> 1.9 TransformFunctionBody.cpp updated: 1.57 -> 1.58 --- Log message: Updated to LLVM Mainline API. This required changing statistics to be non-templated and switching over to using the new cast instructions. --- Diffs of the changes: (+65 -50) AccessTrace.cpp | 4 ++-- PointerCompress.cpp | 41 +++++++++++++++++++++-------------------- PoolAllocate.cpp | 29 ++++++++++++++++++++--------- PoolOptimize.cpp | 2 +- TransformFunctionBody.cpp | 39 +++++++++++++++++++++------------------ 5 files changed, 65 insertions(+), 50 deletions(-) Index: llvm-poolalloc/lib/PoolAllocate/AccessTrace.cpp diff -u llvm-poolalloc/lib/PoolAllocate/AccessTrace.cpp:1.6 llvm-poolalloc/lib/PoolAllocate/AccessTrace.cpp:1.7 --- llvm-poolalloc/lib/PoolAllocate/AccessTrace.cpp:1.6 Tue Oct 24 16:43:50 2006 +++ llvm-poolalloc/lib/PoolAllocate/AccessTrace.cpp Wed Dec 13 14:06:42 2006 @@ -81,10 +81,10 @@ if (Node == 0) return; Value *PD = FI->PoolDescriptors[Node]; - Ptr = new CastInst(Ptr, VoidPtrTy, Ptr->getName(), I); + Ptr = CastInst::createPointerCast (Ptr, VoidPtrTy, Ptr->getName(), I); if (PD) - PD = new CastInst(PD, VoidPtrTy, PD->getName(), I); + PD = CastInst::createPointerCast (PD, VoidPtrTy, PD->getName(), I); else PD = Constant::getNullValue(VoidPtrTy); Index: llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp diff -u llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.72 llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.73 --- llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.72 Fri Nov 3 14:14:34 2006 +++ llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp Wed Dec 13 14:06:42 2006 @@ -54,11 +54,11 @@ cl::desc("Enable Andrew's fixes/hacks")); - Statistic<> NumCompressed("pointercompress", + Statistic NumCompressed("pointercompress", "Number of pools pointer compressed"); - Statistic<> NumNotCompressed("pointercompress", + Statistic NumNotCompressed("pointercompress", "Number of pools not compressible"); - Statistic<> NumCloned ("pointercompress", "Number of functions cloned"); + Statistic NumCloned ("pointercompress", "Number of functions cloned"); class CompressedPoolInfo; @@ -703,7 +703,7 @@ // Add Idx*sizeof(NewElementType) to the index. const Type *ElTy = cast<SequentialType>(NTy)->getElementType(); if (Idx->getType() != SCALARUINTTYPE) - Idx = new CastInst(Idx, SCALARUINTTYPE, Idx->getName(), &GEPI); + Idx = CastInst::createSExtOrBitCast(Idx, SCALARUINTTYPE, Idx->getName(), &GEPI); Constant *Scale = ConstantInt::get(SCALARUINTTYPE, TD.getTypeSize(ElTy)); @@ -729,7 +729,7 @@ // type. if (getPoolInfo(&LI)) { Value *NLI = new LoadInst(LI.getOperand(0), LI.getName()+".cp", &LI); - Value *NC = new CastInst(NLI, SCALARUINTTYPE, NLI->getName(), &LI); + Value *NC = CastInst::createZExtOrBitCast(NLI, SCALARUINTTYPE, NLI->getName(), &LI); setTransformedValue(LI, NC); } return; @@ -746,19 +746,19 @@ std::vector<Value*> Ops; Ops.push_back(getTransformedValue(LI.getOperand(0))); if (Ops[0]->getType() == Type::UShortTy) - Ops[0] = new CastInst(Ops[0], Type::UIntTy, "extend_idx", &LI); + Ops[0] = CastInst::createZExtOrBitCast(Ops[0], Type::UIntTy, "extend_idx", &LI); Value *SrcPtr = new GetElementPtrInst(BasePtr, Ops, LI.getOperand(0)->getName()+".pp", &LI); const Type *DestTy = LoadingCompressedPtr ? MEMUINTTYPE : LI.getType(); - SrcPtr = new CastInst(SrcPtr, PointerType::get(DestTy), - SrcPtr->getName(), &LI); + SrcPtr = CastInst::createPointerCast(SrcPtr, PointerType::get(DestTy), + SrcPtr->getName(), &LI); std::string OldName = LI.getName(); LI.setName(""); Value *NewLoad = new LoadInst(SrcPtr, OldName, &LI); if (LoadingCompressedPtr) { // Convert from MEMUINTTYPE to SCALARUINTTYPE if different. if (MEMUINTTYPE != SCALARUINTTYPE) - NewLoad = new CastInst(NewLoad, SCALARUINTTYPE, NewLoad->getName(), &LI); + NewLoad = CastInst::createZExtOrBitCast(NewLoad, SCALARUINTTYPE, NewLoad->getName(), &LI); setTransformedValue(LI, NewLoad); } else { @@ -777,8 +777,8 @@ // cast the index to a pointer type and store that. if (getPoolInfo(SI.getOperand(0))) { Value *SrcVal = getTransformedValue(SI.getOperand(0)); - SrcVal = new CastInst(SrcVal, SI.getOperand(0)->getType(), - SrcVal->getName(), &SI); + SrcVal = CastInst::createPointerCast(SrcVal, SI.getOperand(0)->getType(), + SrcVal->getName(), &SI); SI.setOperand(0, SrcVal); } return; @@ -798,7 +798,7 @@ // If SCALAR type is not the MEM type, reduce it now. if (SrcVal->getType() != MEMUINTTYPE) - SrcVal = new CastInst(SrcVal, MEMUINTTYPE, SrcVal->getName(), &SI); + SrcVal = CastInst::createZExtOrBitCast(SrcVal, MEMUINTTYPE, SrcVal->getName(), &SI); } } else { // FIXME: This assumes that all null pointers are compressed! @@ -812,13 +812,14 @@ std::vector<Value*> Ops; Ops.push_back(getTransformedValue(SI.getOperand(1))); if (Ops[0]->getType() == Type::UShortTy) - Ops[0] = new CastInst(Ops[0], Type::UIntTy, "extend_idx", &SI); + Ops[0] = CastInst::createZExtOrBitCast(Ops[0], Type::UIntTy, "extend_idx", &SI); Value *DestPtr = new GetElementPtrInst(BasePtr, Ops, SI.getOperand(1)->getName()+".pp", &SI); - DestPtr = new CastInst(DestPtr, PointerType::get(SrcVal->getType()), - DestPtr->getName(), &SI); + DestPtr = CastInst::createPointerCast(DestPtr, + PointerType::get(SrcVal->getType()), + DestPtr->getName(), &SI); new StoreInst(SrcVal, DestPtr, &SI); // Finally, explicitly remove the store from the program, as it does not @@ -951,7 +952,7 @@ Value *BasePtr = DestPI->EmitPoolBaseLoad(CI); Value *SrcPtr = new GetElementPtrInst(BasePtr, Ops, CI.getOperand(2)->getName()+".pp", &CI); - SrcPtr = new CastInst(SrcPtr, CI.getOperand(2)->getType(), "", &CI); + SrcPtr = CastInst::createPointerCast(SrcPtr, CI.getOperand(2)->getType(), "", &CI); CI.setOperand(2, SrcPtr); return; } @@ -962,7 +963,7 @@ Value *BasePtr = DestPI->EmitPoolBaseLoad(CI); Value *SrcPtr = new GetElementPtrInst(BasePtr, Ops, CI.getOperand(1)->getName()+".pp", &CI); - SrcPtr = new CastInst(SrcPtr, CI.getOperand(1)->getType(), "", &CI); + SrcPtr = CastInst::createPointerCast(SrcPtr, CI.getOperand(1)->getType(), "", &CI); CI.setOperand(1, SrcPtr); return; } @@ -975,7 +976,7 @@ Value *BasePtr = DestPI->EmitPoolBaseLoad(CI); Value *SrcPtr = new GetElementPtrInst(BasePtr, Ops, CI.getOperand(1)->getName()+".pp", &CI); - SrcPtr = new CastInst(SrcPtr, CI.getOperand(1)->getType(), "", &CI); + SrcPtr = CastInst::createPointerCast(SrcPtr, CI.getOperand(1)->getType(), "", &CI); CI.setOperand(1, SrcPtr); return; } @@ -989,7 +990,7 @@ Value *BasePtr = DestPI->EmitPoolBaseLoad(CI); Value *SrcPtr = new GetElementPtrInst(BasePtr, Ops, CI.getOperand(1)->getName()+".pp", &CI); - SrcPtr = new CastInst(SrcPtr, CI.getOperand(1)->getType(), "", &CI); + SrcPtr = CastInst::createPointerCast(SrcPtr, CI.getOperand(1)->getType(), "", &CI); CI.setOperand(1, SrcPtr); doret = true; } @@ -999,7 +1000,7 @@ Value *BasePtr = DestPI->EmitPoolBaseLoad(CI); Value *SrcPtr = new GetElementPtrInst(BasePtr, Ops, CI.getOperand(2)->getName()+".pp", &CI); - SrcPtr = new CastInst(SrcPtr, CI.getOperand(2)->getType(), "", &CI); + SrcPtr = CastInst::createPointerCast(SrcPtr, CI.getOperand(2)->getType(), "", &CI); CI.setOperand(2, SrcPtr); doret = true; } Index: llvm-poolalloc/lib/PoolAllocate/PoolAllocate.cpp diff -u llvm-poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.127 llvm-poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.128 --- llvm-poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.127 Fri Nov 3 14:14:34 2006 +++ llvm-poolalloc/lib/PoolAllocate/PoolAllocate.cpp Wed Dec 13 14:06:42 2006 @@ -57,14 +57,14 @@ RegisterPass<PoolAllocatePassAllPools> Y("poolalloc-passing-all-pools", "Pool allocate disjoint data structures"); - Statistic<> NumArgsAdded("poolalloc", "Number of function arguments added"); - Statistic<> MaxArgsAdded("poolalloc", "Maximum function arguments added to one function"); - Statistic<> NumCloned ("poolalloc", "Number of functions cloned"); - Statistic<> NumPools ("poolalloc", "Number of pools allocated"); - Statistic<> NumTSPools ("poolalloc", "Number of typesafe pools"); - Statistic<> NumPoolFree ("poolalloc", "Number of poolfree's elided"); - Statistic<> NumNonprofit("poolalloc", "Number of DSNodes not profitable"); - Statistic<> NumColocated("poolalloc", "Number of DSNodes colocated"); + Statistic NumArgsAdded("poolalloc", "Number of function arguments added"); + Statistic MaxArgsAdded("poolalloc", "Maximum function arguments added to one function"); + Statistic NumCloned ("poolalloc", "Number of functions cloned"); + Statistic NumPools ("poolalloc", "Number of pools allocated"); + Statistic NumTSPools ("poolalloc", "Number of typesafe pools"); + Statistic NumPoolFree ("poolalloc", "Number of poolfree's elided"); + Statistic NumNonprofit("poolalloc", "Number of DSNodes not profitable"); + Statistic NumColocated("poolalloc", "Number of DSNodes colocated"); const Type *VoidPtrTy; @@ -244,7 +244,18 @@ bool CondIsTrue = User->getOpcode() == Instruction::SetNE; User->replaceAllUsesWith(ConstantBool::get(CondIsTrue)); } - } else if (User->getOpcode() == Instruction::Cast) { + } else if ((User->getOpcode() == Instruction::Trunc) || + (User->getOpcode() == Instruction::ZExt) || + (User->getOpcode() == Instruction::SExt) || + (User->getOpcode() == Instruction::FPToUI) || + (User->getOpcode() == Instruction::FPToSI) || + (User->getOpcode() == Instruction::UIToFP) || + (User->getOpcode() == Instruction::SIToFP) || + (User->getOpcode() == Instruction::FPTrunc) || + (User->getOpcode() == Instruction::FPExt) || + (User->getOpcode() == Instruction::PtrToInt) || + (User->getOpcode() == Instruction::IntToPtr) || + (User->getOpcode() == Instruction::BitCast)) { // Casted pointers are also not null. if (isa<PointerType>(User->getType())) OptimizePointerNotNull(User); Index: llvm-poolalloc/lib/PoolAllocate/PoolOptimize.cpp diff -u llvm-poolalloc/lib/PoolAllocate/PoolOptimize.cpp:1.8 llvm-poolalloc/lib/PoolAllocate/PoolOptimize.cpp:1.9 --- llvm-poolalloc/lib/PoolAllocate/PoolOptimize.cpp:1.8 Fri Nov 3 15:07:06 2006 +++ llvm-poolalloc/lib/PoolAllocate/PoolOptimize.cpp Wed Dec 13 14:06:42 2006 @@ -20,7 +20,7 @@ using namespace llvm; namespace { - Statistic<> NumBumpPtr("poolalloc", "Number of bump pointer pools"); + Statistic NumBumpPtr("poolalloc", "Number of bump pointer pools"); struct PoolOptimize : public ModulePass { bool runOnModule(Module &M); Index: llvm-poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp diff -u llvm-poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp:1.57 llvm-poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp:1.58 --- llvm-poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp:1.57 Tue Oct 24 16:43:50 2006 +++ llvm-poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp Wed Dec 13 14:06:42 2006 @@ -149,7 +149,7 @@ std::string Name = I->getName(); I->setName(""); if (Size->getType() != Type::UIntTy) - Size = new CastInst(Size, Type::UIntTy, Size->getName(), I); + Size = CastInst::createZExtOrBitCast(Size, Type::UIntTy, Size->getName(), I); // Insert a call to poolalloc Value *PH = getPoolHandle(I); @@ -162,7 +162,7 @@ // Cast to the appropriate type if necessary Instruction *Casted = V; if (V->getType() != I->getType()) - Casted = new CastInst(V, I->getType(), V->getName(), I); + Casted = CastInst::createPointerCast(V, I->getType(), V->getName(), I); // Update def-use info I->replaceAllUsesWith(Casted); @@ -218,7 +218,7 @@ Value *Casted = AI; Instruction *aiNext = AI->getNext(); if (AI->getType() != PointerType::get(Type::SByteTy)) - Casted = new CastInst(AI, PointerType::get(Type::SByteTy), + Casted = CastInst::createPointerCast(AI, PointerType::get(Type::SByteTy), AI->getName()+".casted",aiNext); Instruction *V = new CallInst(PAInfo.PoolRegister, @@ -246,7 +246,7 @@ MI.getOperand(0), "sizetmp", &MI); // TransformAllocationInstr(&MI, AllocSize); - Instruction *Casted = new CastInst(&MI, PointerType::get(Type::SByteTy), + Instruction *Casted = CastInst::createPointerCast(&MI, PointerType::get(Type::SByteTy), MI.getName()+".casted", MI.getNext()); Instruction *V = new CallInst(PAInfo.PoolRegister, make_vector(PH, Casted, AllocSize, 0), "", Casted->getNext()); @@ -263,7 +263,7 @@ // Insert a cast and a call to poolfree... Value *Casted = Arg; if (Arg->getType() != PointerType::get(Type::SByteTy)) { - Casted = new CastInst(Arg, PointerType::get(Type::SByteTy), + Casted = CastInst::createPointerCast(Arg, PointerType::get(Type::SByteTy), Arg->getName()+".casted", Where); G.getScalarMap()[Casted] = G.getScalarMap()[Arg]; } @@ -302,14 +302,14 @@ Value *V1 = CS.getArgument(0); Value *V2 = CS.getArgument(1); if (V1->getType() != V2->getType()) { - V1 = new CastInst(V1, useLong ? Type::ULongTy : Type::UIntTy, V1->getName(), CS.getInstruction()); - V2 = new CastInst(V2, useLong ? Type::ULongTy : Type::UIntTy, V2->getName(), CS.getInstruction()); + V1 = CastInst::createZExtOrBitCast(V1, useLong ? Type::ULongTy : Type::UIntTy, V1->getName(), CS.getInstruction()); + V2 = CastInst::createZExtOrBitCast(V2, useLong ? Type::ULongTy : Type::UIntTy, V2->getName(), CS.getInstruction()); } V2 = BinaryOperator::create(Instruction::Mul, V1, V2, "size", CS.getInstruction()); if (V2->getType() != (useLong ? Type::ULongTy : Type::UIntTy)) - V2 = new CastInst(V2, useLong ? Type::ULongTy : Type::UIntTy, V2->getName(), CS.getInstruction()); + V2 = CastInst::createZExtOrBitCast(V2, useLong ? Type::ULongTy : Type::UIntTy, V2->getName(), CS.getInstruction()); BasicBlock::iterator BBI = TransformAllocationInstr(CS.getInstruction(), V2); @@ -324,7 +324,7 @@ Type::UIntTy, NULL); if (Ptr->getType() != PointerType::get(Type::SByteTy)) - Ptr = new CastInst(Ptr, PointerType::get(Type::SByteTy), Ptr->getName(), + Ptr = CastInst::createPointerCast(Ptr, PointerType::get(Type::SByteTy), Ptr->getName(), BBI); // We know that the memory returned by poolalloc is at least 4 byte aligned. @@ -342,11 +342,11 @@ Value *Size = CS.getArgument(1); if (Size->getType() != Type::UIntTy) - Size = new CastInst(Size, Type::UIntTy, Size->getName(), I); + Size = CastInst::createZExtOrBitCast(Size, Type::UIntTy, Size->getName(), I); static Type *VoidPtrTy = PointerType::get(Type::SByteTy); if (OldPtr->getType() != VoidPtrTy) - OldPtr = new CastInst(OldPtr, VoidPtrTy, OldPtr->getName(), I); + OldPtr = CastInst::createPointerCast(OldPtr, VoidPtrTy, OldPtr->getName(), I); std::string Name = I->getName(); I->setName(""); Instruction *V = new CallInst(PAInfo.PoolRealloc, make_vector(PH, OldPtr, @@ -354,7 +354,7 @@ Name, I); Instruction *Casted = V; if (V->getType() != I->getType()) - Casted = new CastInst(V, I->getType(), V->getName(), I); + Casted = CastInst::createPointerCast(V, I->getType(), V->getName(), I); // Update def-use info I->replaceAllUsesWith(Casted); @@ -409,13 +409,13 @@ static const Type *PtrPtr=PointerType::get(PointerType::get(Type::SByteTy)); if (ResultDest->getType() != PtrPtr) - ResultDest = new CastInst(ResultDest, PtrPtr, ResultDest->getName(), I); + ResultDest = CastInst::createPointerCast(ResultDest, PtrPtr, ResultDest->getName(), I); } if (Align->getType() != Type::UIntTy) - Align = new CastInst(Align, Type::UIntTy, Align->getName(), I); + Align = CastInst::createZExtOrBitCast(Align, Type::UIntTy, Align->getName(), I); if (Size->getType() != Type::UIntTy) - Size = new CastInst(Size, Type::UIntTy, Size->getName(), I); + Size = CastInst::createZExtOrBitCast(Size, Type::UIntTy, Size->getName(), I); std::string Name = I->getName(); I->setName(""); Instruction *V = new CallInst(PAInfo.PoolMemAlign, @@ -423,7 +423,7 @@ Instruction *Casted = V; if (V->getType() != I->getType()) - Casted = new CastInst(V, I->getType(), V->getName(), I); + Casted = CastInst::createPointerCast(V, I->getType(), V->getName(), I); if (ResultDest) new StoreInst(V, ResultDest, I); @@ -456,8 +456,11 @@ Function *CF = CS.getCalledFunction(); Instruction *TheCall = CS.getInstruction(); + // If the called function is casted from one function type to another, peer + // into the cast instruction and pull out the actual function being called. if (ConstantExpr *CE = dyn_cast<ConstantExpr>(CS.getCalledValue())) - if (CE->getOpcode() == Instruction::Cast && isa<Function>(CE->getOperand(0))) + if (CE->getOpcode() == Instruction::BitCast && + isa<Function>(CE->getOperand(0))) CF = cast<Function>(CE->getOperand(0)); if (isa<InlineAsm>(TheCall->getOperand(0))) { @@ -601,7 +604,7 @@ PointerType *PFTy = PointerType::get(FTy); // If there are any pool arguments cast the func ptr to the right type. - NewCallee = new CastInst(CS.getCalledValue(), PFTy, "tmp", TheCall); + NewCallee = CastInst::createPointerCast(CS.getCalledValue(), PFTy, "tmp", TheCall); } Function::arg_iterator FAI = CF->arg_begin(), E = CF->arg_end(); _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits