diff options
Diffstat (limited to 'lib/Transforms')
41 files changed, 448 insertions, 448 deletions
diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 230bafd..fe0d6d9 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -469,7 +469,7 @@ Function *ArgPromotion::DoPromotion(Function *F, FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg()); // Create the new function body and insert it into the module... - Function *NF = new Function(NFTy, F->getLinkage(), F->getName()); + Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName()); NF->setCallingConv(F->getCallingConv()); // Recompute the parameter attributes list based on the new arguments for @@ -518,9 +518,9 @@ Function *ArgPromotion::DoPromotion(Function *F, Value *Idxs[2] = { ConstantInt::get(Type::Int32Ty, 0), 0 }; for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { Idxs[1] = ConstantInt::get(Type::Int32Ty, i); - Value *Idx = new GetElementPtrInst(*AI, Idxs, Idxs+2, - (*AI)->getName()+"."+utostr(i), - Call); + Value *Idx = GetElementPtrInst::Create(*AI, Idxs, Idxs+2, + (*AI)->getName()+"."+utostr(i), + Call); // TODO: Tell AA about the new values? Args.push_back(new LoadInst(Idx, Idx->getName()+".val", Call)); } @@ -532,8 +532,8 @@ Function *ArgPromotion::DoPromotion(Function *F, Value *V = *AI; LoadInst *OrigLoad = OriginalLoads[*SI]; if (!SI->empty()) { - V = new GetElementPtrInst(V, SI->begin(), SI->end(), - V->getName()+".idx", Call); + V = GetElementPtrInst::Create(V, SI->begin(), SI->end(), + V->getName()+".idx", Call); AA.copyValue(OrigLoad->getOperand(0), V); } Args.push_back(new LoadInst(V, V->getName()+".val", Call)); @@ -553,13 +553,13 @@ Function *ArgPromotion::DoPromotion(Function *F, Instruction *New; if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { - New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), - Args.begin(), Args.end(), "", Call); + New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(), + Args.begin(), Args.end(), "", Call); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); cast<InvokeInst>(New)->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end())); } else { - New = new CallInst(NF, Args.begin(), Args.end(), "", Call); + New = CallInst::Create(NF, Args.begin(), Args.end(), "", Call); cast<CallInst>(New)->setCallingConv(CS.getCallingConv()); cast<CallInst>(New)->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end())); @@ -616,9 +616,9 @@ Function *ArgPromotion::DoPromotion(Function *F, for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { Idxs[1] = ConstantInt::get(Type::Int32Ty, i); - Value *Idx = new GetElementPtrInst(TheAlloca, Idxs, Idxs+2, - TheAlloca->getName()+"."+utostr(i), - InsertPt); + Value *Idx = GetElementPtrInst::Create(TheAlloca, Idxs, Idxs+2, + TheAlloca->getName()+"."+utostr(i), + InsertPt); I2->setName(I->getName()+"."+utostr(i)); new StoreInst(I2++, Idx, InsertPt); } diff --git a/lib/Transforms/IPO/DeadArgumentElimination.cpp b/lib/Transforms/IPO/DeadArgumentElimination.cpp index 8299dbc..6cd128b 100644 --- a/lib/Transforms/IPO/DeadArgumentElimination.cpp +++ b/lib/Transforms/IPO/DeadArgumentElimination.cpp @@ -157,7 +157,7 @@ bool DAE::DeleteDeadVarargs(Function &Fn) { unsigned NumArgs = Params.size(); // Create the new function body and insert it into the module... - Function *NF = new Function(NFTy, Fn.getLinkage()); + Function *NF = Function::Create(NFTy, Fn.getLinkage()); NF->setCallingConv(Fn.getCallingConv()); NF->setParamAttrs(Fn.getParamAttrs()); if (Fn.hasCollector()) @@ -187,12 +187,12 @@ bool DAE::DeleteDeadVarargs(Function &Fn) { Instruction *New; if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { - New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), - Args.begin(), Args.end(), "", Call); + New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(), + Args.begin(), Args.end(), "", Call); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); cast<InvokeInst>(New)->setParamAttrs(PAL); } else { - New = new CallInst(NF, Args.begin(), Args.end(), "", Call); + New = CallInst::Create(NF, Args.begin(), Args.end(), "", Call); cast<CallInst>(New)->setCallingConv(CS.getCallingConv()); cast<CallInst>(New)->setParamAttrs(PAL); if (cast<CallInst>(Call)->isTailCall()) @@ -550,7 +550,7 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg()); // Create the new function body and insert it into the module... - Function *NF = new Function(NFTy, F->getLinkage()); + Function *NF = Function::Create(NFTy, F->getLinkage()); NF->setCallingConv(F->getCallingConv()); NF->setParamAttrs(NewPAL); if (F->hasCollector()) @@ -602,12 +602,12 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { Instruction *New; if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { - New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), - Args.begin(), Args.end(), "", Call); + New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(), + Args.begin(), Args.end(), "", Call); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); cast<InvokeInst>(New)->setParamAttrs(NewCallPAL); } else { - New = new CallInst(NF, Args.begin(), Args.end(), "", Call); + New = CallInst::Create(NF, Args.begin(), Args.end(), "", Call); cast<CallInst>(New)->setCallingConv(CS.getCallingConv()); cast<CallInst>(New)->setParamAttrs(NewCallPAL); if (cast<CallInst>(Call)->isTailCall()) @@ -660,7 +660,7 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) { if (F->getReturnType() != NF->getReturnType()) for (Function::iterator BB = NF->begin(), E = NF->end(); BB != E; ++BB) if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) { - new ReturnInst(0, RI); + ReturnInst::Create(0, RI); BB->getInstList().erase(RI); } diff --git a/lib/Transforms/IPO/ExtractGV.cpp b/lib/Transforms/IPO/ExtractGV.cpp index 882097c..46232b8 100644 --- a/lib/Transforms/IPO/ExtractGV.cpp +++ b/lib/Transforms/IPO/ExtractGV.cpp @@ -121,8 +121,8 @@ namespace { for (Module::iterator I = M.begin(); ; ++I) { if (std::find(Named.begin(), Named.end(), &*I) == Named.end()) { - Function *New = new Function(I->getFunctionType(), - GlobalValue::ExternalLinkage); + Function *New = Function::Create(I->getFunctionType(), + GlobalValue::ExternalLinkage); New->setCallingConv(I->getCallingConv()); New->setParamAttrs(I->getParamAttrs()); if (I->hasCollector()) diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index e542776..50c5ecc 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -546,8 +546,8 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV) { Idxs.push_back(NullInt); for (unsigned i = 3, e = GEPI->getNumOperands(); i != e; ++i) Idxs.push_back(GEPI->getOperand(i)); - NewPtr = new GetElementPtrInst(NewPtr, Idxs.begin(), Idxs.end(), - GEPI->getName()+"."+utostr(Val), GEPI); + NewPtr = GetElementPtrInst::Create(NewPtr, Idxs.begin(), Idxs.end(), + GEPI->getName()+"."+utostr(Val), GEPI); } } GEP->replaceAllUsesWith(NewPtr); @@ -789,8 +789,8 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, MI->getAlignment(), MI->getName(), MI); Value* Indices[2]; Indices[0] = Indices[1] = Constant::getNullValue(Type::Int32Ty); - Value *NewGEP = new GetElementPtrInst(NewMI, Indices, Indices + 2, - NewMI->getName()+".el0", MI); + Value *NewGEP = GetElementPtrInst::Create(NewMI, Indices, Indices + 2, + NewMI->getName()+".el0", MI); MI->replaceAllUsesWith(NewGEP); MI->eraseFromParent(); MI = NewMI; @@ -1054,8 +1054,8 @@ static void RewriteHeapSROALoadUser(LoadInst *Load, Instruction *LoadUser, GEPIdx.push_back(GEPI->getOperand(1)); GEPIdx.append(GEPI->op_begin()+3, GEPI->op_end()); - Value *NGEPI = new GetElementPtrInst(NewPtr, GEPIdx.begin(), GEPIdx.end(), - GEPI->getName(), GEPI); + Value *NGEPI = GetElementPtrInst::Create(NewPtr, GEPIdx.begin(), GEPIdx.end(), + GEPI->getName(), GEPI); GEPI->replaceAllUsesWith(NGEPI); GEPI->eraseFromParent(); return; @@ -1070,8 +1070,8 @@ static void RewriteHeapSROALoadUser(LoadInst *Load, Instruction *LoadUser, for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) { Value *LoadV = GetHeapSROALoad(Load, i, FieldGlobals, InsertedLoadsForPtr); - PHINode *FieldPN = new PHINode(LoadV->getType(), - PN->getName()+"."+utostr(i), PN); + PHINode *FieldPN = PHINode::Create(LoadV->getType(), + PN->getName()+"."+utostr(i), PN); // Fill in the predecessor values. for (unsigned pred = 0, e = PN->getNumIncomingValues(); pred != e; ++pred) { // Each predecessor either uses the load or the original malloc. @@ -1173,13 +1173,13 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI){ // Create the block to check the first condition. Put all these blocks at the // end of the function as they are unlikely to be executed. - BasicBlock *NullPtrBlock = new BasicBlock("malloc_ret_null", - OrigBB->getParent()); + BasicBlock *NullPtrBlock = BasicBlock::Create("malloc_ret_null", + OrigBB->getParent()); // Remove the uncond branch from OrigBB to ContBB, turning it into a cond // branch on RunningOr. OrigBB->getTerminator()->eraseFromParent(); - new BranchInst(NullPtrBlock, ContBB, RunningOr, OrigBB); + BranchInst::Create(NullPtrBlock, ContBB, RunningOr, OrigBB); // Within the NullPtrBlock, we need to emit a comparison and branch for each // pointer, because some may be null while others are not. @@ -1188,21 +1188,20 @@ static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI){ Value *Cmp = new ICmpInst(ICmpInst::ICMP_NE, GVVal, Constant::getNullValue(GVVal->getType()), "tmp", NullPtrBlock); - BasicBlock *FreeBlock = new BasicBlock("free_it", OrigBB->getParent()); - BasicBlock *NextBlock = new BasicBlock("next", OrigBB->getParent()); - new BranchInst(FreeBlock, NextBlock, Cmp, NullPtrBlock); + BasicBlock *FreeBlock = BasicBlock::Create("free_it", OrigBB->getParent()); + BasicBlock *NextBlock = BasicBlock::Create("next", OrigBB->getParent()); + BranchInst::Create(FreeBlock, NextBlock, Cmp, NullPtrBlock); // Fill in FreeBlock. new FreeInst(GVVal, FreeBlock); new StoreInst(Constant::getNullValue(GVVal->getType()), FieldGlobals[i], FreeBlock); - new BranchInst(NextBlock, FreeBlock); + BranchInst::Create(NextBlock, FreeBlock); NullPtrBlock = NextBlock; } - new BranchInst(ContBB, NullPtrBlock); - + BranchInst::Create(ContBB, NullPtrBlock); // MI is no longer needed, remove it. MI->eraseFromParent(); @@ -1411,7 +1410,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) { if (IsOneZero) NSI = new ZExtInst(NLI, LI->getType(), "", LI); else - NSI = new SelectInst(NLI, OtherVal, InitVal, "", LI); + NSI = SelectInst::Create(NLI, OtherVal, InitVal, "", LI); NSI->takeName(LI); LI->replaceAllUsesWith(NSI); } diff --git a/lib/Transforms/IPO/IndMemRemoval.cpp b/lib/Transforms/IPO/IndMemRemoval.cpp index 502c293..2f9c34d 100644 --- a/lib/Transforms/IPO/IndMemRemoval.cpp +++ b/lib/Transforms/IPO/IndMemRemoval.cpp @@ -52,11 +52,11 @@ bool IndMemRemPass::runOnModule(Module &M) { if (Function* F = M.getFunction("free")) { assert(F->isDeclaration() && "free not external?"); if (!F->use_empty()) { - Function* FN = new Function(F->getFunctionType(), - GlobalValue::LinkOnceLinkage, - "free_llvm_bounce", &M); - BasicBlock* bb = new BasicBlock("entry",FN); - Instruction* R = new ReturnInst(bb); + Function* FN = Function::Create(F->getFunctionType(), + GlobalValue::LinkOnceLinkage, + "free_llvm_bounce", &M); + BasicBlock* bb = BasicBlock::Create("entry",FN); + Instruction* R = ReturnInst::Create(bb); new FreeInst(FN->arg_begin(), R); ++NumBounce; NumBounceSites += F->getNumUses(); @@ -67,14 +67,14 @@ bool IndMemRemPass::runOnModule(Module &M) { if (Function* F = M.getFunction("malloc")) { assert(F->isDeclaration() && "malloc not external?"); if (!F->use_empty()) { - Function* FN = new Function(F->getFunctionType(), - GlobalValue::LinkOnceLinkage, - "malloc_llvm_bounce", &M); - BasicBlock* bb = new BasicBlock("entry",FN); + Function* FN = Function::Create(F->getFunctionType(), + GlobalValue::LinkOnceLinkage, + "malloc_llvm_bounce", &M); + BasicBlock* bb = BasicBlock::Create("entry",FN); Instruction* c = CastInst::createIntegerCast( FN->arg_begin(), Type::Int32Ty, false, "c", bb); Instruction* a = new MallocInst(Type::Int8Ty, c, "m", bb); - new ReturnInst(a, bb); + ReturnInst::Create(a, bb); ++NumBounce; NumBounceSites += F->getNumUses(); F->replaceAllUsesWith(FN); diff --git a/lib/Transforms/IPO/LowerSetJmp.cpp b/lib/Transforms/IPO/LowerSetJmp.cpp index d4b8454..2db8257 100644 --- a/lib/Transforms/IPO/LowerSetJmp.cpp +++ b/lib/Transforms/IPO/LowerSetJmp.cpp @@ -268,7 +268,7 @@ void LowerSetJmp::TransformLongJmpCall(CallInst* Inst) SmallVector<Value *, 2> Args; Args.push_back(CI); Args.push_back(Inst->getOperand(2)); - new CallInst(ThrowLongJmp, Args.begin(), Args.end(), "", Inst); + CallInst::Create(ThrowLongJmp, Args.begin(), Args.end(), "", Inst); SwitchValuePair& SVP = SwitchValMap[Inst->getParent()->getParent()]; @@ -276,7 +276,7 @@ void LowerSetJmp::TransformLongJmpCall(CallInst* Inst) // we should branch to the basic block that determines if this longjmp // is applicable here. Otherwise, issue an unwind. if (SVP.first) - new BranchInst(SVP.first->getParent(), Inst); + BranchInst::Create(SVP.first->getParent(), Inst); else new UnwindInst(Inst); @@ -311,7 +311,7 @@ AllocaInst* LowerSetJmp::GetSetJmpMap(Function* Func) // Fill in the alloca and call to initialize the SJ map. const Type *SBPTy = PointerType::getUnqual(Type::Int8Ty); AllocaInst* Map = new AllocaInst(SBPTy, 0, "SJMap", Inst); - new CallInst(InitSJMap, Map, "", Inst); + CallInst::Create(InitSJMap, Map, "", Inst); return SJMap[Func] = Map; } @@ -324,7 +324,7 @@ BasicBlock* LowerSetJmp::GetRethrowBB(Function* Func) // The basic block we're going to jump to if we need to rethrow the // exception. - BasicBlock* Rethrow = new BasicBlock("RethrowExcept", Func); + BasicBlock* Rethrow = BasicBlock::Create("RethrowExcept", Func); // Fill in the "Rethrow" BB with a call to rethrow the exception. This // is the last instruction in the BB since at this point the runtime @@ -340,7 +340,7 @@ LowerSetJmp::SwitchValuePair LowerSetJmp::GetSJSwitch(Function* Func, { if (SwitchValMap[Func].first) return SwitchValMap[Func]; - BasicBlock* LongJmpPre = new BasicBlock("LongJmpBlkPre", Func); + BasicBlock* LongJmpPre = BasicBlock::Create("LongJmpBlkPre", Func); BasicBlock::InstListType& LongJmpPreIL = LongJmpPre->getInstList(); // Keep track of the preliminary basic block for some of the other @@ -348,24 +348,24 @@ LowerSetJmp::SwitchValuePair LowerSetJmp::GetSJSwitch(Function* Func, PrelimBBMap[Func] = LongJmpPre; // Grab the exception. - CallInst* Cond = new CallInst(IsLJException, "IsLJExcept"); + CallInst* Cond = CallInst::Create(IsLJException, "IsLJExcept"); LongJmpPreIL.push_back(Cond); // The "decision basic block" gets the number associated with the // setjmp call returning to switch on and the value returned by // longjmp. - BasicBlock* DecisionBB = new BasicBlock("LJDecisionBB", Func); + BasicBlock* DecisionBB = BasicBlock::Create("LJDecisionBB", Func); BasicBlock::InstListType& DecisionBBIL = DecisionBB->getInstList(); - new BranchInst(DecisionBB, Rethrow, Cond, LongJmpPre); + BranchInst::Create(DecisionBB, Rethrow, Cond, LongJmpPre); // Fill in the "decision" basic block. - CallInst* LJVal = new CallInst(GetLJValue, "LJVal"); + CallInst* LJVal = CallInst::Create(GetLJValue, "LJVal"); DecisionBBIL.push_back(LJVal); - CallInst* SJNum = new CallInst(TryCatchLJ, GetSetJmpMap(Func), "SJNum"); + CallInst* SJNum = CallInst::Create(TryCatchLJ, GetSetJmpMap(Func), "SJNum"); DecisionBBIL.push_back(SJNum); - SwitchInst* SI = new SwitchInst(SJNum, Rethrow, 0, DecisionBB); + SwitchInst* SI = SwitchInst::Create(SJNum, Rethrow, 0, DecisionBB); return SwitchValMap[Func] = SwitchValuePair(SI, LJVal); } @@ -386,7 +386,7 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst) make_vector<Value*>(GetSetJmpMap(Func), BufPtr, ConstantInt::get(Type::Int32Ty, SetJmpIDMap[Func]++), 0); - new CallInst(AddSJToMap, Args.begin(), Args.end(), "", Inst); + CallInst::Create(AddSJToMap, Args.begin(), Args.end(), "", Inst); // We are guaranteed that there are no values live across basic blocks // (because we are "not in SSA form" yet), but there can still be values live @@ -428,7 +428,7 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst) // This PHI node will be in the new block created from the // splitBasicBlock call. - PHINode* PHI = new PHINode(Type::Int32Ty, "SetJmpReturn", Inst); + PHINode* PHI = PHINode::Create(Type::Int32Ty, "SetJmpReturn", Inst); // Coming from a call to setjmp, the return is 0. PHI->addIncoming(ConstantInt::getNullValue(Type::Int32Ty), ABlock); @@ -474,9 +474,9 @@ void LowerSetJmp::visitCallInst(CallInst& CI) // Construct the new "invoke" instruction. TerminatorInst* Term = OldBB->getTerminator(); std::vector<Value*> Params(CI.op_begin() + 1, CI.op_end()); - InvokeInst* II = new - InvokeInst(CI.getCalledValue(), NewBB, PrelimBBMap[Func], - Params.begin(), Params.end(), CI.getName(), Term); + InvokeInst* II = + InvokeInst::Create(CI.getCalledValue(), NewBB, PrelimBBMap[Func], + Params.begin(), Params.end(), CI.getName(), Term); II->setCallingConv(CI.getCallingConv()); II->setParamAttrs(CI.getParamAttrs()); @@ -507,15 +507,15 @@ void LowerSetJmp::visitInvokeInst(InvokeInst& II) BasicBlock* ExceptBB = II.getUnwindDest(); Function* Func = BB->getParent(); - BasicBlock* NewExceptBB = new BasicBlock("InvokeExcept", Func); + BasicBlock* NewExceptBB = BasicBlock::Create("InvokeExcept", Func); BasicBlock::InstListType& InstList = NewExceptBB->getInstList(); // If this is a longjmp exception, then branch to the preliminary BB of // the longjmp exception handling. Otherwise, go to the old exception. - CallInst* IsLJExcept = new CallInst(IsLJException, "IsLJExcept"); + CallInst* IsLJExcept = CallInst::Create(IsLJException, "IsLJExcept"); InstList.push_back(IsLJExcept); - new BranchInst(PrelimBBMap[Func], ExceptBB, IsLJExcept, NewExceptBB); + BranchInst::Create(PrelimBBMap[Func], ExceptBB, IsLJExcept, NewExceptBB); II.setUnwindDest(NewExceptBB); ++InvokesTransformed; @@ -525,14 +525,14 @@ void LowerSetJmp::visitInvokeInst(InvokeInst& II) // function. void LowerSetJmp::visitReturnInst(ReturnInst &RI) { Function* Func = RI.getParent()->getParent(); - new CallInst(DestroySJMap, GetSetJmpMap(Func), "", &RI); + CallInst::Create(DestroySJMap, GetSetJmpMap(Func), "", &RI); } // visitUnwindInst - We want to destroy the setjmp map upon exit from the // function. void LowerSetJmp::visitUnwindInst(UnwindInst &UI) { Function* Func = UI.getParent()->getParent(); - new CallInst(DestroySJMap, GetSetJmpMap(Func), "", &UI); + CallInst::Create(DestroySJMap, GetSetJmpMap(Func), "", &UI); } ModulePass *llvm::createLowerSetJmpPass() { diff --git a/lib/Transforms/IPO/PruneEH.cpp b/lib/Transforms/IPO/PruneEH.cpp index 46e1128..1b9aefc 100644 --- a/lib/Transforms/IPO/PruneEH.cpp +++ b/lib/Transforms/IPO/PruneEH.cpp @@ -158,8 +158,8 @@ bool PruneEH::SimplifyFunction(Function *F) { if (II->doesNotThrow()) { SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end()); // Insert a call instruction before the invoke. - CallInst *Call = new CallInst(II->getCalledValue(), - Args.begin(), Args.end(), "", II); + CallInst *Call = CallInst::Create(II->getCalledValue(), + Args.begin(), Args.end(), "", II); Call->takeName(II); Call->setCallingConv(II->getCallingConv()); Call->setParamAttrs(II->getParamAttrs()); @@ -172,7 +172,7 @@ bool PruneEH::SimplifyFunction(Function *F) { // Insert a branch to the normal destination right before the // invoke. - new BranchInst(II->getNormalDest(), II); + BranchInst::Create(II->getNormalDest(), II); // Finally, delete the invoke instruction! BB->getInstList().pop_back(); diff --git a/lib/Transforms/IPO/RaiseAllocations.cpp b/lib/Transforms/IPO/RaiseAllocations.cpp index e284009..1f12fcf 100644 --- a/lib/Transforms/IPO/RaiseAllocations.cpp +++ b/lib/Transforms/IPO/RaiseAllocations.cpp @@ -175,7 +175,7 @@ bool RaiseAllocations::runOnModule(Module &M) { // If the old instruction was an invoke, add an unconditional branch // before the invoke, which will become the new terminator. if (InvokeInst *II = dyn_cast<InvokeInst>(I)) - new BranchInst(II->getNormalDest(), I); + BranchInst::Create(II->getNormalDest(), I); // Delete the old call site MI->getParent()->getInstList().erase(I); @@ -227,7 +227,7 @@ bool RaiseAllocations::runOnModule(Module &M) { // If the old instruction was an invoke, add an unconditional branch // before the invoke, which will become the new terminator. if (InvokeInst *II = dyn_cast<InvokeInst>(I)) - new BranchInst(II->getNormalDest(), I); + BranchInst::Create(II->getNormalDest(), I); // Delete the old call site if (I->getType() != Type::VoidTy) diff --git a/lib/Transforms/IPO/SimplifyLibCalls.cpp b/lib/Transforms/IPO/SimplifyLibCalls.cpp index 945eb90..bbfd1d2 100644 --- a/lib/Transforms/IPO/SimplifyLibCalls.cpp +++ b/lib/Transforms/IPO/SimplifyLibCalls.cpp @@ -430,7 +430,7 @@ struct VISIBILITY_HIDDEN ExitInMainOptimization : public LibCallOptimization { // Create a return instruction that we'll replace the call with. // Note that the argument of the return is the argument of the call // instruction. - new ReturnInst(ci->getOperand(1), ci); + ReturnInst::Create(ci->getOperand(1), ci); // Split the block at the call instruction which places it in a new // basic block. @@ -496,13 +496,13 @@ public: // We need to find the end of the destination string. That's where the // memory is to be moved to. We just generate a call to strlen. - CallInst *DstLen = new CallInst(SLC.get_strlen(), Dst, - Dst->getName()+".len", CI); + CallInst *DstLen = CallInst::Create(SLC.get_strlen(), Dst, + Dst->getName()+".len", CI); // Now that we have the destination's length, we must index into the // destination's pointer to get the actual memcpy destination (end of // the string .. we're concatenating). - Dst = new GetElementPtrInst(Dst, DstLen, Dst->getName()+".indexed", CI); + Dst = GetElementPtrInst::Create(Dst, DstLen, Dst->getName()+".indexed", CI); // We have enough information to now generate the memcpy call to // do the concatenation for us. @@ -511,7 +511,7 @@ public: ConstantInt::get(SLC.getIntPtrType(), SrcStr.size()+1), // copy nul byte. ConstantInt::get(Type::Int32Ty, 1) // alignment }; - new CallInst(SLC.get_memcpy(), Vals, Vals + 4, "", CI); + CallInst::Create(SLC.get_memcpy(), Vals, Vals + 4, "", CI); return ReplaceCallWith(CI, Dst); } @@ -551,8 +551,8 @@ public: CI->getOperand(2), ConstantInt::get(SLC.getIntPtrType(), Str.size()+1) }; - return ReplaceCallWith(CI, new CallInst(SLC.get_memchr(), Args, Args + 3, - CI->getName(), CI)); + return ReplaceCallWith(CI, CallInst::Create(SLC.get_memchr(), Args, Args + 3, + CI->getName(), CI)); } // strchr can find the nul character. @@ -575,9 +575,9 @@ public: // strchr(s+n,c) -> gep(s+n+i,c) // (if c is a constant integer and s is a constant string) Value *Idx = ConstantInt::get(Type::Int64Ty, i); - Value *GEP = new GetElementPtrInst(CI->getOperand(1), Idx, - CI->getOperand(1)->getName() + - ".strchr", CI); + Value *GEP = GetElementPtrInst::Create(CI->getOperand(1), Idx, + CI->getOperand(1)->getName() + + ".strchr", CI); return ReplaceCallWith(CI, GEP); } } StrChrOptimizer; @@ -754,7 +754,7 @@ public: ConstantInt::get(SLC.getIntPtrType(), SrcStr.size()+1), ConstantInt::get(Type::Int32Ty, 1) // alignment }; - new CallInst(SLC.get_memcpy(), MemcpyOps, MemcpyOps + 4, "", CI); + CallInst::Create(SLC.get_memcpy(), MemcpyOps, MemcpyOps + 4, "", CI); return ReplaceCallWith(CI, Dst); } @@ -900,8 +900,8 @@ struct VISIBILITY_HIDDEN memcmpOptimization : public LibCallOptimization { Value *D1 = BinaryOperator::createSub(S1V1, S2V1, CI->getName()+".d1", CI); Constant *One = ConstantInt::get(Type::Int32Ty, 1); - Value *G1 = new GetElementPtrInst(Op1Cast, One, "next1v", CI); - Value *G2 = new GetElementPtrInst(Op2Cast, One, "next2v", CI); + Value *G1 = GetElementPtrInst::Create(Op1Cast, One, "next1v", CI); + Value *G2 = GetElementPtrInst::Create(Op2Cast, One, "next2v", CI); Value *S1V2 = new LoadInst(G1, LHS->getName()+".val2", CI); Value *S2V2 = new LoadInst(G2, RHS->getName()+".val2", CI); Value *D2 = BinaryOperator::createSub(S1V2, S2V2, @@ -946,7 +946,7 @@ public: CI->getOperand(1), CI->getOperand(2), CI->getOperand(3), ConstantInt::get(Type::Int32Ty, 1) // align = 1 always. }; - new CallInst(SLC.get_memcpy(), MemcpyOps, MemcpyOps + 4, "", CI); + CallInst::Create(SLC.get_memcpy(), MemcpyOps, MemcpyOps + 4, "", CI); // memcpy always returns the destination return ReplaceCallWith(CI, CI->getOperand(1)); } @@ -1162,8 +1162,8 @@ public: Ty==Type::FloatTy ? APFloat(1.0f) : APFloat(1.0))); } else if (Op2->isExactlyValue(0.5)) { // pow(x,0.5) -> sqrt(x) - CallInst* sqrt_inst = new CallInst(SLC.get_sqrt(), base, - ci->getName()+".pow",ci); + CallInst* sqrt_inst = CallInst::Create(SLC.get_sqrt(), base, + ci->getName()+".pow",ci); return ReplaceCallWith(ci, sqrt_inst); } else if (Op2->isExactlyValue(1.0)) { // pow(x,1.0) -> x @@ -1220,7 +1220,7 @@ public: if (FormatStr.size() == 1) { // Turn this into a putchar call, even if it is a %. Value *V = ConstantInt::get(Type::Int32Ty, FormatStr[0]); - new CallInst(SLC.get_putchar(), V, "", CI); + CallInst::Create(SLC.get_putchar(), V, "", CI); if (CI->use_empty()) return ReplaceCallWith(CI, 0); return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1)); } @@ -1240,7 +1240,7 @@ public: CI->getParent()->getParent()->getParent()); // Cast GV to be a pointer to char. GV = ConstantExpr::getBitCast(GV, PointerType::getUnqual(Type::Int8Ty)); - new CallInst(SLC.get_puts(), GV, "", CI); + CallInst::Create(SLC.get_puts(), GV, "", CI); if (CI->use_empty()) return ReplaceCallWith(CI, 0); // The return value from printf includes the \n we just removed, so +1. @@ -1264,8 +1264,8 @@ public: return false; // printf("%s\n",str) -> puts(str) - new CallInst(SLC.get_puts(), CastToCStr(CI->getOperand(2), CI), - CI->getName(), CI); + CallInst::Create(SLC.get_puts(), CastToCStr(CI->getOperand(2), CI), + CI->getName(), CI); return ReplaceCallWith(CI, 0); case 'c': { // printf("%c",c) -> putchar(c) @@ -1279,7 +1279,7 @@ public: V = CastInst::createZExtOrBitCast(V, Type::Int32Ty, CI->getName()+".int", CI); - new CallInst(SLC.get_putchar(), V, "", CI); + CallInst::Create(SLC.get_putchar(), V, "", CI); return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1)); } } @@ -1331,7 +1331,7 @@ public: ConstantInt::get(SLC.getIntPtrType(), 1), CI->getOperand(1) }; - new CallInst(SLC.get_fwrite(FILEty), FWriteArgs, FWriteArgs + 4, CI->getName(), CI); + CallInst::Create(SLC.get_fwrite(FILEty), FWriteArgs, FWriteArgs + 4, CI->getName(), CI); return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), FormatStr.size())); } @@ -1351,7 +1351,7 @@ public: SmallVector<Value *, 2> Args; Args.push_back(C); Args.push_back(CI->getOperand(1)); - new CallInst(SLC.get_fputc(FILETy), Args.begin(), Args.end(), "", CI); + CallInst::Create(SLC.get_fputc(FILETy), Args.begin(), Args.end(), "", CI); return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1)); } case 's': { @@ -1366,8 +1366,8 @@ public: SmallVector<Value *, 2> Args; Args.push_back(CastToCStr(CI->getOperand(3), CI)); Args.push_back(CI->getOperand(1)); - new CallInst(SLC.get_fputs(FILETy), Args.begin(), - Args.end(), CI->getName(), CI); + CallInst::Create(SLC.get_fputs(FILETy), Args.begin(), + Args.end(), CI->getName(), CI); return ReplaceCallWith(CI, 0); } default: @@ -1418,7 +1418,7 @@ public: FormatStr.size()+1), // Copy the nul byte. ConstantInt::get(Type::Int32Ty, 1) }; - new CallInst(SLC.get_memcpy(), MemCpyArgs, MemCpyArgs + 4, "", CI); + CallInst::Create(SLC.get_memcpy(), MemCpyArgs, MemCpyArgs + 4, "", CI); return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), FormatStr.size())); } @@ -1434,18 +1434,18 @@ public: Value *V = CastInst::createTruncOrBitCast(CI->getOperand(3), Type::Int8Ty, "char", CI); new StoreInst(V, CI->getOperand(1), CI); - Value *Ptr = new GetElementPtrInst(CI->getOperand(1), - ConstantInt::get(Type::Int32Ty, 1), - CI->getOperand(1)->getName()+".end", - CI); + Value *Ptr = GetElementPtrInst::Create(CI->getOperand(1), + ConstantInt::get(Type::Int32Ty, 1), + CI->getOperand(1)->getName()+".end", + CI); new StoreInst(ConstantInt::get(Type::Int8Ty,0), Ptr, CI); return ReplaceCallWith(CI, ConstantInt::get(Type::Int32Ty, 1)); } case 's': { // sprintf(dest,"%s",str) -> llvm.memcpy(dest, str, strlen(str)+1, 1) - Value *Len = new CallInst(SLC.get_strlen(), - CastToCStr(CI->getOperand(3), CI), - CI->getOperand(3)->getName()+".len", CI); + Value *Len = CallInst::Create(SLC.get_strlen(), + CastToCStr(CI->getOperand(3), CI), + CI->getOperand(3)->getName()+".len", CI); Value *UnincLen = Len; Len = BinaryOperator::createAdd(Len, ConstantInt::get(Len->getType(), 1), Len->getName()+"1", CI); @@ -1455,7 +1455,7 @@ public: Len, ConstantInt::get(Type::Int32Ty, 1) }; - new CallInst(SLC.get_memcpy(), MemcpyArgs, MemcpyArgs + 4, "", CI); + CallInst::Create(SLC.get_memcpy(), MemcpyArgs, MemcpyArgs + 4, "", CI); // The strlen result is the unincremented number of bytes in the string. if (!CI->use_empty()) { @@ -1507,7 +1507,7 @@ public: ConstantInt::get(SLC.getIntPtrType(), 1), CI->getOperand(2) }; - new CallInst(SLC.get_fwrite(FILETy), FWriteParms, FWriteParms + 4, "", CI); + CallInst::Create(SLC.get_fwrite(FILETy), FWriteParms, FWriteParms + 4, "", CI); return ReplaceCallWith(CI, 0); // Known to have no uses (see above). } } FPutsOptimizer; @@ -1555,7 +1555,7 @@ public: Args.push_back(new ZExtInst(Val, Type::Int32Ty, Val->getName()+".int", CI)); Args.push_back(CI->getOperand(4)); const Type *FILETy = CI->getOperand(4)->getType(); - new CallInst(SLC.get_fputc(FILETy), Args.begin(), Args.end(), "", CI); + CallInst::Create(SLC.get_fputc(FILETy), Args.begin(), Args.end(), "", CI); return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1)); } return false; @@ -1715,7 +1715,7 @@ public: ArgType, NULL); Value *V = CastInst::createIntegerCast(TheCall->getOperand(1), ArgType, false/*ZExt*/, "tmp", TheCall); - Value *V2 = new CallInst(F, V, "tmp", TheCall); + Value *V2 = CallInst::Create(F, V, "tmp", TheCall); V2 = CastInst::createIntegerCast(V2, Type::Int32Ty, false/*ZExt*/, "tmp", TheCall); V2 = BinaryOperator::createAdd(V2, ConstantInt::get(Type::Int32Ty, 1), @@ -1723,8 +1723,8 @@ public: Value *Cond = new ICmpInst(ICmpInst::ICMP_EQ, V, Constant::getNullValue(V->getType()), "tmp", TheCall); - V2 = new SelectInst(Cond, ConstantInt::get(Type::Int32Ty, 0), V2, - TheCall->getName(), TheCall); + V2 = SelectInst::Create(Cond, ConstantInt::get(Type::Int32Ty, 0), V2, + TheCall->getName(), TheCall); return ReplaceCallWith(TheCall, V2); } } FFSOptimizer; @@ -1773,8 +1773,8 @@ struct UnaryDoubleFPOptimizer : public LibCallOptimization { Constant *(SimplifyLibCalls::*FP)()){ if (FPExtInst *Cast = dyn_cast<FPExtInst>(CI->getOperand(1))) if (Cast->getOperand(0)->getType() == Type::FloatTy) { - Value *New = new CallInst((SLC.*FP)(), Cast->getOperand(0), - CI->getName(), CI); + Value *New = CallInst::Create((SLC.*FP)(), Cast->getOperand(0), + CI->getName(), CI); New = new FPExtInst(New, Type::DoubleTy, CI->getName(), CI); CI->replaceAllUsesWith(New); CI->eraseFromParent(); diff --git a/lib/Transforms/IPO/StructRetPromotion.cpp b/lib/Transforms/IPO/StructRetPromotion.cpp index 1e51cb9..80952b7 100644 --- a/lib/Transforms/IPO/StructRetPromotion.cpp +++ b/lib/Transforms/IPO/StructRetPromotion.cpp @@ -116,14 +116,14 @@ bool SRETPromotion::PromoteReturn(CallGraphNode *CGN) { SmallVector<Value*, 2> GEPIdx; GEPIdx.push_back(ConstantInt::get(Type::Int32Ty, 0)); GEPIdx.push_back(ConstantInt::get(Type::Int32Ty, idx)); - Value *NGEPI = new GetElementPtrInst(TheAlloca, GEPIdx.begin(), - GEPIdx.end(), - "mrv.gep", I); + Value *NGEPI = GetElementPtrInst::Create(TheAlloca, GEPIdx.begin(), + GEPIdx.end(), + "mrv.gep", I); Value *NV = new LoadInst(NGEPI, "mrv.ld", I); RetVals.push_back(NV); } - ReturnInst *NR = new ReturnInst(&RetVals[0], RetVals.size(), I); + ReturnInst *NR = ReturnInst::Create(&RetVals[0], RetVals.size(), I); I->replaceAllUsesWith(NR); I->eraseFromParent(); } @@ -222,7 +222,7 @@ Function *SRETPromotion::cloneFunctionBody(Function *F, } FunctionType *NFTy = FunctionType::get(STy, Params, FTy->isVarArg()); - Function *NF = new Function(NFTy, F->getLinkage(), F->getName()); + Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName()); NF->setCallingConv(F->getCallingConv()); NF->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end())); F->getParent()->getFunctionList().insert(F, NF); @@ -283,12 +283,12 @@ void SRETPromotion::updateCallSites(Function *F, Function *NF) { // Build new call instruction. Instruction *New; if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { - New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), - Args.begin(), Args.end(), "", Call); + New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(), + Args.begin(), Args.end(), "", Call); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); cast<InvokeInst>(New)->setParamAttrs(NewPAL); } else { - New = new CallInst(NF, Args.begin(), Args.end(), "", Call); + New = CallInst::Create(NF, Args.begin(), Args.end(), "", Call); cast<CallInst>(New)->setCallingConv(CS.getCallingConv()); cast<CallInst>(New)->setParamAttrs(NewPAL); if (cast<CallInst>(Call)->isTailCall()) diff --git a/lib/Transforms/Instrumentation/ProfilingUtils.cpp b/lib/Transforms/Instrumentation/ProfilingUtils.cpp index fd31cec..4617fbb 100644 --- a/lib/Transforms/Instrumentation/ProfilingUtils.cpp +++ b/lib/Transforms/Instrumentation/ProfilingUtils.cpp @@ -55,8 +55,8 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName, } Args[3] = ConstantInt::get(Type::Int32Ty, NumElements); - Instruction *InitCall = new CallInst(InitFn, Args.begin(), Args.end(), - "newargc", InsertPos); + Instruction *InitCall = CallInst::Create(InitFn, Args.begin(), Args.end(), + "newargc", InsertPos); // If argc or argv are not available in main, just pass null values in. Function::arg_iterator AI; diff --git a/lib/Transforms/Instrumentation/RSProfiling.cpp b/lib/Transforms/Instrumentation/RSProfiling.cpp index d81097b..e7e8efe 100644 --- a/lib/Transforms/Instrumentation/RSProfiling.cpp +++ b/lib/Transforms/Instrumentation/RSProfiling.cpp @@ -216,9 +216,9 @@ void GlobalRandomCounter::ProcessChoicePoint(BasicBlock* bb) { //reset counter BasicBlock* oldnext = t->getSuccessor(0); - BasicBlock* resetblock = new BasicBlock("reset", oldnext->getParent(), - oldnext); - TerminatorInst* t2 = new BranchInst(oldnext, resetblock); + BasicBlock* resetblock = BasicBlock::Create("reset", oldnext->getParent(), + oldnext); + TerminatorInst* t2 = BranchInst::Create(oldnext, resetblock); t->setSuccessor(0, resetblock); new StoreInst(ResetValue, Counter, t2); ReplacePhiPred(oldnext, bb, resetblock); @@ -291,9 +291,9 @@ void GlobalRandomCounterOpt::ProcessChoicePoint(BasicBlock* bb) { //reset counter BasicBlock* oldnext = t->getSuccessor(0); - BasicBlock* resetblock = new BasicBlock("reset", oldnext->getParent(), - oldnext); - TerminatorInst* t2 = new BranchInst(oldnext, resetblock); + BasicBlock* resetblock = BasicBlock::Create("reset", oldnext->getParent(), + oldnext); + TerminatorInst* t2 = BranchInst::Create(oldnext, resetblock); t->setSuccessor(0, resetblock); new StoreInst(ResetValue, AI, t2); ReplacePhiPred(oldnext, bb, resetblock); @@ -311,7 +311,7 @@ void CycleCounter::PrepFunction(Function* F) {} void CycleCounter::ProcessChoicePoint(BasicBlock* bb) { BranchInst* t = cast<BranchInst>(bb->getTerminator()); - CallInst* c = new CallInst(F, "rdcc", t); + CallInst* c = CallInst::Create(F, "rdcc", t); BinaryOperator* b = BinaryOperator::createAnd(c, ConstantInt::get(Type::Int64Ty, rm), "mrdcc", t); @@ -375,8 +375,8 @@ Value* ProfilerRS::Translate(Value* v) { if (bb == &bb->getParent()->getEntryBlock()) TransCache[bb] = bb; //don't translate entry block else - TransCache[bb] = new BasicBlock("dup_" + bb->getName(), bb->getParent(), - NULL); + TransCache[bb] = BasicBlock::Create("dup_" + bb->getName(), bb->getParent(), + NULL); return TransCache[bb]; } else if (Instruction* i = dyn_cast<Instruction>(v)) { //we have already translated this @@ -464,16 +464,16 @@ void ProfilerRS::ProcessBackEdge(BasicBlock* src, BasicBlock* dst, Function& F) //a: Function::iterator BBN = src; ++BBN; - BasicBlock* bbC = new BasicBlock("choice", &F, BBN); + BasicBlock* bbC = BasicBlock::Create("choice", &F, BBN); //ChoicePoints.insert(bbC); BBN = cast<BasicBlock>(Translate(src)); - BasicBlock* bbCp = new BasicBlock("choice", &F, ++BBN); + BasicBlock* bbCp = BasicBlock::Create("choice", &F, ++BBN); ChoicePoints.insert(bbCp); //b: - new BranchInst(cast<BasicBlock>(Translate(dst)), bbC); - new BranchInst(dst, cast<BasicBlock>(Translate(dst)), - ConstantInt::get(Type::Int1Ty, true), bbCp); + BranchInst::Create(cast<BasicBlock>(Translate(dst)), bbC); + BranchInst::Create(dst, cast<BasicBlock>(Translate(dst)), + ConstantInt::get(Type::Int1Ty, true), bbCp); //c: { TerminatorInst* iB = src->getTerminator(); @@ -527,10 +527,11 @@ bool ProfilerRS::runOnFunction(Function& F) { //oh, and add the edge from the reg2mem created entry node to the //duplicated second node TerminatorInst* T = F.getEntryBlock().getTerminator(); - ReplaceInstWithInst(T, new BranchInst(T->getSuccessor(0), - cast<BasicBlock>( - Translate(T->getSuccessor(0))), - ConstantInt::get(Type::Int1Ty, true))); + ReplaceInstWithInst(T, BranchInst::Create(T->getSuccessor(0), + cast<BasicBlock>( + Translate(T->getSuccessor(0))), + ConstantInt::get(Type::Int1Ty, + true))); //do whatever is needed now that the function is duplicated c->PrepFunction(&F); diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index ed9d930..d909d02 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -163,7 +163,7 @@ bool ADCE::deleteDeadInstructionsInLiveBlock(BasicBlock *BB) { /// successors it goes to. This eliminate a use of the condition as well. /// TerminatorInst *ADCE::convertToUnconditionalBranch(TerminatorInst *TI) { - BranchInst *NB = new BranchInst(TI->getSuccessor(0), TI); + BranchInst *NB = BranchInst::Create(TI->getSuccessor(0), TI); BasicBlock *BB = TI->getParent(); // Remove entries from PHI nodes to avoid confusing ourself later... @@ -325,8 +325,8 @@ bool ADCE::doADCE() { // node as a special case. // if (!AliveBlocks.count(&Func->front())) { - BasicBlock *NewEntry = new BasicBlock(); - new BranchInst(&Func->front(), NewEntry); + BasicBlock *NewEntry = BasicBlock::Create(); + BranchInst::Create(&Func->front(), NewEntry); Func->getBasicBlockList().push_front(NewEntry); AliveBlocks.insert(NewEntry); // This block is always alive! LiveSet.insert(NewEntry->getTerminator()); // The branch is live diff --git a/lib/Transforms/Scalar/GCSE.cpp b/lib/Transforms/Scalar/GCSE.cpp index d062297..39a1b25 100644 --- a/lib/Transforms/Scalar/GCSE.cpp +++ b/lib/Transforms/Scalar/GCSE.cpp @@ -192,7 +192,7 @@ void GCSE::ReplaceInstructionWith(Instruction *I, Value *V) { if (InvokeInst *II = dyn_cast<InvokeInst>(I)) { // Removing an invoke instruction requires adding a branch to the normal // destination and removing PHI node entries in the exception destination. - new BranchInst(II->getNormalDest(), II); + BranchInst::Create(II->getNormalDest(), II); II->getUnwindDest()->removePredecessor(II->getParent()); } diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp index 12ce286..c966311 100644 --- a/lib/Transforms/Scalar/GVN.cpp +++ b/lib/Transforms/Scalar/GVN.cpp @@ -793,8 +793,8 @@ Value *GVN::GetValueForBlock(BasicBlock *BB, LoadInst* orig, // Otherwise, the idom is the loop, so we need to insert a PHI node. Do so // now, then get values to fill in the incoming values for the PHI. - PHINode *PN = new PHINode(orig->getType(), orig->getName()+".rle", - BB->begin()); + PHINode *PN = PHINode::Create(orig->getType(), orig->getName()+".rle", + BB->begin()); PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB))); if (Phis.count(BB) == 0) @@ -1370,7 +1370,7 @@ bool GVN::processStore(StoreInst *SI, SmallVectorImpl<Instruction*> &toErase) { ConstantInt::get(Type::Int64Ty, Range.End-Range.Start), // size ConstantInt::get(Type::Int32Ty, Range.Alignment) // align }; - Value *C = new CallInst(MemSetF, Ops, Ops+4, "", InsertPt); + Value *C = CallInst::Create(MemSetF, Ops, Ops+4, "", InsertPt); DEBUG(cerr << "Replace stores:\n"; for (unsigned i = 0, e = Range.TheStores.size(); i != e; ++i) cerr << *Range.TheStores[i]; @@ -1568,7 +1568,7 @@ bool GVN::processMemCpy(MemCpyInst* M, MemCpyInst* MDep, args.push_back(M->getLength()); args.push_back(M->getAlignment()); - CallInst* C = new CallInst(MemCpyFun, args.begin(), args.end(), "", M); + CallInst* C = CallInst::Create(MemCpyFun, args.begin(), args.end(), "", M); MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>(); if (MD.getDependency(C) == MDep) { diff --git a/lib/Transforms/Scalar/GVNPRE.cpp b/lib/Transforms/Scalar/GVNPRE.cpp index 7d38dc7..3bd6bff 100644 --- a/lib/Transforms/Scalar/GVNPRE.cpp +++ b/lib/Transforms/Scalar/GVNPRE.cpp @@ -904,10 +904,10 @@ Value* GVNPRE::phi_translate(Value* V, BasicBlock* pred, BasicBlock* succ) { newVal = new ShuffleVectorInst(newOp1, newOp2, newOp3, S->getName()+".expr"); else if (InsertElementInst* I = dyn_cast<InsertElementInst>(U)) - newVal = new InsertElementInst(newOp1, newOp2, newOp3, - I->getName()+".expr"); + newVal = InsertElementInst::Create(newOp1, newOp2, newOp3, + I->getName()+".expr"); else if (SelectInst* I = dyn_cast<SelectInst>(U)) - newVal = new SelectInst(newOp1, newOp2, newOp3, I->getName()+".expr"); + newVal = SelectInst::Create(newOp1, newOp2, newOp3, I->getName()+".expr"); uint32_t v = VN.lookup_or_add(newVal); @@ -947,9 +947,10 @@ Value* GVNPRE::phi_translate(Value* V, BasicBlock* pred, BasicBlock* succ) { } if (newOp1 != U->getPointerOperand() || changed_idx) { - Instruction* newVal = new GetElementPtrInst(newOp1, - newIdx.begin(), newIdx.end(), - U->getName()+".expr"); + Instruction* newVal = + GetElementPtrInst::Create(newOp1, + newIdx.begin(), newIdx.end(), + U->getName()+".expr"); uint32_t v = VN.lookup_or_add(newVal); @@ -1667,24 +1668,23 @@ void GVNPRE::insertion_pre(Value* e, BasicBlock* BB, newVal = new ShuffleVectorInst(s1, s2, s3, S->getName()+".gvnpre", (*PI)->getTerminator()); else if (InsertElementInst* S = dyn_cast<InsertElementInst>(U)) - newVal = new InsertElementInst(s1, s2, s3, S->getName()+".gvnpre", - (*PI)->getTerminator()); + newVal = InsertElementInst::Create(s1, s2, s3, S->getName()+".gvnpre", + (*PI)->getTerminator()); else if (ExtractElementInst* S = dyn_cast<ExtractElementInst>(U)) newVal = new ExtractElementInst(s1, s2, S->getName()+".gvnpre", (*PI)->getTerminator()); else if (SelectInst* S = dyn_cast<SelectInst>(U)) - newVal = new SelectInst(s1, s2, s3, S->getName()+".gvnpre", - (*PI)->getTerminator()); + newVal = SelectInst::Create(s1, s2, s3, S->getName()+".gvnpre", + (*PI)->getTerminator()); else if (CastInst* C = dyn_cast<CastInst>(U)) newVal = CastInst::create(C->getOpcode(), s1, C->getType(), C->getName()+".gvnpre", (*PI)->getTerminator()); else if (GetElementPtrInst* G = dyn_cast<GetElementPtrInst>(U)) - newVal = new GetElementPtrInst(s1, sVarargs.begin(), sVarargs.end(), - G->getName()+".gvnpre", - (*PI)->getTerminator()); - - + newVal = GetElementPtrInst::Create(s1, sVarargs.begin(), sVarargs.end(), + G->getName()+".gvnpre", + (*PI)->getTerminator()); + VN.add(newVal, VN.lookup(U)); ValueNumberedSet& predAvail = availableOut[*PI]; @@ -1705,7 +1705,7 @@ void GVNPRE::insertion_pre(Value* e, BasicBlock* BB, for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) { if (p == 0) - p = new PHINode(avail[*PI]->getType(), "gvnpre-join", BB->begin()); + p = PHINode::Create(avail[*PI]->getType(), "gvnpre-join", BB->begin()); p->addIncoming(avail[*PI], *PI); } diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 44c3d78..4305422 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -145,8 +145,8 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN, Value *AddedVal = GEPI->getOperand(1); // Insert a new integer PHI node into the top of the block. - PHINode *NewPhi = new PHINode(AddedVal->getType(), - PN->getName()+".rec", PN); + PHINode *NewPhi = PHINode::Create(AddedVal->getType(), + PN->getName()+".rec", PN); NewPhi->addIncoming(Constant::getNullValue(NewPhi->getType()), Preheader); // Create the new add instruction. @@ -181,7 +181,7 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN, Value *Idx[2]; Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = NewAdd; - GetElementPtrInst *NGEPI = new GetElementPtrInst( + GetElementPtrInst *NGEPI = GetElementPtrInst::Create( NCE, Idx, Idx + 2, GEPI->getName(), GEPI); SE->deleteValueFromRecords(GEPI); @@ -200,8 +200,8 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN, BasicBlock::iterator InsertPos = PN; ++InsertPos; while (isa<PHINode>(InsertPos)) ++InsertPos; Value *PreInc = - new GetElementPtrInst(PN->getIncomingValue(PreheaderIdx), - NewPhi, "", InsertPos); + GetElementPtrInst::Create(PN->getIncomingValue(PreheaderIdx), + NewPhi, "", InsertPos); PreInc->takeName(PN); PN->replaceAllUsesWith(PreInc); } diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 9e069fd..beeee49 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -1811,8 +1811,8 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, uint64_t DemandedElts, } Instruction *New = - new InsertElementInst(UndefValue::get(II->getType()), TmpV, 0U, - II->getName()); + InsertElementInst::Create(UndefValue::get(II->getType()), TmpV, 0U, + II->getName()); InsertNewInstBefore(New, *II); AddSoonDeadInstToWorklist(*II, 0); return New; @@ -2007,8 +2007,8 @@ static Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI, Value *SelectTrueVal = FoldOperationIntoSelectOperand(Op, TV, IC); Value *SelectFalseVal = FoldOperationIntoSelectOperand(Op, FV, IC); - return new SelectInst(SI->getCondition(), SelectTrueVal, - SelectFalseVal); + return SelectInst::Create(SI->getCondition(), SelectTrueVal, + SelectFalseVal); } return 0; } @@ -2048,7 +2048,7 @@ Instruction *InstCombiner::FoldOpIntoPhi(Instruction &I) { } // Okay, we can do the transformation: create the new PHI node. - PHINode *NewPN = new PHINode(I.getType(), ""); + PHINode *NewPN = PHINode::Create(I.getType(), ""); NewPN->reserveOperandSpace(PN->getNumOperands()/2); InsertNewInstBefore(NewPN, *PN); NewPN->takeName(PN); @@ -2366,7 +2366,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { cast<PointerType>(CI->getOperand(0)->getType())->getAddressSpace(); Value *I2 = InsertBitCastBefore(CI->getOperand(0), PointerType::get(Type::Int8Ty, AS), I); - I2 = InsertNewInstBefore(new GetElementPtrInst(I2, Other, "ctg2"), I); + I2 = InsertNewInstBefore(GetElementPtrInst::Create(I2, Other, "ctg2"), I); return new PtrToIntInst(I2, CI->getType()); } } @@ -2388,10 +2388,10 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) { // We check both true and false select arguments for a matching subtract. if (match(FV, m_Zero()) && match(TV, m_Sub(m_Value(N), m_Value(A))) && A == Other) // Fold the add into the true select value. - return new SelectInst(SI->getCondition(), N, A); + return SelectInst::Create(SI->getCondition(), N, A); if (match(TV, m_Zero()) && match(FV, m_Sub(m_Value(N), m_Value(A))) && A == Other) // Fold the add into the false select value. - return new SelectInst(SI->getCondition(), A, N); + return SelectInst::Create(SI->getCondition(), A, N); } } @@ -2875,7 +2875,7 @@ Instruction *InstCombiner::visitUDiv(BinaryOperator &I) { FSI = InsertNewInstBefore(FSI, I); // construct the select instruction and return it. - return new SelectInst(SI->getOperand(0), TSI, FSI, SI->getName()); + return SelectInst::Create(SI->getOperand(0), TSI, FSI, SI->getName()); } } return 0; @@ -3049,7 +3049,7 @@ Instruction *InstCombiner::visitURem(BinaryOperator &I) { BinaryOperator::createAnd(Op0, SubOne(STO), SI->getName()+".t"), I); Value *FalseAnd = InsertNewInstBefore( BinaryOperator::createAnd(Op0, SubOne(SFO), SI->getName()+".f"), I); - return new SelectInst(SI->getOperand(0), TrueAnd, FalseAnd); + return SelectInst::Create(SI->getOperand(0), TrueAnd, FalseAnd); } } } @@ -4021,7 +4021,7 @@ Instruction *InstCombiner::MatchBSwap(BinaryOperator &I) { const Type *Tys[] = { ITy }; Module *M = I.getParent()->getParent()->getParent(); Function *F = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1); - return new CallInst(F, V); + return CallInst::Create(F, V); } @@ -4957,7 +4957,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { } if (Op1) - return new SelectInst(LHSI->getOperand(0), Op1, Op2); + return SelectInst::Create(LHSI->getOperand(0), Op1, Op2); break; } } @@ -5257,7 +5257,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { } if (Op1) - return new SelectInst(LHSI->getOperand(0), Op1, Op2); + return SelectInst::Create(LHSI->getOperand(0), Op1, Op2); break; } case Instruction::Malloc: @@ -6953,9 +6953,9 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) { // If we were able to index down into an element, create the GEP // and bitcast the result. This eliminates one bitcast, potentially // two. - Instruction *NGEP = new GetElementPtrInst(OrigBase, - NewIndices.begin(), - NewIndices.end(), ""); + Instruction *NGEP = GetElementPtrInst::Create(OrigBase, + NewIndices.begin(), + NewIndices.end(), ""); InsertNewInstBefore(NGEP, CI); NGEP->takeName(GEP); @@ -7517,7 +7517,7 @@ Instruction *InstCombiner::visitIntToPtr(IntToPtrInst &CI) { // If Offset is evenly divisible by Size, we can do this xform. if (Size && !APIntOps::srem(Offset, APInt(Offset.getBitWidth(), Size))){ Offset = APIntOps::sdiv(Offset, APInt(Offset.getBitWidth(), Size)); - return new GetElementPtrInst(X, ConstantInt::get(Offset)); + return GetElementPtrInst::Create(X, ConstantInt::get(Offset)); } } // TODO: Could handle other cases, e.g. where add is indexing into field of @@ -7540,7 +7540,7 @@ Instruction *InstCombiner::visitIntToPtr(IntToPtrInst &CI) { Instruction *P = InsertNewInstBefore(new IntToPtrInst(X, CI.getType(), "tmp"), CI); - return new GetElementPtrInst(P, ConstantInt::get(Offset), "tmp"); + return GetElementPtrInst::Create(P, ConstantInt::get(Offset), "tmp"); } } return 0; @@ -7601,8 +7601,8 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) { // If we found a path from the src to dest, create the getelementptr now. if (SrcElTy == DstElTy) { SmallVector<Value*, 8> Idxs(NumZeros+1, ZeroUInt); - return new GetElementPtrInst(Src, Idxs.begin(), Idxs.end(), "", - ((Instruction*) NULL)); + return GetElementPtrInst::Create(Src, Idxs.begin(), Idxs.end(), "", + ((Instruction*) NULL)); } } @@ -7699,8 +7699,8 @@ Instruction *InstCombiner::FoldSelectOpOp(SelectInst &SI, Instruction *TI, } // Fold this by inserting a select from the input values. - SelectInst *NewSI = new SelectInst(SI.getCondition(), TI->getOperand(0), - FI->getOperand(0), SI.getName()+".v"); + SelectInst *NewSI = SelectInst::Create(SI.getCondition(), TI->getOperand(0), + FI->getOperand(0), SI.getName()+".v"); InsertNewInstBefore(NewSI, SI); return CastInst::create(Instruction::CastOps(TI->getOpcode()), NewSI, TI->getType()); @@ -7740,8 +7740,8 @@ Instruction *InstCombiner::FoldSelectOpOp(SelectInst &SI, Instruction *TI, } // If we reach here, they do have operations in common. - SelectInst *NewSI = new SelectInst(SI.getCondition(), OtherOpT, - OtherOpF, SI.getName()+".v"); + SelectInst *NewSI = SelectInst::Create(SI.getCondition(), OtherOpT, + OtherOpF, SI.getName()+".v"); InsertNewInstBefore(NewSI, SI); if (BinaryOperator *BO = dyn_cast<BinaryOperator>(TI)) { @@ -7990,7 +7990,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { if (AddOp != TI) std::swap(NewTrueOp, NewFalseOp); Instruction *NewSel = - new SelectInst(CondVal, NewTrueOp,NewFalseOp,SI.getName()+".p"); + SelectInst::Create(CondVal, NewTrueOp,NewFalseOp,SI.getName()+".p"); NewSel = InsertNewInstBefore(NewSel, SI); return BinaryOperator::createAdd(SubOp->getOperand(0), NewSel); @@ -8016,7 +8016,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { if (OpToFold) { Constant *C = GetSelectFoldableConstant(TVI); Instruction *NewSel = - new SelectInst(SI.getCondition(), TVI->getOperand(2-OpToFold), C); + SelectInst::Create(SI.getCondition(), TVI->getOperand(2-OpToFold), C); InsertNewInstBefore(NewSel, SI); NewSel->takeName(TVI); if (BinaryOperator *BO = dyn_cast<BinaryOperator>(TVI)) @@ -8041,7 +8041,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) { if (OpToFold) { Constant *C = GetSelectFoldableConstant(FVI); Instruction *NewSel = - new SelectInst(SI.getCondition(), C, FVI->getOperand(2-OpToFold)); + SelectInst::Create(SI.getCondition(), C, FVI->getOperand(2-OpToFold)); InsertNewInstBefore(NewSel, SI); NewSel->takeName(FVI); if (BinaryOperator *BO = dyn_cast<BinaryOperator>(FVI)) @@ -8369,7 +8369,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) { } // Insert this value into the result vector. - Result = new InsertElementInst(Result, ExtractedElts[Idx], i,"tmp"); + Result = InsertElementInst::Create(Result, ExtractedElts[Idx], i, "tmp"); InsertNewInstBefore(cast<Instruction>(Result), CI); } return CastInst::create(Instruction::BitCast, Result, CI.getType()); @@ -8466,8 +8466,8 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) { if (InvokeInst *II = dyn_cast<InvokeInst>(CS.getInstruction())) { // Don't break the CFG, insert a dummy cond branch. - new BranchInst(II->getNormalDest(), II->getUnwindDest(), - ConstantInt::getTrue(), II); + BranchInst::Create(II->getNormalDest(), II->getUnwindDest(), + ConstantInt::getTrue(), II); } return EraseInstFromFunction(*CS.getInstruction()); } @@ -8678,13 +8678,13 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { Instruction *NC; if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) { - NC = new InvokeInst(Callee, II->getNormalDest(), II->getUnwindDest(), - Args.begin(), Args.end(), Caller->getName(), Caller); + NC = InvokeInst::Create(Callee, II->getNormalDest(), II->getUnwindDest(), + Args.begin(), Args.end(), Caller->getName(), Caller); cast<InvokeInst>(NC)->setCallingConv(II->getCallingConv()); cast<InvokeInst>(NC)->setParamAttrs(NewCallerPAL); } else { - NC = new CallInst(Callee, Args.begin(), Args.end(), - Caller->getName(), Caller); + NC = CallInst::Create(Callee, Args.begin(), Args.end(), + Caller->getName(), Caller); CallInst *CI = cast<CallInst>(Caller); if (CI->isTailCall()) cast<CallInst>(NC)->setTailCall(); @@ -8841,15 +8841,15 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) { Instruction *NewCaller; if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) { - NewCaller = new InvokeInst(NewCallee, - II->getNormalDest(), II->getUnwindDest(), - NewArgs.begin(), NewArgs.end(), - Caller->getName(), Caller); + NewCaller = InvokeInst::Create(NewCallee, + II->getNormalDest(), II->getUnwindDest(), + NewArgs.begin(), NewArgs.end(), + Caller->getName(), Caller); cast<InvokeInst>(NewCaller)->setCallingConv(II->getCallingConv()); cast<InvokeInst>(NewCaller)->setParamAttrs(NewPAL); } else { - NewCaller = new CallInst(NewCallee, NewArgs.begin(), NewArgs.end(), - Caller->getName(), Caller); + NewCaller = CallInst::Create(NewCallee, NewArgs.begin(), NewArgs.end(), + Caller->getName(), Caller); if (cast<CallInst>(Caller)->isTailCall()) cast<CallInst>(NewCaller)->setTailCall(); cast<CallInst>(NewCaller)-> @@ -8921,7 +8921,7 @@ Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) { Value *InRHS = FirstInst->getOperand(1); PHINode *NewLHS = 0, *NewRHS = 0; if (LHSVal == 0) { - NewLHS = new PHINode(LHSType, FirstInst->getOperand(0)->getName()+".pn"); + NewLHS = PHINode::Create(LHSType, FirstInst->getOperand(0)->getName()+".pn"); NewLHS->reserveOperandSpace(PN.getNumOperands()/2); NewLHS->addIncoming(InLHS, PN.getIncomingBlock(0)); InsertNewInstBefore(NewLHS, PN); @@ -8929,7 +8929,7 @@ Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) { } if (RHSVal == 0) { - NewRHS = new PHINode(RHSType, FirstInst->getOperand(1)->getName()+".pn"); + NewRHS = PHINode::Create(RHSType, FirstInst->getOperand(1)->getName()+".pn"); NewRHS->reserveOperandSpace(PN.getNumOperands()/2); NewRHS->addIncoming(InRHS, PN.getIncomingBlock(0)); InsertNewInstBefore(NewRHS, PN); @@ -8955,7 +8955,7 @@ Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) { RHSVal); else { assert(isa<GetElementPtrInst>(FirstInst)); - return new GetElementPtrInst(LHSVal, RHSVal); + return GetElementPtrInst::Create(LHSVal, RHSVal); } } @@ -9057,8 +9057,8 @@ Instruction *InstCombiner::FoldPHIArgOpIntoPHI(PHINode &PN) { // Okay, they are all the same operation. Create a new PHI node of the // correct type, and PHI together all of the LHS's of the instructions. - PHINode *NewPN = new PHINode(FirstInst->getOperand(0)->getType(), - PN.getName()+".in"); + PHINode *NewPN = PHINode::Create(FirstInst->getOperand(0)->getType(), + PN.getName()+".in"); NewPN->reserveOperandSpace(PN.getNumOperands()/2); Value *InVal = FirstInst->getOperand(0); @@ -9405,8 +9405,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { } if (!Indices.empty()) - return new GetElementPtrInst(SrcGEPOperands[0], Indices.begin(), - Indices.end(), GEP.getName()); + return GetElementPtrInst::Create(SrcGEPOperands[0], Indices.begin(), + Indices.end(), GEP.getName()); } else if (GlobalValue *GV = dyn_cast<GlobalValue>(PtrOp)) { // GEP of global variable. If all of the indices for this GEP are @@ -9461,7 +9461,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = GEP.getOperand(1); Value *V = InsertNewInstBefore( - new GetElementPtrInst(X, Idx, Idx + 2, GEP.getName()), GEP); + GetElementPtrInst::Create(X, Idx, Idx + 2, GEP.getName()), GEP); // V and GEP are both pointer types --> BitCast return new BitCastInst(V, GEP.getType()); } @@ -9519,7 +9519,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = NewIdx; Instruction *NewGEP = - new GetElementPtrInst(X, Idx, Idx + 2, GEP.getName()); + GetElementPtrInst::Create(X, Idx, Idx + 2, GEP.getName()); NewGEP = InsertNewInstBefore(NewGEP, GEP); // The NewGEP must be pointer typed, so must the old one -> BitCast return new BitCastInst(NewGEP, GEP.getType()); @@ -9562,8 +9562,8 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) { Value *Idx[2]; Idx[0] = NullIdx; Idx[1] = NullIdx; - Value *V = new GetElementPtrInst(New, Idx, Idx + 2, - New->getName()+".sub", It); + Value *V = GetElementPtrInst::Create(New, Idx, Idx + 2, + New->getName()+".sub", It); // Now make everything use the getelementptr instead of the original // allocation. @@ -9874,7 +9874,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { SI->getOperand(1)->getName()+".val"), LI); Value *V2 = InsertNewInstBefore(new LoadInst(SI->getOperand(2), SI->getOperand(2)->getName()+".val"), LI); - return new SelectInst(SI->getCondition(), V1, V2); + return SelectInst::Create(SI->getCondition(), V1, V2); } // load (select (cond, null, P)) -> load P @@ -10151,7 +10151,7 @@ bool InstCombiner::SimplifyStoreAtEndOfBlock(StoreInst &SI) { // Insert a PHI node now if we need it. Value *MergedVal = OtherStore->getOperand(0); if (MergedVal != SI.getOperand(0)) { - PHINode *PN = new PHINode(MergedVal->getType(), "storemerge"); + PHINode *PN = PHINode::Create(MergedVal->getType(), "storemerge"); PN->reserveOperandSpace(2); PN->addIncoming(SI.getOperand(0), SI.getParent()); PN->addIncoming(OtherStore->getOperand(0), OtherBB); @@ -10437,7 +10437,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) { Value *Ptr = InsertBitCastBefore(I->getOperand(0), PointerType::get(EI.getType(), AS),EI); GetElementPtrInst *GEP = - new GetElementPtrInst(Ptr, EI.getOperand(1), I->getName() + ".gep"); + GetElementPtrInst::Create(Ptr, EI.getOperand(1), I->getName() + ".gep"); InsertNewInstBefore(GEP, EI); return new LoadInst(GEP); } diff --git a/lib/Transforms/Scalar/LoopIndexSplit.cpp b/lib/Transforms/Scalar/LoopIndexSplit.cpp index 48b4535..da6f076 100644 --- a/lib/Transforms/Scalar/LoopIndexSplit.cpp +++ b/lib/Transforms/Scalar/LoopIndexSplit.cpp @@ -772,7 +772,7 @@ void LoopIndexSplit::updateLoopBounds(ICmpInst *CI) { "lsplit.add", PHTerminator); Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, A, UB,"lsplit,c", PHTerminator); - NUB = new SelectInst (C, A, UB, "lsplit.nub", PHTerminator); + NUB = SelectInst::Create(C, A, UB, "lsplit.nub", PHTerminator); } // for (i = LB; i <= UB; ++i) @@ -788,7 +788,7 @@ void LoopIndexSplit::updateLoopBounds(ICmpInst *CI) { || ExitCondition->getPredicate() == ICmpInst::ICMP_ULE) { Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, NV, UB, "lsplit.c", PHTerminator); - NUB = new SelectInst (C, NV, UB, "lsplit.nub", PHTerminator); + NUB = SelectInst::Create(C, NV, UB, "lsplit.nub", PHTerminator); } break; case ICmpInst::ICMP_ULT: @@ -806,7 +806,7 @@ void LoopIndexSplit::updateLoopBounds(ICmpInst *CI) { || ExitCondition->getPredicate() == ICmpInst::ICMP_ULT) { Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, NV, UB, "lsplit.c", PHTerminator); - NUB = new SelectInst (C, NV, UB, "lsplit.nub", PHTerminator); + NUB = SelectInst::Create(C, NV, UB, "lsplit.nub", PHTerminator); } // for (i = LB; i <= UB; ++i) @@ -824,7 +824,7 @@ void LoopIndexSplit::updateLoopBounds(ICmpInst *CI) { "lsplit.add", PHTerminator); Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, S, UB, "lsplit.c", PHTerminator); - NUB = new SelectInst (C, S, UB, "lsplit.nub", PHTerminator); + NUB = SelectInst::Create(C, S, UB, "lsplit.nub", PHTerminator); } break; case ICmpInst::ICMP_UGE: @@ -841,7 +841,7 @@ void LoopIndexSplit::updateLoopBounds(ICmpInst *CI) { { Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, NV, StartValue, "lsplit.c", PHTerminator); - NLB = new SelectInst (C, StartValue, NV, "lsplit.nlb", PHTerminator); + NLB = SelectInst::Create(C, StartValue, NV, "lsplit.nlb", PHTerminator); } break; case ICmpInst::ICMP_UGT: @@ -860,7 +860,7 @@ void LoopIndexSplit::updateLoopBounds(ICmpInst *CI) { "lsplit.add", PHTerminator); Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, A, StartValue, "lsplit.c", PHTerminator); - NLB = new SelectInst (C, StartValue, A, "lsplit.nlb", PHTerminator); + NLB = SelectInst::Create(C, StartValue, A, "lsplit.nlb", PHTerminator); } break; default: @@ -1356,16 +1356,16 @@ void LoopIndexSplit::calculateLoopBounds(SplitInfo &SD) { ExitCondition->getOperand(ExitValueNum), "lsplit.ev", InsertPt); - SD.A_ExitValue = new SelectInst(C1, AEV, - ExitCondition->getOperand(ExitValueNum), - "lsplit.ev", InsertPt); + SD.A_ExitValue = SelectInst::Create(C1, AEV, + ExitCondition->getOperand(ExitValueNum), + "lsplit.ev", InsertPt); Value *C2 = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, BSV, StartValue, "lsplit.sv", PHTerminator); - SD.B_StartValue = new SelectInst(C2, StartValue, BSV, - "lsplit.sv", PHTerminator); + SD.B_StartValue = SelectInst::Create(C2, StartValue, BSV, + "lsplit.sv", PHTerminator); } /// splitLoop - Split current loop L in two loops using split information @@ -1508,7 +1508,7 @@ bool LoopIndexSplit::splitLoop(SplitInfo &SD) { BI != BE; ++BI) { if (PHINode *PN = dyn_cast<PHINode>(BI)) { Value *V1 = PN->getIncomingValueForBlock(A_ExitBlock); - PHINode *newPHI = new PHINode(PN->getType(), PN->getName()); + PHINode *newPHI = PHINode::Create(PN->getType(), PN->getName()); newPHI->addIncoming(V1, A_ExitingBlock); A_ExitBlock->getInstList().push_front(newPHI); PN->removeIncomingValue(A_ExitBlock); @@ -1598,7 +1598,7 @@ void LoopIndexSplit::moveExitCondition(BasicBlock *CondBB, BasicBlock *ActiveBB, CurrentBR->eraseFromParent(); // Connect exiting block to original destination. - new BranchInst(OrigDestBB, ExitingBB); + BranchInst::Create(OrigDestBB, ExitingBB); // Update PHINodes updatePHINodes(ExitBB, ExitingBB, CondBB, IV, IVAdd, LP); diff --git a/lib/Transforms/Scalar/LoopRotation.cpp b/lib/Transforms/Scalar/LoopRotation.cpp index 153f095..51e2cd8 100644 --- a/lib/Transforms/Scalar/LoopRotation.cpp +++ b/lib/Transforms/Scalar/LoopRotation.cpp @@ -208,7 +208,7 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) { // Create new PHI node with two incoming values for NewHeader. // One incoming value is from OrigLatch (through OrigHeader) and // second incoming value is from original pre-header. - PHINode *NH = new PHINode(In->getType(), In->getName()); + PHINode *NH = PHINode::Create(In->getType(), In->getName()); NH->addIncoming(PN->getIncomingValueForBlock(OrigLatch), OrigHeader); NH->addIncoming(NPV, OrigPreHeader); NewHeader->getInstList().push_front(NH); @@ -249,7 +249,7 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) { // create new PHINode for this instruction. Instruction *NewHeaderReplacement = NULL; if (usedOutsideOriginalHeader(In)) { - PHINode *PN = new PHINode(In->getType(), In->getName()); + PHINode *PN = PHINode::Create(In->getType(), In->getName()); PN->addIncoming(In, OrigHeader); PN->addIncoming(C, OrigPreHeader); NewHeader->getInstList().push_front(PN); @@ -336,7 +336,7 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) { } else { // Used outside Exit block. Create a new PHI node from exit block // to receive value from ne new header ane pre header. - PHINode *PN = new PHINode(U->getType(), U->getName()); + PHINode *PN = PHINode::Create(U->getType(), U->getName()); PN->addIncoming(ILoopHeaderInfo.PreHeader, OrigPreHeader); PN->addIncoming(OldPhi, OrigHeader); Exit->getInstList().push_front(PN); @@ -447,12 +447,12 @@ void LoopRotate::preserveCanonicalLoopForm(LPPassManager &LPM) { // Right now original pre-header has two successors, new header and // exit block. Insert new block between original pre-header and // new header such that loop's new pre-header has only one successor. - BasicBlock *NewPreHeader = new BasicBlock("bb.nph", OrigHeader->getParent(), - NewHeader); + BasicBlock *NewPreHeader = BasicBlock::Create("bb.nph", OrigHeader->getParent(), + NewHeader); LoopInfo &LI = LPM.getAnalysis<LoopInfo>(); if (Loop *PL = LI.getLoopFor(OrigPreHeader)) PL->addBasicBlockToLoop(NewPreHeader, LI.getBase()); - new BranchInst(NewHeader, NewPreHeader); + BranchInst::Create(NewHeader, NewPreHeader); BranchInst *OrigPH_BI = cast<BranchInst>(OrigPreHeader->getTerminator()); if (OrigPH_BI->getSuccessor(0) == NewHeader) @@ -560,7 +560,7 @@ void LoopRotate::preserveCanonicalLoopForm(LPPassManager &LPM) { BasicBlock::iterator I = Exit->begin(), E = Exit->end(); PHINode *PN = NULL; for (; (PN = dyn_cast<PHINode>(I)); ++I) { - PHINode *NewPN = new PHINode(PN->getType(), PN->getName()); + PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()); unsigned N = PN->getNumIncomingValues(); for (unsigned index = 0; index < N; ++index) if (PN->getIncomingBlock(index) == NExit) { diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index c6f02e8..fbed3b3 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -1271,7 +1271,7 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride, if (RewriteFactor == 0) { // Create a new Phi for this base, and stick it in the loop header. - NewPHI = new PHINode(ReplacedTy, "iv.", PhiInsertBefore); + NewPHI = PHINode::Create(ReplacedTy, "iv.", PhiInsertBefore); ++NumInserted; // Add common base to the new Phi node. diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index 966038d..58a2fe0 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -568,7 +568,7 @@ void LoopUnswitch::EmitPreheaderBranchOnCondition(Value *LIC, Constant *Val, std::swap(TrueDest, FalseDest); // Insert the new branch. - new BranchInst(TrueDest, FalseDest, BranchVal, InsertPt); + BranchInst::Create(TrueDest, FalseDest, BranchVal, InsertPt); } @@ -673,9 +673,9 @@ void LoopUnswitch::SplitExitEdges(Loop *L, const SmallVector<BasicBlock *, 8> &E for (BasicBlock::iterator I = EndBlock->begin(); (OldLCSSA = dyn_cast<PHINode>(I)); ++I) { Value* OldValue = OldLCSSA->getIncomingValueForBlock(MiddleBlock); - PHINode* NewLCSSA = new PHINode(OldLCSSA->getType(), - OldLCSSA->getName() + ".us-lcssa", - MiddleBlock->getTerminator()); + PHINode* NewLCSSA = PHINode::Create(OldLCSSA->getType(), + OldLCSSA->getName() + ".us-lcssa", + MiddleBlock->getTerminator()); NewLCSSA->addIncoming(OldValue, StartBlock); OldLCSSA->setIncomingValue(OldLCSSA->getBasicBlockIndex(MiddleBlock), NewLCSSA); @@ -687,9 +687,9 @@ void LoopUnswitch::SplitExitEdges(Loop *L, const SmallVector<BasicBlock *, 8> &E for (BasicBlock::iterator I = MiddleBlock->begin(); (OldLCSSA = dyn_cast<PHINode>(I)) && InsertedPHIs.count(OldLCSSA) == 0; ++I) { - PHINode *NewLCSSA = new PHINode(OldLCSSA->getType(), - OldLCSSA->getName() + ".us-lcssa", - InsertPt); + PHINode *NewLCSSA = PHINode::Create(OldLCSSA->getType(), + OldLCSSA->getName() + ".us-lcssa", + InsertPt); OldLCSSA->replaceAllUsesWith(NewLCSSA); NewLCSSA->addIncoming(OldLCSSA, MiddleBlock); } @@ -1155,8 +1155,8 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC, BasicBlock* Split = SplitBlock(Old, SI, this); Instruction* OldTerm = Old->getTerminator(); - new BranchInst(Split, SI->getSuccessor(i), - ConstantInt::getTrue(), OldTerm); + BranchInst::Create(Split, SI->getSuccessor(i), + ConstantInt::getTrue(), OldTerm); LPM->deleteSimpleAnalysisValue(Old->getTerminator(), L); Old->getTerminator()->eraseFromParent(); @@ -1295,7 +1295,7 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist, Loop *L) { BasicBlock *DeadSucc = BI->getSuccessor(CB->getZExtValue()); BasicBlock *LiveSucc = BI->getSuccessor(!CB->getZExtValue()); DeadSucc->removePredecessor(BI->getParent(), true); - Worklist.push_back(new BranchInst(LiveSucc, BI)); + Worklist.push_back(BranchInst::Create(LiveSucc, BI)); LPM->deleteSimpleAnalysisValue(BI, L); BI->eraseFromParent(); RemoveFromWorklist(BI, Worklist); diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index a178507..0fd9316 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -1740,7 +1740,7 @@ bool IPSCCP::runOnModule(Module &M) { // Make this an uncond branch to the first successor. TerminatorInst *TI = I->getParent()->getTerminator(); - new BranchInst(TI->getSuccessor(0), TI); + BranchInst::Create(TI->getSuccessor(0), TI); // Remove entries in successor phi nodes to remove edges. for (unsigned i = 1, e = TI->getNumSuccessors(); i != e; ++i) diff --git a/lib/Transforms/Scalar/ScalarReplAggregates.cpp b/lib/Transforms/Scalar/ScalarReplAggregates.cpp index 2977afa..51aad84 100644 --- a/lib/Transforms/Scalar/ScalarReplAggregates.cpp +++ b/lib/Transforms/Scalar/ScalarReplAggregates.cpp @@ -323,8 +323,8 @@ void SROA::DoScalarReplacement(AllocationInst *AI, SmallVector<Value*, 8> NewArgs; NewArgs.push_back(Constant::getNullValue(Type::Int32Ty)); NewArgs.append(GEPI->op_begin()+3, GEPI->op_end()); - RepValue = new GetElementPtrInst(AllocaToUse, NewArgs.begin(), - NewArgs.end(), "", GEPI); + RepValue = GetElementPtrInst::Create(AllocaToUse, NewArgs.begin(), + NewArgs.end(), "", GEPI); RepValue->takeName(GEPI); } @@ -634,9 +634,9 @@ void SROA::RewriteBitCastUserOfAlloca(Instruction *BCInst, AllocationInst *AI, Value *Idx[2]; Idx[0] = Zero; Idx[1] = ConstantInt::get(Type::Int32Ty, i); - OtherElt = new GetElementPtrInst(OtherPtr, Idx, Idx + 2, - OtherPtr->getNameStr()+"."+utostr(i), - MI); + OtherElt = GetElementPtrInst::Create(OtherPtr, Idx, Idx + 2, + OtherPtr->getNameStr()+"."+utostr(i), + MI); } Value *EltPtr = NewElts[i]; @@ -716,7 +716,7 @@ void SROA::RewriteBitCastUserOfAlloca(Instruction *BCInst, AllocationInst *AI, ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size Zero // Align }; - new CallInst(TheFn, Ops, Ops + 4, "", MI); + CallInst::Create(TheFn, Ops, Ops + 4, "", MI); } else { assert(isa<MemSetInst>(MI)); Value *Ops[] = { @@ -724,7 +724,7 @@ void SROA::RewriteBitCastUserOfAlloca(Instruction *BCInst, AllocationInst *AI, ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size Zero // Align }; - new CallInst(TheFn, Ops, Ops + 4, "", MI); + CallInst::Create(TheFn, Ops, Ops + 4, "", MI); } } @@ -838,22 +838,22 @@ void SROA::CanonicalizeAllocaUsers(AllocationInst *AI) { // Insert the new GEP instructions, which are properly indexed. SmallVector<Value*, 8> Indices(GEPI->op_begin()+1, GEPI->op_end()); Indices[1] = Constant::getNullValue(Type::Int32Ty); - Value *ZeroIdx = new GetElementPtrInst(GEPI->getOperand(0), - Indices.begin(), - Indices.end(), - GEPI->getName()+".0", GEPI); + Value *ZeroIdx = GetElementPtrInst::Create(GEPI->getOperand(0), + Indices.begin(), + Indices.end(), + GEPI->getName()+".0", GEPI); Indices[1] = ConstantInt::get(Type::Int32Ty, 1); - Value *OneIdx = new GetElementPtrInst(GEPI->getOperand(0), - Indices.begin(), - Indices.end(), - GEPI->getName()+".1", GEPI); + Value *OneIdx = GetElementPtrInst::Create(GEPI->getOperand(0), + Indices.begin(), + Indices.end(), + GEPI->getName()+".1", GEPI); // Replace all loads of the variable index GEP with loads from both // indexes and a select. while (!GEPI->use_empty()) { LoadInst *LI = cast<LoadInst>(GEPI->use_back()); Value *Zero = new LoadInst(ZeroIdx, LI->getName()+".0", LI); Value *One = new LoadInst(OneIdx , LI->getName()+".1", LI); - Value *R = new SelectInst(IsOne, One, Zero, LI->getName(), LI); + Value *R = SelectInst::Create(IsOne, One, Zero, LI->getName(), LI); LI->replaceAllUsesWith(R); LI->eraseFromParent(); } @@ -1261,9 +1261,9 @@ Value *SROA::ConvertUsesOfStoreToScalar(StoreInst *SI, AllocaInst *NewAI, // Must be an element insertion. const TargetData &TD = getAnalysis<TargetData>(); unsigned Elt = Offset/TD.getABITypeSizeInBits(PTy->getElementType()); - SV = new InsertElementInst(Old, SV, - ConstantInt::get(Type::Int32Ty, Elt), - "tmp", SI); + SV = InsertElementInst::Create(Old, SV, + ConstantInt::get(Type::Int32Ty, Elt), + "tmp", SI); } } else if (isa<PointerType>(AllocaType)) { // If the alloca type is a pointer, then all the elements must be diff --git a/lib/Transforms/Scalar/SimplifyCFG.cpp b/lib/Transforms/Scalar/SimplifyCFG.cpp index 5cb2b40..48342bd 100644 --- a/lib/Transforms/Scalar/SimplifyCFG.cpp +++ b/lib/Transforms/Scalar/SimplifyCFG.cpp @@ -78,15 +78,15 @@ static void ChangeToUnreachable(Instruction *I) { static void ChangeToCall(InvokeInst *II) { BasicBlock *BB = II->getParent(); SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end()); - CallInst *NewCall = new CallInst(II->getCalledValue(), Args.begin(), - Args.end(), "", II); + CallInst *NewCall = CallInst::Create(II->getCalledValue(), Args.begin(), + Args.end(), "", II); NewCall->takeName(II); NewCall->setCallingConv(II->getCallingConv()); NewCall->setParamAttrs(II->getParamAttrs()); II->replaceAllUsesWith(NewCall); // Follow the call by a branch to the normal destination. - new BranchInst(II->getNormalDest(), II); + BranchInst::Create(II->getNormalDest(), II); // Update PHI nodes in the unwind destination II->getUnwindDest()->removePredecessor(BB); diff --git a/lib/Transforms/Scalar/TailRecursionElimination.cpp b/lib/Transforms/Scalar/TailRecursionElimination.cpp index d1320c9..78b088a 100644 --- a/lib/Transforms/Scalar/TailRecursionElimination.cpp +++ b/lib/Transforms/Scalar/TailRecursionElimination.cpp @@ -377,10 +377,10 @@ bool TailCallElim::ProcessReturningBlock(ReturnInst *Ret, BasicBlock *&OldEntry, // create the new entry block, allowing us to branch back to the old entry. if (OldEntry == 0) { OldEntry = &F->getEntryBlock(); - BasicBlock *NewEntry = new BasicBlock("", F, OldEntry); + BasicBlock *NewEntry = BasicBlock::Create("", F, OldEntry); NewEntry->takeName(OldEntry); OldEntry->setName("tailrecurse"); - new BranchInst(OldEntry, NewEntry); + BranchInst::Create(OldEntry, NewEntry); // If this tail call is marked 'tail' and if there are any allocas in the // entry block, move them up to the new entry block. @@ -400,7 +400,7 @@ bool TailCallElim::ProcessReturningBlock(ReturnInst *Ret, BasicBlock *&OldEntry, Instruction *InsertPos = OldEntry->begin(); for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E; ++I) { - PHINode *PN = new PHINode(I->getType(), I->getName()+".tr", InsertPos); + PHINode *PN = PHINode::Create(I->getType(), I->getName()+".tr", InsertPos); I->replaceAllUsesWith(PN); // Everyone use the PHI node now! PN->addIncoming(I, NewEntry); ArgumentPHIs.push_back(PN); @@ -430,8 +430,8 @@ bool TailCallElim::ProcessReturningBlock(ReturnInst *Ret, BasicBlock *&OldEntry, if (AccumulatorRecursionEliminationInitVal) { Instruction *AccRecInstr = AccumulatorRecursionInstr; // Start by inserting a new PHI node for the accumulator. - PHINode *AccPN = new PHINode(AccRecInstr->getType(), "accumulator.tr", - OldEntry->begin()); + PHINode *AccPN = PHINode::Create(AccRecInstr->getType(), "accumulator.tr", + OldEntry->begin()); // Loop over all of the predecessors of the tail recursion block. For the // real entry into the function we seed the PHI with the initial value, @@ -467,7 +467,7 @@ bool TailCallElim::ProcessReturningBlock(ReturnInst *Ret, BasicBlock *&OldEntry, // Now that all of the PHI nodes are in place, remove the call and // ret instructions, replacing them with an unconditional branch. - new BranchInst(OldEntry, Ret); + BranchInst::Create(OldEntry, Ret); BB->getInstList().erase(Ret); // Remove return. BB->getInstList().erase(CI); // Remove call. ++NumEliminated; diff --git a/lib/Transforms/Utils/BasicBlockUtils.cpp b/lib/Transforms/Utils/BasicBlockUtils.cpp index 0dc38a2..895e44a 100644 --- a/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -98,7 +98,7 @@ void llvm::RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum) { RetVal = Constant::getNullValue(BB->getParent()->getReturnType()); // Create the return... - NewTI = new ReturnInst(RetVal); + NewTI = ReturnInst::Create(RetVal); } break; diff --git a/lib/Transforms/Utils/BreakCriticalEdges.cpp b/lib/Transforms/Utils/BreakCriticalEdges.cpp index 78801db..1a41d95 100644 --- a/lib/Transforms/Utils/BreakCriticalEdges.cpp +++ b/lib/Transforms/Utils/BreakCriticalEdges.cpp @@ -122,10 +122,10 @@ bool llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P, BasicBlock *DestBB = TI->getSuccessor(SuccNum); // Create a new basic block, linking it into the CFG. - BasicBlock *NewBB = new BasicBlock(TIBB->getName() + "." + - DestBB->getName() + "_crit_edge"); + BasicBlock *NewBB = BasicBlock::Create(TIBB->getName() + "." + + DestBB->getName() + "_crit_edge"); // Create our unconditional branch... - new BranchInst(DestBB, NewBB); + BranchInst::Create(DestBB, NewBB); // Branch to the new block, breaking the edge. TI->setSuccessor(SuccNum, NewBB); diff --git a/lib/Transforms/Utils/CloneFunction.cpp b/lib/Transforms/Utils/CloneFunction.cpp index 7387144..ba9b57d 100644 --- a/lib/Transforms/Utils/CloneFunction.cpp +++ b/lib/Transforms/Utils/CloneFunction.cpp @@ -31,7 +31,7 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, DenseMap<const Value*, Value*> &ValueMap, const char *NameSuffix, Function *F, ClonedCodeInfo *CodeInfo) { - BasicBlock *NewBB = new BasicBlock("", F); + BasicBlock *NewBB = BasicBlock::Create("", F); if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix); NewBB->setUnwindDest(const_cast<BasicBlock*>(BB->getUnwindDest())); @@ -144,7 +144,7 @@ Function *llvm::CloneFunction(const Function *F, ArgTypes, F->getFunctionType()->isVarArg()); // Create the new function... - Function *NewF = new Function(FTy, F->getLinkage(), F->getName()); + Function *NewF = Function::Create(FTy, F->getLinkage(), F->getName()); // Loop over the arguments, copying the names of the mapped arguments over... Function::arg_iterator DestI = NewF->arg_begin(); @@ -208,7 +208,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB, // Nope, clone it now. BasicBlock *NewBB; - BBEntry = NewBB = new BasicBlock(); + BBEntry = NewBB = BasicBlock::Create(); if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix); bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false; @@ -253,7 +253,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB, // Constant fold to uncond branch! if (Cond) { BasicBlock *Dest = BI->getSuccessor(!Cond->getZExtValue()); - ValueMap[OldTI] = new BranchInst(Dest, NewBB); + ValueMap[OldTI] = BranchInst::Create(Dest, NewBB); ToClone.push_back(Dest); TerminatorDone = true; } @@ -265,7 +265,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB, Cond = dyn_cast_or_null<ConstantInt>(ValueMap[SI->getCondition()]); if (Cond) { // Constant fold to uncond branch! BasicBlock *Dest = SI->getSuccessor(SI->findCaseValue(Cond)); - ValueMap[OldTI] = new BranchInst(Dest, NewBB); + ValueMap[OldTI] = BranchInst::Create(Dest, NewBB); ToClone.push_back(Dest); TerminatorDone = true; } diff --git a/lib/Transforms/Utils/CloneModule.cpp b/lib/Transforms/Utils/CloneModule.cpp index f0ee1e2..e75f915 100644 --- a/lib/Transforms/Utils/CloneModule.cpp +++ b/lib/Transforms/Utils/CloneModule.cpp @@ -63,8 +63,8 @@ Module *llvm::CloneModule(const Module *M, // Loop over the functions in the module, making external functions as before for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) { Function *NF = - new Function(cast<FunctionType>(I->getType()->getElementType()), - GlobalValue::ExternalLinkage, I->getName(), New); + Function::Create(cast<FunctionType>(I->getType()->getElementType()), + GlobalValue::ExternalLinkage, I->getName(), New); NF->setCallingConv(I->getCallingConv()); NF->setParamAttrs(I->getParamAttrs()); if (I->hasCollector()) diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp index 1be1c72..5434119 100644 --- a/lib/Transforms/Utils/CodeExtractor.cpp +++ b/lib/Transforms/Utils/CodeExtractor.cpp @@ -161,8 +161,8 @@ void CodeExtractor::severSplitPHINodes(BasicBlock *&Header) { PHINode *PN = cast<PHINode>(AfterPHIs); // Create a new PHI node in the new region, which has an incoming value // from OldPred of PN. - PHINode *NewPN = new PHINode(PN->getType(), PN->getName()+".ce", - NewBB->begin()); + PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".ce", + NewBB->begin()); NewPN->addIncoming(PN, OldPred); // Loop over all of the incoming value in PN, moving them to NewPN if they @@ -280,10 +280,10 @@ Function *CodeExtractor::constructFunction(const Values &inputs, const FunctionType *funcType = FunctionType::get(RetTy, paramTy, false); // Create the new function - Function *newFunction = new Function(funcType, - GlobalValue::InternalLinkage, - oldFunction->getName() + "_" + - header->getName(), M); + Function *newFunction = Function::Create(funcType, + GlobalValue::InternalLinkage, + oldFunction->getName() + "_" + + header->getName(), M); newFunction->getBasicBlockList().push_back(newRootNode); // Create an iterator to name all of the arguments we inserted. @@ -299,8 +299,8 @@ Function *CodeExtractor::constructFunction(const Values &inputs, Idx[1] = ConstantInt::get(Type::Int32Ty, i); std::string GEPname = "gep_" + inputs[i]->getName(); TerminatorInst *TI = newFunction->begin()->getTerminator(); - GetElementPtrInst *GEP = new GetElementPtrInst(AI, Idx, Idx+2, - GEPname, TI); + GetElementPtrInst *GEP = GetElementPtrInst::Create(AI, Idx, Idx+2, + GEPname, TI); RewriteVal = new LoadInst(GEP, "load" + GEPname, TI); } else RewriteVal = AI++; @@ -386,8 +386,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = ConstantInt::get(Type::Int32Ty, i); GetElementPtrInst *GEP = - new GetElementPtrInst(Struct, Idx, Idx + 2, - "gep_" + StructValues[i]->getName()); + GetElementPtrInst::Create(Struct, Idx, Idx + 2, + "gep_" + StructValues[i]->getName()); codeReplacer->getInstList().push_back(GEP); StoreInst *SI = new StoreInst(StructValues[i], GEP); codeReplacer->getInstList().push_back(SI); @@ -395,8 +395,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, } // Emit the call to the function - CallInst *call = new CallInst(newFunction, params.begin(), params.end(), - NumExitBlocks > 1 ? "targetBlock" : ""); + CallInst *call = CallInst::Create(newFunction, params.begin(), params.end(), + NumExitBlocks > 1 ? "targetBlock" : ""); codeReplacer->getInstList().push_back(call); Function::arg_iterator OutputArgBegin = newFunction->arg_begin(); @@ -412,8 +412,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i); GetElementPtrInst *GEP - = new GetElementPtrInst(Struct, Idx, Idx + 2, - "gep_reload_" + outputs[i]->getName()); + = GetElementPtrInst::Create(Struct, Idx, Idx + 2, + "gep_reload_" + outputs[i]->getName()); codeReplacer->getInstList().push_back(GEP); Output = GEP; } else { @@ -431,8 +431,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, // Now we can emit a switch statement using the call as a value. SwitchInst *TheSwitch = - new SwitchInst(ConstantInt::getNullValue(Type::Int16Ty), - codeReplacer, 0, codeReplacer); + SwitchInst::Create(ConstantInt::getNullValue(Type::Int16Ty), + codeReplacer, 0, codeReplacer); // Since there may be multiple exits from the original region, make the new // function return an unsigned, switch on that number. This loop iterates @@ -453,8 +453,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, if (!NewTarget) { // If we don't already have an exit stub for this non-extracted // destination, create one now! - NewTarget = new BasicBlock(OldTarget->getName() + ".exitStub", - newFunction); + NewTarget = BasicBlock::Create(OldTarget->getName() + ".exitStub", + newFunction); unsigned SuccNum = switchVal++; Value *brVal = 0; @@ -469,7 +469,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, break; } - ReturnInst *NTRet = new ReturnInst(brVal, NewTarget); + ReturnInst *NTRet = ReturnInst::Create(brVal, NewTarget); // Update the switch instruction. TheSwitch->addCase(ConstantInt::get(Type::Int16Ty, SuccNum), @@ -513,9 +513,9 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out); GetElementPtrInst *GEP = - new GetElementPtrInst(OAI, Idx, Idx + 2, - "gep_" + outputs[out]->getName(), - NTRet); + GetElementPtrInst::Create(OAI, Idx, Idx + 2, + "gep_" + outputs[out]->getName(), + NTRet); new StoreInst(outputs[out], GEP, NTRet); } else { new StoreInst(outputs[out], OAI, NTRet); @@ -541,14 +541,14 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, // Check if the function should return a value if (OldFnRetTy == Type::VoidTy) { - new ReturnInst(0, TheSwitch); // Return void + ReturnInst::Create(0, TheSwitch); // Return void } else if (OldFnRetTy == TheSwitch->getCondition()->getType()) { // return what we have - new ReturnInst(TheSwitch->getCondition(), TheSwitch); + ReturnInst::Create(TheSwitch->getCondition(), TheSwitch); } else { // Otherwise we must have code extracted an unwind or something, just // return whatever we want. - new ReturnInst(Constant::getNullValue(OldFnRetTy), TheSwitch); + ReturnInst::Create(Constant::getNullValue(OldFnRetTy), TheSwitch); } TheSwitch->getParent()->getInstList().erase(TheSwitch); @@ -556,12 +556,12 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer, case 1: // Only a single destination, change the switch into an unconditional // branch. - new BranchInst(TheSwitch->getSuccessor(1), TheSwitch); + BranchInst::Create(TheSwitch->getSuccessor(1), TheSwitch); TheSwitch->getParent()->getInstList().erase(TheSwitch); break; case 2: - new BranchInst(TheSwitch->getSuccessor(1), TheSwitch->getSuccessor(2), - call, TheSwitch); + BranchInst::Create(TheSwitch->getSuccessor(1), TheSwitch->getSuccessor(2), + call, TheSwitch); TheSwitch->getParent()->getInstList().erase(TheSwitch); break; default: @@ -641,12 +641,12 @@ ExtractCodeRegion(const std::vector<BasicBlock*> &code) { Function *oldFunction = header->getParent(); // This takes place of the original loop - BasicBlock *codeReplacer = new BasicBlock("codeRepl", oldFunction, header); + BasicBlock *codeReplacer = BasicBlock::Create("codeRepl", oldFunction, header); // The new function needs a root node because other nodes can branch to the // head of the region, but the entry node of a function cannot have preds. - BasicBlock *newFuncRoot = new BasicBlock("newFuncRoot"); - newFuncRoot->getInstList().push_back(new BranchInst(header)); + BasicBlock *newFuncRoot = BasicBlock::Create("newFuncRoot"); + newFuncRoot->getInstList().push_back(BranchInst::Create(header)); // Find inputs to, outputs from the code region. findInputsOutputs(inputs, outputs); diff --git a/lib/Transforms/Utils/InlineFunction.cpp b/lib/Transforms/Utils/InlineFunction.cpp index 74295ce..2e34984 100644 --- a/lib/Transforms/Utils/InlineFunction.cpp +++ b/lib/Transforms/Utils/InlineFunction.cpp @@ -84,9 +84,9 @@ static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock, // of the old basic block. SmallVector<Value*, 8> InvokeArgs(CI->op_begin()+1, CI->op_end()); InvokeInst *II = - new InvokeInst(CI->getCalledValue(), Split, InvokeDest, - InvokeArgs.begin(), InvokeArgs.end(), - CI->getName(), BB->getTerminator()); + InvokeInst::Create(CI->getCalledValue(), Split, InvokeDest, + InvokeArgs.begin(), InvokeArgs.end(), + CI->getName(), BB->getTerminator()); II->setCallingConv(CI->getCallingConv()); II->setParamAttrs(CI->getParamAttrs()); @@ -116,7 +116,7 @@ static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock, // invoke site. Once this happens, we know that the unwind would cause // a control transfer to the invoke exception destination, so we can // transform it into a direct branch to the exception destination. - new BranchInst(InvokeDest, UI); + BranchInst::Create(InvokeDest, UI); // Delete the unwind instruction! UI->getParent()->getInstList().pop_back(); @@ -275,7 +275,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { DestCast, SrcCast, Size, ConstantInt::get(Type::Int32Ty, 1) }; CallInst *TheMemCpy = - new CallInst(MemCpyFn, CallArgs, CallArgs+4, "", TheCall); + CallInst::Create(MemCpyFn, CallArgs, CallArgs+4, "", TheCall); // If we have a call graph, update it. if (CG) { @@ -366,14 +366,14 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { } // Insert the llvm.stacksave. - CallInst *SavedPtr = new CallInst(StackSave, "savedstack", - FirstNewBlock->begin()); + CallInst *SavedPtr = CallInst::Create(StackSave, "savedstack", + FirstNewBlock->begin()); if (CG) CallerNode->addCalledFunction(SavedPtr, StackSaveCGN); // Insert a call to llvm.stackrestore before any return instructions in the // inlined function. for (unsigned i = 0, e = Returns.size(); i != e; ++i) { - CallInst *CI = new CallInst(StackRestore, SavedPtr, "", Returns[i]); + CallInst *CI = CallInst::Create(StackRestore, SavedPtr, "", Returns[i]); if (CG) CallerNode->addCalledFunction(CI, StackRestoreCGN); } @@ -386,7 +386,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { for (Function::iterator BB = FirstNewBlock, E = Caller->end(); BB != E; ++BB) if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->getTerminator())) { - new CallInst(StackRestore, SavedPtr, "", UI); + CallInst::Create(StackRestore, SavedPtr, "", UI); ++NumStackRestores; } } @@ -428,7 +428,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { BB != E; ++BB) { TerminatorInst *Term = BB->getTerminator(); if (isa<UnwindInst>(Term)) { - new BranchInst(UnwindBB, Term); + BranchInst::Create(UnwindBB, Term); BB->getInstList().erase(Term); } } @@ -452,7 +452,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { // If the call site was an invoke instruction, add a branch to the normal // destination. if (InvokeInst *II = dyn_cast<InvokeInst>(TheCall)) - new BranchInst(II->getNormalDest(), TheCall); + BranchInst::Create(II->getNormalDest(), TheCall); // If the return instruction returned a value, replace uses of the call with // uses of the returned value. @@ -489,7 +489,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { if (InvokeInst *II = dyn_cast<InvokeInst>(TheCall)) { // Add an unconditional branch to make this look like the CallInst case... - BranchInst *NewBr = new BranchInst(II->getNormalDest(), TheCall); + BranchInst *NewBr = BranchInst::Create(II->getNormalDest(), TheCall); // Split the basic block. This guarantees that no PHI nodes will have to be // updated due to new incoming edges, and make the invoke case more @@ -535,9 +535,9 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { // match corresponding return value operand number. Instruction *InsertPt = AfterCallBB->begin(); for (unsigned i = 0; i < NumRetVals; ++i) { - PHINode *PHI = new PHINode(STy->getElementType(i), - TheCall->getName() + "." + utostr(i), - InsertPt); + PHINode *PHI = PHINode::Create(STy->getElementType(i), + TheCall->getName() + "." + utostr(i), + InsertPt); PHIs.push_back(PHI); } // TheCall results are used by GetResult instructions. @@ -547,7 +547,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { GR->eraseFromParent(); } } else { - PHINode *PHI = new PHINode(RTy, TheCall->getName(), AfterCallBB->begin()); + PHINode *PHI = PHINode::Create(RTy, TheCall->getName(), AfterCallBB->begin()); PHIs.push_back(PHI); // Anything that used the result of the function call should now use the // PHI node as their operand. @@ -578,7 +578,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) { // Add a branch to the merge points and remove retrun instructions. for (unsigned i = 0, e = Returns.size(); i != e; ++i) { ReturnInst *RI = Returns[i]; - new BranchInst(AfterCallBB, RI); + BranchInst::Create(AfterCallBB, RI); RI->eraseFromParent(); } } else if (!Returns.empty()) { diff --git a/lib/Transforms/Utils/LCSSA.cpp b/lib/Transforms/Utils/LCSSA.cpp index 567b23e..a9d1dc4 100644 --- a/lib/Transforms/Utils/LCSSA.cpp +++ b/lib/Transforms/Utils/LCSSA.cpp @@ -155,8 +155,8 @@ void LCSSA::ProcessInstruction(Instruction *Instr, DomTreeNode *ExitBBNode = DT->getNode(BB); Value *&Phi = Phis[ExitBBNode]; if (!Phi && DT->dominates(InstrNode, ExitBBNode)) { - PHINode *PN = new PHINode(Instr->getType(), Instr->getName()+".lcssa", - BB->begin()); + PHINode *PN = PHINode::Create(Instr->getType(), Instr->getName()+".lcssa", + BB->begin()); PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB))); // Remember that this phi makes the value alive in this block. @@ -259,8 +259,8 @@ Value *LCSSA::GetValueForBlock(DomTreeNode *BB, Instruction *OrigInst, // Otherwise, the idom is the loop, so we need to insert a PHI node. Do so // now, then get values to fill in the incoming values for the PHI. - PHINode *PN = new PHINode(OrigInst->getType(), OrigInst->getName()+".lcssa", - BBN->begin()); + PHINode *PN = PHINode::Create(OrigInst->getType(), OrigInst->getName()+".lcssa", + BBN->begin()); PN->reserveOperandSpace(std::distance(pred_begin(BBN), pred_end(BBN))); V = PN; diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp index 0d852bb..0f7d02c 100644 --- a/lib/Transforms/Utils/Local.cpp +++ b/lib/Transforms/Utils/Local.cpp @@ -134,7 +134,7 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB) { // now. if (TheOnlyDest) { // Insert the new branch.. - new BranchInst(TheOnlyDest, SI); + BranchInst::Create(TheOnlyDest, SI); BasicBlock *BB = SI->getParent(); // Remove entries from PHI nodes which we no longer branch to... @@ -156,7 +156,7 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB) { Value *Cond = new ICmpInst(ICmpInst::ICMP_EQ, SI->getCondition(), SI->getSuccessorValue(1), "cond", SI); // Insert the new branch... - new BranchInst(SI->getSuccessor(1), SI->getSuccessor(0), Cond, SI); + BranchInst::Create(SI->getSuccessor(1), SI->getSuccessor(0), Cond, SI); // Delete the old switch... SI->getParent()->getInstList().erase(SI); diff --git a/lib/Transforms/Utils/LoopSimplify.cpp b/lib/Transforms/Utils/LoopSimplify.cpp index 16cb30c..e6f5e7c 100644 --- a/lib/Transforms/Utils/LoopSimplify.cpp +++ b/lib/Transforms/Utils/LoopSimplify.cpp @@ -270,10 +270,10 @@ BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB, const std::vector<BasicBlock*> &Preds) { // Create new basic block, insert right before the original block... - BasicBlock *NewBB = new BasicBlock(BB->getName()+Suffix, BB->getParent(), BB); + BasicBlock *NewBB = BasicBlock::Create(BB->getName()+Suffix, BB->getParent(), BB); // The preheader first gets an unconditional branch to the loop header... - BranchInst *BI = new BranchInst(BB, NewBB); + BranchInst *BI = BranchInst::Create(BB, NewBB); // For every PHI node in the block, insert a PHI node into NewBB where the // incoming values from the out of loop edges are moved to NewBB. We have two @@ -300,7 +300,7 @@ BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB, // If the values coming into the block are not the same, we need a PHI. if (InVal == 0) { // Create the new PHI node, insert it into NewBB at the end of the block - PHINode *NewPHI = new PHINode(PN->getType(), PN->getName()+".ph", BI); + PHINode *NewPHI = PHINode::Create(PN->getType(), PN->getName()+".ph", BI); if (AA) AA->copyValue(PN, NewPHI); // Move all of the edges from blocks outside the loop to the new PHI @@ -623,8 +623,8 @@ void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L) { if (*I != Preheader) BackedgeBlocks.push_back(*I); // Create and insert the new backedge block... - BasicBlock *BEBlock = new BasicBlock(Header->getName()+".backedge", F); - BranchInst *BETerminator = new BranchInst(Header, BEBlock); + BasicBlock *BEBlock = BasicBlock::Create(Header->getName()+".backedge", F); + BranchInst *BETerminator = BranchInst::Create(Header, BEBlock); // Move the new backedge block to right after the last backedge block. Function::iterator InsertPos = BackedgeBlocks.back(); ++InsertPos; @@ -634,8 +634,8 @@ void LoopSimplify::InsertUniqueBackedgeBlock(Loop *L) { // the backedge block which correspond to any PHI nodes in the header block. for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) { PHINode *PN = cast<PHINode>(I); - PHINode *NewPN = new PHINode(PN->getType(), PN->getName()+".be", - BETerminator); + PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".be", + BETerminator); NewPN->reserveOperandSpace(BackedgeBlocks.size()); if (AA) AA->copyValue(PN, NewPN); diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp index 2f42260..8708f99 100644 --- a/lib/Transforms/Utils/LowerAllocations.cpp +++ b/lib/Transforms/Utils/LowerAllocations.cpp @@ -141,7 +141,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) { } // Create the call to Malloc. - CallInst *MCall = new CallInst(MallocFunc, MallocArg, "", I); + CallInst *MCall = CallInst::Create(MallocFunc, MallocArg, "", I); MCall->setTailCall(); // Create a cast instruction to convert to the right type... @@ -162,7 +162,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) { PointerType::getUnqual(Type::Int8Ty), "", I); // Insert a call to the free function... - (new CallInst(FreeFunc, PtrCast, "", I))->setTailCall(); + CallInst::Create(FreeFunc, PtrCast, "", I)->setTailCall(); // Delete the old free instruction I = --BBIL.erase(I); diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp index 7f0ef85..7f85b10 100644 --- a/lib/Transforms/Utils/LowerInvoke.cpp +++ b/lib/Transforms/Utils/LowerInvoke.cpp @@ -211,15 +211,15 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) { if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) { std::vector<Value*> CallArgs(II->op_begin()+3, II->op_end()); // Insert a normal call instruction... - CallInst *NewCall = new CallInst(II->getCalledValue(), - CallArgs.begin(), CallArgs.end(), "",II); + CallInst *NewCall = CallInst::Create(II->getCalledValue(), + CallArgs.begin(), CallArgs.end(), "",II); NewCall->takeName(II); NewCall->setCallingConv(II->getCallingConv()); NewCall->setParamAttrs(II->getParamAttrs()); II->replaceAllUsesWith(NewCall); // Insert an unconditional branch to the normal destination. - new BranchInst(II->getNormalDest(), II); + BranchInst::Create(II->getNormalDest(), II); // Remove any PHI node entries from the exception destination. II->getUnwindDest()->removePredecessor(BB); @@ -233,12 +233,12 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) { writeAbortMessage(UI); // Insert a call to abort() - (new CallInst(AbortFn, "", UI))->setTailCall(); + CallInst::Create(AbortFn, "", UI)->setTailCall(); // Insert a return instruction. This really should be a "barrier", as it // is unreachable. - new ReturnInst(F.getReturnType() == Type::VoidTy ? 0 : - Constant::getNullValue(F.getReturnType()), UI); + ReturnInst::Create(F.getReturnType() == Type::VoidTy ? 0 : + Constant::getNullValue(F.getReturnType()), UI); // Remove the unwind instruction now. BB->getInstList().erase(UI); @@ -280,16 +280,16 @@ void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo, // Insert a normal call instruction. std::vector<Value*> CallArgs(II->op_begin()+3, II->op_end()); - CallInst *NewCall = new CallInst(II->getCalledValue(), - CallArgs.begin(), CallArgs.end(), "", - II); + CallInst *NewCall = CallInst::Create(II->getCalledValue(), + CallArgs.begin(), CallArgs.end(), "", + II); NewCall->takeName(II); NewCall->setCallingConv(II->getCallingConv()); NewCall->setParamAttrs(II->getParamAttrs()); II->replaceAllUsesWith(NewCall); // Replace the invoke with an uncond branch. - new BranchInst(II->getNormalDest(), NewCall->getParent()); + BranchInst::Create(II->getNormalDest(), NewCall->getParent()); II->eraseFromParent(); } @@ -463,8 +463,8 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { std::vector<Value*> Idx; Idx.push_back(Constant::getNullValue(Type::Int32Ty)); Idx.push_back(ConstantInt::get(Type::Int32Ty, 1)); - OldJmpBufPtr = new GetElementPtrInst(JmpBuf, Idx.begin(), Idx.end(), - "OldBuf", EntryBB->getTerminator()); + OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(), + "OldBuf", EntryBB->getTerminator()); // Copy the JBListHead to the alloca. Value *OldBuf = new LoadInst(JBListHead, "oldjmpbufptr", true, @@ -476,7 +476,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { // Create the catch block. The catch block is basically a big switch // statement that goes to all of the invoke catch blocks. - BasicBlock *CatchBB = new BasicBlock("setjmp.catch", &F); + BasicBlock *CatchBB = BasicBlock::Create("setjmp.catch", &F); // Create an alloca which keeps track of which invoke is currently // executing. For normal calls it contains zero. @@ -488,12 +488,12 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { // Insert a load in the Catch block, and a switch on its value. By default, // we go to a block that just does an unwind (which is the correct action // for a standard call). - BasicBlock *UnwindBB = new BasicBlock("unwindbb", &F); + BasicBlock *UnwindBB = BasicBlock::Create("unwindbb", &F); Unwinds.push_back(new UnwindInst(UnwindBB)); Value *CatchLoad = new LoadInst(InvokeNum, "invoke.num", true, CatchBB); - SwitchInst *CatchSwitch = - new SwitchInst(CatchLoad, UnwindBB, Invokes.size(), CatchBB); + SwitchInst *CatchSwitch = + SwitchInst::Create(CatchLoad, UnwindBB, Invokes.size(), CatchBB); // Now that things are set up, insert the setjmp call itself. @@ -502,11 +502,11 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { "setjmp.cont"); Idx[1] = ConstantInt::get(Type::Int32Ty, 0); - Value *JmpBufPtr = new GetElementPtrInst(JmpBuf, Idx.begin(), Idx.end(), - "TheJmpBuf", - EntryBB->getTerminator()); - Value *SJRet = new CallInst(SetJmpFn, JmpBufPtr, "sjret", - EntryBB->getTerminator()); + Value *JmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(), + "TheJmpBuf", + EntryBB->getTerminator()); + Value *SJRet = CallInst::Create(SetJmpFn, JmpBufPtr, "sjret", + EntryBB->getTerminator()); // Compare the return value to zero. Value *IsNormal = new ICmpInst(ICmpInst::ICMP_EQ, SJRet, @@ -516,7 +516,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { EntryBB->getTerminator()->eraseFromParent(); // Put in a new condbranch in its place. - new BranchInst(ContBlock, CatchBB, IsNormal, EntryBB); + BranchInst::Create(ContBlock, CatchBB, IsNormal, EntryBB); // At this point, we are all set up, rewrite each invoke instruction. for (unsigned i = 0, e = Invokes.size(); i != e; ++i) @@ -528,9 +528,9 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { // Create three new blocks, the block to load the jmpbuf ptr and compare // against null, the block to do the longjmp, and the error block for if it // is null. Add them at the end of the function because they are not hot. - BasicBlock *UnwindHandler = new BasicBlock("dounwind", &F); - BasicBlock *UnwindBlock = new BasicBlock("unwind", &F); - BasicBlock *TermBlock = new BasicBlock("unwinderror", &F); + BasicBlock *UnwindHandler = BasicBlock::Create("dounwind", &F); + BasicBlock *UnwindBlock = BasicBlock::Create("unwind", &F); + BasicBlock *TermBlock = BasicBlock::Create("unwinderror", &F); // If this function contains an invoke, restore the old jumpbuf ptr. Value *BufPtr; @@ -546,17 +546,17 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { Value *NotNull = new ICmpInst(ICmpInst::ICMP_NE, BufPtr, Constant::getNullValue(BufPtr->getType()), "notnull", UnwindHandler); - new BranchInst(UnwindBlock, TermBlock, NotNull, UnwindHandler); + BranchInst::Create(UnwindBlock, TermBlock, NotNull, UnwindHandler); // Create the block to do the longjmp. // Get a pointer to the jmpbuf and longjmp. std::vector<Value*> Idx; Idx.push_back(Constant::getNullValue(Type::Int32Ty)); Idx.push_back(ConstantInt::get(Type::Int32Ty, 0)); - Idx[0] = new GetElementPtrInst(BufPtr, Idx.begin(), Idx.end(), "JmpBuf", - UnwindBlock); + Idx[0] = GetElementPtrInst::Create(BufPtr, Idx.begin(), Idx.end(), "JmpBuf", + UnwindBlock); Idx[1] = ConstantInt::get(Type::Int32Ty, 1); - new CallInst(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock); + CallInst::Create(LongJmpFn, Idx.begin(), Idx.end(), "", UnwindBlock); new UnreachableInst(UnwindBlock); // Set up the term block ("throw without a catch"). @@ -566,13 +566,13 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) { writeAbortMessage(TermBlock->getTerminator()); // Insert a call to abort() - (new CallInst(AbortFn, "", - TermBlock->getTerminator()))->setTailCall(); + CallInst::Create(AbortFn, "", + TermBlock->getTerminator())->setTailCall(); // Replace all unwinds with a branch to the unwind handler. for (unsigned i = 0, e = Unwinds.size(); i != e; ++i) { - new BranchInst(UnwindHandler, Unwinds[i]); + BranchInst::Create(UnwindHandler, Unwinds[i]); Unwinds[i]->eraseFromParent(); } diff --git a/lib/Transforms/Utils/LowerSwitch.cpp b/lib/Transforms/Utils/LowerSwitch.cpp index e31a87f..d75880f 100644 --- a/lib/Transforms/Utils/LowerSwitch.cpp +++ b/lib/Transforms/Utils/LowerSwitch.cpp @@ -158,13 +158,13 @@ BasicBlock* LowerSwitch::switchConvert(CaseItr Begin, CaseItr End, // Create a new node that checks if the value is < pivot. Go to the // left branch if it is and right branch if not. Function* F = OrigBlock->getParent(); - BasicBlock* NewNode = new BasicBlock("NodeBlock"); + BasicBlock* NewNode = BasicBlock::Create("NodeBlock"); Function::iterator FI = OrigBlock; F->getBasicBlockList().insert(++FI, NewNode); ICmpInst* Comp = new ICmpInst(ICmpInst::ICMP_SLT, Val, Pivot.Low, "Pivot"); NewNode->getInstList().push_back(Comp); - new BranchInst(LBranch, RBranch, Comp, NewNode); + BranchInst::Create(LBranch, RBranch, Comp, NewNode); return NewNode; } @@ -179,7 +179,7 @@ BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val, BasicBlock* Default) { Function* F = OrigBlock->getParent(); - BasicBlock* NewLeaf = new BasicBlock("LeafBlock"); + BasicBlock* NewLeaf = BasicBlock::Create("LeafBlock"); Function::iterator FI = OrigBlock; F->getBasicBlockList().insert(++FI, NewLeaf); @@ -213,7 +213,7 @@ BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val, // Make the conditional branch... BasicBlock* Succ = Leaf.BB; - new BranchInst(Succ, Default, Comp, NewLeaf); + BranchInst::Create(Succ, Default, Comp, NewLeaf); // If there were any PHI nodes in this successor, rewrite one entry // from OrigBlock to come from NewLeaf. @@ -284,17 +284,17 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) { // If there is only the default destination, don't bother with the code below. if (SI->getNumOperands() == 2) { - new BranchInst(SI->getDefaultDest(), CurBlock); + BranchInst::Create(SI->getDefaultDest(), CurBlock); CurBlock->getInstList().erase(SI); return; } // Create a new, empty default block so that the new hierarchy of // if-then statements go to this and the PHI nodes are happy. - BasicBlock* NewDefault = new BasicBlock("NewDefault"); + BasicBlock* NewDefault = BasicBlock::Create("NewDefault"); F->getBasicBlockList().insert(Default, NewDefault); - new BranchInst(Default, NewDefault); + BranchInst::Create(Default, NewDefault); // If there is an entry in any PHI nodes for the default edge, make sure // to update them as well. @@ -317,7 +317,7 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) { OrigBlock, NewDefault); // Branch to our shiny new if-then stuff... - new BranchInst(SwitchBlock, OrigBlock); + BranchInst::Create(SwitchBlock, OrigBlock); // We are now done with the switch instruction, delete it. CurBlock->getInstList().erase(SI); diff --git a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp index 3d25dee..ebd68dd 100644 --- a/lib/Transforms/Utils/PromoteMemoryToRegister.cpp +++ b/lib/Transforms/Utils/PromoteMemoryToRegister.cpp @@ -834,9 +834,9 @@ bool PromoteMem2Reg::QueuePhiNode(BasicBlock *BB, unsigned AllocaNo, // Create a PhiNode using the dereferenced type... and add the phi-node to the // BasicBlock. - PN = new PHINode(Allocas[AllocaNo]->getAllocatedType(), - Allocas[AllocaNo]->getName() + "." + - utostr(Version++), BB->begin()); + PN = PHINode::Create(Allocas[AllocaNo]->getAllocatedType(), + Allocas[AllocaNo]->getName() + "." + + utostr(Version++), BB->begin()); ++NumPHIInsert; PhiToAllocaMap[PN] = AllocaNo; PN->reserveOperandSpace(getNumPreds(BB)); diff --git a/lib/Transforms/Utils/SimplifyCFG.cpp b/lib/Transforms/Utils/SimplifyCFG.cpp index b9a20c1..d11bbb0 100644 --- a/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/lib/Transforms/Utils/SimplifyCFG.cpp @@ -619,7 +619,7 @@ static bool SimplifyEqualityComparisonWithOnlyPredecessor(TerminatorInst *TI, assert(ThisCases.size() == 1 && "Branch can only have one case!"); Value *Cond = BTI->getCondition(); // Insert the new branch. - Instruction *NI = new BranchInst(ThisDef, TI); + Instruction *NI = BranchInst::Create(ThisDef, TI); // Remove PHI node entries for the dead edge. ThisCases[0].second->removePredecessor(TI->getParent()); @@ -689,7 +689,7 @@ static bool SimplifyEqualityComparisonWithOnlyPredecessor(TerminatorInst *TI, CheckEdge = 0; // Insert the new branch. - Instruction *NI = new BranchInst(TheRealDest, TI); + Instruction *NI = BranchInst::Create(TheRealDest, TI); DOUT << "Threading pred instr: " << *Pred->getTerminator() << "Through successor TI: " << *TI << "Leaving: " << *NI << "\n"; @@ -802,7 +802,7 @@ static bool FoldValueComparisonIntoPredecessors(TerminatorInst *TI) { AddPredecessorToBlock(NewSuccessors[i], Pred, BB); // Now that the successors are updated, create the new Switch instruction. - SwitchInst *NewSI = new SwitchInst(CV, PredDefault, PredCases.size(),PTI); + SwitchInst *NewSI = SwitchInst::Create(CV, PredDefault, PredCases.size(), PTI); for (unsigned i = 0, e = PredCases.size(); i != e; ++i) NewSI->addCase(PredCases[i].first, PredCases[i].second); @@ -824,8 +824,8 @@ static bool FoldValueComparisonIntoPredecessors(TerminatorInst *TI) { if (InfLoopBlock == 0) { // Insert it at the end of the loop, because it's either code, // or it won't matter if it's hot. :) - InfLoopBlock = new BasicBlock("infloop", BB->getParent()); - new BranchInst(InfLoopBlock, InfLoopBlock); + InfLoopBlock = BasicBlock::Create("infloop", BB->getParent()); + BranchInst::Create(InfLoopBlock, InfLoopBlock); } NewSI->setSuccessor(i, InfLoopBlock); } @@ -902,8 +902,8 @@ HoistTerminator: // that determines the right value. SelectInst *&SI = InsertedSelects[std::make_pair(BB1V, BB2V)]; if (SI == 0) - SI = new SelectInst(BI->getCondition(), BB1V, BB2V, - BB1V->getName()+"."+BB2V->getName(), NT); + SI = SelectInst::Create(BI->getCondition(), BB1V, BB2V, + BB1V->getName()+"."+BB2V->getName(), NT); // Make the PHI node use the select for all incoming values for BB1/BB2 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) if (PN->getIncomingBlock(i) == BB1 || PN->getIncomingBlock(i) == BB2) @@ -987,9 +987,9 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) { // difficult cases. Instead of being smart about this, just insert a new // block that jumps to the destination block, effectively splitting // the edge we are about to create. - BasicBlock *EdgeBB = new BasicBlock(RealDest->getName()+".critedge", - RealDest->getParent(), RealDest); - new BranchInst(RealDest, EdgeBB); + BasicBlock *EdgeBB = BasicBlock::Create(RealDest->getName()+".critedge", + RealDest->getParent(), RealDest); + BranchInst::Create(RealDest, EdgeBB); PHINode *PN; for (BasicBlock::iterator BBI = RealDest->begin(); (PN = dyn_cast<PHINode>(BBI)); ++BBI) { @@ -1156,7 +1156,7 @@ static bool FoldTwoEntryPHINode(PHINode *PN) { Value *FalseVal = PN->getIncomingValue(PN->getIncomingBlock(0) == IfTrue); - Value *NV = new SelectInst(IfCond, TrueVal, FalseVal, "", AfterPHIIt); + Value *NV = SelectInst::Create(IfCond, TrueVal, FalseVal, "", AfterPHIIt); PN->replaceAllUsesWith(NV); NV->takeName(PN); @@ -1307,7 +1307,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { if (RI->getNumOperands() == 0) { TrueSucc->removePredecessor(BI->getParent()); FalseSucc->removePredecessor(BI->getParent()); - new ReturnInst(0, BI); + ReturnInst::Create(0, BI); BI->getParent()->getInstList().erase(BI); return true; } @@ -1341,8 +1341,8 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { Value *NewRetVal; Value *BrCond = BI->getCondition(); if (TrueValue != FalseValue) - NewRetVal = new SelectInst(BrCond, TrueValue, - FalseValue, "retval", BI); + NewRetVal = SelectInst::Create(BrCond, TrueValue, + FalseValue, "retval", BI); else NewRetVal = TrueValue; @@ -1350,7 +1350,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { << "\n " << *BI << "Select = " << *NewRetVal << "TRUEBLOCK: " << *TrueSucc << "FALSEBLOCK: "<< *FalseSucc; - new ReturnInst(NewRetVal, BI); + ReturnInst::Create(NewRetVal, BI); BI->eraseFromParent(); if (Instruction *BrCondI = dyn_cast<Instruction>(BrCond)) if (isInstructionTriviallyDead(BrCondI)) @@ -1386,13 +1386,13 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { if (II->getUnwindDest() == BB) { // Insert a new branch instruction before the invoke, because this // is now a fall through... - BranchInst *BI = new BranchInst(II->getNormalDest(), II); + BranchInst *BI = BranchInst::Create(II->getNormalDest(), II); Pred->getInstList().remove(II); // Take out of symbol table // Insert the call now... SmallVector<Value*,8> Args(II->op_begin()+3, II->op_end()); - CallInst *CI = new CallInst(II->getCalledValue(), - Args.begin(), Args.end(), II->getName(), BI); + CallInst *CI = CallInst::Create(II->getCalledValue(), + Args.begin(), Args.end(), II->getName(), BI); CI->setCallingConv(II->getCallingConv()); CI->setParamAttrs(II->getParamAttrs()); // If the invoke produced a value, the Call now does instead @@ -1540,9 +1540,9 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { // Otherwise, if there are multiple predecessors, insert a PHI // that merges in the constant and simplify the block result. if (BlockIsSimpleEnoughToThreadThrough(BB)) { - PHINode *NewPN = new PHINode(Type::Int1Ty, - BI->getCondition()->getName()+".pr", - BB->begin()); + PHINode *NewPN = PHINode::Create(Type::Int1Ty, + BI->getCondition()->getName()+".pr", + BB->begin()); for (PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) if ((PBI = dyn_cast<BranchInst>((*PI)->getTerminator())) && PBI != BI && PBI->isConditional() && @@ -1661,8 +1661,8 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { Value *PBIV = PN->getIncomingValue(PBBIdx); if (BIV != PBIV) { // Insert a select in PBI to pick the right value. - Value *NV = new SelectInst(PBICond, PBIV, BIV, - PBIV->getName()+".mux", PBI); + Value *NV = SelectInst::Create(PBICond, PBIV, BIV, + PBIV->getName()+".mux", PBI); PN->setIncomingValue(PBBIdx, NV); } } @@ -1705,10 +1705,10 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { } } else { if (BI->getSuccessor(0) == BB) { - new BranchInst(BI->getSuccessor(1), BI); + BranchInst::Create(BI->getSuccessor(1), BI); BI->eraseFromParent(); } else if (BI->getSuccessor(1) == BB) { - new BranchInst(BI->getSuccessor(0), BI); + BranchInst::Create(BI->getSuccessor(0), BI); BI->eraseFromParent(); Changed = true; } @@ -1761,14 +1761,14 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { if (II->getUnwindDest() == BB) { // Convert the invoke to a call instruction. This would be a good // place to note that the call does not throw though. - BranchInst *BI = new BranchInst(II->getNormalDest(), II); + BranchInst *BI = BranchInst::Create(II->getNormalDest(), II); II->removeFromParent(); // Take out of symbol table // Insert the call now... SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end()); - CallInst *CI = new CallInst(II->getCalledValue(), - Args.begin(), Args.end(), - II->getName(), BI); + CallInst *CI = CallInst::Create(II->getCalledValue(), + Args.begin(), Args.end(), + II->getName(), BI); CI->setCallingConv(II->getCallingConv()); CI->setParamAttrs(II->getParamAttrs()); // If the invoke produced a value, the Call does now instead. @@ -1894,7 +1894,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) { if (!TrueWhenEqual) std::swap(DefaultBB, EdgeBB); // Create the new switch instruction now. - SwitchInst *New = new SwitchInst(CompVal, DefaultBB,Values.size(),BI); + SwitchInst *New = SwitchInst::Create(CompVal, DefaultBB,Values.size(),BI); // Add all of the 'cases' to the switch instruction. for (unsigned i = 0, e = Values.size(); i != e; ++i) diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp index 9f129a8..76b565c 100644 --- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp +++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp @@ -69,14 +69,14 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) { } else if (UnwindingBlocks.size() == 1) { UnwindBlock = UnwindingBlocks.front(); } else { - UnwindBlock = new BasicBlock("UnifiedUnwindBlock", &F); + UnwindBlock = BasicBlock::Create("UnifiedUnwindBlock", &F); new UnwindInst(UnwindBlock); for (std::vector<BasicBlock*>::iterator I = UnwindingBlocks.begin(), E = UnwindingBlocks.end(); I != E; ++I) { BasicBlock *BB = *I; BB->getInstList().pop_back(); // Remove the unwind insn - new BranchInst(UnwindBlock, BB); + BranchInst::Create(UnwindBlock, BB); } } @@ -86,14 +86,14 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) { } else if (UnreachableBlocks.size() == 1) { UnreachableBlock = UnreachableBlocks.front(); } else { - UnreachableBlock = new BasicBlock("UnifiedUnreachableBlock", &F); + UnreachableBlock = BasicBlock::Create("UnifiedUnreachableBlock", &F); new UnreachableInst(UnreachableBlock); for (std::vector<BasicBlock*>::iterator I = UnreachableBlocks.begin(), E = UnreachableBlocks.end(); I != E; ++I) { BasicBlock *BB = *I; BB->getInstList().pop_back(); // Remove the unreachable inst. - new BranchInst(UnreachableBlock, BB); + BranchInst::Create(UnreachableBlock, BB); } } @@ -110,27 +110,27 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) { // nodes (if the function returns values), and convert all of the return // instructions into unconditional branches. // - BasicBlock *NewRetBlock = new BasicBlock("UnifiedReturnBlock", &F); + BasicBlock *NewRetBlock = BasicBlock::Create("UnifiedReturnBlock", &F); SmallVector<Value *, 4> Phis; unsigned NumRetVals = ReturningBlocks[0]->getTerminator()->getNumOperands(); if (NumRetVals == 0) - new ReturnInst(NULL, NewRetBlock); + ReturnInst::Create(NULL, NewRetBlock); else if (const StructType *STy = dyn_cast<StructType>(F.getReturnType())) { Instruction *InsertPt = NewRetBlock->getFirstNonPHI(); for (unsigned i = 0; i < NumRetVals; ++i) { - PHINode *PN = new PHINode(STy->getElementType(i), "UnifiedRetVal." - + utostr(i), InsertPt); + PHINode *PN = PHINode::Create(STy->getElementType(i), "UnifiedRetVal." + + utostr(i), InsertPt); Phis.push_back(PN); } - new ReturnInst(&Phis[0], NumRetVals); + ReturnInst::Create(&Phis[0], NumRetVals); } else { // If the function doesn't return void... add a PHI node to the block... - PHINode *PN = new PHINode(F.getReturnType(), "UnifiedRetVal"); + PHINode *PN = PHINode::Create(F.getReturnType(), "UnifiedRetVal"); NewRetBlock->getInstList().push_back(PN); Phis.push_back(PN); - new ReturnInst(PN, NewRetBlock); + ReturnInst::Create(PN, NewRetBlock); } // Loop over all of the blocks, replacing the return instruction with an @@ -149,7 +149,7 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) { } BB->getInstList().pop_back(); // Remove the return insn - new BranchInst(NewRetBlock, BB); + BranchInst::Create(NewRetBlock, BB); } ReturnBlock = NewRetBlock; return true; |