summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabor Greif <ggreif@gmail.com>2008-04-06 20:25:17 +0000
committerGabor Greif <ggreif@gmail.com>2008-04-06 20:25:17 +0000
commit051a950000e21935165db56695e35bade668193b (patch)
tree76db4bc690c153a1cfbd2989849c3b1d95500390
parentd963ab1f58adb6daa028533ff3285841d7e45f80 (diff)
downloadllvm-051a950000e21935165db56695e35bade668193b.tar.gz
llvm-051a950000e21935165db56695e35bade668193b.tar.bz2
llvm-051a950000e21935165db56695e35bade668193b.tar.xz
API changes for class Use size reduction, wave 1.
Specifically, introduction of XXX::Create methods for Users that have a potentially variable number of Uses. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49277 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--examples/BrainF/BrainF.cpp28
-rw-r--r--examples/BrainF/BrainFDriver.cpp8
-rw-r--r--examples/Fibonacci/fibonacci.cpp16
-rw-r--r--examples/HowToUseJIT/HowToUseJIT.cpp10
-rw-r--r--examples/ModuleMaker/ModuleMaker.cpp6
-rw-r--r--examples/ParallelJIT/ParallelJIT.cpp20
-rw-r--r--include/llvm/BasicBlock.h17
-rw-r--r--include/llvm/Constants.h31
-rw-r--r--include/llvm/Function.h9
-rw-r--r--include/llvm/GlobalAlias.h4
-rw-r--r--include/llvm/GlobalVariable.h5
-rw-r--r--include/llvm/InstrTypes.h16
-rw-r--r--include/llvm/Instructions.h197
-rw-r--r--include/llvm/Support/LLVMBuilder.h32
-rw-r--r--include/llvm/User.h6
-rw-r--r--lib/Analysis/ScalarEvolutionExpander.cpp6
-rw-r--r--lib/AsmParser/llvmAsmParser.y38
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp34
-rw-r--r--lib/CodeGen/IntrinsicLowering.cpp82
-rw-r--r--lib/CodeGen/ShadowStackCollector.cpp10
-rw-r--r--lib/ExecutionEngine/JIT/JIT.cpp12
-rw-r--r--lib/Linker/LinkModules.cpp8
-rw-r--r--lib/Target/X86/X86TargetAsmInfo.cpp2
-rw-r--r--lib/Transforms/IPO/ArgumentPromotion.cpp24
-rw-r--r--lib/Transforms/IPO/DeadArgumentElimination.cpp18
-rw-r--r--lib/Transforms/IPO/ExtractGV.cpp4
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp35
-rw-r--r--lib/Transforms/IPO/IndMemRemoval.cpp20
-rw-r--r--lib/Transforms/IPO/LowerSetJmp.cpp42
-rw-r--r--lib/Transforms/IPO/PruneEH.cpp6
-rw-r--r--lib/Transforms/IPO/RaiseAllocations.cpp4
-rw-r--r--lib/Transforms/IPO/SimplifyLibCalls.cpp82
-rw-r--r--lib/Transforms/IPO/StructRetPromotion.cpp16
-rw-r--r--lib/Transforms/Instrumentation/ProfilingUtils.cpp4
-rw-r--r--lib/Transforms/Instrumentation/RSProfiling.cpp37
-rw-r--r--lib/Transforms/Scalar/ADCE.cpp6
-rw-r--r--lib/Transforms/Scalar/GCSE.cpp2
-rw-r--r--lib/Transforms/Scalar/GVN.cpp8
-rw-r--r--lib/Transforms/Scalar/GVNPRE.cpp32
-rw-r--r--lib/Transforms/Scalar/IndVarSimplify.cpp10
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp108
-rw-r--r--lib/Transforms/Scalar/LoopIndexSplit.cpp26
-rw-r--r--lib/Transforms/Scalar/LoopRotation.cpp14
-rw-r--r--lib/Transforms/Scalar/LoopStrengthReduce.cpp2
-rw-r--r--lib/Transforms/Scalar/LoopUnswitch.cpp20
-rw-r--r--lib/Transforms/Scalar/SCCP.cpp2
-rw-r--r--lib/Transforms/Scalar/ScalarReplAggregates.cpp38
-rw-r--r--lib/Transforms/Scalar/SimplifyCFG.cpp6
-rw-r--r--lib/Transforms/Scalar/TailRecursionElimination.cpp12
-rw-r--r--lib/Transforms/Utils/BasicBlockUtils.cpp2
-rw-r--r--lib/Transforms/Utils/BreakCriticalEdges.cpp6
-rw-r--r--lib/Transforms/Utils/CloneFunction.cpp10
-rw-r--r--lib/Transforms/Utils/CloneModule.cpp4
-rw-r--r--lib/Transforms/Utils/CodeExtractor.cpp62
-rw-r--r--lib/Transforms/Utils/InlineFunction.cpp34
-rw-r--r--lib/Transforms/Utils/LCSSA.cpp8
-rw-r--r--lib/Transforms/Utils/Local.cpp4
-rw-r--r--lib/Transforms/Utils/LoopSimplify.cpp14
-rw-r--r--lib/Transforms/Utils/LowerAllocations.cpp4
-rw-r--r--lib/Transforms/Utils/LowerInvoke.cpp64
-rw-r--r--lib/Transforms/Utils/LowerSwitch.cpp16
-rw-r--r--lib/Transforms/Utils/PromoteMemoryToRegister.cpp6
-rw-r--r--lib/Transforms/Utils/SimplifyCFG.cpp60
-rw-r--r--lib/Transforms/Utils/UnifyFunctionExitNodes.cpp24
-rw-r--r--lib/VMCore/AutoUpgrade.cpp15
-rw-r--r--lib/VMCore/BasicBlock.cpp10
-rw-r--r--lib/VMCore/Constants.cpp47
-rw-r--r--lib/VMCore/Core.cpp10
-rw-r--r--lib/VMCore/Function.cpp2
-rw-r--r--lib/VMCore/Instructions.cpp16
-rw-r--r--lib/VMCore/Module.cpp4
-rw-r--r--tools/bugpoint/CrashDebugger.cpp4
-rw-r--r--tools/bugpoint/Miscompilation.cpp56
73 files changed, 972 insertions, 685 deletions
diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp
index a920793648..b2959f2000 100644
--- a/examples/BrainF/BrainF.cpp
+++ b/examples/BrainF/BrainF.cpp
@@ -74,7 +74,7 @@ void BrainF::header() {
brainf_func = cast<Function>(module->
getOrInsertFunction("brainf", Type::VoidTy, NULL));
- builder = new LLVMBuilder(new BasicBlock(label, brainf_func));
+ builder = new LLVMBuilder(BasicBlock::Create(label, brainf_func));
//%arr = malloc i8, i32 %d
ConstantInt *val_mem = ConstantInt::get(APInt(32, memtotal));
@@ -110,13 +110,13 @@ void BrainF::header() {
//Function footer
//brainf.end:
- endbb = new BasicBlock(label, brainf_func);
+ endbb = BasicBlock::Create(label, brainf_func);
//free i8 *%arr
new FreeInst(ptr_arr, endbb);
//ret void
- new ReturnInst(endbb);
+ ReturnInst::Create(endbb);
@@ -141,7 +141,7 @@ void BrainF::header() {
PointerType::getUnqual(IntegerType::Int8Ty), NULL));
//brainf.aberror:
- aberrorbb = new BasicBlock(label, brainf_func);
+ aberrorbb = BasicBlock::Create(label, brainf_func);
//call i32 @puts(i8 *getelementptr([%d x i8] *@aberrormsg, i32 0, i32 0))
{
@@ -161,14 +161,14 @@ void BrainF::header() {
};
CallInst *puts_call =
- new CallInst(puts_func,
- puts_params, array_endof(puts_params),
- "", aberrorbb);
+ CallInst::Create(puts_func,
+ puts_params, array_endof(puts_params),
+ "", aberrorbb);
puts_call->setTailCall(false);
}
//br label %brainf.end
- new BranchInst(endbb, aberrorbb);
+ BranchInst::Create(endbb, aberrorbb);
}
}
@@ -247,7 +247,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) {
CreateOr(test_0, test_1, testreg);
//br i1 %test.%d, label %main.%d, label %main.%d
- BasicBlock *nextbb = new BasicBlock(label, brainf_func);
+ BasicBlock *nextbb = BasicBlock::Create(label, brainf_func);
builder->CreateCondBr(test_2, aberrorbb, nextbb);
//main.%d:
@@ -273,16 +273,16 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) {
case SYM_LOOP:
{
//br label %main.%d
- BasicBlock *testbb = new BasicBlock(label, brainf_func);
+ BasicBlock *testbb = BasicBlock::Create(label, brainf_func);
builder->CreateBr(testbb);
//main.%d:
BasicBlock *bb_0 = builder->GetInsertBlock();
- BasicBlock *bb_1 = new BasicBlock(label, brainf_func);
+ BasicBlock *bb_1 = BasicBlock::Create(label, brainf_func);
builder->SetInsertPoint(bb_1);
//Make part of PHI instruction now, wait until end of loop to finish
- PHINode *phi_0 = new PHINode(PointerType::getUnqual(IntegerType::Int8Ty),
+ PHINode *phi_0 = PHINode::Create(PointerType::getUnqual(IntegerType::Int8Ty),
headreg, testbb);
phi_0->reserveOperandSpace(2);
phi_0->addIncoming(curhead, bb_0);
@@ -431,8 +431,8 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) {
testbb);
//br i1 %test.%d, label %main.%d, label %main.%d
- BasicBlock *bb_0 = new BasicBlock(label, brainf_func);
- new BranchInst(bb_0, oldbb, test_0, testbb);
+ BasicBlock *bb_0 = BasicBlock::Create(label, brainf_func);
+ BranchInst::Create(bb_0, oldbb, test_0, testbb);
//main.%d:
builder->SetInsertPoint(bb_0);
diff --git a/examples/BrainF/BrainFDriver.cpp b/examples/BrainF/BrainFDriver.cpp
index 2a3d546bde..0a24d7b665 100644
--- a/examples/BrainF/BrainFDriver.cpp
+++ b/examples/BrainF/BrainFDriver.cpp
@@ -70,17 +70,17 @@ void addMainFunction(Module *mod) {
}
//main.0:
- BasicBlock *bb = new BasicBlock("main.0", main_func);
+ BasicBlock *bb = BasicBlock::Create("main.0", main_func);
//call void @brainf()
{
- CallInst *brainf_call = new CallInst(mod->getFunction("brainf"),
- "", bb);
+ CallInst *brainf_call = CallInst::Create(mod->getFunction("brainf"),
+ "", bb);
brainf_call->setTailCall(false);
}
//ret i32 0
- new ReturnInst(ConstantInt::get(APInt(32, 0)), bb);
+ ReturnInst::Create(ConstantInt::get(APInt(32, 0)), bb);
}
int main(int argc, char **argv) {
diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp
index b028c4b794..f5ef0d02a8 100644
--- a/examples/Fibonacci/fibonacci.cpp
+++ b/examples/Fibonacci/fibonacci.cpp
@@ -43,7 +43,7 @@ static Function *CreateFibFunction(Module *M) {
(Type *)0));
// Add a basic block to the function.
- BasicBlock *BB = new BasicBlock("EntryBlock", FibF);
+ BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF);
// Get pointers to the constants.
Value *One = ConstantInt::get(Type::Int32Ty, 1);
@@ -54,25 +54,25 @@ static Function *CreateFibFunction(Module *M) {
ArgX->setName("AnArg"); // Give it a nice symbolic name for fun.
// Create the true_block.
- BasicBlock *RetBB = new BasicBlock("return", FibF);
+ BasicBlock *RetBB = BasicBlock::Create("return", FibF);
// Create an exit block.
- BasicBlock* RecurseBB = new BasicBlock("recurse", FibF);
+ BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);
// Create the "if (arg <= 2) goto exitbb"
Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB);
- new BranchInst(RetBB, RecurseBB, CondInst, BB);
+ BranchInst::Create(RetBB, RecurseBB, CondInst, BB);
// Create: ret int 1
- new ReturnInst(One, RetBB);
+ ReturnInst::Create(One, RetBB);
// create fib(x-1)
Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB);
- CallInst *CallFibX1 = new CallInst(FibF, Sub, "fibx1", RecurseBB);
+ CallInst *CallFibX1 = CallInst::Create(FibF, Sub, "fibx1", RecurseBB);
CallFibX1->setTailCall();
// create fib(x-2)
Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB);
- CallInst *CallFibX2 = new CallInst(FibF, Sub, "fibx2", RecurseBB);
+ CallInst *CallFibX2 = CallInst::Create(FibF, Sub, "fibx2", RecurseBB);
CallFibX2->setTailCall();
@@ -81,7 +81,7 @@ static Function *CreateFibFunction(Module *M) {
"addresult", RecurseBB);
// Create the return instruction and add it to the basic block
- new ReturnInst(Sum, RecurseBB);
+ ReturnInst::Create(Sum, RecurseBB);
return FibF;
}
diff --git a/examples/HowToUseJIT/HowToUseJIT.cpp b/examples/HowToUseJIT/HowToUseJIT.cpp
index b79c6d42eb..2aba8e1128 100644
--- a/examples/HowToUseJIT/HowToUseJIT.cpp
+++ b/examples/HowToUseJIT/HowToUseJIT.cpp
@@ -58,7 +58,7 @@ int main() {
// Add a basic block to the function. As before, it automatically inserts
// because of the last argument.
- BasicBlock *BB = new BasicBlock("EntryBlock", Add1F);
+ BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F);
// Get pointers to the constant `1'.
Value *One = ConstantInt::get(Type::Int32Ty, 1);
@@ -72,7 +72,7 @@ int main() {
Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB);
// Create the return instruction and add it to the basic block
- new ReturnInst(Add, BB);
+ ReturnInst::Create(Add, BB);
// Now, function add1 is ready.
@@ -83,17 +83,17 @@ int main() {
cast<Function>(M->getOrInsertFunction("foo", Type::Int32Ty, (Type *)0));
// Add a basic block to the FooF function.
- BB = new BasicBlock("EntryBlock", FooF);
+ BB = BasicBlock::Create("EntryBlock", FooF);
// Get pointers to the constant `10'.
Value *Ten = ConstantInt::get(Type::Int32Ty, 10);
// Pass Ten to the call call:
- CallInst *Add1CallRes = new CallInst(Add1F, Ten, "add1", BB);
+ CallInst *Add1CallRes = CallInst::Create(Add1F, Ten, "add1", BB);
Add1CallRes->setTailCall(true);
// Create the return instruction and add it to the basic block.
- new ReturnInst(Add1CallRes, BB);
+ ReturnInst::Create(Add1CallRes, BB);
// Now we create the JIT.
ExistingModuleProvider* MP = new ExistingModuleProvider(M);
diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp
index 1d630a4d77..40d2fa99f4 100644
--- a/examples/ModuleMaker/ModuleMaker.cpp
+++ b/examples/ModuleMaker/ModuleMaker.cpp
@@ -32,11 +32,11 @@ int main() {
// By passing a module as the last parameter to the Function constructor,
// it automatically gets appended to the Module.
- Function *F = new Function(FT, Function::ExternalLinkage, "main", M);
+ Function *F = Function::Create(FT, Function::ExternalLinkage, "main", M);
// Add a basic block to the function... again, it automatically inserts
// because of the last argument.
- BasicBlock *BB = new BasicBlock("EntryBlock", F);
+ BasicBlock *BB = BasicBlock::Create("EntryBlock", F);
// Get pointers to the constant integers...
Value *Two = ConstantInt::get(Type::Int32Ty, 2);
@@ -50,7 +50,7 @@ int main() {
BB->getInstList().push_back(Add);
// Create the return instruction and add it to the basic block
- BB->getInstList().push_back(new ReturnInst(Add));
+ BB->getInstList().push_back(ReturnInst::Create(Add));
// Output the bitcode file to stdout
WriteBitcodeToFile(M, std::cout);
diff --git a/examples/ParallelJIT/ParallelJIT.cpp b/examples/ParallelJIT/ParallelJIT.cpp
index 92d8f27f8b..300c432863 100644
--- a/examples/ParallelJIT/ParallelJIT.cpp
+++ b/examples/ParallelJIT/ParallelJIT.cpp
@@ -39,7 +39,7 @@ static Function* createAdd1(Module *M) {
// Add a basic block to the function. As before, it automatically inserts
// because of the last argument.
- BasicBlock *BB = new BasicBlock("EntryBlock", Add1F);
+ BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F);
// Get pointers to the constant `1'.
Value *One = ConstantInt::get(Type::Int32Ty, 1);
@@ -53,7 +53,7 @@ static Function* createAdd1(Module *M) {
Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB);
// Create the return instruction and add it to the basic block
- new ReturnInst(Add, BB);
+ ReturnInst::Create(Add, BB);
// Now, function add1 is ready.
return Add1F;
@@ -67,7 +67,7 @@ static Function *CreateFibFunction(Module *M) {
(Type *)0));
// Add a basic block to the function.
- BasicBlock *BB = new BasicBlock("EntryBlock", FibF);
+ BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF);
// Get pointers to the constants.
Value *One = ConstantInt::get(Type::Int32Ty, 1);
@@ -78,31 +78,31 @@ static Function *CreateFibFunction(Module *M) {
ArgX->setName("AnArg"); // Give it a nice symbolic name for fun.
// Create the true_block.
- BasicBlock *RetBB = new BasicBlock("return", FibF);
+ BasicBlock *RetBB = BasicBlock::Create("return", FibF);
// Create an exit block.
- BasicBlock* RecurseBB = new BasicBlock("recurse", FibF);
+ BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);
// Create the "if (arg < 2) goto exitbb"
Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB);
- new BranchInst(RetBB, RecurseBB, CondInst, BB);
+ BranchInst::Create(RetBB, RecurseBB, CondInst, BB);
// Create: ret int 1
- new ReturnInst(One, RetBB);
+ ReturnInst::Create(One, RetBB);
// create fib(x-1)
Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB);
- Value *CallFibX1 = new CallInst(FibF, Sub, "fibx1", RecurseBB);
+ Value *CallFibX1 = CallInst::Create(FibF, Sub, "fibx1", RecurseBB);
// create fib(x-2)
Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB);
- Value *CallFibX2 = new CallInst(FibF, Sub, "fibx2", RecurseBB);
+ Value *CallFibX2 = CallInst::Create(FibF, Sub, "fibx2", RecurseBB);
// fib(x-1)+fib(x-2)
Value *Sum =
BinaryOperator::createAdd(CallFibX1, CallFibX2, "addresult", RecurseBB);
// Create the return instruction and add it to the basic block
- new ReturnInst(Sum, RecurseBB);
+ ReturnInst::Create(Sum, RecurseBB);
return FibF;
}
diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h
index 253a8fa1a0..797f50e864 100644
--- a/include/llvm/BasicBlock.h
+++ b/include/llvm/BasicBlock.h
@@ -66,17 +66,22 @@ private :
BasicBlock(const BasicBlock &); // Do not implement
void operator=(const BasicBlock &); // Do not implement
-public:
- /// Instruction iterators...
- typedef InstListType::iterator iterator;
- typedef InstListType::const_iterator const_iterator;
-
/// BasicBlock ctor - If the function parameter is specified, the basic block
/// is automatically inserted at either the end of the function (if
/// InsertBefore is null), or before the specified basic block.
///
explicit BasicBlock(const std::string &Name = "", Function *Parent = 0,
- BasicBlock *InsertBefore = 0, BasicBlock *unwindDest = 0);
+ BasicBlock *InsertBefore = 0, BasicBlock *UnwindDest = 0);
+public:
+ /// Instruction iterators...
+ typedef InstListType::iterator iterator;
+ typedef InstListType::const_iterator const_iterator;
+
+ // allocate space for exactly zero operands
+ static BasicBlock *Create(const std::string &Name = "", Function *Parent = 0,
+ BasicBlock *InsertBefore = 0, BasicBlock *UnwindDest = 0) {
+ return new(!!UnwindDest) BasicBlock(Name, Parent, InsertBefore, UnwindDest);
+ }
~BasicBlock();
/// getUnwindDest - Returns the BasicBlock that flow will enter if an unwind
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index f71c655455..13df601f41 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -43,9 +43,15 @@ struct ConvertConstantType;
/// @brief Class for constant integers.
class ConstantInt : public Constant {
static ConstantInt *TheTrueVal, *TheFalseVal;
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
ConstantInt(const IntegerType *Ty, const APInt& V);
APInt Val;
+protected:
+ // allocate space for exactly zero operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 0);
+ }
public:
/// Return the constant as an APInt value reference. This allows clients to
/// obtain a copy of the value, with all its precision in tact.
@@ -215,9 +221,15 @@ private:
///
class ConstantFP : public Constant {
APFloat Val;
+ void *operator new(size_t, unsigned);// DO NOT IMPLEMENT
ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
protected:
ConstantFP(const Type *Ty, const APFloat& V);
+protected:
+ // allocate space for exactly zero operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 0);
+ }
public:
/// get() - Static factory methods - Return objects of the specified value
static ConstantFP *get(const Type *Ty, const APFloat& V);
@@ -262,10 +274,16 @@ public:
///
class ConstantAggregateZero : public Constant {
friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
protected:
explicit ConstantAggregateZero(const Type *Ty)
: Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
+protected:
+ // allocate space for exactly zero operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 0);
+ }
public:
/// get() - static factory method for creating a null aggregate. It is
/// illegal to call this method with a non-aggregate type.
@@ -457,14 +475,19 @@ public:
///
class ConstantPointerNull : public Constant {
friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
protected:
explicit ConstantPointerNull(const PointerType *T)
: Constant(reinterpret_cast<const Type*>(T),
Value::ConstantPointerNullVal, 0, 0) {}
+protected:
+ // allocate space for exactly zero operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 0);
+ }
public:
-
/// get() - Static factory methods - Return objects of the specified value
static ConstantPointerNull *get(const PointerType *T);
@@ -706,9 +729,15 @@ public:
///
class UndefValue : public Constant {
friend struct ConstantCreator<UndefValue, Type, char>;
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
UndefValue(const UndefValue &); // DO NOT IMPLEMENT
protected:
explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
+protected:
+ // allocate space for exactly zero operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 0);
+ }
public:
/// get() - Static factory methods - Return an 'undef' object of the specified
/// type.
diff --git a/include/llvm/Function.h b/include/llvm/Function.h
index 36b0dd3df8..ae51fe2f00 100644
--- a/include/llvm/Function.h
+++ b/include/llvm/Function.h
@@ -104,13 +104,20 @@ private:
Function(const Function&); // DO NOT IMPLEMENT
void operator=(const Function&); // DO NOT IMPLEMENT
-public:
+
/// Function ctor - If the (optional) Module argument is specified, the
/// function is automatically inserted into the end of the function list for
/// the module.
///
Function(const FunctionType *Ty, LinkageTypes Linkage,
const std::string &N = "", Module *M = 0);
+
+public:
+ static Function *Create(const FunctionType *Ty, LinkageTypes Linkage,
+ const std::string &N = "", Module *M = 0) {
+ return new(0) Function(Ty, Linkage, N, M);
+ }
+
~Function();
const Type *getReturnType() const; // Return the type of the ret val
diff --git a/include/llvm/GlobalAlias.h b/include/llvm/GlobalAlias.h
index 161cb58cbb..b59537c9af 100644
--- a/include/llvm/GlobalAlias.h
+++ b/include/llvm/GlobalAlias.h
@@ -44,6 +44,10 @@ class GlobalAlias : public GlobalValue {
Use Aliasee;
public:
+ // allocate space for exactly zero operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 0);
+ }
/// GlobalAlias ctor - If a parent module is specified, the alias is
/// automatically inserted into the end of the specified module's alias list.
GlobalAlias(const Type *Ty, LinkageTypes Linkage, const std::string &Name = "",
diff --git a/include/llvm/GlobalVariable.h b/include/llvm/GlobalVariable.h
index d733798479..8c6d8030c6 100644
--- a/include/llvm/GlobalVariable.h
+++ b/include/llvm/GlobalVariable.h
@@ -32,6 +32,7 @@ template<typename ValueSubClass, typename ItemParentClass>
class GlobalVariable : public GlobalValue {
friend class SymbolTableListTraits<GlobalVariable, Module>;
+ void *operator new(size_t, unsigned); // Do not implement
void operator=(const GlobalVariable &); // Do not implement
GlobalVariable(const GlobalVariable &); // Do not implement
@@ -46,6 +47,10 @@ class GlobalVariable : public GlobalValue {
Use Initializer;
public:
+ // allocate space for exactly zero operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 0);
+ }
/// GlobalVariable ctor - If a parent module is specified, the global is
/// automatically inserted into the end of the specified modules global list.
GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage,
diff --git a/include/llvm/InstrTypes.h b/include/llvm/InstrTypes.h
index 7441a104b5..ef0ee89a3e 100644
--- a/include/llvm/InstrTypes.h
+++ b/include/llvm/InstrTypes.h
@@ -83,6 +83,7 @@ public:
//===----------------------------------------------------------------------===//
class UnaryInstruction : public Instruction {
+ void *operator new(size_t, unsigned); // Do not implement
Use Op;
// avoiding warning: 'this' : used in base member initializer list
@@ -95,6 +96,11 @@ protected:
: Instruction(Ty, iType, &Op, 1, IAE), Op(V, this_()) {
}
public:
+ // allocate space for exactly one operand
+ void *operator new(size_t s) {
+ return User::operator new(s, 1);
+ }
+
// Out of line virtual method, so the vtable, etc has a home.
~UnaryInstruction();
@@ -129,6 +135,7 @@ public:
//===----------------------------------------------------------------------===//
class BinaryOperator : public Instruction {
+ void *operator new(size_t, unsigned); // Do not implement
Use Ops[2];
protected:
void init(BinaryOps iType);
@@ -137,6 +144,10 @@ protected:
BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
const std::string &Name, BasicBlock *InsertAtEnd);
public:
+ // allocate space for exactly two operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 2);
+ }
/// Transparently provide more efficient getOperand methods.
Value *getOperand(unsigned i) const {
@@ -489,6 +500,7 @@ public:
/// This class is the base class for the comparison instructions.
/// @brief Abstract base class of comparison instructions.
class CmpInst: public Instruction {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
CmpInst(); // do not implement
protected:
CmpInst(Instruction::OtherOps op, unsigned short pred, Value *LHS, Value *RHS,
@@ -500,6 +512,10 @@ protected:
Use Ops[2]; // CmpInst instructions always have 2 operands, optimize
public:
+ // allocate space for exactly two operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 2);
+ }
/// Construct a compare instruction, given the opcode, the predicate and
/// the two operands. Optionally (if InstBefore is specified) insert the
/// instruction into a BasicBlock right before the specified instruction.
diff --git a/include/llvm/Instructions.h b/include/llvm/Instructions.h
index 2f66ffce22..137c5e2231 100644
--- a/include/llvm/Instructions.h
+++ b/include/llvm/Instructions.h
@@ -45,7 +45,7 @@ protected:
AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
const std::string &Name, BasicBlock *InsertAtEnd);
public:
- // Out of line virtual method, so the vtable, etc has a home.
+ // Out of line virtual method, so the vtable, etc. has a home.
virtual ~AllocationInst();
/// isArrayAllocation - Return true if there is an allocation size parameter
@@ -287,6 +287,7 @@ public:
/// StoreInst - an instruction for storing to memory
///
class StoreInst : public Instruction {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Ops[2];
StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
@@ -301,6 +302,10 @@ class StoreInst : public Instruction {
}
void AssertOK();
public:
+ // allocate space for exactly two operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 2);
+ }
StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
@@ -438,7 +443,6 @@ class GetElementPtrInst : public Instruction {
}
}
-public:
/// Constructors - Create a getelementptr instruction with a base pointer an
/// list of indices. The first ctor can optionally insert before an existing
/// instruction, the second appends the new instruction to the specified
@@ -447,7 +451,7 @@ public:
GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
InputIterator IdxEnd,
const std::string &Name = "",
- Instruction *InsertBefore =0)
+ Instruction *InsertBefore = 0)
: Instruction(PointerType::get(
checkType(getIndexedType(Ptr->getType(),
IdxBegin, IdxEnd, true)),
@@ -471,9 +475,33 @@ public:
/// Constructors - These two constructors are convenience methods because one
/// and two index getelementptr instructions are so common.
GetElementPtrInst(Value *Ptr, Value *Idx,
- const std::string &Name = "", Instruction *InsertBefore =0);
+ const std::string &Name = "", Instruction *InsertBefore = 0);
GetElementPtrInst(Value *Ptr, Value *Idx,
const std::string &Name, BasicBlock *InsertAtEnd);
+public:
+ template<typename InputIterator>
+ static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
+ InputIterator IdxEnd,
+ const std::string &Name = "",
+ Instruction *InsertBefore = 0) {
+ return new(0/*FIXME*/) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name, InsertBefore);
+ }
+ template<typename InputIterator>
+ static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
+ const std::string &Name, BasicBlock *InsertAtEnd) {
+ return new(0/*FIXME*/) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name, InsertAtEnd);
+ }
+
+ /// Constructors - These two constructors are convenience methods because one
+ /// and two index getelementptr instructions are so common.
+ static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
+ const std::string &Name = "", Instruction *InsertBefore = 0) {
+ return new(2/*FIXME*/) GetElementPtrInst(Ptr, Idx, Name, InsertBefore);
+ }
+ static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
+ const std::string &Name, BasicBlock *InsertAtEnd) {
+ return new(2/*FIXME*/) GetElementPtrInst(Ptr, Idx, Name, InsertAtEnd);
+ }
~GetElementPtrInst();
virtual GetElementPtrInst *clone() const;
@@ -866,7 +894,6 @@ class CallInst : public Instruction {
setName(Name);
}
-public:
/// Construct a CallInst given a range of arguments. InputIterator
/// must be a random-access iterator pointing to contiguous storage
/// (e.g. a std::vector<>::iterator). Checks are made for
@@ -906,6 +933,33 @@ public:
explicit CallInst(Value *F, const std::string &Name = "",
Instruction *InsertBefore = 0);
CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
+public:
+ template<typename InputIterator>
+ static CallInst *Create(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
+ const std::string &Name = "", Instruction *InsertBefore = 0) {
+ return new(ArgEnd - ArgBegin + 1) CallInst(Func, ArgBegin, ArgEnd, Name, InsertBefore);
+ }
+ template<typename InputIterator>
+ static CallInst *Create(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
+ const std::string &Name, BasicBlock *InsertAtEnd) {
+ return new(ArgEnd - ArgBegin + 1) CallInst(Func, ArgBegin, ArgEnd, Name, InsertAtEnd);
+ }
+ static CallInst *Create(Value *F, Value *Actual, const std::string& Name = "",
+ Instruction *InsertBefore = 0) {
+ return new(2) CallInst(F, Actual, Name, InsertBefore);
+ }
+ static CallInst *Create(Value *F, Value *Actual, const std::string& Name,
+ BasicBlock *InsertAtEnd) {
+ return new(2) CallInst(F, Actual, Name, InsertAtEnd);
+ }
+ static CallInst *Create(Value *F, const std::string &Name = "",
+ Instruction *InsertBefore = 0) {
+ return new(1) CallInst(F, Name, InsertBefore);
+ }
+ static CallInst *Create(Value *F, const std::string &Name, BasicBlock *InsertAtEnd) {
+ return new(1) CallInst(F, Name, InsertAtEnd);
+ }
+
~CallInst();
virtual CallInst *clone() const;
@@ -1011,7 +1065,6 @@ class SelectInst : public Instruction {
: Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
}
-public:
SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
Instruction *InsertBefore = 0)
: Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
@@ -1024,6 +1077,15 @@ public:
init(C, S1, S2);
setName(Name);
}
+public:
+ static SelectInst *Create(Value *C, Value *S1, Value *S2, const std::string &Name = "",
+ Instruction *InsertBefore = 0) {
+ return new(3) SelectInst(C, S1, S2, Name, InsertBefore);
+ }
+ static SelectInst *Create(Value *C, Value *S1, Value *S2, const std::string &Name,
+ BasicBlock *InsertAtEnd) {
+ return new(3) SelectInst(C, S1, S2, Name, InsertAtEnd);
+ }
Value *getCondition() const { return Ops[0]; }
Value *getTrueValue() const { return Ops[1]; }
@@ -1106,6 +1168,10 @@ class ExtractElementInst : public Instruction {
}
public:
+ // allocate space for exactly two operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 2); // FIXME: unsigned Idx forms of constructor?
+ }
ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
Instruction *InsertBefore = 0);
ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
@@ -1152,7 +1218,6 @@ public:
class InsertElementInst : public Instruction {
Use Ops[3];
InsertElementInst(const InsertElementInst &IE);
-public:
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
const std::string &Name = "",Instruction *InsertBefore = 0);
InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
@@ -1161,6 +1226,26 @@ public:
const std::string &Name, BasicBlock *InsertAtEnd);
InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
const std::string &Name, BasicBlock *InsertAtEnd);
+public:
+ static InsertElementInst *Create(const InsertElementInst &IE) {
+ return new(IE.getNumOperands()) InsertElementInst(IE);
+ }
+ static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
+ const std::string &Name = "",Instruction *InsertBefore = 0) {
+ return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
+ }
+ static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
+ const std::string &Name = "",Instruction *InsertBefore = 0) {
+ return new(3/*FIXME*/) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
+ }
+ static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
+ const std::string &Name, BasicBlock *InsertAtEnd) {
+ return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
+ }
+ static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
+ const std::string &Name, BasicBlock *InsertAtEnd) {
+ return new(3/*FIXME*/) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
+ }
/// isValidOperands - Return true if an insertelement instruction can be
/// formed with the specified operands.
@@ -1207,6 +1292,10 @@ class ShuffleVectorInst : public Instruction {
Use Ops[3];
ShuffleVectorInst(const ShuffleVectorInst &IE);
public:
+ // allocate space for exactly three operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 3);
+ }
ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
const std::string &Name = "", Instruction *InsertBefor = 0);
ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
@@ -1265,11 +1354,15 @@ public:
// scientist's overactive imagination.
//
class PHINode : public Instruction {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
/// ReservedSpace - The number of operands actually allocated. NumOperands is
/// the number actually in use.
unsigned ReservedSpace;
PHINode(const PHINode &PN);
-public:
+ // allocate space for exactly zero operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 0);
+ }
explicit PHINode(const Type *Ty, const std::string &Name = "",
Instruction *InsertBefore = 0)
: Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
@@ -1282,7 +1375,14 @@ public:
ReservedSpace(0) {
setName(Name);
}
-
+public:
+ static PHINode *Create(const Type *Ty, const std::string &Name = "",
+ Instruction *InsertBefore = 0) {
+ return new PHINode(Ty, Name, InsertBefore);
+ }
+ static PHINode *Create(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) {
+ return new PHINode(Ty, Name, InsertAtEnd);
+ }
~PHINode();
/// reserveOperandSpace - This method can be used to avoid repeated
@@ -1401,7 +1501,7 @@ class ReturnInst : public TerminatorInst {
ReturnInst(const ReturnInst &RI);
void init(Value * const* retVals, unsigned N);
-public:
+private:
// ReturnInst constructors:
// ReturnInst() - 'ret void' instruction
// ReturnInst( null) - 'ret void' instruction
@@ -1422,6 +1522,25 @@ public:
ReturnInst(Value * const* retVals, unsigned N, Instruction *InsertBefore);
ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd);
explicit ReturnInst(BasicBlock *InsertAtEnd);
+public:
+ static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) {
+ return new(!!retVal) ReturnInst(retVal, InsertBefore);
+ }
+ static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) {
+ return new(!!retVal) ReturnInst(retVal, InsertAtEnd);
+ }
+ static ReturnInst* Create(Value * const* retVals, unsigned N) {
+ return new(N) ReturnInst(retVals, N);
+ }
+ static ReturnInst* Create(Value * const* retVals, unsigned N, Instruction *InsertBefore) {
+ return new(N) ReturnInst(retVals, N, InsertBefore);
+ }
+ static ReturnInst* Create(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd) {
+ return new(N) ReturnInst(retVals, N, InsertAtEnd);
+ }
+ static ReturnInst* Create(BasicBlock *InsertAtEnd) {
+ return new(0) ReturnInst(InsertAtEnd);
+ }
virtual ~ReturnInst();
virtual ReturnInst *clone() const;
@@ -1467,7 +1586,6 @@ class BranchInst : public TerminatorInst {
Use Ops[3];
BranchInst(const BranchInst &BI);
void AssertOK();
-public:
// BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
// BranchInst(BB *B) - 'br B'
// BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
@@ -1481,6 +1599,21 @@ public:
BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
BasicBlock *InsertAtEnd);
+public:
+ static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
+ return new(1) BranchInst(IfTrue, InsertBefore);
+ }
+ static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
+ Instruction *InsertBefore = 0) {
+ return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
+ }
+ static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
+ return new(1) BranchInst(IfTrue, InsertAtEnd);
+ }
+ static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
+ BasicBlock *InsertAtEnd) {
+ return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
+ }
/// Transparently provide more efficient getOperand methods.
Value *getOperand(unsigned i) const {
@@ -1561,7 +1694,6 @@ class SwitchInst : public TerminatorInst {
SwitchInst(const SwitchInst &RI);
void init(Value *Value, BasicBlock *Default, unsigned NumCases);
void resizeOperands(unsigned No);
-public:
/// SwitchInst ctor - Create a new switch instruction, specifying a value to
/// switch on and a default destination. The number of additional cases can
/// be specified here to make memory allocation more efficient. This
@@ -1575,9 +1707,17 @@ public:
/// constructor also autoinserts at the end of the specified BasicBlock.
SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
BasicBlock *InsertAtEnd);
+public:
+ static SwitchInst *Create(Value *Value, BasicBlock *Default, unsigned NumCases,
+ Instruction *InsertBefore = 0) {
+ return new(NumCases/*FIXME*/) SwitchInst(Value, Default, NumCases, InsertBefore);
+ }
+ static SwitchInst *Create(Value *Value, BasicBlock *Default, unsigned NumCases,
+ BasicBlock *InsertAtEnd) {
+ return new(NumCases/*FIXME*/) SwitchInst(Value, Default, NumCases, InsertAtEnd);
+ }
~SwitchInst();
-
// Accessor Methods for Switch stmt
Value *getCondition() const { return getOperand(0); }
void setCondition(Value *V) { setOperand(0, V); }
@@ -1703,7 +1843,6 @@ class InvokeInst : public TerminatorInst {
setName(Name);
}
-public:
/// Construct an InvokeInst given a range of arguments.
/// InputIterator must be a random-access iterator pointing to
/// contiguous storage (e.g. a std::vector<>::iterator). Checks are
@@ -1739,6 +1878,19 @@ public:
init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
typename std::iterator_traits<InputIterator>::iterator_category());
}
+public:
+ template<typename InputIterator>
+ static InvokeInst *Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
+ InputIterator ArgBegin, InputIterator ArgEnd,
+ const std::string &Name = "", Instruction *InsertBefore = 0) {
+ return new(ArgEnd - ArgBegin + 3) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, InsertBefore);
+ }
+ template<typename InputIterator>
+ static InvokeInst *Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
+ InputIterator ArgBegin, InputIterator ArgEnd,
+ const std::string &Name, BasicBlock *InsertAtEnd) {
+ return new(ArgEnd - ArgBegin + 3) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, InsertAtEnd);
+ }
~InvokeInst();
@@ -1856,7 +2008,12 @@ private:
/// until an invoke instruction is found.
///
class UnwindInst : public TerminatorInst {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
public:
+ // allocate space for exactly zero operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 0);
+ }
explicit UnwindInst(Instruction *InsertBefore = 0);
explicit UnwindInst(BasicBlock *InsertAtEnd);
@@ -1888,7 +2045,12 @@ private:
/// end of the block cannot be reached.
///
class UnreachableInst : public TerminatorInst {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
public:
+ // allocate space for exactly zero operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 0);
+ }
explicit UnreachableInst(Instruction *InsertBefore = 0);
explicit UnreachableInst(BasicBlock *InsertAtEnd);
@@ -2388,7 +2550,8 @@ public:
/// GetResultInst - This instruction extracts individual result value from
/// aggregate value, where aggregate value is returned by CallInst.
///
-class GetResultInst : public Instruction {
+class GetResultInst : public /*FIXME: Unary*/Instruction {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Aggr;
unsigned Idx;
GetResultInst(const GetResultInst &GRI) :
@@ -2398,6 +2561,10 @@ class GetResultInst : public Instruction {
}
public:
+ // allocate space for exactly one operand
+ void *operator new(size_t s) {
+ return User::operator new(s, 1);
+ }
explicit GetResultInst(Value *Aggr, unsigned index,
const std::string &Name = "",
Instruction *InsertBefore = 0);
diff --git a/include/llvm/Support/LLVMBuilder.h b/include/llvm/Support/LLVMBuilder.h
index 2a7fc635d7..c82bfd7b18 100644
--- a/include/llvm/Support/LLVMBuilder.h
+++ b/include/llvm/Support/LLVMBuilder.h
@@ -87,32 +87,32 @@ public:
/// CreateRetVoid - Create a 'ret void' instruction.
ReturnInst *CreateRetVoid() {
- return Insert(new ReturnInst());
+ return Insert(ReturnInst::Create());
}
/// @verbatim
/// CreateRet - Create a 'ret <val>' instruction.
/// @endverbatim
ReturnInst *CreateRet(Value *V) {
- return Insert(new ReturnInst(V));
+ return Insert(ReturnInst::Create(V));
}
/// CreateBr - Create an unconditional 'br label X' instruction.
BranchInst *CreateBr(BasicBlock *Dest) {
- return Insert(new BranchInst(Dest));
+ return Insert(BranchInst::Create(Dest));
}
/// CreateCondBr - Create a conditional 'br Cond, TrueDest, FalseDest'
/// instruction.
BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False) {
- return Insert(new BranchInst(True, False, Cond));
+ return Insert(BranchInst::Create(True, False, Cond));
}
/// CreateSwitch - Create a switch instruction with the specified value,
/// default dest, and with a hint for the number of cases that will be added
/// (for efficient allocation).
SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10) {
- return Insert(new SwitchInst(V, Dest, NumCases));
+ return Insert(SwitchInst::Create(V, Dest, NumCases));
}
/// CreateInvoke - Create an invoke instruction.
@@ -120,8 +120,8 @@ public:
InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
BasicBlock *UnwindDest, InputIterator ArgBegin,
InputIterator ArgEnd, const char *Name = "") {
- return(Insert(new InvokeInst(Callee, NormalDest, UnwindDest,
- ArgBegin, ArgEnd, Name)));
+ return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest,
+ ArgBegin, ArgEnd, Name));
}
UnwindInst *CreateUnwind() {
@@ -221,10 +221,10 @@ public:
template<typename InputIterator>
GetElementPtrInst *CreateGEP(Value *Ptr, InputIterator IdxBegin,
InputIterator IdxEnd, const char *Name = "") {
- return(Insert(new GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name)));
+ return(Insert(GetElementPtrInst::Create(Ptr, IdxBegin, IdxEnd, Name)));
}
GetElementPtrInst *CreateGEP(Value *Ptr, Value *Idx, const char *Name = "") {
- return Insert(new GetElementPtrInst(Ptr, Idx, Name));
+ return Insert(GetElementPtrInst::Create(Ptr, Idx, Name));
}
GetElementPtrInst *CreateStructGEP(Value *Ptr, unsigned Idx,
const char *Name = "") {
@@ -232,7 +232,7 @@ public:
ConstantInt::get(llvm::Type::Int32Ty, 0),
ConstantInt::get(llvm::Type::Int32Ty, Idx)
};
- return Insert(new GetElementPtrInst(Ptr, Idxs, Idxs+2, Name));
+ return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2, Name));
}
//===--------------------------------------------------------------------===//
@@ -384,25 +384,25 @@ public:
//===--------------------------------------------------------------------===//
PHINode *CreatePHI(const Type *Ty, const char *Name = "") {
- return Insert(new PHINode(Ty, Name));
+ return Insert(PHINode::Create(Ty, Name));
}
CallInst *CreateCall(Value *Callee, const char *Name = "") {
- return Insert(new CallInst(Callee, Name));
+ return Insert(CallInst::Create(Callee, Name));
}
CallInst *CreateCall(Value *Callee, Value *Arg, const char *Name = "") {
- return Insert(new CallInst(Callee, Arg, Name));
+ return Insert(CallInst::Create(Callee, Arg, Name));
}
template<typename InputIterator>
CallInst *CreateCall(Value *Callee, InputIterator ArgBegin,
InputIterator ArgEnd, const char *Name = "") {
- return(Insert(new CallInst(Callee, ArgBegin, ArgEnd, Name)));
+ return Insert(CallInst::Create(Callee, ArgBegin, ArgEnd, Name));
}
SelectInst *CreateSelect(Value *C, Value *True, Value *False,
const char *Name = "") {
- return Insert(new SelectInst(C, True, False, Name));
+ return Insert(SelectInst::Create(C, True, False, Name));
}
VAArgInst *CreateVAArg(Value *List, const Type *Ty, const char *Name = "") {
@@ -416,7 +416,7 @@ public:
InsertElementInst *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx,
const char *Name = "") {
- return Insert(new InsertElementInst(Vec, NewElt, Idx, Name));
+ return Insert(InsertElementInst::Create(Vec, NewElt, Idx, Name));
}
ShuffleVectorInst *CreateShuffleVector(Value *V1, Value *V2, Value *Mask,
diff --git a/include/llvm/User.h b/include/llvm/User.h
index 0f1dcfe7a0..77bba9de64 100644
--- a/include/llvm/User.h
+++ b/include/llvm/User.h
@@ -25,6 +25,7 @@ namespace llvm {
class User : public Value {
User(const User &); // Do not implement
+ void *operator new(size_t); // Do not implement
protected:
/// OperandList - This is a pointer to the array of Users for this operand.
/// For nodes of fixed arity (e.g. a binary operator) this array will live
@@ -38,10 +39,13 @@ protected:
///
unsigned NumOperands;
-public:
+ void *operator new(size_t s, unsigned) {
+ return ::operator new(s);
+ }
User(const Type *Ty, unsigned vty, Use *OpList, unsigned NumOps)
: Value(Ty, vty), OperandList(OpList), NumOperands(NumOps) {}
+public:
Value *getOperand(unsigned i) const {
assert(i < NumOperands && "getOperand() out of range!");
return OperandList[i];
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
index 0a0327d925..7ef1948b6a 100644
--- a/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -143,7 +143,7 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) {
// Create and insert the PHI node for the induction variable in the
// specified loop.
BasicBlock *Header = L->getHeader();
- PHINode *PN = new PHINode(Ty, "indvar", Header->begin());
+ PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin());
PN->addIncoming(Constant::getNullValue(Ty), L->getLoopPreheader());
pred_iterator HPI = pred_begin(Header);
@@ -215,7 +215,7 @@ Value *SCEVExpander::visitSMaxExpr(SCEVSMaxExpr *S) {
for (unsigned i = 1; i < S->getNumOperands(); ++i) {
Value *RHS = expand(S->getOperand(i));
Value *ICmp = new ICmpInst(ICmpInst::ICMP_SGT, LHS, RHS, "tmp", InsertPt);
- LHS = new SelectInst(ICmp, LHS, RHS, "smax", InsertPt);
+ LHS = SelectInst::Create(ICmp, LHS, RHS, "smax", InsertPt);
}
return LHS;
}
@@ -225,7 +225,7 @@ Value *SCEVExpander::visitUMaxExpr(SCEVUMaxExpr *S) {
for (unsigned i = 1; i < S->getNumOperands(); ++i) {
Value *RHS = expand(S->getOperand(i));
Value *ICmp = new ICmpInst(ICmpInst::ICMP_UGT, LHS, RHS, "tmp", InsertPt);
- LHS = new SelectInst(ICmp, LHS, RHS, "umax", InsertPt);
+ LHS = SelectInst::Create(ICmp, LHS, RHS, "umax", InsertPt);
}
return LHS;
}
diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y
index 6aab1fe40b..5209d21830 100644
--- a/lib/AsmParser/llvmAsmParser.y
+++ b/lib/AsmParser/llvmAsmParser.y
@@ -493,7 +493,7 @@ static Value *getVal(const Type *Ty, const ValID &ID) {
}
const Type* ElTy = PTy->getElementType();
if (const FunctionType *FTy = dyn_cast<FunctionType>(ElTy))
- V = new Function(FTy, GlobalValue::ExternalLinkage);
+ V = Function::Create(FTy, GlobalValue::ExternalLinkage);
else
V = new GlobalVariable(ElTy, false, GlobalValue::ExternalLinkage, 0, "",
(Module*)0, false, PTy->getAddressSpace());
@@ -551,7 +551,7 @@ static BasicBlock *defineBBVal(const ValID &ID, BasicBlock *unwindDest) {
// We haven't seen this BB before and its first mention is a definition.
// Just create it and return it.
std::string Name (ID.Type == ValID::LocalName ? ID.getName() : "");
- BB = new BasicBlock(Name, CurFun.CurrentFunction);
+ BB = BasicBlock::Create(Name, CurFun.CurrentFunction);
if (ID.Type == ValID::LocalID) {
assert(ID.Num == CurFun.NextValNum && "Invalid new block number");
InsertValue(BB);
@@ -607,7 +607,7 @@ static BasicBlock *getBBVal(const ValID &ID) {
std::string Name;
if (ID.Type == ValID::LocalName)
Name = ID.getName();
- BB = new BasicBlock(Name, CurFun.CurrentFunction);
+ BB = BasicBlock::Create(Name, CurFun.CurrentFunction);
// Insert it in the forward refs map.
CurFun.BBForwardRefs[ID] = BB;
@@ -1779,8 +1779,8 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
GlobalValue *GV;
if (const FunctionType *FTy =
dyn_cast<FunctionType>(PT->getElementType())) {
- GV = new Function(FTy, GlobalValue::ExternalWeakLinkage, Name,
- CurModule.CurrentModule);
+ GV = Function::Create(FTy, GlobalValue::ExternalWeakLinkage, Name,
+ CurModule.CurrentModule);
} else {
GV = new GlobalVariable(PT->getElementType(), false,
GlobalValue::ExternalWeakLinkage, 0,
@@ -2319,8 +2319,8 @@ FunctionHeaderH : OptCallingConv ResultTypes GlobalName '(' ArgList ')'
AI->setName("");
}
} else { // Not already defined?
- Fn = new Function(FT, GlobalValue::ExternalWeakLinkage, FunctionName,
- CurModule.CurrentModule);
+ Fn = Function::Create(FT, GlobalValue::ExternalWeakLinkage, FunctionName,
+ CurModule.CurrentModule);
InsertValue(Fn, CurModule.Values);
}
@@ -2579,18 +2579,18 @@ BBTerminatorInst :
RET ReturnedVal { // Return with a result...
ValueList &VL = *$2;
assert(!VL.empty() && "Invalid ret operands!");
- $$ = new ReturnInst(&VL[0], VL.size());
+ $$ = ReturnInst::Create(&VL[0], VL.size());
delete $2;
CHECK_FOR_ERROR
}
| RET VOID { // Return with no result...
- $$ = new ReturnInst();
+ $$ = ReturnInst::Create();
CHECK_FOR_ERROR
}
| BR LABEL ValueRef { // Unconditional Branch...
BasicBlock* tmpBB = getBBVal($3);
CHECK_FOR_ERROR
- $$ = new BranchInst(tmpBB);
+ $$ = BranchInst::Create(tmpBB);
} // Conditional Branch...
| BR INTTYPE ValueRef ',' LABEL ValueRef ',' LABEL ValueRef {
assert(cast<IntegerType>($2)->getBitWidth() == 1 && "Not Bool?");
@@ -2600,14 +2600,14 @@ BBTerminatorInst :
CHECK_FOR_ERROR
Value* tmpVal = getVal(Type::Int1Ty, $3);
CHECK_FOR_ERROR
- $$ = new BranchInst(tmpBBA, tmpBBB, tmpVal);
+ $$ = BranchInst::Create(tmpBBA, tmpBBB, tmpVal);
}
| SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' {
Value* tmpVal = getVal($2, $3);
CHECK_FOR_ERROR
BasicBlock* tmpBB = getBBVal($6);
CHECK_FOR_ERROR
- SwitchInst *S = new SwitchInst(tmpVal, tmpBB, $8->size());
+ SwitchInst *S = SwitchInst::Create(tmpVal, tmpBB, $8->size());
$$ = S;
std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = $8->begin(),
@@ -2626,7 +2626,7 @@ BBTerminatorInst :
CHECK_FOR_ERROR
BasicBlock* tmpBB = getBBVal($6);
CHECK_FOR_ERROR
- SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0);
+ SwitchInst *S = SwitchInst::Create(tmpVal, tmpBB, 0);
$$ = S;
CHECK_FOR_ERROR
}
@@ -2704,7 +2704,7 @@ BBTerminatorInst :
PAL = PAListPtr::get(Attrs.begin(), Attrs.end());
// Create the InvokeInst
- InvokeInst *II = new InvokeInst(V, Normal, Except, Args.begin(),Args.end());
+ InvokeInst *II = InvokeInst::Create(V, Normal, Except, Args.begin(),Args.end());
II->setCallingConv($2);
II->setParamAttrs(PAL);
$$ = II;
@@ -2911,7 +2911,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
GEN_ERROR("select condition must be boolean");
if ($4->getType() != $6->getType())
GEN_ERROR("select value types should match");
- $$ = new SelectInst($2, $4, $6);
+ $$ = SelectInst::Create($2, $4, $6);
CHECK_FOR_ERROR
}
| VAARG ResolvedVal ',' Types {
@@ -2930,7 +2930,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
| INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
if (!InsertElementInst::isValidOperands($2, $4, $6))
GEN_ERROR("Invalid insertelement operands");
- $$ = new InsertElementInst($2, $4, $6);
+ $$ = InsertElementInst::Create($2, $4, $6);
CHECK_FOR_ERROR
}
| SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal {
@@ -2943,7 +2943,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
const Type *Ty = $2->front().first->getType();
if (!Ty->isFirstClassType())
GEN_ERROR("PHI node operands must be of first class type");
- $$ = new PHINode(Ty);
+ $$ = PHINode::Create(Ty);
((PHINode*)$$)->reserveOperandSpace($2->size());
while ($2->begin() != $2->end()) {
if ($2->front().first->getType() != Ty)
@@ -3031,7 +3031,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
PAL = PAListPtr::get(Attrs.begin(), Attrs.end());
// Create the call node
- CallInst *CI = new CallInst(V, Args.begin(), Args.end());
+ CallInst *CI = CallInst::Create(V, Args.begin(), Args.end());
CI->setTailCall($1);
CI->setCallingConv($2);
CI->setParamAttrs(PAL);
@@ -3144,7 +3144,7 @@ MemoryInst : MALLOC Types OptCAlign {
(*$2)->getDescription()+ "'");
Value* tmpVal = getVal(*$2, $3);
CHECK_FOR_ERROR
- $$ = new GetElementPtrInst(tmpVal, $4->begin(), $4->end());
+ $$ = GetElementPtrInst::Create(tmpVal, $4->begin(), $4->end());
delete $2;
delete $4;
};
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index e948329fe8..1d8def907c 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -122,8 +122,12 @@ namespace {
class ConstantPlaceHolder : public ConstantExpr {
ConstantPlaceHolder(); // DO NOT IMPLEMENT
void operator=(const ConstantPlaceHolder &); // DO NOT IMPLEMENT
- public:
Use Op;
+ public:
+ // allocate space for exactly one operand
+ void *operator new(size_t s) {
+ return User::operator new(s, 1);
+ }
explicit ConstantPlaceHolder(const Type *Ty)
: ConstantExpr(Ty, Instruction::UserOp1, &Op, 1),
Op(UndefValue::get(Type::Int32Ty), this) {
@@ -1046,8 +1050,8 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) {
if (!FTy)
return Error("Function not a pointer to function type!");
- Function *Func = new Function(FTy, GlobalValue::ExternalLinkage,
- "", TheModule);
+ Function *Func = Function::Create(FTy, GlobalValue::ExternalLinkage,
+ "", TheModule);
Func->setCallingConv(Record[1]);
bool isProto = Record[2];
@@ -1216,7 +1220,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
// Create all the basic blocks for the function.
FunctionBBs.resize(Record[0]);
for (unsigned i = 0, e = FunctionBBs.size(); i != e; ++i)
- FunctionBBs[i] = new BasicBlock("", F);
+ FunctionBBs[i] = BasicBlock::Create("", F);
CurBB = FunctionBBs[0];
continue;
@@ -1270,7 +1274,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
GEPIdx.push_back(Op);
}
- I = new GetElementPtrInst(BasePtr, GEPIdx.begin(), GEPIdx.end());
+ I = GetElementPtrInst::Create(BasePtr, GEPIdx.begin(), GEPIdx.end());
break;
}
@@ -1282,7 +1286,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
getValue(Record, OpNum, Type::Int1Ty, Cond))
return Error("Invalid SELECT record");
- I = new SelectInst(Cond, TrueVal, FalseVal);
+ I = SelectInst::Create(Cond, TrueVal, FalseVal);
break;
}
@@ -1304,7 +1308,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
cast<VectorType>(Vec->getType())->getElementType(), Elt) ||
getValue(Record, OpNum, Type::Int32Ty, Idx))
return Error("Invalid INSERTELT record");
- I = new InsertElementInst(Vec, Elt, Idx);
+ I = InsertElementInst::Create(Vec, Elt, Idx);
break;
}
@@ -1354,7 +1358,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
{
unsigned Size = Record.size();
if (Size == 0) {
- I = new ReturnInst();
+ I = ReturnInst::Create();
break;
} else {
unsigned OpNum = 0;
@@ -1367,7 +1371,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
} while(OpNum != Record.size());
// SmallVector Vs has at least one element.
- I = new ReturnInst(&Vs[0], Vs.size());
+ I = ReturnInst::Create(&Vs[0], Vs.size());
break;
}
}
@@ -1379,13 +1383,13 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
return Error("Invalid BR record");
if (Record.size() == 1)
- I = new BranchInst(TrueDest);
+ I = BranchInst::Create(TrueDest);
else {
BasicBlock *FalseDest = getBasicBlock(Record[1]);
Value *Cond = getFnValueByID(Record[2], Type::Int1Ty);
if (FalseDest == 0 || Cond == 0)
return Error("Invalid BR record");
- I = new BranchInst(TrueDest, FalseDest, Cond);
+ I = BranchInst::Create(TrueDest, FalseDest, Cond);
}
break;
}
@@ -1398,7 +1402,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
if (OpTy == 0 || Cond == 0 || Default == 0)
return Error("Invalid SWITCH record");
unsigned NumCases = (Record.size()-3)/2;
- SwitchInst *SI = new SwitchInst(Cond, Default, NumCases);
+ SwitchInst *SI = SwitchInst::Create(Cond, Default, NumCases);
for (unsigned i = 0, e = NumCases; i != e; ++i) {
ConstantInt *CaseVal =
dyn_cast_or_null<ConstantInt>(getFnValueByID(Record[3+i*2], OpTy));
@@ -1454,7 +1458,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
}
}
- I = new InvokeInst(Callee, NormalBB, UnwindBB, Ops.begin(), Ops.end());
+ I = InvokeInst::Create(Callee, NormalBB, UnwindBB, Ops.begin(), Ops.end());
cast<InvokeInst>(I)->setCallingConv(CCInfo);
cast<InvokeInst>(I)->setParamAttrs(PAL);
break;
@@ -1471,7 +1475,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
const Type *Ty = getTypeByID(Record[0]);
if (!Ty) return Error("Invalid PHI record");
- PHINode *PN = new PHINode(Ty);
+ PHINode *PN = PHINode::Create(Ty);
PN->reserveOperandSpace(Record.size()-1);
for (unsigned i = 0, e = Record.size()-1; i != e; i += 2) {
@@ -1591,7 +1595,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
}
}
- I = new CallInst(Callee, Args.begin(), Args.end());
+ I = CallInst::Create(Callee, Args.begin(), Args.end());
cast<CallInst>(I)->setCallingConv(CCInfo>>1);
cast<CallInst>(I)->setTailCall(CCInfo & 1);
cast<CallInst>(I)->setParamAttrs(PAL);
diff --git a/lib/CodeGen/IntrinsicLowering.cpp b/lib/CodeGen/IntrinsicLowering.cpp
index 5c0484f2a7..0500bfb496 100644
--- a/lib/CodeGen/IntrinsicLowering.cpp
+++ b/lib/CodeGen/IntrinsicLowering.cpp
@@ -55,8 +55,8 @@ static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI,
}
SmallVector<Value *, 8> Args(ArgBegin, ArgEnd);
- CallInst *NewCI = new CallInst(FCache, Args.begin(), Args.end(),
- CI->getName(), CI);
+ CallInst *NewCI = CallInst::Create(FCache, Args.begin(), Args.end(),
+ CI->getName(), CI);
if (!CI->use_empty())
CI->replaceAllUsesWith(NewCI);
return NewCI;
@@ -339,19 +339,19 @@ static Instruction *LowerPartSelect(CallInst *CI) {
Function::arg_iterator args = F->arg_begin();
Value* Val = args++; Val->setName("Val");
Value* Lo = args++; Lo->setName("Lo");
- Value* Hi = args++; Hi->setName("High");
+ Value* Hi = args++; Hi->setName("High");
// We want to select a range of bits here such that [Hi, Lo] is shifted
// down to the low bits. However, it is quite possible that Hi is smaller
// than Lo in which case the bits have to be reversed.
// Create the blocks we will need for the two cases (forward, reverse)
- BasicBlock* CurBB = new BasicBlock("entry", F);
- BasicBlock *RevSize = new BasicBlock("revsize", CurBB->getParent());
- BasicBlock *FwdSize = new BasicBlock("fwdsize", CurBB->getParent());
- BasicBlock *Compute = new BasicBlock("compute", CurBB->getParent());
- BasicBlock *Reverse = new BasicBlock("reverse", CurBB->getParent());
- BasicBlock *RsltBlk = new BasicBlock("result", CurBB->getParent());
+ BasicBlock* CurBB = BasicBlock::Create("entry", F);
+ BasicBlock *RevSize = BasicBlock::Create("revsize", CurBB->getParent());
+ BasicBlock *FwdSize = BasicBlock::Create("fwdsize", CurBB->getParent());
+ BasicBlock *Compute = BasicBlock::Create("compute", CurBB->getParent());
+ BasicBlock *Reverse = BasicBlock::Create("reverse", CurBB->getParent());
+ BasicBlock *RsltBlk = BasicBlock::Create("result", CurBB->getParent());
// Cast Hi and Lo to the size of Val so the widths are all the same
if (Hi->getType() != Val->getType())
@@ -369,17 +369,17 @@ static Instruction *LowerPartSelect(CallInst *CI) {
// Compare the Hi and Lo bit positions. This is used to determine
// which case we have (forward or reverse)
ICmpInst *Cmp = new ICmpInst(ICmpInst::ICMP_ULT, Hi, Lo, "less",CurBB);
- new BranchInst(RevSize, FwdSize, Cmp, CurBB);
+ BranchInst::Create(RevSize, FwdSize, Cmp, CurBB);
// First, copmute the number of bits in the forward case.
Instruction* FBitSize =
BinaryOperator::createSub(Hi, Lo,"fbits", FwdSize);
- new BranchInst(Compute, FwdSize);
+ BranchInst::Create(Compute, FwdSize);
// Second, compute the number of bits in the reverse case.
Instruction* RBitSize =
BinaryOperator::createSub(Lo, Hi, "rbits", RevSize);
- new BranchInst(Compute, RevSize);
+ BranchInst::Create(Compute, RevSize);
// Now, compute the bit range. Start by getting the bitsize and the shift
// amount (either Hi or Lo) from PHI nodes. Then we compute a mask for
@@ -389,13 +389,13 @@ static Instruction *LowerPartSelect(CallInst *CI) {
// reversed.
// Get the BitSize from one of the two subtractions
- PHINode *BitSize = new PHINode(Val->getType(), "bits", Compute);
+ PHINode *BitSize = PHINode::Create(Val->getType(), "bits", Compute);
BitSize->reserveOperandSpace(2);
BitSize->addIncoming(FBitSize, FwdSize);
BitSize->addIncoming(RBitSize, RevSize);
// Get the ShiftAmount as the smaller of Hi/Lo
- PHINode *ShiftAmt = new PHINode(Val->getType(), "shiftamt", Compute);
+ PHINode *ShiftAmt = PHINode::Create(Val->getType(), "shiftamt", Compute);
ShiftAmt->reserveOperandSpace(2);
ShiftAmt->addIncoming(Lo, FwdSize);
ShiftAmt->addIncoming(Hi, RevSize);
@@ -413,24 +413,24 @@ static Instruction *LowerPartSelect(CallInst *CI) {
Instruction* FRes =
BinaryOperator::createLShr(Val, ShiftAmt, "fres", Compute);
FRes = BinaryOperator::createAnd(FRes, Mask, "fres", Compute);
- new BranchInst(Reverse, RsltBlk, Cmp, Compute);
+ BranchInst::Create(Reverse, RsltBlk, Cmp, Compute);
// In the Reverse block we have the mask already in FRes but we must reverse
// it by shifting FRes bits right and putting them in RRes by shifting them
// in from left.
// First set up our loop counters
- PHINode *Count = new PHINode(Val->getType(), "count", Reverse);
+ PHINode *Count = PHINode::Create(Val->getType(), "count", Reverse);
Count->reserveOperandSpace(2);
Count->addIncoming(BitSizePlusOne, Compute);
// Next, get the value that we are shifting.
- PHINode *BitsToShift = new PHINode(Val->getType(), "val", Reverse);
+ PHINode *BitsToShift = PHINode::Create(Val->getType(), "val", Reverse);
BitsToShift->reserveOperandSpace(2);
BitsToShift->addIncoming(FRes, Compute);
// Finally, get the result of the last computation
- PHINode *RRes = new PHINode(Val->getType(), "rres", Reverse);
+ PHINode *RRes = PHINode::Create(Val->getType(), "rres", Reverse);
RRes->reserveOperandSpace(2);
RRes->addIncoming(Zero, Compute);
@@ -456,16 +456,16 @@ static Instruction *LowerPartSelect(CallInst *CI) {
// Terminate loop if we've moved all the bits.
ICmpInst *Cond =
new ICmpInst(ICmpInst::ICMP_EQ, Decr, Zero, "cond", Reverse);
- new BranchInst(RsltBlk, Reverse, Cond, Reverse);
+ BranchInst::Create(RsltBlk, Reverse, Cond, Reverse);
// Finally, in the result block, select one of the two results with a PHI
// node and return the result;
CurBB = RsltBlk;
- PHINode *BitSelect = new PHINode(Val->getType(), "part_select", CurBB);
+ PHINode *BitSelect = PHINode::Create(Val->getType(), "part_select", CurBB);
BitSelect->reserveOperandSpace(2);
BitSelect->addIncoming(FRes, Compute);
BitSelect->addIncoming(NewRes, Reverse);
- new ReturnInst(BitSelect, CurBB);
+ ReturnInst::Create(BitSelect, CurBB);
}
// Return a call to the implementation function
@@ -474,7 +474,7 @@ static Instruction *LowerPartSelect(CallInst *CI) {
CI->getOperand(2),
CI->getOperand(3)
};
- return new CallInst(F, Args, array_endof(Args), CI->getName(), CI);
+ return CallInst::Create(F, Args, array_endof(Args), CI->getName(), CI);
}
/// Convert the llvm.part.set.iX.iY.iZ intrinsic. This intrinsic takes
@@ -531,18 +531,18 @@ static Instruction *LowerPartSet(CallInst *CI) {
ConstantInt* ValZero = ConstantInt::get(ValTy, 0);
// Basic blocks we fill in below.
- BasicBlock* entry = new BasicBlock("entry", F, 0);
- BasicBlock* large = new BasicBlock("large", F, 0);
- BasicBlock* small = new BasicBlock("small", F, 0);
- BasicBlock* reverse = new BasicBlock("reverse", F, 0);
- BasicBlock* result = new BasicBlock("result", F, 0);
+ BasicBlock* entry = BasicBlock::Create("entry", F, 0);
+ BasicBlock* large = BasicBlock::Create("large", F, 0);
+ BasicBlock* small = BasicBlock::Create("small", F, 0);
+ BasicBlock* reverse = BasicBlock::Create("reverse", F, 0);
+ BasicBlock* result = BasicBlock::Create("result", F, 0);
// BASIC BLOCK: entry
// First, get the number of bits that we're placing as an i32
ICmpInst* is_forward =
new ICmpInst(ICmpInst::ICMP_ULT, Lo, Hi, "", entry);
- SelectInst* Hi_pn = new SelectInst(is_forward, Hi, Lo, "", entry);
- SelectInst* Lo_pn = new SelectInst(is_forward, Lo, Hi, "", entry);
+ SelectInst* Hi_pn = SelectInst::Create(is_forward, Hi, Lo, "", entry);
+ SelectInst* Lo_pn = SelectInst::Create(is_forward, Lo, Hi, "", entry);
BinaryOperator* NumBits = BinaryOperator::createSub(Hi_pn, Lo_pn, "",entry);
NumBits = BinaryOperator::createAdd(NumBits, One, "", entry);
// Now, convert Lo and Hi to ValTy bit width
@@ -555,7 +555,7 @@ static Instruction *LowerPartSet(CallInst *CI) {
// are replacing and deal with it.
ICmpInst* is_large =
new ICmpInst(ICmpInst::ICMP_ULT, NumBits, RepBitWidth, "", entry);
- new BranchInst(large, small, is_large, entry);
+ BranchInst::Create(large, small, is_large, entry);
// BASIC BLOCK: large
Instruction* MaskBits =
@@ -565,10 +565,10 @@ static Instruction *LowerPartSet(CallInst *CI) {
BinaryOperator* Mask1 =
BinaryOperator::createLShr(RepMask, MaskBits, "", large);
BinaryOperator* Rep2 = BinaryOperator::createAnd(Mask1, Rep, "", large);
- new BranchInst(small, large);
+ BranchInst::Create(small, large);
// BASIC BLOCK: small
- PHINode* Rep3 = new PHINode(RepTy, "", small);
+ PHINode* Rep3 = PHINode::Create(RepTy, "", small);
Rep3->reserveOperandSpace(2);
Rep3->addIncoming(Rep2, large);
Rep3->addIncoming(Rep, entry);
@@ -577,23 +577,23 @@ static Instruction *LowerPartSet(CallInst *CI) {
Rep4 = new ZExtInst(Rep3, ValTy, "", small);
else if (ValBits < RepBits)
Rep4 = new TruncInst(Rep3, ValTy, "", small);
- new BranchInst(result, reverse, is_forward, small);
+ BranchInst::Create(result, reverse, is_forward, small);
// BASIC BLOCK: reverse (reverses the bits of the replacement)
// Set up our loop counter as a PHI so we can decrement on each iteration.
// We will loop for the number of bits in the replacement value.
- PHINode *Count = new PHINode(Type::Int32Ty, "count", reverse);
+ PHINode *Count = PHINode::Create(Type::Int32Ty, "count", reverse);
Count->reserveOperandSpace(2);
Count->addIncoming(NumBits, small);
// Get the value that we are shifting bits out of as a PHI because
// we'll change this with each iteration.
- PHINode *BitsToShift = new PHINode(Val->getType(), "val", reverse);
+ PHINode *BitsToShift = PHINode::Create(Val->getType(), "val", reverse);
BitsToShift->reserveOperandSpace(2);
BitsToShift->addIncoming(Rep4, small);
// Get the result of the last computation or zero on first iteration
- PHINode *RRes = new PHINode(Val->getType(), "rres", reverse);
+ PHINode *RRes = PHINode::Create(Val->getType(), "rres", reverse);
RRes->reserveOperandSpace(2);
RRes->addIncoming(ValZero, small);
@@ -615,10 +615,10 @@ static Instruction *LowerPartSet(CallInst *CI) {
// Terminate loop if we've moved all the bits.
ICmpInst *Cond = new ICmpInst(ICmpInst::ICMP_EQ, Decr, Zero, "", reverse);
- new BranchInst(result, reverse, Cond, reverse);
+ BranchInst::Create(result, reverse, Cond, reverse);
// BASIC BLOCK: result
- PHINode *Rplcmnt = new PHINode(Val->getType(), "", result);
+ PHINode *Rplcmnt = PHINode::Create(Val->getType(), "", result);
Rplcmnt->reserveOperandSpace(2);
Rplcmnt->addIncoming(NewRes, reverse);
Rplcmnt->addIncoming(Rep4, small);
@@ -630,7 +630,7 @@ static Instruction *LowerPartSet(CallInst *CI) {
Value* t5 = BinaryOperator::createAnd(t4, Val, "", result);
Value* t6 = BinaryOperator::createShl(Rplcmnt, Lo, "", result);
Value* Rslt = BinaryOperator::createOr(t5, t6, "part_set", result);
- new ReturnInst(Rslt, result);
+ ReturnInst::Create(Rslt, result);
}
// Return a call to the implementation function
@@ -640,7 +640,7 @@ static Instruction *LowerPartSet(CallInst *CI) {
CI->getOperand(3),
CI->getOperand(4)
};
- return new CallInst(F, Args, array_endof(Args), CI->getName(), CI);
+ return CallInst::Create(F, Args, array_endof(Args), CI->getName(), CI);
}
@@ -705,7 +705,7 @@ void IntrinsicLowering::LowerIntrinsicCall(CallInst *CI) {
// cttz(x) -> ctpop(~X & (X-1))
Value *Src = CI->getOperand(1);
Value *NotSrc = BinaryOperator::createNot(Src, Src->getName()+".not", CI);
- Value *SrcM1 = ConstantInt::get(Src->getType(), 1);
+ Value *SrcM1 = ConstantInt::get(Src->getType(), 1);
SrcM1 = BinaryOperator::createSub(Src, SrcM1, "", CI);
Src = LowerCTPOP(BinaryOperator::createAnd(NotSrc, SrcM1, "", CI), CI);
CI->replaceAllUsesWith(Src);
diff --git a/lib/CodeGen/ShadowStackCollector.cpp b/lib/CodeGen/ShadowStackCollector.cpp
index 46a7c551c8..2a703d8e44 100644
--- a/lib/CodeGen/ShadowStackCollector.cpp
+++ b/lib/CodeGen/ShadowStackCollector.cpp
@@ -133,7 +133,7 @@ namespace {
return 0;
// Create a cleanup block.
- BasicBlock *CleanupBB = new BasicBlock(CleanupBBName, &F);
+ BasicBlock *CleanupBB = BasicBlock::Create(CleanupBBName, &F);
UnwindInst *UI = new UnwindInst(CleanupBB);
// Transform the 'call' instructions into 'invoke's branching to the
@@ -155,10 +155,10 @@ namespace {
Args.clear();
Args.append(CI->op_begin() + 1, CI->op_end());
- InvokeInst *II = new InvokeInst(CI->getOperand(0),
- NewBB, CleanupBB,
- Args.begin(), Args.end(),
- CI->getName(), CallBB);
+ InvokeInst *II = InvokeInst::Create(CI->getOperand(0),
+ NewBB, CleanupBB,
+ Args.begin(), Args.end(),
+ CI->getName(), CallBB);
II->setCallingConv(CI->getCallingConv());
II->setParamAttrs(CI->getParamAttrs());
CI->replaceAllUsesWith(II);
diff --git a/lib/ExecutionEngine/JIT/JIT.cpp b/lib/ExecutionEngine/JIT/JIT.cpp
index f92842abdc..776129e6b2 100644
--- a/lib/ExecutionEngine/JIT/JIT.cpp
+++ b/lib/ExecutionEngine/JIT/JIT.cpp
@@ -220,11 +220,11 @@ GenericValue JIT::runFunction(Function *F,
// First, create the function.
FunctionType *STy=FunctionType::get(RetTy, std::vector<const Type*>(), false);
- Function *Stub = new Function(STy, Function::InternalLinkage, "",
- F->getParent());
+ Function *Stub = Function::Create(STy, Function::InternalLinkage, "",
+ F->getParent());
// Insert a basic block.
- BasicBlock *StubBB = new BasicBlock("", Stub);
+ BasicBlock *StubBB = BasicBlock::Create("", Stub);
// Convert all of the GenericValue arguments over to constants. Note that we
// currently don't support varargs.
@@ -257,12 +257,12 @@ GenericValue JIT::runFunction(Function *F,
Args.push_back(C);
}
- CallInst *TheCall = new CallInst(F, Args.begin(), Args.end(), "", StubBB);
+ CallInst *TheCall = CallInst::Create(F, Args.begin(), Args.end(), "", StubBB);
TheCall->setTailCall();
if (TheCall->getType() != Type::VoidTy)
- new ReturnInst(TheCall, StubBB); // Return result of the call.
+ ReturnInst::Create(TheCall, StubBB); // Return result of the call.
else
- new ReturnInst(StubBB); // Just return void.
+ ReturnInst::Create(StubBB); // Just return void.
// Finally, return the value returned by our nullary stub function.
return runFunction(Stub, std::vector<GenericValue>());
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index 32c49903da..a82b266bbd 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -822,8 +822,8 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// We have a definition of the same name but different type in the
// source module. Copy the prototype to the destination and replace
// uses of the destination's prototype with the new prototype.
- Function *NewDF = new Function(SF->getFunctionType(), SF->getLinkage(),
- SF->getName(), Dest);
+ Function *NewDF = Function::Create(SF->getFunctionType(), SF->getLinkage(),
+ SF->getName(), Dest);
CopyGVAttributes(NewDF, SF);
// Any uses of DF need to change to NewDF, with cast
@@ -858,8 +858,8 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
} else if (!DF || SF->hasInternalLinkage() || DF->hasInternalLinkage()) {
// Function does not already exist, simply insert an function signature
// identical to SF into the dest module.
- Function *NewDF = new Function(SF->getFunctionType(), SF->getLinkage(),
- SF->getName(), Dest);
+ Function *NewDF = Function::Create(SF->getFunctionType(), SF->getLinkage(),
+ SF->getName(), Dest);
CopyGVAttributes(NewDF, SF);
// If the LLVM runtime renamed the function, but it is an externally
diff --git a/lib/Target/X86/X86TargetAsmInfo.cpp b/lib/Target/X86/X86TargetAsmInfo.cpp
index 1f78cfd08a..7636d77f08 100644
--- a/lib/Target/X86/X86TargetAsmInfo.cpp
+++ b/lib/Target/X86/X86TargetAsmInfo.cpp
@@ -254,7 +254,7 @@ bool X86TargetAsmInfo::LowerToBSwap(CallInst *CI) const {
Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
Value *Op = CI->getOperand(1);
- Op = new CallInst(Int, Op, CI->getName(), CI);
+ Op = CallInst::Create(Int, Op, CI->getName(), CI);
CI->replaceAllUsesWith(Op);
CI->eraseFromParent();
diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp
index 230bafd6f0..fe0d6d98f2 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 8299dbc0d8..6cd128b7c4 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 882097cae5..46232b880b 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 e5427766bf..50c5eccbd8 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 502c293da1..2f9c34d5cf 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 d4b8454e37..2db8257b84 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 46e11280b0..1b9aefc582 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 e284009247..1f12fcf79d 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 945eb909e5..bbfd1d2da3 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 1e51cb96c9..80952b7c70 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 fd31cec643..4617fbbd80 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 d81097b447..e7e8efea88 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 ed9d9309d0..d909d0227c 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 d062297c55..39a1b25725 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 12ce28660c..c966311c9e 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 7d38dc75a1..3bd6bff5d6 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 44c3d78e8f..43054227ae 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 9e069fd05b..beeee4911a 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 48b45351a0..da6f076a9a 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 153f09563d..51e2cd8900 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 c6f02e8978..fbed3b3e38 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 966038ddff..58a2fe0ba7 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 a178507c1c..0fd9316347 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 2977afa179..51aad84c07 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 5cb2b4086b..48342bdc11 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 d1320c990d..78b088a644 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 0dc38a2b84..895e44a4f7 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 78801db4cd..1a41d95a03 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 7387144b5e..ba9b57d4f5 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 f0ee1e2ae0..e75f915cb9 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 1be1c729c0..54341196fb 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 74295cecaa..2e34984564 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 567b23e6ff..a9d1dc40cf 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 0d852bb864..0f7d02c888 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 16cb30ca9c..e6f5e7c39c 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 2f422609fe..8708f994fe 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 7f0ef85d75..7f85b10af4 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 e31a87fba8..d75880f585 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 3d25dee1e8..ebd68ddcbe 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 b9a20c113f..d11bbb0b64 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 9f129a85be..76b565c0e2 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;
diff --git a/lib/VMCore/AutoUpgrade.cpp b/lib/VMCore/AutoUpgrade.cpp
index 343a4b6431..2fb0e8079a 100644
--- a/lib/VMCore/AutoUpgrade.cpp
+++ b/lib/VMCore/AutoUpgrade.cpp
@@ -216,7 +216,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
return;
}
- switch(NewFn->getIntrinsicID()) {
+ switch (NewFn->getIntrinsicID()) {
default: assert(0 && "Unknown function for CallInst upgrade.");
case Intrinsic::x86_mmx_psll_d:
case Intrinsic::x86_mmx_psll_q:
@@ -237,8 +237,8 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
Operands[1] = BC;
// Construct a new CallInst
- CallInst *NewCI = new CallInst(NewFn, Operands, Operands+2,
- "upgraded."+CI->getName(), CI);
+ CallInst *NewCI = CallInst::Create(NewFn, Operands, Operands+2,
+ "upgraded."+CI->getName(), CI);
NewCI->setTailCall(CI->isTailCall());
NewCI->setCallingConv(CI->getCallingConv());
@@ -254,14 +254,14 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
}
case Intrinsic::ctlz:
case Intrinsic::ctpop:
- case Intrinsic::cttz:
+ case Intrinsic::cttz: {
// Build a small vector of the 1..(N-1) operands, which are the
// parameters.
SmallVector<Value*, 8> Operands(CI->op_begin()+1, CI->op_end());
// Construct a new CallInst
- CallInst *NewCI = new CallInst(NewFn, Operands.begin(), Operands.end(),
- "upgraded."+CI->getName(), CI);
+ CallInst *NewCI = CallInst::Create(NewFn, Operands.begin(), Operands.end(),
+ "upgraded."+CI->getName(), CI);
NewCI->setTailCall(CI->isTailCall());
NewCI->setCallingConv(CI->getCallingConv());
@@ -287,7 +287,8 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
// Clean up the old call now that it has been completely upgraded.
CI->eraseFromParent();
- break;
+ }
+ break;
}
}
diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp
index 1288fdf32c..16aa7faa08 100644
--- a/lib/VMCore/BasicBlock.cpp
+++ b/lib/VMCore/BasicBlock.cpp
@@ -35,6 +35,10 @@ namespace {
/// DummyInst - An instance of this class is used to mark the end of the
/// instruction list. This is not a real instruction.
struct VISIBILITY_HIDDEN DummyInst : public Instruction {
+ // allocate space for exactly zero operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 0);
+ }
DummyInst() : Instruction(Type::VoidTy, OtherOpsEnd, 0, 0) {
// This should not be garbage monitored.
LeakDetector::removeGarbageObject(this);
@@ -71,7 +75,7 @@ template class SymbolTableListTraits<Instruction, BasicBlock>;
BasicBlock::BasicBlock(const std::string &Name, Function *NewParent,
BasicBlock *InsertBefore, BasicBlock *Dest)
- : User(Type::LabelTy, Value::BasicBlockVal, &unwindDest, 0), Parent(0) {
+ : User(Type::LabelTy, Value::BasicBlockVal, &unwindDest, 0/*FIXME*/), Parent(0) {
// Make sure that we get added to a function
LeakDetector::addGarbageObject(this);
@@ -283,14 +287,14 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const std::string &BBName) {
assert(I != InstList.end() &&
"Trying to get me to create degenerate basic block!");
- BasicBlock *New = new BasicBlock(BBName, getParent(), getNext());
+ BasicBlock *New = new(0/*FIXME*/) BasicBlock(BBName, getParent(), getNext());
// Move all of the specified instructions from the original basic block into
// the new basic block.
New->getInstList().splice(New->end(), this->getInstList(), I, end());
// Add a branch instruction to the newly formed basic block.
- new BranchInst(New, this);
+ BranchInst::Create(New, this);
// Now we must loop through all of the successors of the New block (which
// _were_ the successors of the 'this' block), and update any PHI nodes in
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 470e247e4c..78d24ef5f5 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -410,8 +410,13 @@ namespace {
/// UnaryConstantExpr - This class is private to Constants.cpp, and is used
/// behind the scenes to implement unary constant exprs.
class VISIBILITY_HIDDEN UnaryConstantExpr : public ConstantExpr {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Op;
public:
+ // allocate space for exactly one operand
+ void *operator new(size_t s) {
+ return User::operator new(s, 1);
+ }
UnaryConstantExpr(unsigned Opcode, Constant *C, const Type *Ty)
: ConstantExpr(Ty, Opcode, &Op, 1), Op(C, this) {}
};
@@ -419,8 +424,13 @@ public:
/// BinaryConstantExpr - This class is private to Constants.cpp, and is used
/// behind the scenes to implement binary constant exprs.
class VISIBILITY_HIDDEN BinaryConstantExpr : public ConstantExpr {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Ops[2];
public:
+ // allocate space for exactly two operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 2);
+ }
BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2)
: ConstantExpr(C1->getType(), Opcode, Ops, 2) {
Ops[0].init(C1, this);
@@ -431,8 +441,13 @@ public:
/// SelectConstantExpr - This class is private to Constants.cpp, and is used
/// behind the scenes to implement select constant exprs.
class VISIBILITY_HIDDEN SelectConstantExpr : public ConstantExpr {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Ops[3];
public:
+ // allocate space for exactly three operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 3);
+ }
SelectConstantExpr(Constant *C1, Constant *C2, Constant *C3)
: ConstantExpr(C2->getType(), Instruction::Select, Ops, 3) {
Ops[0].init(C1, this);
@@ -445,8 +460,13 @@ public:
/// Constants.cpp, and is used behind the scenes to implement
/// extractelement constant exprs.
class VISIBILITY_HIDDEN ExtractElementConstantExpr : public ConstantExpr {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Ops[2];
public:
+ // allocate space for exactly two operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 2);
+ }
ExtractElementConstantExpr(Constant *C1, Constant *C2)
: ConstantExpr(cast<VectorType>(C1->getType())->getElementType(),
Instruction::ExtractElement, Ops, 2) {
@@ -459,8 +479,13 @@ public:
/// Constants.cpp, and is used behind the scenes to implement
/// insertelement constant exprs.
class VISIBILITY_HIDDEN InsertElementConstantExpr : public ConstantExpr {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Ops[3];
public:
+ // allocate space for exactly three operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 3);
+ }
InsertElementConstantExpr(Constant *C1, Constant *C2, Constant *C3)
: ConstantExpr(C1->getType(), Instruction::InsertElement,
Ops, 3) {
@@ -474,8 +499,13 @@ public:
/// Constants.cpp, and is used behind the scenes to implement
/// shufflevector constant exprs.
class VISIBILITY_HIDDEN ShuffleVectorConstantExpr : public ConstantExpr {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Ops[3];
public:
+ // allocate space for exactly three operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 3);
+ }
ShuffleVectorConstantExpr(Constant *C1, Constant *C2, Constant *C3)
: ConstantExpr(C1->getType(), Instruction::ShuffleVector,
Ops, 3) {
@@ -487,7 +517,7 @@ public:
/// GetElementPtrConstantExpr - This class is private to Constants.cpp, and is
/// used behind the scenes to implement getelementpr constant exprs.
-struct VISIBILITY_HIDDEN GetElementPtrConstantExpr : public ConstantExpr {
+class VISIBILITY_HIDDEN GetElementPtrConstantExpr : public ConstantExpr {
GetElementPtrConstantExpr(Constant *C, const std::vector<Constant*> &IdxList,
const Type *DestTy)
: ConstantExpr(DestTy, Instruction::GetElementPtr,
@@ -496,6 +526,11 @@ struct VISIBILITY_HIDDEN GetElementPtrConstantExpr : public ConstantExpr {
for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
OperandList[i+1].init(IdxList[i], this);
}
+public:
+ static GetElementPtrConstantExpr *Create(Constant *C, const std::vector<Constant*> &IdxList,
+ const Type *DestTy) {
+ return new(IdxList.size() + 1/*FIXME*/) GetElementPtrConstantExpr(C, IdxList, DestTy);
+ }
~GetElementPtrConstantExpr() {
delete [] OperandList;
}
@@ -505,6 +540,11 @@ struct VISIBILITY_HIDDEN GetElementPtrConstantExpr : public ConstantExpr {
// behind the scenes to implement ICmp and FCmp constant expressions. This is
// needed in order to store the predicate value for these instructions.
struct VISIBILITY_HIDDEN CompareConstantExpr : public ConstantExpr {
+ void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
+ // allocate space for exactly two operands
+ void *operator new(size_t s) {
+ return User::operator new(s, 2);
+ }
unsigned short predicate;
Use Ops[2];
CompareConstantExpr(Instruction::OtherOps opc, unsigned short pred,
@@ -771,7 +811,8 @@ namespace llvm {
template<class ConstantClass, class TypeClass, class ValType>
struct VISIBILITY_HIDDEN ConstantCreator {
static ConstantClass *create(const TypeClass *Ty, const ValType &V) {
- return new ConstantClass(Ty, V);
+ unsigned FIXME; // = traits<ValType>::uses(V)
+ return new(FIXME) ConstantClass(Ty, V);
}
};
@@ -1433,7 +1474,7 @@ namespace llvm {
V.operands[2]);
if (V.opcode == Instruction::GetElementPtr) {
std::vector<Constant*> IdxList(V.operands.begin()+1, V.operands.end());
- return new GetElementPtrConstantExpr(V.operands[0], IdxList, Ty);
+ return GetElementPtrConstantExpr::Create(V.operands[0], IdxList, Ty);
}
// The compare instructions are weird. We have to encode the predicate
diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp
index c35c85dcc0..8c9626af57 100644
--- a/lib/VMCore/Core.cpp
+++ b/lib/VMCore/Core.cpp
@@ -670,8 +670,8 @@ void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant) {
LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
LLVMTypeRef FunctionTy) {
- return wrap(new Function(unwrap<FunctionType>(FunctionTy),
- GlobalValue::ExternalLinkage, Name, unwrap(M)));
+ return wrap(Function::Create(unwrap<FunctionType>(FunctionTy),
+ GlobalValue::ExternalLinkage, Name, unwrap(M)));
}
LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) {
@@ -864,14 +864,14 @@ LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) {
}
LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) {
- return wrap(new BasicBlock(Name, unwrap<Function>(FnRef)));
+ return wrap(BasicBlock::Create(Name, unwrap<Function>(FnRef)));
}
LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBBRef,
const char *Name) {
BasicBlock *InsertBeforeBB = unwrap(InsertBeforeBBRef);
- return wrap(new BasicBlock(Name, InsertBeforeBB->getParent(),
- InsertBeforeBB));
+ return wrap(BasicBlock::Create(Name, InsertBeforeBB->getParent(),
+ InsertBeforeBB));
}
void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) {
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 6fd3af4f9d..302eff30ff 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -24,7 +24,7 @@
using namespace llvm;
BasicBlock *ilist_traits<BasicBlock>::createSentinel() {
- BasicBlock *Ret = new BasicBlock();
+ BasicBlock *Ret = BasicBlock::Create();
// This should not be garbage monitored.
LeakDetector::removeGarbageObject(Ret);
return Ret;
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index 33ab1c66eb..ad99c78c1a 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -2710,7 +2710,7 @@ bool GetResultInst::isValidOperands(const Value *Aggregate, unsigned Index) {
// unit that uses these classes.
GetElementPtrInst *GetElementPtrInst::clone() const {
- return new GetElementPtrInst(*this);
+ return new(getNumOperands()) GetElementPtrInst(*this);
}
BinaryOperator *BinaryOperator::clone() const {
@@ -2741,24 +2741,24 @@ CastInst *FPToSIInst::clone() const { return new FPToSIInst(*this); }
CastInst *PtrToIntInst::clone() const { return new PtrToIntInst(*this); }
CastInst *IntToPtrInst::clone() const { return new IntToPtrInst(*this); }
CastInst *BitCastInst::clone() const { return new BitCastInst(*this); }
-CallInst *CallInst::clone() const { return new CallInst(*this); }
-SelectInst *SelectInst::clone() const { return new SelectInst(*this); }
+CallInst *CallInst::clone() const { return new(getNumOperands()) CallInst(*this); }
+SelectInst *SelectInst::clone() const { return new(getNumOperands()) SelectInst(*this); }
VAArgInst *VAArgInst::clone() const { return new VAArgInst(*this); }
ExtractElementInst *ExtractElementInst::clone() const {
return new ExtractElementInst(*this);
}
InsertElementInst *InsertElementInst::clone() const {
- return new InsertElementInst(*this);
+ return InsertElementInst::Create(*this);
}
ShuffleVectorInst *ShuffleVectorInst::clone() const {
return new ShuffleVectorInst(*this);
}
PHINode *PHINode::clone() const { return new PHINode(*this); }
-ReturnInst *ReturnInst::clone() const { return new ReturnInst(*this); }
-BranchInst *BranchInst::clone() const { return new BranchInst(*this); }
-SwitchInst *SwitchInst::clone() const { return new SwitchInst(*this); }
-InvokeInst *InvokeInst::clone() const { return new InvokeInst(*this); }
+ReturnInst *ReturnInst::clone() const { return new(getNumOperands()) ReturnInst(*this); }
+BranchInst *BranchInst::clone() const { return new(getNumOperands()) BranchInst(*this); }
+SwitchInst *SwitchInst::clone() const { return new(getNumOperands()) SwitchInst(*this); }
+InvokeInst *InvokeInst::clone() const { return new(getNumOperands()) InvokeInst(*this); }
UnwindInst *UnwindInst::clone() const { return new UnwindInst(); }
UnreachableInst *UnreachableInst::clone() const { return new UnreachableInst();}
GetResultInst *GetResultInst::clone() const { return new GetResultInst(*this); }
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp
index 864ec04654..429cf1a4c6 100644
--- a/lib/VMCore/Module.cpp
+++ b/lib/VMCore/Module.cpp
@@ -32,7 +32,7 @@ using namespace llvm;
Function *ilist_traits<Function>::createSentinel() {
FunctionType *FTy =
FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false);
- Function *Ret = new Function(FTy, GlobalValue::ExternalLinkage);
+ Function *Ret = Function::Create(FTy, GlobalValue::ExternalLinkage);
// This should not be garbage monitored.
LeakDetector::removeGarbageObject(Ret);
return Ret;
@@ -149,7 +149,7 @@ Constant *Module::getOrInsertFunction(const std::string &Name,
GlobalValue *F = dyn_cast_or_null<GlobalValue>(SymTab.lookup(Name));
if (F == 0) {
// Nope, add it
- Function *New = new Function(Ty, GlobalVariable::ExternalLinkage, Name);
+ Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name);
FunctionList.push_back(New);
return New; // Return the new prototype.
}
diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp
index 419e1f1998..d1a57eb585 100644
--- a/tools/bugpoint/CrashDebugger.cpp
+++ b/tools/bugpoint/CrashDebugger.cpp
@@ -309,8 +309,8 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock*> &BBs) {
// Add a new return instruction of the appropriate type...
const Type *RetTy = BB->getParent()->getReturnType();
- new ReturnInst(RetTy == Type::VoidTy ? 0 :
- Constant::getNullValue(RetTy), BB);
+ ReturnInst::Create(RetTy == Type::VoidTy ? 0 :
+ Constant::getNullValue(RetTy), BB);
}
// The CFG Simplifier pass may delete one of the basic blocks we are
diff --git a/tools/bugpoint/Miscompilation.cpp b/tools/bugpoint/Miscompilation.cpp
index f2b1c724b6..536c3dbd74 100644
--- a/tools/bugpoint/Miscompilation.cpp
+++ b/tools/bugpoint/Miscompilation.cpp
@@ -644,14 +644,14 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Rename it
oldMain->setName("llvm_bugpoint_old_main");
// Create a NEW `main' function with same type in the test module.
- Function *newMain = new Function(oldMain->getFunctionType(),
- GlobalValue::ExternalLinkage,
- "main", Test);
+ Function *newMain = Function::Create(oldMain->getFunctionType(),
+ GlobalValue::ExternalLinkage,
+ "main", Test);
// Create an `oldmain' prototype in the test module, which will
// corresponds to the real main function in the same module.
- Function *oldMainProto = new Function(oldMain->getFunctionType(),
- GlobalValue::ExternalLinkage,
- oldMain->getName(), Test);
+ Function *oldMainProto = Function::Create(oldMain->getFunctionType(),
+ GlobalValue::ExternalLinkage,
+ oldMain->getName(), Test);
// Set up and remember the argument list for the main function.
std::vector<Value*> args;
for (Function::arg_iterator
@@ -662,12 +662,12 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
}
// Call the old main function and return its result
- BasicBlock *BB = new BasicBlock("entry", newMain);
- CallInst *call = new CallInst(oldMainProto, args.begin(), args.end(),
- "", BB);
+ BasicBlock *BB = BasicBlock::Create("entry", newMain);
+ CallInst *call = CallInst::Create(oldMainProto, args.begin(), args.end(),
+ "", BB);
// If the type of old function wasn't void, return value of call
- new ReturnInst(call, BB);
+ ReturnInst::Create(call, BB);
}
// The second nasty issue we must deal with in the JIT is that the Safe
@@ -717,35 +717,35 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Construct a new stub function that will re-route calls to F
const FunctionType *FuncTy = F->getFunctionType();
- Function *FuncWrapper = new Function(FuncTy,
- GlobalValue::InternalLinkage,
- F->getName() + "_wrapper",
- F->getParent());
- BasicBlock *EntryBB = new BasicBlock("entry", FuncWrapper);
- BasicBlock *DoCallBB = new BasicBlock("usecache", FuncWrapper);
- BasicBlock *LookupBB = new BasicBlock("lookupfp", FuncWrapper);
+ Function *FuncWrapper = Function::Create(FuncTy,
+ GlobalValue::InternalLinkage,
+ F->getName() + "_wrapper",
+ F->getParent());
+ BasicBlock *EntryBB = BasicBlock::Create("entry", FuncWrapper);
+ BasicBlock *DoCallBB = BasicBlock::Create("usecache", FuncWrapper);
+ BasicBlock *LookupBB = BasicBlock::Create("lookupfp", FuncWrapper);
// Check to see if we already looked up the value.
Value *CachedVal = new LoadInst(Cache, "fpcache", EntryBB);
Value *IsNull = new ICmpInst(ICmpInst::ICMP_EQ, CachedVal,
NullPtr, "isNull", EntryBB);
- new BranchInst(LookupBB, DoCallBB, IsNull, EntryBB);
+ BranchInst::Create(LookupBB, DoCallBB, IsNull, EntryBB);
// Resolve the call to function F via the JIT API:
//
// call resolver(GetElementPtr...)
- CallInst *Resolver = new CallInst(resolverFunc, ResolverArgs.begin(),
- ResolverArgs.end(),
- "resolver", LookupBB);
+ CallInst *Resolver = CallInst::Create(resolverFunc, ResolverArgs.begin(),
+ ResolverArgs.end(),
+ "resolver", LookupBB);
// cast the result from the resolver to correctly-typed function
CastInst *CastedResolver = new BitCastInst(Resolver,
PointerType::getUnqual(F->getFunctionType()), "resolverCast", LookupBB);
// Save the value in our cache.
new StoreInst(CastedResolver, Cache, LookupBB);
- new BranchInst(DoCallBB, LookupBB);
+ BranchInst::Create(DoCallBB, LookupBB);
- PHINode *FuncPtr = new PHINode(NullPtr->getType(), "fp", DoCallBB);
+ PHINode *FuncPtr = PHINode::Create(NullPtr->getType(), "fp", DoCallBB);
FuncPtr->addIncoming(CastedResolver, LookupBB);
FuncPtr->addIncoming(CachedVal, EntryBB);
@@ -757,12 +757,12 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Pass on the arguments to the real function, return its result
if (F->getReturnType() == Type::VoidTy) {
- new CallInst(FuncPtr, Args.begin(), Args.end(), "", DoCallBB);
- new ReturnInst(DoCallBB);
+ CallInst::Create(FuncPtr, Args.begin(), Args.end(), "", DoCallBB);
+ ReturnInst::Create(DoCallBB);
} else {
- CallInst *Call = new CallInst(FuncPtr, Args.begin(), Args.end(),
- "retval", DoCallBB);
- new ReturnInst(Call, DoCallBB);
+ CallInst *Call = CallInst::Create(FuncPtr, Args.begin(), Args.end(),
+ "retval", DoCallBB);
+ ReturnInst::Create(Call, DoCallBB);
}
// Use the wrapper function instead of the old function