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
This commit is contained in:
Gabor Greif 2008-04-06 20:25:17 +00:00
parent d963ab1f58
commit 051a950000
73 changed files with 979 additions and 692 deletions

View File

@ -74,7 +74,7 @@ void BrainF::header() {
brainf_func = cast<Function>(module-> brainf_func = cast<Function>(module->
getOrInsertFunction("brainf", Type::VoidTy, NULL)); 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 //%arr = malloc i8, i32 %d
ConstantInt *val_mem = ConstantInt::get(APInt(32, memtotal)); ConstantInt *val_mem = ConstantInt::get(APInt(32, memtotal));
@ -110,13 +110,13 @@ void BrainF::header() {
//Function footer //Function footer
//brainf.end: //brainf.end:
endbb = new BasicBlock(label, brainf_func); endbb = BasicBlock::Create(label, brainf_func);
//free i8 *%arr //free i8 *%arr
new FreeInst(ptr_arr, endbb); new FreeInst(ptr_arr, endbb);
//ret void //ret void
new ReturnInst(endbb); ReturnInst::Create(endbb);
@ -141,7 +141,7 @@ void BrainF::header() {
PointerType::getUnqual(IntegerType::Int8Ty), NULL)); PointerType::getUnqual(IntegerType::Int8Ty), NULL));
//brainf.aberror: //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)) //call i32 @puts(i8 *getelementptr([%d x i8] *@aberrormsg, i32 0, i32 0))
{ {
@ -161,14 +161,14 @@ void BrainF::header() {
}; };
CallInst *puts_call = CallInst *puts_call =
new CallInst(puts_func, CallInst::Create(puts_func,
puts_params, array_endof(puts_params), puts_params, array_endof(puts_params),
"", aberrorbb); "", aberrorbb);
puts_call->setTailCall(false); puts_call->setTailCall(false);
} }
//br label %brainf.end //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); CreateOr(test_0, test_1, testreg);
//br i1 %test.%d, label %main.%d, label %main.%d //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); builder->CreateCondBr(test_2, aberrorbb, nextbb);
//main.%d: //main.%d:
@ -273,16 +273,16 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) {
case SYM_LOOP: case SYM_LOOP:
{ {
//br label %main.%d //br label %main.%d
BasicBlock *testbb = new BasicBlock(label, brainf_func); BasicBlock *testbb = BasicBlock::Create(label, brainf_func);
builder->CreateBr(testbb); builder->CreateBr(testbb);
//main.%d: //main.%d:
BasicBlock *bb_0 = builder->GetInsertBlock(); 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); builder->SetInsertPoint(bb_1);
//Make part of PHI instruction now, wait until end of loop to finish //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); headreg, testbb);
phi_0->reserveOperandSpace(2); phi_0->reserveOperandSpace(2);
phi_0->addIncoming(curhead, bb_0); phi_0->addIncoming(curhead, bb_0);
@ -431,8 +431,8 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) {
testbb); testbb);
//br i1 %test.%d, label %main.%d, label %main.%d //br i1 %test.%d, label %main.%d, label %main.%d
BasicBlock *bb_0 = new BasicBlock(label, brainf_func); BasicBlock *bb_0 = BasicBlock::Create(label, brainf_func);
new BranchInst(bb_0, oldbb, test_0, testbb); BranchInst::Create(bb_0, oldbb, test_0, testbb);
//main.%d: //main.%d:
builder->SetInsertPoint(bb_0); builder->SetInsertPoint(bb_0);

View File

@ -70,17 +70,17 @@ void addMainFunction(Module *mod) {
} }
//main.0: //main.0:
BasicBlock *bb = new BasicBlock("main.0", main_func); BasicBlock *bb = BasicBlock::Create("main.0", main_func);
//call void @brainf() //call void @brainf()
{ {
CallInst *brainf_call = new CallInst(mod->getFunction("brainf"), CallInst *brainf_call = CallInst::Create(mod->getFunction("brainf"),
"", bb); "", bb);
brainf_call->setTailCall(false); brainf_call->setTailCall(false);
} }
//ret i32 0 //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) { int main(int argc, char **argv) {

View File

@ -43,7 +43,7 @@ static Function *CreateFibFunction(Module *M) {
(Type *)0)); (Type *)0));
// Add a basic block to the function. // Add a basic block to the function.
BasicBlock *BB = new BasicBlock("EntryBlock", FibF); BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF);
// Get pointers to the constants. // Get pointers to the constants.
Value *One = ConstantInt::get(Type::Int32Ty, 1); 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. ArgX->setName("AnArg"); // Give it a nice symbolic name for fun.
// Create the true_block. // Create the true_block.
BasicBlock *RetBB = new BasicBlock("return", FibF); BasicBlock *RetBB = BasicBlock::Create("return", FibF);
// Create an exit block. // Create an exit block.
BasicBlock* RecurseBB = new BasicBlock("recurse", FibF); BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);
// Create the "if (arg <= 2) goto exitbb" // Create the "if (arg <= 2) goto exitbb"
Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB); 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 // Create: ret int 1
new ReturnInst(One, RetBB); ReturnInst::Create(One, RetBB);
// create fib(x-1) // create fib(x-1)
Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB); 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(); CallFibX1->setTailCall();
// create fib(x-2) // create fib(x-2)
Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB); 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(); CallFibX2->setTailCall();
@ -81,7 +81,7 @@ static Function *CreateFibFunction(Module *M) {
"addresult", RecurseBB); "addresult", RecurseBB);
// Create the return instruction and add it to the basic block // Create the return instruction and add it to the basic block
new ReturnInst(Sum, RecurseBB); ReturnInst::Create(Sum, RecurseBB);
return FibF; return FibF;
} }

View File

@ -58,7 +58,7 @@ int main() {
// Add a basic block to the function. As before, it automatically inserts // Add a basic block to the function. As before, it automatically inserts
// because of the last argument. // because of the last argument.
BasicBlock *BB = new BasicBlock("EntryBlock", Add1F); BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F);
// Get pointers to the constant `1'. // Get pointers to the constant `1'.
Value *One = ConstantInt::get(Type::Int32Ty, 1); Value *One = ConstantInt::get(Type::Int32Ty, 1);
@ -72,7 +72,7 @@ int main() {
Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB); Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB);
// Create the return instruction and add it to the basic block // Create the return instruction and add it to the basic block
new ReturnInst(Add, BB); ReturnInst::Create(Add, BB);
// Now, function add1 is ready. // Now, function add1 is ready.
@ -83,17 +83,17 @@ int main() {
cast<Function>(M->getOrInsertFunction("foo", Type::Int32Ty, (Type *)0)); cast<Function>(M->getOrInsertFunction("foo", Type::Int32Ty, (Type *)0));
// Add a basic block to the FooF function. // Add a basic block to the FooF function.
BB = new BasicBlock("EntryBlock", FooF); BB = BasicBlock::Create("EntryBlock", FooF);
// Get pointers to the constant `10'. // Get pointers to the constant `10'.
Value *Ten = ConstantInt::get(Type::Int32Ty, 10); Value *Ten = ConstantInt::get(Type::Int32Ty, 10);
// Pass Ten to the call call: // 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); Add1CallRes->setTailCall(true);
// Create the return instruction and add it to the basic block. // Create the return instruction and add it to the basic block.
new ReturnInst(Add1CallRes, BB); ReturnInst::Create(Add1CallRes, BB);
// Now we create the JIT. // Now we create the JIT.
ExistingModuleProvider* MP = new ExistingModuleProvider(M); ExistingModuleProvider* MP = new ExistingModuleProvider(M);

View File

@ -32,11 +32,11 @@ int main() {
// By passing a module as the last parameter to the Function constructor, // By passing a module as the last parameter to the Function constructor,
// it automatically gets appended to the Module. // 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 // Add a basic block to the function... again, it automatically inserts
// because of the last argument. // because of the last argument.
BasicBlock *BB = new BasicBlock("EntryBlock", F); BasicBlock *BB = BasicBlock::Create("EntryBlock", F);
// Get pointers to the constant integers... // Get pointers to the constant integers...
Value *Two = ConstantInt::get(Type::Int32Ty, 2); Value *Two = ConstantInt::get(Type::Int32Ty, 2);
@ -50,7 +50,7 @@ int main() {
BB->getInstList().push_back(Add); BB->getInstList().push_back(Add);
// Create the return instruction and add it to the basic block // 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 // Output the bitcode file to stdout
WriteBitcodeToFile(M, std::cout); WriteBitcodeToFile(M, std::cout);

View File

@ -39,7 +39,7 @@ static Function* createAdd1(Module *M) {
// Add a basic block to the function. As before, it automatically inserts // Add a basic block to the function. As before, it automatically inserts
// because of the last argument. // because of the last argument.
BasicBlock *BB = new BasicBlock("EntryBlock", Add1F); BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F);
// Get pointers to the constant `1'. // Get pointers to the constant `1'.
Value *One = ConstantInt::get(Type::Int32Ty, 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); Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB);
// Create the return instruction and add it to the basic block // Create the return instruction and add it to the basic block
new ReturnInst(Add, BB); ReturnInst::Create(Add, BB);
// Now, function add1 is ready. // Now, function add1 is ready.
return Add1F; return Add1F;
@ -67,7 +67,7 @@ static Function *CreateFibFunction(Module *M) {
(Type *)0)); (Type *)0));
// Add a basic block to the function. // Add a basic block to the function.
BasicBlock *BB = new BasicBlock("EntryBlock", FibF); BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF);
// Get pointers to the constants. // Get pointers to the constants.
Value *One = ConstantInt::get(Type::Int32Ty, 1); 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. ArgX->setName("AnArg"); // Give it a nice symbolic name for fun.
// Create the true_block. // Create the true_block.
BasicBlock *RetBB = new BasicBlock("return", FibF); BasicBlock *RetBB = BasicBlock::Create("return", FibF);
// Create an exit block. // Create an exit block.
BasicBlock* RecurseBB = new BasicBlock("recurse", FibF); BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);
// Create the "if (arg < 2) goto exitbb" // Create the "if (arg < 2) goto exitbb"
Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB); 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 // Create: ret int 1
new ReturnInst(One, RetBB); ReturnInst::Create(One, RetBB);
// create fib(x-1) // create fib(x-1)
Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB); 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) // create fib(x-2)
Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB); 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) // fib(x-1)+fib(x-2)
Value *Sum = Value *Sum =
BinaryOperator::createAdd(CallFibX1, CallFibX2, "addresult", RecurseBB); BinaryOperator::createAdd(CallFibX1, CallFibX2, "addresult", RecurseBB);
// Create the return instruction and add it to the basic block // Create the return instruction and add it to the basic block
new ReturnInst(Sum, RecurseBB); ReturnInst::Create(Sum, RecurseBB);
return FibF; return FibF;
} }

View File

@ -66,17 +66,22 @@ private :
BasicBlock(const BasicBlock &); // Do not implement BasicBlock(const BasicBlock &); // Do not implement
void operator=(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 /// BasicBlock ctor - If the function parameter is specified, the basic block
/// is automatically inserted at either the end of the function (if /// is automatically inserted at either the end of the function (if
/// InsertBefore is null), or before the specified basic block. /// InsertBefore is null), or before the specified basic block.
/// ///
explicit BasicBlock(const std::string &Name = "", Function *Parent = 0, 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(); ~BasicBlock();
/// getUnwindDest - Returns the BasicBlock that flow will enter if an unwind /// getUnwindDest - Returns the BasicBlock that flow will enter if an unwind

View File

@ -43,9 +43,15 @@ struct ConvertConstantType;
/// @brief Class for constant integers. /// @brief Class for constant integers.
class ConstantInt : public Constant { class ConstantInt : public Constant {
static ConstantInt *TheTrueVal, *TheFalseVal; static ConstantInt *TheTrueVal, *TheFalseVal;
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
ConstantInt(const IntegerType *Ty, const APInt& V); ConstantInt(const IntegerType *Ty, const APInt& V);
APInt Val; APInt Val;
protected:
// allocate space for exactly zero operands
void *operator new(size_t s) {
return User::operator new(s, 0);
}
public: public:
/// Return the constant as an APInt value reference. This allows clients to /// Return the constant as an APInt value reference. This allows clients to
/// obtain a copy of the value, with all its precision in tact. /// obtain a copy of the value, with all its precision in tact.
@ -215,9 +221,15 @@ private:
/// ///
class ConstantFP : public Constant { class ConstantFP : public Constant {
APFloat Val; APFloat Val;
void *operator new(size_t, unsigned);// DO NOT IMPLEMENT
ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
protected: protected:
ConstantFP(const Type *Ty, const APFloat& V); 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: public:
/// get() - Static factory methods - Return objects of the specified value /// get() - Static factory methods - Return objects of the specified value
static ConstantFP *get(const Type *Ty, const APFloat& V); static ConstantFP *get(const Type *Ty, const APFloat& V);
@ -262,10 +274,16 @@ public:
/// ///
class ConstantAggregateZero : public Constant { class ConstantAggregateZero : public Constant {
friend struct ConstantCreator<ConstantAggregateZero, Type, char>; friend struct ConstantCreator<ConstantAggregateZero, Type, char>;
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
protected: protected:
explicit ConstantAggregateZero(const Type *Ty) explicit ConstantAggregateZero(const Type *Ty)
: Constant(Ty, ConstantAggregateZeroVal, 0, 0) {} : 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: public:
/// get() - static factory method for creating a null aggregate. It is /// get() - static factory method for creating a null aggregate. It is
/// illegal to call this method with a non-aggregate type. /// illegal to call this method with a non-aggregate type.
@ -457,14 +475,19 @@ public:
/// ///
class ConstantPointerNull : public Constant { class ConstantPointerNull : public Constant {
friend struct ConstantCreator<ConstantPointerNull, PointerType, char>; friend struct ConstantCreator<ConstantPointerNull, PointerType, char>;
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
protected: protected:
explicit ConstantPointerNull(const PointerType *T) explicit ConstantPointerNull(const PointerType *T)
: Constant(reinterpret_cast<const Type*>(T), : Constant(reinterpret_cast<const Type*>(T),
Value::ConstantPointerNullVal, 0, 0) {} Value::ConstantPointerNullVal, 0, 0) {}
protected:
// allocate space for exactly zero operands
void *operator new(size_t s) {
return User::operator new(s, 0);
}
public: public:
/// get() - Static factory methods - Return objects of the specified value /// get() - Static factory methods - Return objects of the specified value
static ConstantPointerNull *get(const PointerType *T); static ConstantPointerNull *get(const PointerType *T);
@ -706,9 +729,15 @@ public:
/// ///
class UndefValue : public Constant { class UndefValue : public Constant {
friend struct ConstantCreator<UndefValue, Type, char>; friend struct ConstantCreator<UndefValue, Type, char>;
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
UndefValue(const UndefValue &); // DO NOT IMPLEMENT UndefValue(const UndefValue &); // DO NOT IMPLEMENT
protected: protected:
explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {} 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: public:
/// get() - Static factory methods - Return an 'undef' object of the specified /// get() - Static factory methods - Return an 'undef' object of the specified
/// type. /// type.

View File

@ -104,13 +104,20 @@ private:
Function(const Function&); // DO NOT IMPLEMENT Function(const Function&); // DO NOT IMPLEMENT
void operator=(const Function&); // DO NOT IMPLEMENT void operator=(const Function&); // DO NOT IMPLEMENT
public:
/// Function ctor - If the (optional) Module argument is specified, the /// Function ctor - If the (optional) Module argument is specified, the
/// function is automatically inserted into the end of the function list for /// function is automatically inserted into the end of the function list for
/// the module. /// the module.
/// ///
Function(const FunctionType *Ty, LinkageTypes Linkage, Function(const FunctionType *Ty, LinkageTypes Linkage,
const std::string &N = "", Module *M = 0); 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(); ~Function();
const Type *getReturnType() const; // Return the type of the ret val const Type *getReturnType() const; // Return the type of the ret val

View File

@ -44,6 +44,10 @@ class GlobalAlias : public GlobalValue {
Use Aliasee; Use Aliasee;
public: 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 /// GlobalAlias ctor - If a parent module is specified, the alias is
/// automatically inserted into the end of the specified module's alias list. /// automatically inserted into the end of the specified module's alias list.
GlobalAlias(const Type *Ty, LinkageTypes Linkage, const std::string &Name = "", GlobalAlias(const Type *Ty, LinkageTypes Linkage, const std::string &Name = "",

View File

@ -32,6 +32,7 @@ template<typename ValueSubClass, typename ItemParentClass>
class GlobalVariable : public GlobalValue { class GlobalVariable : public GlobalValue {
friend class SymbolTableListTraits<GlobalVariable, Module>; friend class SymbolTableListTraits<GlobalVariable, Module>;
void *operator new(size_t, unsigned); // Do not implement
void operator=(const GlobalVariable &); // Do not implement void operator=(const GlobalVariable &); // Do not implement
GlobalVariable(const GlobalVariable &); // Do not implement GlobalVariable(const GlobalVariable &); // Do not implement
@ -46,6 +47,10 @@ class GlobalVariable : public GlobalValue {
Use Initializer; Use Initializer;
public: 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 /// GlobalVariable ctor - If a parent module is specified, the global is
/// automatically inserted into the end of the specified modules global list. /// automatically inserted into the end of the specified modules global list.
GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage, GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage,

View File

@ -83,6 +83,7 @@ public:
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
class UnaryInstruction : public Instruction { class UnaryInstruction : public Instruction {
void *operator new(size_t, unsigned); // Do not implement
Use Op; Use Op;
// avoiding warning: 'this' : used in base member initializer list // avoiding warning: 'this' : used in base member initializer list
@ -95,6 +96,11 @@ protected:
: Instruction(Ty, iType, &Op, 1, IAE), Op(V, this_()) { : Instruction(Ty, iType, &Op, 1, IAE), Op(V, this_()) {
} }
public: 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. // Out of line virtual method, so the vtable, etc has a home.
~UnaryInstruction(); ~UnaryInstruction();
@ -129,6 +135,7 @@ public:
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
class BinaryOperator : public Instruction { class BinaryOperator : public Instruction {
void *operator new(size_t, unsigned); // Do not implement
Use Ops[2]; Use Ops[2];
protected: protected:
void init(BinaryOps iType); void init(BinaryOps iType);
@ -137,6 +144,10 @@ protected:
BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty, BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
const std::string &Name, BasicBlock *InsertAtEnd); const std::string &Name, BasicBlock *InsertAtEnd);
public: 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. /// Transparently provide more efficient getOperand methods.
Value *getOperand(unsigned i) const { Value *getOperand(unsigned i) const {
@ -489,6 +500,7 @@ public:
/// This class is the base class for the comparison instructions. /// This class is the base class for the comparison instructions.
/// @brief Abstract base class of comparison instructions. /// @brief Abstract base class of comparison instructions.
class CmpInst: public Instruction { class CmpInst: public Instruction {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
CmpInst(); // do not implement CmpInst(); // do not implement
protected: protected:
CmpInst(Instruction::OtherOps op, unsigned short pred, Value *LHS, Value *RHS, 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 Use Ops[2]; // CmpInst instructions always have 2 operands, optimize
public: 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 /// Construct a compare instruction, given the opcode, the predicate and
/// the two operands. Optionally (if InstBefore is specified) insert the /// the two operands. Optionally (if InstBefore is specified) insert the
/// instruction into a BasicBlock right before the specified instruction. /// instruction into a BasicBlock right before the specified instruction.

View File

@ -45,7 +45,7 @@ protected:
AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align, AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
const std::string &Name, BasicBlock *InsertAtEnd); const std::string &Name, BasicBlock *InsertAtEnd);
public: 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(); virtual ~AllocationInst();
/// isArrayAllocation - Return true if there is an allocation size parameter /// isArrayAllocation - Return true if there is an allocation size parameter
@ -287,6 +287,7 @@ public:
/// StoreInst - an instruction for storing to memory /// StoreInst - an instruction for storing to memory
/// ///
class StoreInst : public Instruction { class StoreInst : public Instruction {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Ops[2]; Use Ops[2];
StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) { StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
@ -301,6 +302,10 @@ class StoreInst : public Instruction {
} }
void AssertOK(); void AssertOK();
public: 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, Instruction *InsertBefore);
StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd); StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
StoreInst(Value *Val, Value *Ptr, bool isVolatile = false, 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 /// Constructors - Create a getelementptr instruction with a base pointer an
/// list of indices. The first ctor can optionally insert before an existing /// list of indices. The first ctor can optionally insert before an existing
/// instruction, the second appends the new instruction to the specified /// instruction, the second appends the new instruction to the specified
@ -447,7 +451,7 @@ public:
GetElementPtrInst(Value *Ptr, InputIterator IdxBegin, GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
InputIterator IdxEnd, InputIterator IdxEnd,
const std::string &Name = "", const std::string &Name = "",
Instruction *InsertBefore =0) Instruction *InsertBefore = 0)
: Instruction(PointerType::get( : Instruction(PointerType::get(
checkType(getIndexedType(Ptr->getType(), checkType(getIndexedType(Ptr->getType(),
IdxBegin, IdxEnd, true)), IdxBegin, IdxEnd, true)),
@ -471,9 +475,33 @@ public:
/// Constructors - These two constructors are convenience methods because one /// Constructors - These two constructors are convenience methods because one
/// and two index getelementptr instructions are so common. /// and two index getelementptr instructions are so common.
GetElementPtrInst(Value *Ptr, Value *Idx, GetElementPtrInst(Value *Ptr, Value *Idx,
const std::string &Name = "", Instruction *InsertBefore =0); const std::string &Name = "", Instruction *InsertBefore = 0);
GetElementPtrInst(Value *Ptr, Value *Idx, GetElementPtrInst(Value *Ptr, Value *Idx,
const std::string &Name, BasicBlock *InsertAtEnd); 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(); ~GetElementPtrInst();
virtual GetElementPtrInst *clone() const; virtual GetElementPtrInst *clone() const;
@ -866,7 +894,6 @@ class CallInst : public Instruction {
setName(Name); setName(Name);
} }
public:
/// Construct a CallInst given a range of arguments. InputIterator /// Construct a CallInst given a range of arguments. InputIterator
/// must be a random-access iterator pointing to contiguous storage /// must be a random-access iterator pointing to contiguous storage
/// (e.g. a std::vector<>::iterator). Checks are made for /// (e.g. a std::vector<>::iterator). Checks are made for
@ -906,6 +933,33 @@ public:
explicit CallInst(Value *F, const std::string &Name = "", explicit CallInst(Value *F, const std::string &Name = "",
Instruction *InsertBefore = 0); Instruction *InsertBefore = 0);
CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd); 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(); ~CallInst();
virtual CallInst *clone() const; virtual CallInst *clone() const;
@ -1011,7 +1065,6 @@ class SelectInst : public Instruction {
: Instruction(SI.getType(), SI.getOpcode(), Ops, 3) { : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
init(SI.Ops[0], SI.Ops[1], SI.Ops[2]); init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
} }
public:
SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "", SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
Instruction *InsertBefore = 0) Instruction *InsertBefore = 0)
: Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) { : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
@ -1024,6 +1077,15 @@ public:
init(C, S1, S2); init(C, S1, S2);
setName(Name); 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 *getCondition() const { return Ops[0]; }
Value *getTrueValue() const { return Ops[1]; } Value *getTrueValue() const { return Ops[1]; }
@ -1106,6 +1168,10 @@ class ExtractElementInst : public Instruction {
} }
public: 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 = "", ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
Instruction *InsertBefore = 0); Instruction *InsertBefore = 0);
ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "", ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
@ -1152,15 +1218,34 @@ public:
class InsertElementInst : public Instruction { class InsertElementInst : public Instruction {
Use Ops[3]; Use Ops[3];
InsertElementInst(const InsertElementInst &IE); InsertElementInst(const InsertElementInst &IE);
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
const std::string &Name = "",Instruction *InsertBefore = 0);
InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
const std::string &Name = "",Instruction *InsertBefore = 0);
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
const std::string &Name, BasicBlock *InsertAtEnd);
InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
const std::string &Name, BasicBlock *InsertAtEnd);
public: public:
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, static InsertElementInst *Create(const InsertElementInst &IE) {
const std::string &Name = "",Instruction *InsertBefore = 0); return new(IE.getNumOperands()) InsertElementInst(IE);
InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx, }
const std::string &Name = "",Instruction *InsertBefore = 0); static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const std::string &Name = "",Instruction *InsertBefore = 0) {
const std::string &Name, BasicBlock *InsertAtEnd); return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx, }
const std::string &Name, BasicBlock *InsertAtEnd); 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 /// isValidOperands - Return true if an insertelement instruction can be
/// formed with the specified operands. /// formed with the specified operands.
@ -1207,6 +1292,10 @@ class ShuffleVectorInst : public Instruction {
Use Ops[3]; Use Ops[3];
ShuffleVectorInst(const ShuffleVectorInst &IE); ShuffleVectorInst(const ShuffleVectorInst &IE);
public: 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, ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
const std::string &Name = "", Instruction *InsertBefor = 0); const std::string &Name = "", Instruction *InsertBefor = 0);
ShuffleVectorInst(Value *V1, Value *V2, Value *Mask, ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
@ -1265,11 +1354,15 @@ public:
// scientist's overactive imagination. // scientist's overactive imagination.
// //
class PHINode : public Instruction { class PHINode : public Instruction {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
/// ReservedSpace - The number of operands actually allocated. NumOperands is /// ReservedSpace - The number of operands actually allocated. NumOperands is
/// the number actually in use. /// the number actually in use.
unsigned ReservedSpace; unsigned ReservedSpace;
PHINode(const PHINode &PN); 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 = "", explicit PHINode(const Type *Ty, const std::string &Name = "",
Instruction *InsertBefore = 0) Instruction *InsertBefore = 0)
: Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore), : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
@ -1282,7 +1375,14 @@ public:
ReservedSpace(0) { ReservedSpace(0) {
setName(Name); 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(); ~PHINode();
/// reserveOperandSpace - This method can be used to avoid repeated /// reserveOperandSpace - This method can be used to avoid repeated
@ -1401,7 +1501,7 @@ class ReturnInst : public TerminatorInst {
ReturnInst(const ReturnInst &RI); ReturnInst(const ReturnInst &RI);
void init(Value * const* retVals, unsigned N); void init(Value * const* retVals, unsigned N);
public: private:
// ReturnInst constructors: // ReturnInst constructors:
// ReturnInst() - 'ret void' instruction // ReturnInst() - 'ret void' instruction
// ReturnInst( null) - '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, Instruction *InsertBefore);
ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd); ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd);
explicit ReturnInst(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();
virtual ReturnInst *clone() const; virtual ReturnInst *clone() const;
@ -1467,7 +1586,6 @@ class BranchInst : public TerminatorInst {
Use Ops[3]; Use Ops[3];
BranchInst(const BranchInst &BI); BranchInst(const BranchInst &BI);
void AssertOK(); void AssertOK();
public:
// BranchInst constructors (where {B, T, F} are blocks, and C is a condition): // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
// BranchInst(BB *B) - 'br B' // BranchInst(BB *B) - 'br B'
// BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F' // 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 *InsertAtEnd);
BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond, BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
BasicBlock *InsertAtEnd); 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. /// Transparently provide more efficient getOperand methods.
Value *getOperand(unsigned i) const { Value *getOperand(unsigned i) const {
@ -1561,7 +1694,6 @@ class SwitchInst : public TerminatorInst {
SwitchInst(const SwitchInst &RI); SwitchInst(const SwitchInst &RI);
void init(Value *Value, BasicBlock *Default, unsigned NumCases); void init(Value *Value, BasicBlock *Default, unsigned NumCases);
void resizeOperands(unsigned No); void resizeOperands(unsigned No);
public:
/// SwitchInst ctor - Create a new switch instruction, specifying a value to /// SwitchInst ctor - Create a new switch instruction, specifying a value to
/// switch on and a default destination. The number of additional cases can /// switch on and a default destination. The number of additional cases can
/// be specified here to make memory allocation more efficient. This /// 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. /// constructor also autoinserts at the end of the specified BasicBlock.
SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases, SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
BasicBlock *InsertAtEnd); 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(); ~SwitchInst();
// Accessor Methods for Switch stmt // Accessor Methods for Switch stmt
Value *getCondition() const { return getOperand(0); } Value *getCondition() const { return getOperand(0); }
void setCondition(Value *V) { setOperand(0, V); } void setCondition(Value *V) { setOperand(0, V); }
@ -1703,7 +1843,6 @@ class InvokeInst : public TerminatorInst {
setName(Name); setName(Name);
} }
public:
/// Construct an InvokeInst given a range of arguments. /// Construct an InvokeInst given a range of arguments.
/// InputIterator must be a random-access iterator pointing to /// InputIterator must be a random-access iterator pointing to
/// contiguous storage (e.g. a std::vector<>::iterator). Checks are /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
@ -1739,6 +1878,19 @@ public:
init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
typename std::iterator_traits<InputIterator>::iterator_category()); 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(); ~InvokeInst();
@ -1856,7 +2008,12 @@ private:
/// until an invoke instruction is found. /// until an invoke instruction is found.
/// ///
class UnwindInst : public TerminatorInst { class UnwindInst : public TerminatorInst {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
public: 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(Instruction *InsertBefore = 0);
explicit UnwindInst(BasicBlock *InsertAtEnd); explicit UnwindInst(BasicBlock *InsertAtEnd);
@ -1888,7 +2045,12 @@ private:
/// end of the block cannot be reached. /// end of the block cannot be reached.
/// ///
class UnreachableInst : public TerminatorInst { class UnreachableInst : public TerminatorInst {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
public: 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(Instruction *InsertBefore = 0);
explicit UnreachableInst(BasicBlock *InsertAtEnd); explicit UnreachableInst(BasicBlock *InsertAtEnd);
@ -2388,7 +2550,8 @@ public:
/// GetResultInst - This instruction extracts individual result value from /// GetResultInst - This instruction extracts individual result value from
/// aggregate value, where aggregate value is returned by CallInst. /// 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; Use Aggr;
unsigned Idx; unsigned Idx;
GetResultInst(const GetResultInst &GRI) : GetResultInst(const GetResultInst &GRI) :
@ -2398,6 +2561,10 @@ class GetResultInst : public Instruction {
} }
public: 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, explicit GetResultInst(Value *Aggr, unsigned index,
const std::string &Name = "", const std::string &Name = "",
Instruction *InsertBefore = 0); Instruction *InsertBefore = 0);

View File

@ -87,32 +87,32 @@ public:
/// CreateRetVoid - Create a 'ret void' instruction. /// CreateRetVoid - Create a 'ret void' instruction.
ReturnInst *CreateRetVoid() { ReturnInst *CreateRetVoid() {
return Insert(new ReturnInst()); return Insert(ReturnInst::Create());
} }
/// @verbatim /// @verbatim
/// CreateRet - Create a 'ret <val>' instruction. /// CreateRet - Create a 'ret <val>' instruction.
/// @endverbatim /// @endverbatim
ReturnInst *CreateRet(Value *V) { ReturnInst *CreateRet(Value *V) {
return Insert(new ReturnInst(V)); return Insert(ReturnInst::Create(V));
} }
/// CreateBr - Create an unconditional 'br label X' instruction. /// CreateBr - Create an unconditional 'br label X' instruction.
BranchInst *CreateBr(BasicBlock *Dest) { BranchInst *CreateBr(BasicBlock *Dest) {
return Insert(new BranchInst(Dest)); return Insert(BranchInst::Create(Dest));
} }
/// CreateCondBr - Create a conditional 'br Cond, TrueDest, FalseDest' /// CreateCondBr - Create a conditional 'br Cond, TrueDest, FalseDest'
/// instruction. /// instruction.
BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False) { 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, /// CreateSwitch - Create a switch instruction with the specified value,
/// default dest, and with a hint for the number of cases that will be added /// default dest, and with a hint for the number of cases that will be added
/// (for efficient allocation). /// (for efficient allocation).
SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10) { 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. /// CreateInvoke - Create an invoke instruction.
@ -120,8 +120,8 @@ public:
InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest, InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
BasicBlock *UnwindDest, InputIterator ArgBegin, BasicBlock *UnwindDest, InputIterator ArgBegin,
InputIterator ArgEnd, const char *Name = "") { InputIterator ArgEnd, const char *Name = "") {
return(Insert(new InvokeInst(Callee, NormalDest, UnwindDest, return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest,
ArgBegin, ArgEnd, Name))); ArgBegin, ArgEnd, Name));
} }
UnwindInst *CreateUnwind() { UnwindInst *CreateUnwind() {
@ -221,10 +221,10 @@ public:
template<typename InputIterator> template<typename InputIterator>
GetElementPtrInst *CreateGEP(Value *Ptr, InputIterator IdxBegin, GetElementPtrInst *CreateGEP(Value *Ptr, InputIterator IdxBegin,
InputIterator IdxEnd, const char *Name = "") { 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 = "") { 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, GetElementPtrInst *CreateStructGEP(Value *Ptr, unsigned Idx,
const char *Name = "") { const char *Name = "") {
@ -232,7 +232,7 @@ public:
ConstantInt::get(llvm::Type::Int32Ty, 0), ConstantInt::get(llvm::Type::Int32Ty, 0),
ConstantInt::get(llvm::Type::Int32Ty, Idx) 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 = "") { 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 = "") { 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 = "") { 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> template<typename InputIterator>
CallInst *CreateCall(Value *Callee, InputIterator ArgBegin, CallInst *CreateCall(Value *Callee, InputIterator ArgBegin,
InputIterator ArgEnd, const char *Name = "") { 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, SelectInst *CreateSelect(Value *C, Value *True, Value *False,
const char *Name = "") { 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 = "") { VAArgInst *CreateVAArg(Value *List, const Type *Ty, const char *Name = "") {
@ -416,7 +416,7 @@ public:
InsertElementInst *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx, InsertElementInst *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx,
const char *Name = "") { 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, ShuffleVectorInst *CreateShuffleVector(Value *V1, Value *V2, Value *Mask,

View File

@ -25,6 +25,7 @@ namespace llvm {
class User : public Value { class User : public Value {
User(const User &); // Do not implement User(const User &); // Do not implement
void *operator new(size_t); // Do not implement
protected: protected:
/// OperandList - This is a pointer to the array of Users for this operand. /// 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 /// For nodes of fixed arity (e.g. a binary operator) this array will live
@ -38,10 +39,13 @@ protected:
/// ///
unsigned NumOperands; unsigned NumOperands;
public: void *operator new(size_t s, unsigned) {
return ::operator new(s);
}
User(const Type *Ty, unsigned vty, Use *OpList, unsigned NumOps) User(const Type *Ty, unsigned vty, Use *OpList, unsigned NumOps)
: Value(Ty, vty), OperandList(OpList), NumOperands(NumOps) {} : Value(Ty, vty), OperandList(OpList), NumOperands(NumOps) {}
public:
Value *getOperand(unsigned i) const { Value *getOperand(unsigned i) const {
assert(i < NumOperands && "getOperand() out of range!"); assert(i < NumOperands && "getOperand() out of range!");
return OperandList[i]; return OperandList[i];

View File

@ -143,7 +143,7 @@ Value *SCEVExpander::visitAddRecExpr(SCEVAddRecExpr *S) {
// Create and insert the PHI node for the induction variable in the // Create and insert the PHI node for the induction variable in the
// specified loop. // specified loop.
BasicBlock *Header = L->getHeader(); 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()); PN->addIncoming(Constant::getNullValue(Ty), L->getLoopPreheader());
pred_iterator HPI = pred_begin(Header); pred_iterator HPI = pred_begin(Header);
@ -215,7 +215,7 @@ Value *SCEVExpander::visitSMaxExpr(SCEVSMaxExpr *S) {
for (unsigned i = 1; i < S->getNumOperands(); ++i) { for (unsigned i = 1; i < S->getNumOperands(); ++i) {
Value *RHS = expand(S->getOperand(i)); Value *RHS = expand(S->getOperand(i));
Value *ICmp = new ICmpInst(ICmpInst::ICMP_SGT, LHS, RHS, "tmp", InsertPt); 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; return LHS;
} }
@ -225,7 +225,7 @@ Value *SCEVExpander::visitUMaxExpr(SCEVUMaxExpr *S) {
for (unsigned i = 1; i < S->getNumOperands(); ++i) { for (unsigned i = 1; i < S->getNumOperands(); ++i) {
Value *RHS = expand(S->getOperand(i)); Value *RHS = expand(S->getOperand(i));
Value *ICmp = new ICmpInst(ICmpInst::ICMP_UGT, LHS, RHS, "tmp", InsertPt); 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; return LHS;
} }

View File

@ -493,7 +493,7 @@ static Value *getVal(const Type *Ty, const ValID &ID) {
} }
const Type* ElTy = PTy->getElementType(); const Type* ElTy = PTy->getElementType();
if (const FunctionType *FTy = dyn_cast<FunctionType>(ElTy)) if (const FunctionType *FTy = dyn_cast<FunctionType>(ElTy))
V = new Function(FTy, GlobalValue::ExternalLinkage); V = Function::Create(FTy, GlobalValue::ExternalLinkage);
else else
V = new GlobalVariable(ElTy, false, GlobalValue::ExternalLinkage, 0, "", V = new GlobalVariable(ElTy, false, GlobalValue::ExternalLinkage, 0, "",
(Module*)0, false, PTy->getAddressSpace()); (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. // We haven't seen this BB before and its first mention is a definition.
// Just create it and return it. // Just create it and return it.
std::string Name (ID.Type == ValID::LocalName ? ID.getName() : ""); 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) { if (ID.Type == ValID::LocalID) {
assert(ID.Num == CurFun.NextValNum && "Invalid new block number"); assert(ID.Num == CurFun.NextValNum && "Invalid new block number");
InsertValue(BB); InsertValue(BB);
@ -607,7 +607,7 @@ static BasicBlock *getBBVal(const ValID &ID) {
std::string Name; std::string Name;
if (ID.Type == ValID::LocalName) if (ID.Type == ValID::LocalName)
Name = ID.getName(); Name = ID.getName();
BB = new BasicBlock(Name, CurFun.CurrentFunction); BB = BasicBlock::Create(Name, CurFun.CurrentFunction);
// Insert it in the forward refs map. // Insert it in the forward refs map.
CurFun.BBForwardRefs[ID] = BB; CurFun.BBForwardRefs[ID] = BB;
@ -1779,8 +1779,8 @@ ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
GlobalValue *GV; GlobalValue *GV;
if (const FunctionType *FTy = if (const FunctionType *FTy =
dyn_cast<FunctionType>(PT->getElementType())) { dyn_cast<FunctionType>(PT->getElementType())) {
GV = new Function(FTy, GlobalValue::ExternalWeakLinkage, Name, GV = Function::Create(FTy, GlobalValue::ExternalWeakLinkage, Name,
CurModule.CurrentModule); CurModule.CurrentModule);
} else { } else {
GV = new GlobalVariable(PT->getElementType(), false, GV = new GlobalVariable(PT->getElementType(), false,
GlobalValue::ExternalWeakLinkage, 0, GlobalValue::ExternalWeakLinkage, 0,
@ -2319,8 +2319,8 @@ FunctionHeaderH : OptCallingConv ResultTypes GlobalName '(' ArgList ')'
AI->setName(""); AI->setName("");
} }
} else { // Not already defined? } else { // Not already defined?
Fn = new Function(FT, GlobalValue::ExternalWeakLinkage, FunctionName, Fn = Function::Create(FT, GlobalValue::ExternalWeakLinkage, FunctionName,
CurModule.CurrentModule); CurModule.CurrentModule);
InsertValue(Fn, CurModule.Values); InsertValue(Fn, CurModule.Values);
} }
@ -2579,18 +2579,18 @@ BBTerminatorInst :
RET ReturnedVal { // Return with a result... RET ReturnedVal { // Return with a result...
ValueList &VL = *$2; ValueList &VL = *$2;
assert(!VL.empty() && "Invalid ret operands!"); assert(!VL.empty() && "Invalid ret operands!");
$$ = new ReturnInst(&VL[0], VL.size()); $$ = ReturnInst::Create(&VL[0], VL.size());
delete $2; delete $2;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| RET VOID { // Return with no result... | RET VOID { // Return with no result...
$$ = new ReturnInst(); $$ = ReturnInst::Create();
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| BR LABEL ValueRef { // Unconditional Branch... | BR LABEL ValueRef { // Unconditional Branch...
BasicBlock* tmpBB = getBBVal($3); BasicBlock* tmpBB = getBBVal($3);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$ = new BranchInst(tmpBB); $$ = BranchInst::Create(tmpBB);
} // Conditional Branch... } // Conditional Branch...
| BR INTTYPE ValueRef ',' LABEL ValueRef ',' LABEL ValueRef { | BR INTTYPE ValueRef ',' LABEL ValueRef ',' LABEL ValueRef {
assert(cast<IntegerType>($2)->getBitWidth() == 1 && "Not Bool?"); assert(cast<IntegerType>($2)->getBitWidth() == 1 && "Not Bool?");
@ -2600,14 +2600,14 @@ BBTerminatorInst :
CHECK_FOR_ERROR CHECK_FOR_ERROR
Value* tmpVal = getVal(Type::Int1Ty, $3); Value* tmpVal = getVal(Type::Int1Ty, $3);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$ = new BranchInst(tmpBBA, tmpBBB, tmpVal); $$ = BranchInst::Create(tmpBBA, tmpBBB, tmpVal);
} }
| SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' { | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' {
Value* tmpVal = getVal($2, $3); Value* tmpVal = getVal($2, $3);
CHECK_FOR_ERROR CHECK_FOR_ERROR
BasicBlock* tmpBB = getBBVal($6); BasicBlock* tmpBB = getBBVal($6);
CHECK_FOR_ERROR CHECK_FOR_ERROR
SwitchInst *S = new SwitchInst(tmpVal, tmpBB, $8->size()); SwitchInst *S = SwitchInst::Create(tmpVal, tmpBB, $8->size());
$$ = S; $$ = S;
std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = $8->begin(), std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = $8->begin(),
@ -2626,7 +2626,7 @@ BBTerminatorInst :
CHECK_FOR_ERROR CHECK_FOR_ERROR
BasicBlock* tmpBB = getBBVal($6); BasicBlock* tmpBB = getBBVal($6);
CHECK_FOR_ERROR CHECK_FOR_ERROR
SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0); SwitchInst *S = SwitchInst::Create(tmpVal, tmpBB, 0);
$$ = S; $$ = S;
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
@ -2704,7 +2704,7 @@ BBTerminatorInst :
PAL = PAListPtr::get(Attrs.begin(), Attrs.end()); PAL = PAListPtr::get(Attrs.begin(), Attrs.end());
// Create the InvokeInst // 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->setCallingConv($2);
II->setParamAttrs(PAL); II->setParamAttrs(PAL);
$$ = II; $$ = II;
@ -2911,7 +2911,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
GEN_ERROR("select condition must be boolean"); GEN_ERROR("select condition must be boolean");
if ($4->getType() != $6->getType()) if ($4->getType() != $6->getType())
GEN_ERROR("select value types should match"); GEN_ERROR("select value types should match");
$$ = new SelectInst($2, $4, $6); $$ = SelectInst::Create($2, $4, $6);
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| VAARG ResolvedVal ',' Types { | VAARG ResolvedVal ',' Types {
@ -2930,7 +2930,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
| INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal { | INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
if (!InsertElementInst::isValidOperands($2, $4, $6)) if (!InsertElementInst::isValidOperands($2, $4, $6))
GEN_ERROR("Invalid insertelement operands"); GEN_ERROR("Invalid insertelement operands");
$$ = new InsertElementInst($2, $4, $6); $$ = InsertElementInst::Create($2, $4, $6);
CHECK_FOR_ERROR CHECK_FOR_ERROR
} }
| SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal { | SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal {
@ -2943,7 +2943,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
const Type *Ty = $2->front().first->getType(); const Type *Ty = $2->front().first->getType();
if (!Ty->isFirstClassType()) if (!Ty->isFirstClassType())
GEN_ERROR("PHI node operands must be of first class type"); GEN_ERROR("PHI node operands must be of first class type");
$$ = new PHINode(Ty); $$ = PHINode::Create(Ty);
((PHINode*)$$)->reserveOperandSpace($2->size()); ((PHINode*)$$)->reserveOperandSpace($2->size());
while ($2->begin() != $2->end()) { while ($2->begin() != $2->end()) {
if ($2->front().first->getType() != Ty) if ($2->front().first->getType() != Ty)
@ -3031,7 +3031,7 @@ InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
PAL = PAListPtr::get(Attrs.begin(), Attrs.end()); PAL = PAListPtr::get(Attrs.begin(), Attrs.end());
// Create the call node // 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->setTailCall($1);
CI->setCallingConv($2); CI->setCallingConv($2);
CI->setParamAttrs(PAL); CI->setParamAttrs(PAL);
@ -3144,7 +3144,7 @@ MemoryInst : MALLOC Types OptCAlign {
(*$2)->getDescription()+ "'"); (*$2)->getDescription()+ "'");
Value* tmpVal = getVal(*$2, $3); Value* tmpVal = getVal(*$2, $3);
CHECK_FOR_ERROR CHECK_FOR_ERROR
$$ = new GetElementPtrInst(tmpVal, $4->begin(), $4->end()); $$ = GetElementPtrInst::Create(tmpVal, $4->begin(), $4->end());
delete $2; delete $2;
delete $4; delete $4;
}; };

View File

@ -122,8 +122,12 @@ namespace {
class ConstantPlaceHolder : public ConstantExpr { class ConstantPlaceHolder : public ConstantExpr {
ConstantPlaceHolder(); // DO NOT IMPLEMENT ConstantPlaceHolder(); // DO NOT IMPLEMENT
void operator=(const ConstantPlaceHolder &); // DO NOT IMPLEMENT void operator=(const ConstantPlaceHolder &); // DO NOT IMPLEMENT
public:
Use Op; 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) explicit ConstantPlaceHolder(const Type *Ty)
: ConstantExpr(Ty, Instruction::UserOp1, &Op, 1), : ConstantExpr(Ty, Instruction::UserOp1, &Op, 1),
Op(UndefValue::get(Type::Int32Ty), this) { Op(UndefValue::get(Type::Int32Ty), this) {
@ -1046,8 +1050,8 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) {
if (!FTy) if (!FTy)
return Error("Function not a pointer to function type!"); return Error("Function not a pointer to function type!");
Function *Func = new Function(FTy, GlobalValue::ExternalLinkage, Function *Func = Function::Create(FTy, GlobalValue::ExternalLinkage,
"", TheModule); "", TheModule);
Func->setCallingConv(Record[1]); Func->setCallingConv(Record[1]);
bool isProto = Record[2]; bool isProto = Record[2];
@ -1216,7 +1220,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
// Create all the basic blocks for the function. // Create all the basic blocks for the function.
FunctionBBs.resize(Record[0]); FunctionBBs.resize(Record[0]);
for (unsigned i = 0, e = FunctionBBs.size(); i != e; ++i) for (unsigned i = 0, e = FunctionBBs.size(); i != e; ++i)
FunctionBBs[i] = new BasicBlock("", F); FunctionBBs[i] = BasicBlock::Create("", F);
CurBB = FunctionBBs[0]; CurBB = FunctionBBs[0];
continue; continue;
@ -1270,7 +1274,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
GEPIdx.push_back(Op); GEPIdx.push_back(Op);
} }
I = new GetElementPtrInst(BasePtr, GEPIdx.begin(), GEPIdx.end()); I = GetElementPtrInst::Create(BasePtr, GEPIdx.begin(), GEPIdx.end());
break; break;
} }
@ -1282,7 +1286,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
getValue(Record, OpNum, Type::Int1Ty, Cond)) getValue(Record, OpNum, Type::Int1Ty, Cond))
return Error("Invalid SELECT record"); return Error("Invalid SELECT record");
I = new SelectInst(Cond, TrueVal, FalseVal); I = SelectInst::Create(Cond, TrueVal, FalseVal);
break; break;
} }
@ -1304,7 +1308,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
cast<VectorType>(Vec->getType())->getElementType(), Elt) || cast<VectorType>(Vec->getType())->getElementType(), Elt) ||
getValue(Record, OpNum, Type::Int32Ty, Idx)) getValue(Record, OpNum, Type::Int32Ty, Idx))
return Error("Invalid INSERTELT record"); return Error("Invalid INSERTELT record");
I = new InsertElementInst(Vec, Elt, Idx); I = InsertElementInst::Create(Vec, Elt, Idx);
break; break;
} }
@ -1354,7 +1358,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
{ {
unsigned Size = Record.size(); unsigned Size = Record.size();
if (Size == 0) { if (Size == 0) {
I = new ReturnInst(); I = ReturnInst::Create();
break; break;
} else { } else {
unsigned OpNum = 0; unsigned OpNum = 0;
@ -1367,7 +1371,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
} while(OpNum != Record.size()); } while(OpNum != Record.size());
// SmallVector Vs has at least one element. // SmallVector Vs has at least one element.
I = new ReturnInst(&Vs[0], Vs.size()); I = ReturnInst::Create(&Vs[0], Vs.size());
break; break;
} }
} }
@ -1379,13 +1383,13 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
return Error("Invalid BR record"); return Error("Invalid BR record");
if (Record.size() == 1) if (Record.size() == 1)
I = new BranchInst(TrueDest); I = BranchInst::Create(TrueDest);
else { else {
BasicBlock *FalseDest = getBasicBlock(Record[1]); BasicBlock *FalseDest = getBasicBlock(Record[1]);
Value *Cond = getFnValueByID(Record[2], Type::Int1Ty); Value *Cond = getFnValueByID(Record[2], Type::Int1Ty);
if (FalseDest == 0 || Cond == 0) if (FalseDest == 0 || Cond == 0)
return Error("Invalid BR record"); return Error("Invalid BR record");
I = new BranchInst(TrueDest, FalseDest, Cond); I = BranchInst::Create(TrueDest, FalseDest, Cond);
} }
break; break;
} }
@ -1398,7 +1402,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
if (OpTy == 0 || Cond == 0 || Default == 0) if (OpTy == 0 || Cond == 0 || Default == 0)
return Error("Invalid SWITCH record"); return Error("Invalid SWITCH record");
unsigned NumCases = (Record.size()-3)/2; 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) { for (unsigned i = 0, e = NumCases; i != e; ++i) {
ConstantInt *CaseVal = ConstantInt *CaseVal =
dyn_cast_or_null<ConstantInt>(getFnValueByID(Record[3+i*2], OpTy)); 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)->setCallingConv(CCInfo);
cast<InvokeInst>(I)->setParamAttrs(PAL); cast<InvokeInst>(I)->setParamAttrs(PAL);
break; break;
@ -1471,7 +1475,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
const Type *Ty = getTypeByID(Record[0]); const Type *Ty = getTypeByID(Record[0]);
if (!Ty) return Error("Invalid PHI record"); if (!Ty) return Error("Invalid PHI record");
PHINode *PN = new PHINode(Ty); PHINode *PN = PHINode::Create(Ty);
PN->reserveOperandSpace(Record.size()-1); PN->reserveOperandSpace(Record.size()-1);
for (unsigned i = 0, e = Record.size()-1; i != e; i += 2) { 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)->setCallingConv(CCInfo>>1);
cast<CallInst>(I)->setTailCall(CCInfo & 1); cast<CallInst>(I)->setTailCall(CCInfo & 1);
cast<CallInst>(I)->setParamAttrs(PAL); cast<CallInst>(I)->setParamAttrs(PAL);

View File

@ -55,8 +55,8 @@ static CallInst *ReplaceCallWith(const char *NewFn, CallInst *CI,
} }
SmallVector<Value *, 8> Args(ArgBegin, ArgEnd); SmallVector<Value *, 8> Args(ArgBegin, ArgEnd);
CallInst *NewCI = new CallInst(FCache, Args.begin(), Args.end(), CallInst *NewCI = CallInst::Create(FCache, Args.begin(), Args.end(),
CI->getName(), CI); CI->getName(), CI);
if (!CI->use_empty()) if (!CI->use_empty())
CI->replaceAllUsesWith(NewCI); CI->replaceAllUsesWith(NewCI);
return NewCI; return NewCI;
@ -339,19 +339,19 @@ static Instruction *LowerPartSelect(CallInst *CI) {
Function::arg_iterator args = F->arg_begin(); Function::arg_iterator args = F->arg_begin();
Value* Val = args++; Val->setName("Val"); Value* Val = args++; Val->setName("Val");
Value* Lo = args++; Lo->setName("Lo"); 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 // 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 // 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. // than Lo in which case the bits have to be reversed.
// Create the blocks we will need for the two cases (forward, reverse) // Create the blocks we will need for the two cases (forward, reverse)
BasicBlock* CurBB = new BasicBlock("entry", F); BasicBlock* CurBB = BasicBlock::Create("entry", F);
BasicBlock *RevSize = new BasicBlock("revsize", CurBB->getParent()); BasicBlock *RevSize = BasicBlock::Create("revsize", CurBB->getParent());
BasicBlock *FwdSize = new BasicBlock("fwdsize", CurBB->getParent()); BasicBlock *FwdSize = BasicBlock::Create("fwdsize", CurBB->getParent());
BasicBlock *Compute = new BasicBlock("compute", CurBB->getParent()); BasicBlock *Compute = BasicBlock::Create("compute", CurBB->getParent());
BasicBlock *Reverse = new BasicBlock("reverse", CurBB->getParent()); BasicBlock *Reverse = BasicBlock::Create("reverse", CurBB->getParent());
BasicBlock *RsltBlk = new BasicBlock("result", 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 // Cast Hi and Lo to the size of Val so the widths are all the same
if (Hi->getType() != Val->getType()) 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 // Compare the Hi and Lo bit positions. This is used to determine
// which case we have (forward or reverse) // which case we have (forward or reverse)
ICmpInst *Cmp = new ICmpInst(ICmpInst::ICMP_ULT, Hi, Lo, "less",CurBB); 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. // First, copmute the number of bits in the forward case.
Instruction* FBitSize = Instruction* FBitSize =
BinaryOperator::createSub(Hi, Lo,"fbits", FwdSize); BinaryOperator::createSub(Hi, Lo,"fbits", FwdSize);
new BranchInst(Compute, FwdSize); BranchInst::Create(Compute, FwdSize);
// Second, compute the number of bits in the reverse case. // Second, compute the number of bits in the reverse case.
Instruction* RBitSize = Instruction* RBitSize =
BinaryOperator::createSub(Lo, Hi, "rbits", RevSize); 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 // 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 // amount (either Hi or Lo) from PHI nodes. Then we compute a mask for
@ -389,13 +389,13 @@ static Instruction *LowerPartSelect(CallInst *CI) {
// reversed. // reversed.
// Get the BitSize from one of the two subtractions // 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->reserveOperandSpace(2);
BitSize->addIncoming(FBitSize, FwdSize); BitSize->addIncoming(FBitSize, FwdSize);
BitSize->addIncoming(RBitSize, RevSize); BitSize->addIncoming(RBitSize, RevSize);
// Get the ShiftAmount as the smaller of Hi/Lo // 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->reserveOperandSpace(2);
ShiftAmt->addIncoming(Lo, FwdSize); ShiftAmt->addIncoming(Lo, FwdSize);
ShiftAmt->addIncoming(Hi, RevSize); ShiftAmt->addIncoming(Hi, RevSize);
@ -413,24 +413,24 @@ static Instruction *LowerPartSelect(CallInst *CI) {
Instruction* FRes = Instruction* FRes =
BinaryOperator::createLShr(Val, ShiftAmt, "fres", Compute); BinaryOperator::createLShr(Val, ShiftAmt, "fres", Compute);
FRes = BinaryOperator::createAnd(FRes, Mask, "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 // 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 // it by shifting FRes bits right and putting them in RRes by shifting them
// in from left. // in from left.
// First set up our loop counters // 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->reserveOperandSpace(2);
Count->addIncoming(BitSizePlusOne, Compute); Count->addIncoming(BitSizePlusOne, Compute);
// Next, get the value that we are shifting. // 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->reserveOperandSpace(2);
BitsToShift->addIncoming(FRes, Compute); BitsToShift->addIncoming(FRes, Compute);
// Finally, get the result of the last computation // 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->reserveOperandSpace(2);
RRes->addIncoming(Zero, Compute); RRes->addIncoming(Zero, Compute);
@ -456,16 +456,16 @@ static Instruction *LowerPartSelect(CallInst *CI) {
// Terminate loop if we've moved all the bits. // Terminate loop if we've moved all the bits.
ICmpInst *Cond = ICmpInst *Cond =
new ICmpInst(ICmpInst::ICMP_EQ, Decr, Zero, "cond", Reverse); 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 // Finally, in the result block, select one of the two results with a PHI
// node and return the result; // node and return the result;
CurBB = RsltBlk; CurBB = RsltBlk;
PHINode *BitSelect = new PHINode(Val->getType(), "part_select", CurBB); PHINode *BitSelect = PHINode::Create(Val->getType(), "part_select", CurBB);
BitSelect->reserveOperandSpace(2); BitSelect->reserveOperandSpace(2);
BitSelect->addIncoming(FRes, Compute); BitSelect->addIncoming(FRes, Compute);
BitSelect->addIncoming(NewRes, Reverse); BitSelect->addIncoming(NewRes, Reverse);
new ReturnInst(BitSelect, CurBB); ReturnInst::Create(BitSelect, CurBB);
} }
// Return a call to the implementation function // Return a call to the implementation function
@ -474,7 +474,7 @@ static Instruction *LowerPartSelect(CallInst *CI) {
CI->getOperand(2), CI->getOperand(2),
CI->getOperand(3) 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 /// 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); ConstantInt* ValZero = ConstantInt::get(ValTy, 0);
// Basic blocks we fill in below. // Basic blocks we fill in below.
BasicBlock* entry = new BasicBlock("entry", F, 0); BasicBlock* entry = BasicBlock::Create("entry", F, 0);
BasicBlock* large = new BasicBlock("large", F, 0); BasicBlock* large = BasicBlock::Create("large", F, 0);
BasicBlock* small = new BasicBlock("small", F, 0); BasicBlock* small = BasicBlock::Create("small", F, 0);
BasicBlock* reverse = new BasicBlock("reverse", F, 0); BasicBlock* reverse = BasicBlock::Create("reverse", F, 0);
BasicBlock* result = new BasicBlock("result", F, 0); BasicBlock* result = BasicBlock::Create("result", F, 0);
// BASIC BLOCK: entry // BASIC BLOCK: entry
// First, get the number of bits that we're placing as an i32 // First, get the number of bits that we're placing as an i32
ICmpInst* is_forward = ICmpInst* is_forward =
new ICmpInst(ICmpInst::ICMP_ULT, Lo, Hi, "", entry); new ICmpInst(ICmpInst::ICMP_ULT, Lo, Hi, "", entry);
SelectInst* Hi_pn = new SelectInst(is_forward, Hi, Lo, "", entry); SelectInst* Hi_pn = SelectInst::Create(is_forward, Hi, Lo, "", entry);
SelectInst* Lo_pn = new SelectInst(is_forward, Lo, Hi, "", entry); SelectInst* Lo_pn = SelectInst::Create(is_forward, Lo, Hi, "", entry);
BinaryOperator* NumBits = BinaryOperator::createSub(Hi_pn, Lo_pn, "",entry); BinaryOperator* NumBits = BinaryOperator::createSub(Hi_pn, Lo_pn, "",entry);
NumBits = BinaryOperator::createAdd(NumBits, One, "", entry); NumBits = BinaryOperator::createAdd(NumBits, One, "", entry);
// Now, convert Lo and Hi to ValTy bit width // Now, convert Lo and Hi to ValTy bit width
@ -555,7 +555,7 @@ static Instruction *LowerPartSet(CallInst *CI) {
// are replacing and deal with it. // are replacing and deal with it.
ICmpInst* is_large = ICmpInst* is_large =
new ICmpInst(ICmpInst::ICMP_ULT, NumBits, RepBitWidth, "", entry); 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 // BASIC BLOCK: large
Instruction* MaskBits = Instruction* MaskBits =
@ -565,10 +565,10 @@ static Instruction *LowerPartSet(CallInst *CI) {
BinaryOperator* Mask1 = BinaryOperator* Mask1 =
BinaryOperator::createLShr(RepMask, MaskBits, "", large); BinaryOperator::createLShr(RepMask, MaskBits, "", large);
BinaryOperator* Rep2 = BinaryOperator::createAnd(Mask1, Rep, "", large); BinaryOperator* Rep2 = BinaryOperator::createAnd(Mask1, Rep, "", large);
new BranchInst(small, large); BranchInst::Create(small, large);
// BASIC BLOCK: small // BASIC BLOCK: small
PHINode* Rep3 = new PHINode(RepTy, "", small); PHINode* Rep3 = PHINode::Create(RepTy, "", small);
Rep3->reserveOperandSpace(2); Rep3->reserveOperandSpace(2);
Rep3->addIncoming(Rep2, large); Rep3->addIncoming(Rep2, large);
Rep3->addIncoming(Rep, entry); Rep3->addIncoming(Rep, entry);
@ -577,23 +577,23 @@ static Instruction *LowerPartSet(CallInst *CI) {
Rep4 = new ZExtInst(Rep3, ValTy, "", small); Rep4 = new ZExtInst(Rep3, ValTy, "", small);
else if (ValBits < RepBits) else if (ValBits < RepBits)
Rep4 = new TruncInst(Rep3, ValTy, "", small); 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) // BASIC BLOCK: reverse (reverses the bits of the replacement)
// Set up our loop counter as a PHI so we can decrement on each iteration. // 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. // 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->reserveOperandSpace(2);
Count->addIncoming(NumBits, small); Count->addIncoming(NumBits, small);
// Get the value that we are shifting bits out of as a PHI because // Get the value that we are shifting bits out of as a PHI because
// we'll change this with each iteration. // 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->reserveOperandSpace(2);
BitsToShift->addIncoming(Rep4, small); BitsToShift->addIncoming(Rep4, small);
// Get the result of the last computation or zero on first iteration // 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->reserveOperandSpace(2);
RRes->addIncoming(ValZero, small); RRes->addIncoming(ValZero, small);
@ -615,10 +615,10 @@ static Instruction *LowerPartSet(CallInst *CI) {
// Terminate loop if we've moved all the bits. // Terminate loop if we've moved all the bits.
ICmpInst *Cond = new ICmpInst(ICmpInst::ICMP_EQ, Decr, Zero, "", reverse); 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 // BASIC BLOCK: result
PHINode *Rplcmnt = new PHINode(Val->getType(), "", result); PHINode *Rplcmnt = PHINode::Create(Val->getType(), "", result);
Rplcmnt->reserveOperandSpace(2); Rplcmnt->reserveOperandSpace(2);
Rplcmnt->addIncoming(NewRes, reverse); Rplcmnt->addIncoming(NewRes, reverse);
Rplcmnt->addIncoming(Rep4, small); Rplcmnt->addIncoming(Rep4, small);
@ -630,7 +630,7 @@ static Instruction *LowerPartSet(CallInst *CI) {
Value* t5 = BinaryOperator::createAnd(t4, Val, "", result); Value* t5 = BinaryOperator::createAnd(t4, Val, "", result);
Value* t6 = BinaryOperator::createShl(Rplcmnt, Lo, "", result); Value* t6 = BinaryOperator::createShl(Rplcmnt, Lo, "", result);
Value* Rslt = BinaryOperator::createOr(t5, t6, "part_set", 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 // Return a call to the implementation function
@ -640,7 +640,7 @@ static Instruction *LowerPartSet(CallInst *CI) {
CI->getOperand(3), CI->getOperand(3),
CI->getOperand(4) 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)) // cttz(x) -> ctpop(~X & (X-1))
Value *Src = CI->getOperand(1); Value *Src = CI->getOperand(1);
Value *NotSrc = BinaryOperator::createNot(Src, Src->getName()+".not", CI); 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); SrcM1 = BinaryOperator::createSub(Src, SrcM1, "", CI);
Src = LowerCTPOP(BinaryOperator::createAnd(NotSrc, SrcM1, "", CI), CI); Src = LowerCTPOP(BinaryOperator::createAnd(NotSrc, SrcM1, "", CI), CI);
CI->replaceAllUsesWith(Src); CI->replaceAllUsesWith(Src);

View File

@ -133,7 +133,7 @@ namespace {
return 0; return 0;
// Create a cleanup block. // Create a cleanup block.
BasicBlock *CleanupBB = new BasicBlock(CleanupBBName, &F); BasicBlock *CleanupBB = BasicBlock::Create(CleanupBBName, &F);
UnwindInst *UI = new UnwindInst(CleanupBB); UnwindInst *UI = new UnwindInst(CleanupBB);
// Transform the 'call' instructions into 'invoke's branching to the // Transform the 'call' instructions into 'invoke's branching to the
@ -155,10 +155,10 @@ namespace {
Args.clear(); Args.clear();
Args.append(CI->op_begin() + 1, CI->op_end()); Args.append(CI->op_begin() + 1, CI->op_end());
InvokeInst *II = new InvokeInst(CI->getOperand(0), InvokeInst *II = InvokeInst::Create(CI->getOperand(0),
NewBB, CleanupBB, NewBB, CleanupBB,
Args.begin(), Args.end(), Args.begin(), Args.end(),
CI->getName(), CallBB); CI->getName(), CallBB);
II->setCallingConv(CI->getCallingConv()); II->setCallingConv(CI->getCallingConv());
II->setParamAttrs(CI->getParamAttrs()); II->setParamAttrs(CI->getParamAttrs());
CI->replaceAllUsesWith(II); CI->replaceAllUsesWith(II);

View File

@ -220,11 +220,11 @@ GenericValue JIT::runFunction(Function *F,
// First, create the function. // First, create the function.
FunctionType *STy=FunctionType::get(RetTy, std::vector<const Type*>(), false); FunctionType *STy=FunctionType::get(RetTy, std::vector<const Type*>(), false);
Function *Stub = new Function(STy, Function::InternalLinkage, "", Function *Stub = Function::Create(STy, Function::InternalLinkage, "",
F->getParent()); F->getParent());
// Insert a basic block. // 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 // Convert all of the GenericValue arguments over to constants. Note that we
// currently don't support varargs. // currently don't support varargs.
@ -257,12 +257,12 @@ GenericValue JIT::runFunction(Function *F,
Args.push_back(C); 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(); TheCall->setTailCall();
if (TheCall->getType() != Type::VoidTy) if (TheCall->getType() != Type::VoidTy)
new ReturnInst(TheCall, StubBB); // Return result of the call. ReturnInst::Create(TheCall, StubBB); // Return result of the call.
else else
new ReturnInst(StubBB); // Just return void. ReturnInst::Create(StubBB); // Just return void.
// Finally, return the value returned by our nullary stub function. // Finally, return the value returned by our nullary stub function.
return runFunction(Stub, std::vector<GenericValue>()); return runFunction(Stub, std::vector<GenericValue>());

View File

@ -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 // We have a definition of the same name but different type in the
// source module. Copy the prototype to the destination and replace // source module. Copy the prototype to the destination and replace
// uses of the destination's prototype with the new prototype. // uses of the destination's prototype with the new prototype.
Function *NewDF = new Function(SF->getFunctionType(), SF->getLinkage(), Function *NewDF = Function::Create(SF->getFunctionType(), SF->getLinkage(),
SF->getName(), Dest); SF->getName(), Dest);
CopyGVAttributes(NewDF, SF); CopyGVAttributes(NewDF, SF);
// Any uses of DF need to change to NewDF, with cast // 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()) { } else if (!DF || SF->hasInternalLinkage() || DF->hasInternalLinkage()) {
// Function does not already exist, simply insert an function signature // Function does not already exist, simply insert an function signature
// identical to SF into the dest module. // identical to SF into the dest module.
Function *NewDF = new Function(SF->getFunctionType(), SF->getLinkage(), Function *NewDF = Function::Create(SF->getFunctionType(), SF->getLinkage(),
SF->getName(), Dest); SF->getName(), Dest);
CopyGVAttributes(NewDF, SF); CopyGVAttributes(NewDF, SF);
// If the LLVM runtime renamed the function, but it is an externally // If the LLVM runtime renamed the function, but it is an externally

View File

@ -254,7 +254,7 @@ bool X86TargetAsmInfo::LowerToBSwap(CallInst *CI) const {
Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1); Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
Value *Op = CI->getOperand(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->replaceAllUsesWith(Op);
CI->eraseFromParent(); CI->eraseFromParent();

View File

@ -469,7 +469,7 @@ Function *ArgPromotion::DoPromotion(Function *F,
FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg()); FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg());
// Create the new function body and insert it into the module... // 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()); NF->setCallingConv(F->getCallingConv());
// Recompute the parameter attributes list based on the new arguments for // 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 }; Value *Idxs[2] = { ConstantInt::get(Type::Int32Ty, 0), 0 };
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
Idxs[1] = ConstantInt::get(Type::Int32Ty, i); Idxs[1] = ConstantInt::get(Type::Int32Ty, i);
Value *Idx = new GetElementPtrInst(*AI, Idxs, Idxs+2, Value *Idx = GetElementPtrInst::Create(*AI, Idxs, Idxs+2,
(*AI)->getName()+"."+utostr(i), (*AI)->getName()+"."+utostr(i),
Call); Call);
// TODO: Tell AA about the new values? // TODO: Tell AA about the new values?
Args.push_back(new LoadInst(Idx, Idx->getName()+".val", Call)); Args.push_back(new LoadInst(Idx, Idx->getName()+".val", Call));
} }
@ -532,8 +532,8 @@ Function *ArgPromotion::DoPromotion(Function *F,
Value *V = *AI; Value *V = *AI;
LoadInst *OrigLoad = OriginalLoads[*SI]; LoadInst *OrigLoad = OriginalLoads[*SI];
if (!SI->empty()) { if (!SI->empty()) {
V = new GetElementPtrInst(V, SI->begin(), SI->end(), V = GetElementPtrInst::Create(V, SI->begin(), SI->end(),
V->getName()+".idx", Call); V->getName()+".idx", Call);
AA.copyValue(OrigLoad->getOperand(0), V); AA.copyValue(OrigLoad->getOperand(0), V);
} }
Args.push_back(new LoadInst(V, V->getName()+".val", Call)); Args.push_back(new LoadInst(V, V->getName()+".val", Call));
@ -553,13 +553,13 @@ Function *ArgPromotion::DoPromotion(Function *F,
Instruction *New; Instruction *New;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
Args.begin(), Args.end(), "", Call); Args.begin(), Args.end(), "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
cast<InvokeInst>(New)->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), cast<InvokeInst>(New)->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(),
ParamAttrsVec.end())); ParamAttrsVec.end()));
} else { } 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)->setCallingConv(CS.getCallingConv());
cast<CallInst>(New)->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), cast<CallInst>(New)->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(),
ParamAttrsVec.end())); ParamAttrsVec.end()));
@ -616,9 +616,9 @@ Function *ArgPromotion::DoPromotion(Function *F,
for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) { for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
Idxs[1] = ConstantInt::get(Type::Int32Ty, i); Idxs[1] = ConstantInt::get(Type::Int32Ty, i);
Value *Idx = new GetElementPtrInst(TheAlloca, Idxs, Idxs+2, Value *Idx = GetElementPtrInst::Create(TheAlloca, Idxs, Idxs+2,
TheAlloca->getName()+"."+utostr(i), TheAlloca->getName()+"."+utostr(i),
InsertPt); InsertPt);
I2->setName(I->getName()+"."+utostr(i)); I2->setName(I->getName()+"."+utostr(i));
new StoreInst(I2++, Idx, InsertPt); new StoreInst(I2++, Idx, InsertPt);
} }

View File

@ -157,7 +157,7 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
unsigned NumArgs = Params.size(); unsigned NumArgs = Params.size();
// Create the new function body and insert it into the module... // 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->setCallingConv(Fn.getCallingConv());
NF->setParamAttrs(Fn.getParamAttrs()); NF->setParamAttrs(Fn.getParamAttrs());
if (Fn.hasCollector()) if (Fn.hasCollector())
@ -187,12 +187,12 @@ bool DAE::DeleteDeadVarargs(Function &Fn) {
Instruction *New; Instruction *New;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
Args.begin(), Args.end(), "", Call); Args.begin(), Args.end(), "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
cast<InvokeInst>(New)->setParamAttrs(PAL); cast<InvokeInst>(New)->setParamAttrs(PAL);
} else { } 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)->setCallingConv(CS.getCallingConv());
cast<CallInst>(New)->setParamAttrs(PAL); cast<CallInst>(New)->setParamAttrs(PAL);
if (cast<CallInst>(Call)->isTailCall()) if (cast<CallInst>(Call)->isTailCall())
@ -550,7 +550,7 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) {
FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg()); FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg());
// Create the new function body and insert it into the module... // 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->setCallingConv(F->getCallingConv());
NF->setParamAttrs(NewPAL); NF->setParamAttrs(NewPAL);
if (F->hasCollector()) if (F->hasCollector())
@ -602,12 +602,12 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) {
Instruction *New; Instruction *New;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
Args.begin(), Args.end(), "", Call); Args.begin(), Args.end(), "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
cast<InvokeInst>(New)->setParamAttrs(NewCallPAL); cast<InvokeInst>(New)->setParamAttrs(NewCallPAL);
} else { } 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)->setCallingConv(CS.getCallingConv());
cast<CallInst>(New)->setParamAttrs(NewCallPAL); cast<CallInst>(New)->setParamAttrs(NewCallPAL);
if (cast<CallInst>(Call)->isTailCall()) if (cast<CallInst>(Call)->isTailCall())
@ -660,7 +660,7 @@ void DAE::RemoveDeadArgumentsFromFunction(Function *F) {
if (F->getReturnType() != NF->getReturnType()) if (F->getReturnType() != NF->getReturnType())
for (Function::iterator BB = NF->begin(), E = NF->end(); BB != E; ++BB) for (Function::iterator BB = NF->begin(), E = NF->end(); BB != E; ++BB)
if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) { if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator())) {
new ReturnInst(0, RI); ReturnInst::Create(0, RI);
BB->getInstList().erase(RI); BB->getInstList().erase(RI);
} }

View File

@ -121,8 +121,8 @@ namespace {
for (Module::iterator I = M.begin(); ; ++I) { for (Module::iterator I = M.begin(); ; ++I) {
if (std::find(Named.begin(), Named.end(), &*I) == Named.end()) { if (std::find(Named.begin(), Named.end(), &*I) == Named.end()) {
Function *New = new Function(I->getFunctionType(), Function *New = Function::Create(I->getFunctionType(),
GlobalValue::ExternalLinkage); GlobalValue::ExternalLinkage);
New->setCallingConv(I->getCallingConv()); New->setCallingConv(I->getCallingConv());
New->setParamAttrs(I->getParamAttrs()); New->setParamAttrs(I->getParamAttrs());
if (I->hasCollector()) if (I->hasCollector())

View File

@ -546,8 +546,8 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV) {
Idxs.push_back(NullInt); Idxs.push_back(NullInt);
for (unsigned i = 3, e = GEPI->getNumOperands(); i != e; ++i) for (unsigned i = 3, e = GEPI->getNumOperands(); i != e; ++i)
Idxs.push_back(GEPI->getOperand(i)); Idxs.push_back(GEPI->getOperand(i));
NewPtr = new GetElementPtrInst(NewPtr, Idxs.begin(), Idxs.end(), NewPtr = GetElementPtrInst::Create(NewPtr, Idxs.begin(), Idxs.end(),
GEPI->getName()+"."+utostr(Val), GEPI); GEPI->getName()+"."+utostr(Val), GEPI);
} }
} }
GEP->replaceAllUsesWith(NewPtr); GEP->replaceAllUsesWith(NewPtr);
@ -789,8 +789,8 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
MI->getAlignment(), MI->getName(), MI); MI->getAlignment(), MI->getName(), MI);
Value* Indices[2]; Value* Indices[2];
Indices[0] = Indices[1] = Constant::getNullValue(Type::Int32Ty); Indices[0] = Indices[1] = Constant::getNullValue(Type::Int32Ty);
Value *NewGEP = new GetElementPtrInst(NewMI, Indices, Indices + 2, Value *NewGEP = GetElementPtrInst::Create(NewMI, Indices, Indices + 2,
NewMI->getName()+".el0", MI); NewMI->getName()+".el0", MI);
MI->replaceAllUsesWith(NewGEP); MI->replaceAllUsesWith(NewGEP);
MI->eraseFromParent(); MI->eraseFromParent();
MI = NewMI; MI = NewMI;
@ -1054,8 +1054,8 @@ static void RewriteHeapSROALoadUser(LoadInst *Load, Instruction *LoadUser,
GEPIdx.push_back(GEPI->getOperand(1)); GEPIdx.push_back(GEPI->getOperand(1));
GEPIdx.append(GEPI->op_begin()+3, GEPI->op_end()); GEPIdx.append(GEPI->op_begin()+3, GEPI->op_end());
Value *NGEPI = new GetElementPtrInst(NewPtr, GEPIdx.begin(), GEPIdx.end(), Value *NGEPI = GetElementPtrInst::Create(NewPtr, GEPIdx.begin(), GEPIdx.end(),
GEPI->getName(), GEPI); GEPI->getName(), GEPI);
GEPI->replaceAllUsesWith(NGEPI); GEPI->replaceAllUsesWith(NGEPI);
GEPI->eraseFromParent(); GEPI->eraseFromParent();
return; return;
@ -1070,8 +1070,8 @@ static void RewriteHeapSROALoadUser(LoadInst *Load, Instruction *LoadUser,
for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) { for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
Value *LoadV = GetHeapSROALoad(Load, i, FieldGlobals, InsertedLoadsForPtr); Value *LoadV = GetHeapSROALoad(Load, i, FieldGlobals, InsertedLoadsForPtr);
PHINode *FieldPN = new PHINode(LoadV->getType(), PHINode *FieldPN = PHINode::Create(LoadV->getType(),
PN->getName()+"."+utostr(i), PN); PN->getName()+"."+utostr(i), PN);
// Fill in the predecessor values. // Fill in the predecessor values.
for (unsigned pred = 0, e = PN->getNumIncomingValues(); pred != e; ++pred) { for (unsigned pred = 0, e = PN->getNumIncomingValues(); pred != e; ++pred) {
// Each predecessor either uses the load or the original malloc. // 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 // 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. // end of the function as they are unlikely to be executed.
BasicBlock *NullPtrBlock = new BasicBlock("malloc_ret_null", BasicBlock *NullPtrBlock = BasicBlock::Create("malloc_ret_null",
OrigBB->getParent()); OrigBB->getParent());
// Remove the uncond branch from OrigBB to ContBB, turning it into a cond // Remove the uncond branch from OrigBB to ContBB, turning it into a cond
// branch on RunningOr. // branch on RunningOr.
OrigBB->getTerminator()->eraseFromParent(); 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 // Within the NullPtrBlock, we need to emit a comparison and branch for each
// pointer, because some may be null while others are not. // 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, Value *Cmp = new ICmpInst(ICmpInst::ICMP_NE, GVVal,
Constant::getNullValue(GVVal->getType()), Constant::getNullValue(GVVal->getType()),
"tmp", NullPtrBlock); "tmp", NullPtrBlock);
BasicBlock *FreeBlock = new BasicBlock("free_it", OrigBB->getParent()); BasicBlock *FreeBlock = BasicBlock::Create("free_it", OrigBB->getParent());
BasicBlock *NextBlock = new BasicBlock("next", OrigBB->getParent()); BasicBlock *NextBlock = BasicBlock::Create("next", OrigBB->getParent());
new BranchInst(FreeBlock, NextBlock, Cmp, NullPtrBlock); BranchInst::Create(FreeBlock, NextBlock, Cmp, NullPtrBlock);
// Fill in FreeBlock. // Fill in FreeBlock.
new FreeInst(GVVal, FreeBlock); new FreeInst(GVVal, FreeBlock);
new StoreInst(Constant::getNullValue(GVVal->getType()), FieldGlobals[i], new StoreInst(Constant::getNullValue(GVVal->getType()), FieldGlobals[i],
FreeBlock); FreeBlock);
new BranchInst(NextBlock, FreeBlock); BranchInst::Create(NextBlock, FreeBlock);
NullPtrBlock = NextBlock; NullPtrBlock = NextBlock;
} }
new BranchInst(ContBB, NullPtrBlock); BranchInst::Create(ContBB, NullPtrBlock);
// MI is no longer needed, remove it. // MI is no longer needed, remove it.
MI->eraseFromParent(); MI->eraseFromParent();
@ -1411,7 +1410,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal) {
if (IsOneZero) if (IsOneZero)
NSI = new ZExtInst(NLI, LI->getType(), "", LI); NSI = new ZExtInst(NLI, LI->getType(), "", LI);
else else
NSI = new SelectInst(NLI, OtherVal, InitVal, "", LI); NSI = SelectInst::Create(NLI, OtherVal, InitVal, "", LI);
NSI->takeName(LI); NSI->takeName(LI);
LI->replaceAllUsesWith(NSI); LI->replaceAllUsesWith(NSI);
} }

View File

@ -52,11 +52,11 @@ bool IndMemRemPass::runOnModule(Module &M) {
if (Function* F = M.getFunction("free")) { if (Function* F = M.getFunction("free")) {
assert(F->isDeclaration() && "free not external?"); assert(F->isDeclaration() && "free not external?");
if (!F->use_empty()) { if (!F->use_empty()) {
Function* FN = new Function(F->getFunctionType(), Function* FN = Function::Create(F->getFunctionType(),
GlobalValue::LinkOnceLinkage, GlobalValue::LinkOnceLinkage,
"free_llvm_bounce", &M); "free_llvm_bounce", &M);
BasicBlock* bb = new BasicBlock("entry",FN); BasicBlock* bb = BasicBlock::Create("entry",FN);
Instruction* R = new ReturnInst(bb); Instruction* R = ReturnInst::Create(bb);
new FreeInst(FN->arg_begin(), R); new FreeInst(FN->arg_begin(), R);
++NumBounce; ++NumBounce;
NumBounceSites += F->getNumUses(); NumBounceSites += F->getNumUses();
@ -67,14 +67,14 @@ bool IndMemRemPass::runOnModule(Module &M) {
if (Function* F = M.getFunction("malloc")) { if (Function* F = M.getFunction("malloc")) {
assert(F->isDeclaration() && "malloc not external?"); assert(F->isDeclaration() && "malloc not external?");
if (!F->use_empty()) { if (!F->use_empty()) {
Function* FN = new Function(F->getFunctionType(), Function* FN = Function::Create(F->getFunctionType(),
GlobalValue::LinkOnceLinkage, GlobalValue::LinkOnceLinkage,
"malloc_llvm_bounce", &M); "malloc_llvm_bounce", &M);
BasicBlock* bb = new BasicBlock("entry",FN); BasicBlock* bb = BasicBlock::Create("entry",FN);
Instruction* c = CastInst::createIntegerCast( Instruction* c = CastInst::createIntegerCast(
FN->arg_begin(), Type::Int32Ty, false, "c", bb); FN->arg_begin(), Type::Int32Ty, false, "c", bb);
Instruction* a = new MallocInst(Type::Int8Ty, c, "m", bb); Instruction* a = new MallocInst(Type::Int8Ty, c, "m", bb);
new ReturnInst(a, bb); ReturnInst::Create(a, bb);
++NumBounce; ++NumBounce;
NumBounceSites += F->getNumUses(); NumBounceSites += F->getNumUses();
F->replaceAllUsesWith(FN); F->replaceAllUsesWith(FN);

View File

@ -268,7 +268,7 @@ void LowerSetJmp::TransformLongJmpCall(CallInst* Inst)
SmallVector<Value *, 2> Args; SmallVector<Value *, 2> Args;
Args.push_back(CI); Args.push_back(CI);
Args.push_back(Inst->getOperand(2)); 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()]; 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 // we should branch to the basic block that determines if this longjmp
// is applicable here. Otherwise, issue an unwind. // is applicable here. Otherwise, issue an unwind.
if (SVP.first) if (SVP.first)
new BranchInst(SVP.first->getParent(), Inst); BranchInst::Create(SVP.first->getParent(), Inst);
else else
new UnwindInst(Inst); new UnwindInst(Inst);
@ -311,7 +311,7 @@ AllocaInst* LowerSetJmp::GetSetJmpMap(Function* Func)
// Fill in the alloca and call to initialize the SJ map. // Fill in the alloca and call to initialize the SJ map.
const Type *SBPTy = PointerType::getUnqual(Type::Int8Ty); const Type *SBPTy = PointerType::getUnqual(Type::Int8Ty);
AllocaInst* Map = new AllocaInst(SBPTy, 0, "SJMap", Inst); AllocaInst* Map = new AllocaInst(SBPTy, 0, "SJMap", Inst);
new CallInst(InitSJMap, Map, "", Inst); CallInst::Create(InitSJMap, Map, "", Inst);
return SJMap[Func] = Map; 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 // The basic block we're going to jump to if we need to rethrow the
// exception. // 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 // 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 // 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]; if (SwitchValMap[Func].first) return SwitchValMap[Func];
BasicBlock* LongJmpPre = new BasicBlock("LongJmpBlkPre", Func); BasicBlock* LongJmpPre = BasicBlock::Create("LongJmpBlkPre", Func);
BasicBlock::InstListType& LongJmpPreIL = LongJmpPre->getInstList(); BasicBlock::InstListType& LongJmpPreIL = LongJmpPre->getInstList();
// Keep track of the preliminary basic block for some of the other // 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; PrelimBBMap[Func] = LongJmpPre;
// Grab the exception. // Grab the exception.
CallInst* Cond = new CallInst(IsLJException, "IsLJExcept"); CallInst* Cond = CallInst::Create(IsLJException, "IsLJExcept");
LongJmpPreIL.push_back(Cond); LongJmpPreIL.push_back(Cond);
// The "decision basic block" gets the number associated with the // The "decision basic block" gets the number associated with the
// setjmp call returning to switch on and the value returned by // setjmp call returning to switch on and the value returned by
// longjmp. // longjmp.
BasicBlock* DecisionBB = new BasicBlock("LJDecisionBB", Func); BasicBlock* DecisionBB = BasicBlock::Create("LJDecisionBB", Func);
BasicBlock::InstListType& DecisionBBIL = DecisionBB->getInstList(); BasicBlock::InstListType& DecisionBBIL = DecisionBB->getInstList();
new BranchInst(DecisionBB, Rethrow, Cond, LongJmpPre); BranchInst::Create(DecisionBB, Rethrow, Cond, LongJmpPre);
// Fill in the "decision" basic block. // Fill in the "decision" basic block.
CallInst* LJVal = new CallInst(GetLJValue, "LJVal"); CallInst* LJVal = CallInst::Create(GetLJValue, "LJVal");
DecisionBBIL.push_back(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); 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); return SwitchValMap[Func] = SwitchValuePair(SI, LJVal);
} }
@ -386,7 +386,7 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
make_vector<Value*>(GetSetJmpMap(Func), BufPtr, make_vector<Value*>(GetSetJmpMap(Func), BufPtr,
ConstantInt::get(Type::Int32Ty, ConstantInt::get(Type::Int32Ty,
SetJmpIDMap[Func]++), 0); 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 // 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 // (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 // This PHI node will be in the new block created from the
// splitBasicBlock call. // 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. // Coming from a call to setjmp, the return is 0.
PHI->addIncoming(ConstantInt::getNullValue(Type::Int32Ty), ABlock); PHI->addIncoming(ConstantInt::getNullValue(Type::Int32Ty), ABlock);
@ -474,9 +474,9 @@ void LowerSetJmp::visitCallInst(CallInst& CI)
// Construct the new "invoke" instruction. // Construct the new "invoke" instruction.
TerminatorInst* Term = OldBB->getTerminator(); TerminatorInst* Term = OldBB->getTerminator();
std::vector<Value*> Params(CI.op_begin() + 1, CI.op_end()); std::vector<Value*> Params(CI.op_begin() + 1, CI.op_end());
InvokeInst* II = new InvokeInst* II =
InvokeInst(CI.getCalledValue(), NewBB, PrelimBBMap[Func], InvokeInst::Create(CI.getCalledValue(), NewBB, PrelimBBMap[Func],
Params.begin(), Params.end(), CI.getName(), Term); Params.begin(), Params.end(), CI.getName(), Term);
II->setCallingConv(CI.getCallingConv()); II->setCallingConv(CI.getCallingConv());
II->setParamAttrs(CI.getParamAttrs()); II->setParamAttrs(CI.getParamAttrs());
@ -507,15 +507,15 @@ void LowerSetJmp::visitInvokeInst(InvokeInst& II)
BasicBlock* ExceptBB = II.getUnwindDest(); BasicBlock* ExceptBB = II.getUnwindDest();
Function* Func = BB->getParent(); Function* Func = BB->getParent();
BasicBlock* NewExceptBB = new BasicBlock("InvokeExcept", Func); BasicBlock* NewExceptBB = BasicBlock::Create("InvokeExcept", Func);
BasicBlock::InstListType& InstList = NewExceptBB->getInstList(); BasicBlock::InstListType& InstList = NewExceptBB->getInstList();
// If this is a longjmp exception, then branch to the preliminary BB of // If this is a longjmp exception, then branch to the preliminary BB of
// the longjmp exception handling. Otherwise, go to the old exception. // 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); InstList.push_back(IsLJExcept);
new BranchInst(PrelimBBMap[Func], ExceptBB, IsLJExcept, NewExceptBB); BranchInst::Create(PrelimBBMap[Func], ExceptBB, IsLJExcept, NewExceptBB);
II.setUnwindDest(NewExceptBB); II.setUnwindDest(NewExceptBB);
++InvokesTransformed; ++InvokesTransformed;
@ -525,14 +525,14 @@ void LowerSetJmp::visitInvokeInst(InvokeInst& II)
// function. // function.
void LowerSetJmp::visitReturnInst(ReturnInst &RI) { void LowerSetJmp::visitReturnInst(ReturnInst &RI) {
Function* Func = RI.getParent()->getParent(); 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 // visitUnwindInst - We want to destroy the setjmp map upon exit from the
// function. // function.
void LowerSetJmp::visitUnwindInst(UnwindInst &UI) { void LowerSetJmp::visitUnwindInst(UnwindInst &UI) {
Function* Func = UI.getParent()->getParent(); Function* Func = UI.getParent()->getParent();
new CallInst(DestroySJMap, GetSetJmpMap(Func), "", &UI); CallInst::Create(DestroySJMap, GetSetJmpMap(Func), "", &UI);
} }
ModulePass *llvm::createLowerSetJmpPass() { ModulePass *llvm::createLowerSetJmpPass() {

View File

@ -158,8 +158,8 @@ bool PruneEH::SimplifyFunction(Function *F) {
if (II->doesNotThrow()) { if (II->doesNotThrow()) {
SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end()); SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
// Insert a call instruction before the invoke. // Insert a call instruction before the invoke.
CallInst *Call = new CallInst(II->getCalledValue(), CallInst *Call = CallInst::Create(II->getCalledValue(),
Args.begin(), Args.end(), "", II); Args.begin(), Args.end(), "", II);
Call->takeName(II); Call->takeName(II);
Call->setCallingConv(II->getCallingConv()); Call->setCallingConv(II->getCallingConv());
Call->setParamAttrs(II->getParamAttrs()); Call->setParamAttrs(II->getParamAttrs());
@ -172,7 +172,7 @@ bool PruneEH::SimplifyFunction(Function *F) {
// Insert a branch to the normal destination right before the // Insert a branch to the normal destination right before the
// invoke. // invoke.
new BranchInst(II->getNormalDest(), II); BranchInst::Create(II->getNormalDest(), II);
// Finally, delete the invoke instruction! // Finally, delete the invoke instruction!
BB->getInstList().pop_back(); BB->getInstList().pop_back();

View File

@ -175,7 +175,7 @@ bool RaiseAllocations::runOnModule(Module &M) {
// If the old instruction was an invoke, add an unconditional branch // If the old instruction was an invoke, add an unconditional branch
// before the invoke, which will become the new terminator. // before the invoke, which will become the new terminator.
if (InvokeInst *II = dyn_cast<InvokeInst>(I)) if (InvokeInst *II = dyn_cast<InvokeInst>(I))
new BranchInst(II->getNormalDest(), I); BranchInst::Create(II->getNormalDest(), I);
// Delete the old call site // Delete the old call site
MI->getParent()->getInstList().erase(I); 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 // If the old instruction was an invoke, add an unconditional branch
// before the invoke, which will become the new terminator. // before the invoke, which will become the new terminator.
if (InvokeInst *II = dyn_cast<InvokeInst>(I)) if (InvokeInst *II = dyn_cast<InvokeInst>(I))
new BranchInst(II->getNormalDest(), I); BranchInst::Create(II->getNormalDest(), I);
// Delete the old call site // Delete the old call site
if (I->getType() != Type::VoidTy) if (I->getType() != Type::VoidTy)

View File

@ -430,7 +430,7 @@ struct VISIBILITY_HIDDEN ExitInMainOptimization : public LibCallOptimization {
// Create a return instruction that we'll replace the call with. // Create a return instruction that we'll replace the call with.
// Note that the argument of the return is the argument of the call // Note that the argument of the return is the argument of the call
// instruction. // 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 // Split the block at the call instruction which places it in a new
// basic block. // basic block.
@ -496,13 +496,13 @@ public:
// We need to find the end of the destination string. That's where the // 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. // memory is to be moved to. We just generate a call to strlen.
CallInst *DstLen = new CallInst(SLC.get_strlen(), Dst, CallInst *DstLen = CallInst::Create(SLC.get_strlen(), Dst,
Dst->getName()+".len", CI); Dst->getName()+".len", CI);
// Now that we have the destination's length, we must index into the // Now that we have the destination's length, we must index into the
// destination's pointer to get the actual memcpy destination (end of // destination's pointer to get the actual memcpy destination (end of
// the string .. we're concatenating). // 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 // We have enough information to now generate the memcpy call to
// do the concatenation for us. // do the concatenation for us.
@ -511,7 +511,7 @@ public:
ConstantInt::get(SLC.getIntPtrType(), SrcStr.size()+1), // copy nul byte. ConstantInt::get(SLC.getIntPtrType(), SrcStr.size()+1), // copy nul byte.
ConstantInt::get(Type::Int32Ty, 1) // alignment 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); return ReplaceCallWith(CI, Dst);
} }
@ -551,8 +551,8 @@ public:
CI->getOperand(2), CI->getOperand(2),
ConstantInt::get(SLC.getIntPtrType(), Str.size()+1) ConstantInt::get(SLC.getIntPtrType(), Str.size()+1)
}; };
return ReplaceCallWith(CI, new CallInst(SLC.get_memchr(), Args, Args + 3, return ReplaceCallWith(CI, CallInst::Create(SLC.get_memchr(), Args, Args + 3,
CI->getName(), CI)); CI->getName(), CI));
} }
// strchr can find the nul character. // strchr can find the nul character.
@ -575,9 +575,9 @@ public:
// strchr(s+n,c) -> gep(s+n+i,c) // strchr(s+n,c) -> gep(s+n+i,c)
// (if c is a constant integer and s is a constant string) // (if c is a constant integer and s is a constant string)
Value *Idx = ConstantInt::get(Type::Int64Ty, i); Value *Idx = ConstantInt::get(Type::Int64Ty, i);
Value *GEP = new GetElementPtrInst(CI->getOperand(1), Idx, Value *GEP = GetElementPtrInst::Create(CI->getOperand(1), Idx,
CI->getOperand(1)->getName() + CI->getOperand(1)->getName() +
".strchr", CI); ".strchr", CI);
return ReplaceCallWith(CI, GEP); return ReplaceCallWith(CI, GEP);
} }
} StrChrOptimizer; } StrChrOptimizer;
@ -754,7 +754,7 @@ public:
ConstantInt::get(SLC.getIntPtrType(), SrcStr.size()+1), ConstantInt::get(SLC.getIntPtrType(), SrcStr.size()+1),
ConstantInt::get(Type::Int32Ty, 1) // alignment 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); return ReplaceCallWith(CI, Dst);
} }
@ -900,8 +900,8 @@ struct VISIBILITY_HIDDEN memcmpOptimization : public LibCallOptimization {
Value *D1 = BinaryOperator::createSub(S1V1, S2V1, Value *D1 = BinaryOperator::createSub(S1V1, S2V1,
CI->getName()+".d1", CI); CI->getName()+".d1", CI);
Constant *One = ConstantInt::get(Type::Int32Ty, 1); Constant *One = ConstantInt::get(Type::Int32Ty, 1);
Value *G1 = new GetElementPtrInst(Op1Cast, One, "next1v", CI); Value *G1 = GetElementPtrInst::Create(Op1Cast, One, "next1v", CI);
Value *G2 = new GetElementPtrInst(Op2Cast, One, "next2v", CI); Value *G2 = GetElementPtrInst::Create(Op2Cast, One, "next2v", CI);
Value *S1V2 = new LoadInst(G1, LHS->getName()+".val2", CI); Value *S1V2 = new LoadInst(G1, LHS->getName()+".val2", CI);
Value *S2V2 = new LoadInst(G2, RHS->getName()+".val2", CI); Value *S2V2 = new LoadInst(G2, RHS->getName()+".val2", CI);
Value *D2 = BinaryOperator::createSub(S1V2, S2V2, Value *D2 = BinaryOperator::createSub(S1V2, S2V2,
@ -946,7 +946,7 @@ public:
CI->getOperand(1), CI->getOperand(2), CI->getOperand(3), CI->getOperand(1), CI->getOperand(2), CI->getOperand(3),
ConstantInt::get(Type::Int32Ty, 1) // align = 1 always. 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 // memcpy always returns the destination
return ReplaceCallWith(CI, CI->getOperand(1)); return ReplaceCallWith(CI, CI->getOperand(1));
} }
@ -1162,8 +1162,8 @@ public:
Ty==Type::FloatTy ? APFloat(1.0f) : APFloat(1.0))); Ty==Type::FloatTy ? APFloat(1.0f) : APFloat(1.0)));
} else if (Op2->isExactlyValue(0.5)) { } else if (Op2->isExactlyValue(0.5)) {
// pow(x,0.5) -> sqrt(x) // pow(x,0.5) -> sqrt(x)
CallInst* sqrt_inst = new CallInst(SLC.get_sqrt(), base, CallInst* sqrt_inst = CallInst::Create(SLC.get_sqrt(), base,
ci->getName()+".pow",ci); ci->getName()+".pow",ci);
return ReplaceCallWith(ci, sqrt_inst); return ReplaceCallWith(ci, sqrt_inst);
} else if (Op2->isExactlyValue(1.0)) { } else if (Op2->isExactlyValue(1.0)) {
// pow(x,1.0) -> x // pow(x,1.0) -> x
@ -1220,7 +1220,7 @@ public:
if (FormatStr.size() == 1) { if (FormatStr.size() == 1) {
// Turn this into a putchar call, even if it is a %. // Turn this into a putchar call, even if it is a %.
Value *V = ConstantInt::get(Type::Int32Ty, FormatStr[0]); 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); if (CI->use_empty()) return ReplaceCallWith(CI, 0);
return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1)); return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1));
} }
@ -1240,7 +1240,7 @@ public:
CI->getParent()->getParent()->getParent()); CI->getParent()->getParent()->getParent());
// Cast GV to be a pointer to char. // Cast GV to be a pointer to char.
GV = ConstantExpr::getBitCast(GV, PointerType::getUnqual(Type::Int8Ty)); 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); if (CI->use_empty()) return ReplaceCallWith(CI, 0);
// The return value from printf includes the \n we just removed, so +1. // The return value from printf includes the \n we just removed, so +1.
@ -1264,8 +1264,8 @@ public:
return false; return false;
// printf("%s\n",str) -> puts(str) // printf("%s\n",str) -> puts(str)
new CallInst(SLC.get_puts(), CastToCStr(CI->getOperand(2), CI), CallInst::Create(SLC.get_puts(), CastToCStr(CI->getOperand(2), CI),
CI->getName(), CI); CI->getName(), CI);
return ReplaceCallWith(CI, 0); return ReplaceCallWith(CI, 0);
case 'c': { case 'c': {
// printf("%c",c) -> putchar(c) // printf("%c",c) -> putchar(c)
@ -1279,7 +1279,7 @@ public:
V = CastInst::createZExtOrBitCast(V, Type::Int32Ty, CI->getName()+".int", V = CastInst::createZExtOrBitCast(V, Type::Int32Ty, CI->getName()+".int",
CI); CI);
new CallInst(SLC.get_putchar(), V, "", CI); CallInst::Create(SLC.get_putchar(), V, "", CI);
return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1)); return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1));
} }
} }
@ -1331,7 +1331,7 @@ public:
ConstantInt::get(SLC.getIntPtrType(), 1), ConstantInt::get(SLC.getIntPtrType(), 1),
CI->getOperand(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(), return ReplaceCallWith(CI, ConstantInt::get(CI->getType(),
FormatStr.size())); FormatStr.size()));
} }
@ -1351,7 +1351,7 @@ public:
SmallVector<Value *, 2> Args; SmallVector<Value *, 2> Args;
Args.push_back(C); Args.push_back(C);
Args.push_back(CI->getOperand(1)); 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)); return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1));
} }
case 's': { case 's': {
@ -1366,8 +1366,8 @@ public:
SmallVector<Value *, 2> Args; SmallVector<Value *, 2> Args;
Args.push_back(CastToCStr(CI->getOperand(3), CI)); Args.push_back(CastToCStr(CI->getOperand(3), CI));
Args.push_back(CI->getOperand(1)); Args.push_back(CI->getOperand(1));
new CallInst(SLC.get_fputs(FILETy), Args.begin(), CallInst::Create(SLC.get_fputs(FILETy), Args.begin(),
Args.end(), CI->getName(), CI); Args.end(), CI->getName(), CI);
return ReplaceCallWith(CI, 0); return ReplaceCallWith(CI, 0);
} }
default: default:
@ -1418,7 +1418,7 @@ public:
FormatStr.size()+1), // Copy the nul byte. FormatStr.size()+1), // Copy the nul byte.
ConstantInt::get(Type::Int32Ty, 1) 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(), return ReplaceCallWith(CI, ConstantInt::get(CI->getType(),
FormatStr.size())); FormatStr.size()));
} }
@ -1434,18 +1434,18 @@ public:
Value *V = CastInst::createTruncOrBitCast(CI->getOperand(3), Value *V = CastInst::createTruncOrBitCast(CI->getOperand(3),
Type::Int8Ty, "char", CI); Type::Int8Ty, "char", CI);
new StoreInst(V, CI->getOperand(1), CI); new StoreInst(V, CI->getOperand(1), CI);
Value *Ptr = new GetElementPtrInst(CI->getOperand(1), Value *Ptr = GetElementPtrInst::Create(CI->getOperand(1),
ConstantInt::get(Type::Int32Ty, 1), ConstantInt::get(Type::Int32Ty, 1),
CI->getOperand(1)->getName()+".end", CI->getOperand(1)->getName()+".end",
CI); CI);
new StoreInst(ConstantInt::get(Type::Int8Ty,0), Ptr, CI); new StoreInst(ConstantInt::get(Type::Int8Ty,0), Ptr, CI);
return ReplaceCallWith(CI, ConstantInt::get(Type::Int32Ty, 1)); return ReplaceCallWith(CI, ConstantInt::get(Type::Int32Ty, 1));
} }
case 's': { case 's': {
// sprintf(dest,"%s",str) -> llvm.memcpy(dest, str, strlen(str)+1, 1) // sprintf(dest,"%s",str) -> llvm.memcpy(dest, str, strlen(str)+1, 1)
Value *Len = new CallInst(SLC.get_strlen(), Value *Len = CallInst::Create(SLC.get_strlen(),
CastToCStr(CI->getOperand(3), CI), CastToCStr(CI->getOperand(3), CI),
CI->getOperand(3)->getName()+".len", CI); CI->getOperand(3)->getName()+".len", CI);
Value *UnincLen = Len; Value *UnincLen = Len;
Len = BinaryOperator::createAdd(Len, ConstantInt::get(Len->getType(), 1), Len = BinaryOperator::createAdd(Len, ConstantInt::get(Len->getType(), 1),
Len->getName()+"1", CI); Len->getName()+"1", CI);
@ -1455,7 +1455,7 @@ public:
Len, Len,
ConstantInt::get(Type::Int32Ty, 1) 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. // The strlen result is the unincremented number of bytes in the string.
if (!CI->use_empty()) { if (!CI->use_empty()) {
@ -1507,7 +1507,7 @@ public:
ConstantInt::get(SLC.getIntPtrType(), 1), ConstantInt::get(SLC.getIntPtrType(), 1),
CI->getOperand(2) 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). return ReplaceCallWith(CI, 0); // Known to have no uses (see above).
} }
} FPutsOptimizer; } FPutsOptimizer;
@ -1555,7 +1555,7 @@ public:
Args.push_back(new ZExtInst(Val, Type::Int32Ty, Val->getName()+".int", CI)); Args.push_back(new ZExtInst(Val, Type::Int32Ty, Val->getName()+".int", CI));
Args.push_back(CI->getOperand(4)); Args.push_back(CI->getOperand(4));
const Type *FILETy = CI->getOperand(4)->getType(); 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 ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1));
} }
return false; return false;
@ -1715,7 +1715,7 @@ public:
ArgType, NULL); ArgType, NULL);
Value *V = CastInst::createIntegerCast(TheCall->getOperand(1), ArgType, Value *V = CastInst::createIntegerCast(TheCall->getOperand(1), ArgType,
false/*ZExt*/, "tmp", TheCall); 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*/, V2 = CastInst::createIntegerCast(V2, Type::Int32Ty, false/*ZExt*/,
"tmp", TheCall); "tmp", TheCall);
V2 = BinaryOperator::createAdd(V2, ConstantInt::get(Type::Int32Ty, 1), V2 = BinaryOperator::createAdd(V2, ConstantInt::get(Type::Int32Ty, 1),
@ -1723,8 +1723,8 @@ public:
Value *Cond = new ICmpInst(ICmpInst::ICMP_EQ, V, Value *Cond = new ICmpInst(ICmpInst::ICMP_EQ, V,
Constant::getNullValue(V->getType()), "tmp", Constant::getNullValue(V->getType()), "tmp",
TheCall); TheCall);
V2 = new SelectInst(Cond, ConstantInt::get(Type::Int32Ty, 0), V2, V2 = SelectInst::Create(Cond, ConstantInt::get(Type::Int32Ty, 0), V2,
TheCall->getName(), TheCall); TheCall->getName(), TheCall);
return ReplaceCallWith(TheCall, V2); return ReplaceCallWith(TheCall, V2);
} }
} FFSOptimizer; } FFSOptimizer;
@ -1773,8 +1773,8 @@ struct UnaryDoubleFPOptimizer : public LibCallOptimization {
Constant *(SimplifyLibCalls::*FP)()){ Constant *(SimplifyLibCalls::*FP)()){
if (FPExtInst *Cast = dyn_cast<FPExtInst>(CI->getOperand(1))) if (FPExtInst *Cast = dyn_cast<FPExtInst>(CI->getOperand(1)))
if (Cast->getOperand(0)->getType() == Type::FloatTy) { if (Cast->getOperand(0)->getType() == Type::FloatTy) {
Value *New = new CallInst((SLC.*FP)(), Cast->getOperand(0), Value *New = CallInst::Create((SLC.*FP)(), Cast->getOperand(0),
CI->getName(), CI); CI->getName(), CI);
New = new FPExtInst(New, Type::DoubleTy, CI->getName(), CI); New = new FPExtInst(New, Type::DoubleTy, CI->getName(), CI);
CI->replaceAllUsesWith(New); CI->replaceAllUsesWith(New);
CI->eraseFromParent(); CI->eraseFromParent();

View File

@ -116,14 +116,14 @@ bool SRETPromotion::PromoteReturn(CallGraphNode *CGN) {
SmallVector<Value*, 2> GEPIdx; SmallVector<Value*, 2> GEPIdx;
GEPIdx.push_back(ConstantInt::get(Type::Int32Ty, 0)); GEPIdx.push_back(ConstantInt::get(Type::Int32Ty, 0));
GEPIdx.push_back(ConstantInt::get(Type::Int32Ty, idx)); GEPIdx.push_back(ConstantInt::get(Type::Int32Ty, idx));
Value *NGEPI = new GetElementPtrInst(TheAlloca, GEPIdx.begin(), Value *NGEPI = GetElementPtrInst::Create(TheAlloca, GEPIdx.begin(),
GEPIdx.end(), GEPIdx.end(),
"mrv.gep", I); "mrv.gep", I);
Value *NV = new LoadInst(NGEPI, "mrv.ld", I); Value *NV = new LoadInst(NGEPI, "mrv.ld", I);
RetVals.push_back(NV); 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->replaceAllUsesWith(NR);
I->eraseFromParent(); I->eraseFromParent();
} }
@ -222,7 +222,7 @@ Function *SRETPromotion::cloneFunctionBody(Function *F,
} }
FunctionType *NFTy = FunctionType::get(STy, Params, FTy->isVarArg()); 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->setCallingConv(F->getCallingConv());
NF->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end())); NF->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end()));
F->getParent()->getFunctionList().insert(F, NF); F->getParent()->getFunctionList().insert(F, NF);
@ -283,12 +283,12 @@ void SRETPromotion::updateCallSites(Function *F, Function *NF) {
// Build new call instruction. // Build new call instruction.
Instruction *New; Instruction *New;
if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) { if (InvokeInst *II = dyn_cast<InvokeInst>(Call)) {
New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(), New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
Args.begin(), Args.end(), "", Call); Args.begin(), Args.end(), "", Call);
cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv()); cast<InvokeInst>(New)->setCallingConv(CS.getCallingConv());
cast<InvokeInst>(New)->setParamAttrs(NewPAL); cast<InvokeInst>(New)->setParamAttrs(NewPAL);
} else { } 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)->setCallingConv(CS.getCallingConv());
cast<CallInst>(New)->setParamAttrs(NewPAL); cast<CallInst>(New)->setParamAttrs(NewPAL);
if (cast<CallInst>(Call)->isTailCall()) if (cast<CallInst>(Call)->isTailCall())

View File

@ -55,8 +55,8 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
} }
Args[3] = ConstantInt::get(Type::Int32Ty, NumElements); Args[3] = ConstantInt::get(Type::Int32Ty, NumElements);
Instruction *InitCall = new CallInst(InitFn, Args.begin(), Args.end(), Instruction *InitCall = CallInst::Create(InitFn, Args.begin(), Args.end(),
"newargc", InsertPos); "newargc", InsertPos);
// If argc or argv are not available in main, just pass null values in. // If argc or argv are not available in main, just pass null values in.
Function::arg_iterator AI; Function::arg_iterator AI;

View File

@ -216,9 +216,9 @@ void GlobalRandomCounter::ProcessChoicePoint(BasicBlock* bb) {
//reset counter //reset counter
BasicBlock* oldnext = t->getSuccessor(0); BasicBlock* oldnext = t->getSuccessor(0);
BasicBlock* resetblock = new BasicBlock("reset", oldnext->getParent(), BasicBlock* resetblock = BasicBlock::Create("reset", oldnext->getParent(),
oldnext); oldnext);
TerminatorInst* t2 = new BranchInst(oldnext, resetblock); TerminatorInst* t2 = BranchInst::Create(oldnext, resetblock);
t->setSuccessor(0, resetblock); t->setSuccessor(0, resetblock);
new StoreInst(ResetValue, Counter, t2); new StoreInst(ResetValue, Counter, t2);
ReplacePhiPred(oldnext, bb, resetblock); ReplacePhiPred(oldnext, bb, resetblock);
@ -291,9 +291,9 @@ void GlobalRandomCounterOpt::ProcessChoicePoint(BasicBlock* bb) {
//reset counter //reset counter
BasicBlock* oldnext = t->getSuccessor(0); BasicBlock* oldnext = t->getSuccessor(0);
BasicBlock* resetblock = new BasicBlock("reset", oldnext->getParent(), BasicBlock* resetblock = BasicBlock::Create("reset", oldnext->getParent(),
oldnext); oldnext);
TerminatorInst* t2 = new BranchInst(oldnext, resetblock); TerminatorInst* t2 = BranchInst::Create(oldnext, resetblock);
t->setSuccessor(0, resetblock); t->setSuccessor(0, resetblock);
new StoreInst(ResetValue, AI, t2); new StoreInst(ResetValue, AI, t2);
ReplacePhiPred(oldnext, bb, resetblock); ReplacePhiPred(oldnext, bb, resetblock);
@ -311,7 +311,7 @@ void CycleCounter::PrepFunction(Function* F) {}
void CycleCounter::ProcessChoicePoint(BasicBlock* bb) { void CycleCounter::ProcessChoicePoint(BasicBlock* bb) {
BranchInst* t = cast<BranchInst>(bb->getTerminator()); BranchInst* t = cast<BranchInst>(bb->getTerminator());
CallInst* c = new CallInst(F, "rdcc", t); CallInst* c = CallInst::Create(F, "rdcc", t);
BinaryOperator* b = BinaryOperator* b =
BinaryOperator::createAnd(c, ConstantInt::get(Type::Int64Ty, rm), BinaryOperator::createAnd(c, ConstantInt::get(Type::Int64Ty, rm),
"mrdcc", t); "mrdcc", t);
@ -375,8 +375,8 @@ Value* ProfilerRS::Translate(Value* v) {
if (bb == &bb->getParent()->getEntryBlock()) if (bb == &bb->getParent()->getEntryBlock())
TransCache[bb] = bb; //don't translate entry block TransCache[bb] = bb; //don't translate entry block
else else
TransCache[bb] = new BasicBlock("dup_" + bb->getName(), bb->getParent(), TransCache[bb] = BasicBlock::Create("dup_" + bb->getName(), bb->getParent(),
NULL); NULL);
return TransCache[bb]; return TransCache[bb];
} else if (Instruction* i = dyn_cast<Instruction>(v)) { } else if (Instruction* i = dyn_cast<Instruction>(v)) {
//we have already translated this //we have already translated this
@ -464,16 +464,16 @@ void ProfilerRS::ProcessBackEdge(BasicBlock* src, BasicBlock* dst, Function& F)
//a: //a:
Function::iterator BBN = src; ++BBN; Function::iterator BBN = src; ++BBN;
BasicBlock* bbC = new BasicBlock("choice", &F, BBN); BasicBlock* bbC = BasicBlock::Create("choice", &F, BBN);
//ChoicePoints.insert(bbC); //ChoicePoints.insert(bbC);
BBN = cast<BasicBlock>(Translate(src)); BBN = cast<BasicBlock>(Translate(src));
BasicBlock* bbCp = new BasicBlock("choice", &F, ++BBN); BasicBlock* bbCp = BasicBlock::Create("choice", &F, ++BBN);
ChoicePoints.insert(bbCp); ChoicePoints.insert(bbCp);
//b: //b:
new BranchInst(cast<BasicBlock>(Translate(dst)), bbC); BranchInst::Create(cast<BasicBlock>(Translate(dst)), bbC);
new BranchInst(dst, cast<BasicBlock>(Translate(dst)), BranchInst::Create(dst, cast<BasicBlock>(Translate(dst)),
ConstantInt::get(Type::Int1Ty, true), bbCp); ConstantInt::get(Type::Int1Ty, true), bbCp);
//c: //c:
{ {
TerminatorInst* iB = src->getTerminator(); 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 //oh, and add the edge from the reg2mem created entry node to the
//duplicated second node //duplicated second node
TerminatorInst* T = F.getEntryBlock().getTerminator(); TerminatorInst* T = F.getEntryBlock().getTerminator();
ReplaceInstWithInst(T, new BranchInst(T->getSuccessor(0), ReplaceInstWithInst(T, BranchInst::Create(T->getSuccessor(0),
cast<BasicBlock>( cast<BasicBlock>(
Translate(T->getSuccessor(0))), Translate(T->getSuccessor(0))),
ConstantInt::get(Type::Int1Ty, true))); ConstantInt::get(Type::Int1Ty,
true)));
//do whatever is needed now that the function is duplicated //do whatever is needed now that the function is duplicated
c->PrepFunction(&F); c->PrepFunction(&F);

View File

@ -163,7 +163,7 @@ bool ADCE::deleteDeadInstructionsInLiveBlock(BasicBlock *BB) {
/// successors it goes to. This eliminate a use of the condition as well. /// successors it goes to. This eliminate a use of the condition as well.
/// ///
TerminatorInst *ADCE::convertToUnconditionalBranch(TerminatorInst *TI) { 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(); BasicBlock *BB = TI->getParent();
// Remove entries from PHI nodes to avoid confusing ourself later... // Remove entries from PHI nodes to avoid confusing ourself later...
@ -325,8 +325,8 @@ bool ADCE::doADCE() {
// node as a special case. // node as a special case.
// //
if (!AliveBlocks.count(&Func->front())) { if (!AliveBlocks.count(&Func->front())) {
BasicBlock *NewEntry = new BasicBlock(); BasicBlock *NewEntry = BasicBlock::Create();
new BranchInst(&Func->front(), NewEntry); BranchInst::Create(&Func->front(), NewEntry);
Func->getBasicBlockList().push_front(NewEntry); Func->getBasicBlockList().push_front(NewEntry);
AliveBlocks.insert(NewEntry); // This block is always alive! AliveBlocks.insert(NewEntry); // This block is always alive!
LiveSet.insert(NewEntry->getTerminator()); // The branch is live LiveSet.insert(NewEntry->getTerminator()); // The branch is live

View File

@ -192,7 +192,7 @@ void GCSE::ReplaceInstructionWith(Instruction *I, Value *V) {
if (InvokeInst *II = dyn_cast<InvokeInst>(I)) { if (InvokeInst *II = dyn_cast<InvokeInst>(I)) {
// Removing an invoke instruction requires adding a branch to the normal // Removing an invoke instruction requires adding a branch to the normal
// destination and removing PHI node entries in the exception destination. // 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()); II->getUnwindDest()->removePredecessor(II->getParent());
} }

View File

@ -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 // 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. // now, then get values to fill in the incoming values for the PHI.
PHINode *PN = new PHINode(orig->getType(), orig->getName()+".rle", PHINode *PN = PHINode::Create(orig->getType(), orig->getName()+".rle",
BB->begin()); BB->begin());
PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB))); PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB)));
if (Phis.count(BB) == 0) 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::Int64Ty, Range.End-Range.Start), // size
ConstantInt::get(Type::Int32Ty, Range.Alignment) // align 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"; DEBUG(cerr << "Replace stores:\n";
for (unsigned i = 0, e = Range.TheStores.size(); i != e; ++i) for (unsigned i = 0, e = Range.TheStores.size(); i != e; ++i)
cerr << *Range.TheStores[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->getLength());
args.push_back(M->getAlignment()); 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>(); MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
if (MD.getDependency(C) == MDep) { if (MD.getDependency(C) == MDep) {

View File

@ -904,10 +904,10 @@ Value* GVNPRE::phi_translate(Value* V, BasicBlock* pred, BasicBlock* succ) {
newVal = new ShuffleVectorInst(newOp1, newOp2, newOp3, newVal = new ShuffleVectorInst(newOp1, newOp2, newOp3,
S->getName()+".expr"); S->getName()+".expr");
else if (InsertElementInst* I = dyn_cast<InsertElementInst>(U)) else if (InsertElementInst* I = dyn_cast<InsertElementInst>(U))
newVal = new InsertElementInst(newOp1, newOp2, newOp3, newVal = InsertElementInst::Create(newOp1, newOp2, newOp3,
I->getName()+".expr"); I->getName()+".expr");
else if (SelectInst* I = dyn_cast<SelectInst>(U)) 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); 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) { if (newOp1 != U->getPointerOperand() || changed_idx) {
Instruction* newVal = new GetElementPtrInst(newOp1, Instruction* newVal =
newIdx.begin(), newIdx.end(), GetElementPtrInst::Create(newOp1,
U->getName()+".expr"); newIdx.begin(), newIdx.end(),
U->getName()+".expr");
uint32_t v = VN.lookup_or_add(newVal); 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", newVal = new ShuffleVectorInst(s1, s2, s3, S->getName()+".gvnpre",
(*PI)->getTerminator()); (*PI)->getTerminator());
else if (InsertElementInst* S = dyn_cast<InsertElementInst>(U)) else if (InsertElementInst* S = dyn_cast<InsertElementInst>(U))
newVal = new InsertElementInst(s1, s2, s3, S->getName()+".gvnpre", newVal = InsertElementInst::Create(s1, s2, s3, S->getName()+".gvnpre",
(*PI)->getTerminator()); (*PI)->getTerminator());
else if (ExtractElementInst* S = dyn_cast<ExtractElementInst>(U)) else if (ExtractElementInst* S = dyn_cast<ExtractElementInst>(U))
newVal = new ExtractElementInst(s1, s2, S->getName()+".gvnpre", newVal = new ExtractElementInst(s1, s2, S->getName()+".gvnpre",
(*PI)->getTerminator()); (*PI)->getTerminator());
else if (SelectInst* S = dyn_cast<SelectInst>(U)) else if (SelectInst* S = dyn_cast<SelectInst>(U))
newVal = new SelectInst(s1, s2, s3, S->getName()+".gvnpre", newVal = SelectInst::Create(s1, s2, s3, S->getName()+".gvnpre",
(*PI)->getTerminator()); (*PI)->getTerminator());
else if (CastInst* C = dyn_cast<CastInst>(U)) else if (CastInst* C = dyn_cast<CastInst>(U))
newVal = CastInst::create(C->getOpcode(), s1, C->getType(), newVal = CastInst::create(C->getOpcode(), s1, C->getType(),
C->getName()+".gvnpre", C->getName()+".gvnpre",
(*PI)->getTerminator()); (*PI)->getTerminator());
else if (GetElementPtrInst* G = dyn_cast<GetElementPtrInst>(U)) else if (GetElementPtrInst* G = dyn_cast<GetElementPtrInst>(U))
newVal = new GetElementPtrInst(s1, sVarargs.begin(), sVarargs.end(), newVal = GetElementPtrInst::Create(s1, sVarargs.begin(), sVarargs.end(),
G->getName()+".gvnpre", G->getName()+".gvnpre",
(*PI)->getTerminator()); (*PI)->getTerminator());
VN.add(newVal, VN.lookup(U)); VN.add(newVal, VN.lookup(U));
ValueNumberedSet& predAvail = availableOut[*PI]; 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) { for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) {
if (p == 0) 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); p->addIncoming(avail[*PI], *PI);
} }

View File

@ -145,8 +145,8 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN,
Value *AddedVal = GEPI->getOperand(1); Value *AddedVal = GEPI->getOperand(1);
// Insert a new integer PHI node into the top of the block. // Insert a new integer PHI node into the top of the block.
PHINode *NewPhi = new PHINode(AddedVal->getType(), PHINode *NewPhi = PHINode::Create(AddedVal->getType(),
PN->getName()+".rec", PN); PN->getName()+".rec", PN);
NewPhi->addIncoming(Constant::getNullValue(NewPhi->getType()), Preheader); NewPhi->addIncoming(Constant::getNullValue(NewPhi->getType()), Preheader);
// Create the new add instruction. // Create the new add instruction.
@ -181,7 +181,7 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN,
Value *Idx[2]; Value *Idx[2];
Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = NewAdd; Idx[1] = NewAdd;
GetElementPtrInst *NGEPI = new GetElementPtrInst( GetElementPtrInst *NGEPI = GetElementPtrInst::Create(
NCE, Idx, Idx + 2, NCE, Idx, Idx + 2,
GEPI->getName(), GEPI); GEPI->getName(), GEPI);
SE->deleteValueFromRecords(GEPI); SE->deleteValueFromRecords(GEPI);
@ -200,8 +200,8 @@ void IndVarSimplify::EliminatePointerRecurrence(PHINode *PN,
BasicBlock::iterator InsertPos = PN; ++InsertPos; BasicBlock::iterator InsertPos = PN; ++InsertPos;
while (isa<PHINode>(InsertPos)) ++InsertPos; while (isa<PHINode>(InsertPos)) ++InsertPos;
Value *PreInc = Value *PreInc =
new GetElementPtrInst(PN->getIncomingValue(PreheaderIdx), GetElementPtrInst::Create(PN->getIncomingValue(PreheaderIdx),
NewPhi, "", InsertPos); NewPhi, "", InsertPos);
PreInc->takeName(PN); PreInc->takeName(PN);
PN->replaceAllUsesWith(PreInc); PN->replaceAllUsesWith(PreInc);
} }

View File

@ -1811,8 +1811,8 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, uint64_t DemandedElts,
} }
Instruction *New = Instruction *New =
new InsertElementInst(UndefValue::get(II->getType()), TmpV, 0U, InsertElementInst::Create(UndefValue::get(II->getType()), TmpV, 0U,
II->getName()); II->getName());
InsertNewInstBefore(New, *II); InsertNewInstBefore(New, *II);
AddSoonDeadInstToWorklist(*II, 0); AddSoonDeadInstToWorklist(*II, 0);
return New; return New;
@ -2007,8 +2007,8 @@ static Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI,
Value *SelectTrueVal = FoldOperationIntoSelectOperand(Op, TV, IC); Value *SelectTrueVal = FoldOperationIntoSelectOperand(Op, TV, IC);
Value *SelectFalseVal = FoldOperationIntoSelectOperand(Op, FV, IC); Value *SelectFalseVal = FoldOperationIntoSelectOperand(Op, FV, IC);
return new SelectInst(SI->getCondition(), SelectTrueVal, return SelectInst::Create(SI->getCondition(), SelectTrueVal,
SelectFalseVal); SelectFalseVal);
} }
return 0; return 0;
} }
@ -2048,7 +2048,7 @@ Instruction *InstCombiner::FoldOpIntoPhi(Instruction &I) {
} }
// Okay, we can do the transformation: create the new PHI node. // 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); NewPN->reserveOperandSpace(PN->getNumOperands()/2);
InsertNewInstBefore(NewPN, *PN); InsertNewInstBefore(NewPN, *PN);
NewPN->takeName(PN); NewPN->takeName(PN);
@ -2366,7 +2366,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
cast<PointerType>(CI->getOperand(0)->getType())->getAddressSpace(); cast<PointerType>(CI->getOperand(0)->getType())->getAddressSpace();
Value *I2 = InsertBitCastBefore(CI->getOperand(0), Value *I2 = InsertBitCastBefore(CI->getOperand(0),
PointerType::get(Type::Int8Ty, AS), I); 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()); 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. // 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))) && 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. 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))) && 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. 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); FSI = InsertNewInstBefore(FSI, I);
// construct the select instruction and return it. // 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; return 0;
@ -3049,7 +3049,7 @@ Instruction *InstCombiner::visitURem(BinaryOperator &I) {
BinaryOperator::createAnd(Op0, SubOne(STO), SI->getName()+".t"), I); BinaryOperator::createAnd(Op0, SubOne(STO), SI->getName()+".t"), I);
Value *FalseAnd = InsertNewInstBefore( Value *FalseAnd = InsertNewInstBefore(
BinaryOperator::createAnd(Op0, SubOne(SFO), SI->getName()+".f"), I); 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 }; const Type *Tys[] = { ITy };
Module *M = I.getParent()->getParent()->getParent(); Module *M = I.getParent()->getParent()->getParent();
Function *F = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1); 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) if (Op1)
return new SelectInst(LHSI->getOperand(0), Op1, Op2); return SelectInst::Create(LHSI->getOperand(0), Op1, Op2);
break; break;
} }
} }
@ -5257,7 +5257,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
} }
if (Op1) if (Op1)
return new SelectInst(LHSI->getOperand(0), Op1, Op2); return SelectInst::Create(LHSI->getOperand(0), Op1, Op2);
break; break;
} }
case Instruction::Malloc: 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 // If we were able to index down into an element, create the GEP
// and bitcast the result. This eliminates one bitcast, potentially // and bitcast the result. This eliminates one bitcast, potentially
// two. // two.
Instruction *NGEP = new GetElementPtrInst(OrigBase, Instruction *NGEP = GetElementPtrInst::Create(OrigBase,
NewIndices.begin(), NewIndices.begin(),
NewIndices.end(), ""); NewIndices.end(), "");
InsertNewInstBefore(NGEP, CI); InsertNewInstBefore(NGEP, CI);
NGEP->takeName(GEP); 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 Offset is evenly divisible by Size, we can do this xform.
if (Size && !APIntOps::srem(Offset, APInt(Offset.getBitWidth(), Size))){ if (Size && !APIntOps::srem(Offset, APInt(Offset.getBitWidth(), Size))){
Offset = APIntOps::sdiv(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 // 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(), Instruction *P = InsertNewInstBefore(new IntToPtrInst(X, CI.getType(),
"tmp"), CI); "tmp"), CI);
return new GetElementPtrInst(P, ConstantInt::get(Offset), "tmp"); return GetElementPtrInst::Create(P, ConstantInt::get(Offset), "tmp");
} }
} }
return 0; 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 we found a path from the src to dest, create the getelementptr now.
if (SrcElTy == DstElTy) { if (SrcElTy == DstElTy) {
SmallVector<Value*, 8> Idxs(NumZeros+1, ZeroUInt); SmallVector<Value*, 8> Idxs(NumZeros+1, ZeroUInt);
return new GetElementPtrInst(Src, Idxs.begin(), Idxs.end(), "", return GetElementPtrInst::Create(Src, Idxs.begin(), Idxs.end(), "",
((Instruction*) NULL)); ((Instruction*) NULL));
} }
} }
@ -7699,8 +7699,8 @@ Instruction *InstCombiner::FoldSelectOpOp(SelectInst &SI, Instruction *TI,
} }
// Fold this by inserting a select from the input values. // Fold this by inserting a select from the input values.
SelectInst *NewSI = new SelectInst(SI.getCondition(), TI->getOperand(0), SelectInst *NewSI = SelectInst::Create(SI.getCondition(), TI->getOperand(0),
FI->getOperand(0), SI.getName()+".v"); FI->getOperand(0), SI.getName()+".v");
InsertNewInstBefore(NewSI, SI); InsertNewInstBefore(NewSI, SI);
return CastInst::create(Instruction::CastOps(TI->getOpcode()), NewSI, return CastInst::create(Instruction::CastOps(TI->getOpcode()), NewSI,
TI->getType()); TI->getType());
@ -7740,8 +7740,8 @@ Instruction *InstCombiner::FoldSelectOpOp(SelectInst &SI, Instruction *TI,
} }
// If we reach here, they do have operations in common. // If we reach here, they do have operations in common.
SelectInst *NewSI = new SelectInst(SI.getCondition(), OtherOpT, SelectInst *NewSI = SelectInst::Create(SI.getCondition(), OtherOpT,
OtherOpF, SI.getName()+".v"); OtherOpF, SI.getName()+".v");
InsertNewInstBefore(NewSI, SI); InsertNewInstBefore(NewSI, SI);
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(TI)) { if (BinaryOperator *BO = dyn_cast<BinaryOperator>(TI)) {
@ -7990,7 +7990,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
if (AddOp != TI) if (AddOp != TI)
std::swap(NewTrueOp, NewFalseOp); std::swap(NewTrueOp, NewFalseOp);
Instruction *NewSel = Instruction *NewSel =
new SelectInst(CondVal, NewTrueOp,NewFalseOp,SI.getName()+".p"); SelectInst::Create(CondVal, NewTrueOp,NewFalseOp,SI.getName()+".p");
NewSel = InsertNewInstBefore(NewSel, SI); NewSel = InsertNewInstBefore(NewSel, SI);
return BinaryOperator::createAdd(SubOp->getOperand(0), NewSel); return BinaryOperator::createAdd(SubOp->getOperand(0), NewSel);
@ -8016,7 +8016,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
if (OpToFold) { if (OpToFold) {
Constant *C = GetSelectFoldableConstant(TVI); Constant *C = GetSelectFoldableConstant(TVI);
Instruction *NewSel = Instruction *NewSel =
new SelectInst(SI.getCondition(), TVI->getOperand(2-OpToFold), C); SelectInst::Create(SI.getCondition(), TVI->getOperand(2-OpToFold), C);
InsertNewInstBefore(NewSel, SI); InsertNewInstBefore(NewSel, SI);
NewSel->takeName(TVI); NewSel->takeName(TVI);
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(TVI)) if (BinaryOperator *BO = dyn_cast<BinaryOperator>(TVI))
@ -8041,7 +8041,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
if (OpToFold) { if (OpToFold) {
Constant *C = GetSelectFoldableConstant(FVI); Constant *C = GetSelectFoldableConstant(FVI);
Instruction *NewSel = Instruction *NewSel =
new SelectInst(SI.getCondition(), C, FVI->getOperand(2-OpToFold)); SelectInst::Create(SI.getCondition(), C, FVI->getOperand(2-OpToFold));
InsertNewInstBefore(NewSel, SI); InsertNewInstBefore(NewSel, SI);
NewSel->takeName(FVI); NewSel->takeName(FVI);
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(FVI)) if (BinaryOperator *BO = dyn_cast<BinaryOperator>(FVI))
@ -8369,7 +8369,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
} }
// Insert this value into the result vector. // 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); InsertNewInstBefore(cast<Instruction>(Result), CI);
} }
return CastInst::create(Instruction::BitCast, Result, CI.getType()); 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())) { if (InvokeInst *II = dyn_cast<InvokeInst>(CS.getInstruction())) {
// Don't break the CFG, insert a dummy cond branch. // Don't break the CFG, insert a dummy cond branch.
new BranchInst(II->getNormalDest(), II->getUnwindDest(), BranchInst::Create(II->getNormalDest(), II->getUnwindDest(),
ConstantInt::getTrue(), II); ConstantInt::getTrue(), II);
} }
return EraseInstFromFunction(*CS.getInstruction()); return EraseInstFromFunction(*CS.getInstruction());
} }
@ -8678,13 +8678,13 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
Instruction *NC; Instruction *NC;
if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) { if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
NC = new InvokeInst(Callee, II->getNormalDest(), II->getUnwindDest(), NC = InvokeInst::Create(Callee, II->getNormalDest(), II->getUnwindDest(),
Args.begin(), Args.end(), Caller->getName(), Caller); Args.begin(), Args.end(), Caller->getName(), Caller);
cast<InvokeInst>(NC)->setCallingConv(II->getCallingConv()); cast<InvokeInst>(NC)->setCallingConv(II->getCallingConv());
cast<InvokeInst>(NC)->setParamAttrs(NewCallerPAL); cast<InvokeInst>(NC)->setParamAttrs(NewCallerPAL);
} else { } else {
NC = new CallInst(Callee, Args.begin(), Args.end(), NC = CallInst::Create(Callee, Args.begin(), Args.end(),
Caller->getName(), Caller); Caller->getName(), Caller);
CallInst *CI = cast<CallInst>(Caller); CallInst *CI = cast<CallInst>(Caller);
if (CI->isTailCall()) if (CI->isTailCall())
cast<CallInst>(NC)->setTailCall(); cast<CallInst>(NC)->setTailCall();
@ -8841,15 +8841,15 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) {
Instruction *NewCaller; Instruction *NewCaller;
if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) { if (InvokeInst *II = dyn_cast<InvokeInst>(Caller)) {
NewCaller = new InvokeInst(NewCallee, NewCaller = InvokeInst::Create(NewCallee,
II->getNormalDest(), II->getUnwindDest(), II->getNormalDest(), II->getUnwindDest(),
NewArgs.begin(), NewArgs.end(), NewArgs.begin(), NewArgs.end(),
Caller->getName(), Caller); Caller->getName(), Caller);
cast<InvokeInst>(NewCaller)->setCallingConv(II->getCallingConv()); cast<InvokeInst>(NewCaller)->setCallingConv(II->getCallingConv());
cast<InvokeInst>(NewCaller)->setParamAttrs(NewPAL); cast<InvokeInst>(NewCaller)->setParamAttrs(NewPAL);
} else { } else {
NewCaller = new CallInst(NewCallee, NewArgs.begin(), NewArgs.end(), NewCaller = CallInst::Create(NewCallee, NewArgs.begin(), NewArgs.end(),
Caller->getName(), Caller); Caller->getName(), Caller);
if (cast<CallInst>(Caller)->isTailCall()) if (cast<CallInst>(Caller)->isTailCall())
cast<CallInst>(NewCaller)->setTailCall(); cast<CallInst>(NewCaller)->setTailCall();
cast<CallInst>(NewCaller)-> cast<CallInst>(NewCaller)->
@ -8921,7 +8921,7 @@ Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) {
Value *InRHS = FirstInst->getOperand(1); Value *InRHS = FirstInst->getOperand(1);
PHINode *NewLHS = 0, *NewRHS = 0; PHINode *NewLHS = 0, *NewRHS = 0;
if (LHSVal == 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->reserveOperandSpace(PN.getNumOperands()/2);
NewLHS->addIncoming(InLHS, PN.getIncomingBlock(0)); NewLHS->addIncoming(InLHS, PN.getIncomingBlock(0));
InsertNewInstBefore(NewLHS, PN); InsertNewInstBefore(NewLHS, PN);
@ -8929,7 +8929,7 @@ Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) {
} }
if (RHSVal == 0) { 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->reserveOperandSpace(PN.getNumOperands()/2);
NewRHS->addIncoming(InRHS, PN.getIncomingBlock(0)); NewRHS->addIncoming(InRHS, PN.getIncomingBlock(0));
InsertNewInstBefore(NewRHS, PN); InsertNewInstBefore(NewRHS, PN);
@ -8955,7 +8955,7 @@ Instruction *InstCombiner::FoldPHIArgBinOpIntoPHI(PHINode &PN) {
RHSVal); RHSVal);
else { else {
assert(isa<GetElementPtrInst>(FirstInst)); 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 // 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. // correct type, and PHI together all of the LHS's of the instructions.
PHINode *NewPN = new PHINode(FirstInst->getOperand(0)->getType(), PHINode *NewPN = PHINode::Create(FirstInst->getOperand(0)->getType(),
PN.getName()+".in"); PN.getName()+".in");
NewPN->reserveOperandSpace(PN.getNumOperands()/2); NewPN->reserveOperandSpace(PN.getNumOperands()/2);
Value *InVal = FirstInst->getOperand(0); Value *InVal = FirstInst->getOperand(0);
@ -9405,8 +9405,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
} }
if (!Indices.empty()) if (!Indices.empty())
return new GetElementPtrInst(SrcGEPOperands[0], Indices.begin(), return GetElementPtrInst::Create(SrcGEPOperands[0], Indices.begin(),
Indices.end(), GEP.getName()); Indices.end(), GEP.getName());
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(PtrOp)) { } else if (GlobalValue *GV = dyn_cast<GlobalValue>(PtrOp)) {
// GEP of global variable. If all of the indices for this GEP are // 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[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = GEP.getOperand(1); Idx[1] = GEP.getOperand(1);
Value *V = InsertNewInstBefore( 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 // V and GEP are both pointer types --> BitCast
return new BitCastInst(V, GEP.getType()); return new BitCastInst(V, GEP.getType());
} }
@ -9519,7 +9519,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = NewIdx; Idx[1] = NewIdx;
Instruction *NewGEP = Instruction *NewGEP =
new GetElementPtrInst(X, Idx, Idx + 2, GEP.getName()); GetElementPtrInst::Create(X, Idx, Idx + 2, GEP.getName());
NewGEP = InsertNewInstBefore(NewGEP, GEP); NewGEP = InsertNewInstBefore(NewGEP, GEP);
// The NewGEP must be pointer typed, so must the old one -> BitCast // The NewGEP must be pointer typed, so must the old one -> BitCast
return new BitCastInst(NewGEP, GEP.getType()); return new BitCastInst(NewGEP, GEP.getType());
@ -9562,8 +9562,8 @@ Instruction *InstCombiner::visitAllocationInst(AllocationInst &AI) {
Value *Idx[2]; Value *Idx[2];
Idx[0] = NullIdx; Idx[0] = NullIdx;
Idx[1] = NullIdx; Idx[1] = NullIdx;
Value *V = new GetElementPtrInst(New, Idx, Idx + 2, Value *V = GetElementPtrInst::Create(New, Idx, Idx + 2,
New->getName()+".sub", It); New->getName()+".sub", It);
// Now make everything use the getelementptr instead of the original // Now make everything use the getelementptr instead of the original
// allocation. // allocation.
@ -9874,7 +9874,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
SI->getOperand(1)->getName()+".val"), LI); SI->getOperand(1)->getName()+".val"), LI);
Value *V2 = InsertNewInstBefore(new LoadInst(SI->getOperand(2), Value *V2 = InsertNewInstBefore(new LoadInst(SI->getOperand(2),
SI->getOperand(2)->getName()+".val"), LI); 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 // 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. // Insert a PHI node now if we need it.
Value *MergedVal = OtherStore->getOperand(0); Value *MergedVal = OtherStore->getOperand(0);
if (MergedVal != SI.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->reserveOperandSpace(2);
PN->addIncoming(SI.getOperand(0), SI.getParent()); PN->addIncoming(SI.getOperand(0), SI.getParent());
PN->addIncoming(OtherStore->getOperand(0), OtherBB); PN->addIncoming(OtherStore->getOperand(0), OtherBB);
@ -10437,7 +10437,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
Value *Ptr = InsertBitCastBefore(I->getOperand(0), Value *Ptr = InsertBitCastBefore(I->getOperand(0),
PointerType::get(EI.getType(), AS),EI); PointerType::get(EI.getType(), AS),EI);
GetElementPtrInst *GEP = GetElementPtrInst *GEP =
new GetElementPtrInst(Ptr, EI.getOperand(1), I->getName() + ".gep"); GetElementPtrInst::Create(Ptr, EI.getOperand(1), I->getName() + ".gep");
InsertNewInstBefore(GEP, EI); InsertNewInstBefore(GEP, EI);
return new LoadInst(GEP); return new LoadInst(GEP);
} }

View File

@ -772,7 +772,7 @@ void LoopIndexSplit::updateLoopBounds(ICmpInst *CI) {
"lsplit.add", PHTerminator); "lsplit.add", PHTerminator);
Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
A, UB,"lsplit,c", PHTerminator); 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) // for (i = LB; i <= UB; ++i)
@ -788,7 +788,7 @@ void LoopIndexSplit::updateLoopBounds(ICmpInst *CI) {
|| ExitCondition->getPredicate() == ICmpInst::ICMP_ULE) { || ExitCondition->getPredicate() == ICmpInst::ICMP_ULE) {
Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
NV, UB, "lsplit.c", PHTerminator); NV, UB, "lsplit.c", PHTerminator);
NUB = new SelectInst (C, NV, UB, "lsplit.nub", PHTerminator); NUB = SelectInst::Create(C, NV, UB, "lsplit.nub", PHTerminator);
} }
break; break;
case ICmpInst::ICMP_ULT: case ICmpInst::ICMP_ULT:
@ -806,7 +806,7 @@ void LoopIndexSplit::updateLoopBounds(ICmpInst *CI) {
|| ExitCondition->getPredicate() == ICmpInst::ICMP_ULT) { || ExitCondition->getPredicate() == ICmpInst::ICMP_ULT) {
Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
NV, UB, "lsplit.c", PHTerminator); 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) // for (i = LB; i <= UB; ++i)
@ -824,7 +824,7 @@ void LoopIndexSplit::updateLoopBounds(ICmpInst *CI) {
"lsplit.add", PHTerminator); "lsplit.add", PHTerminator);
Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
S, UB, "lsplit.c", PHTerminator); S, UB, "lsplit.c", PHTerminator);
NUB = new SelectInst (C, S, UB, "lsplit.nub", PHTerminator); NUB = SelectInst::Create(C, S, UB, "lsplit.nub", PHTerminator);
} }
break; break;
case ICmpInst::ICMP_UGE: case ICmpInst::ICMP_UGE:
@ -841,7 +841,7 @@ void LoopIndexSplit::updateLoopBounds(ICmpInst *CI) {
{ {
Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
NV, StartValue, "lsplit.c", PHTerminator); NV, StartValue, "lsplit.c", PHTerminator);
NLB = new SelectInst (C, StartValue, NV, "lsplit.nlb", PHTerminator); NLB = SelectInst::Create(C, StartValue, NV, "lsplit.nlb", PHTerminator);
} }
break; break;
case ICmpInst::ICMP_UGT: case ICmpInst::ICMP_UGT:
@ -860,7 +860,7 @@ void LoopIndexSplit::updateLoopBounds(ICmpInst *CI) {
"lsplit.add", PHTerminator); "lsplit.add", PHTerminator);
Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
A, StartValue, "lsplit.c", PHTerminator); A, StartValue, "lsplit.c", PHTerminator);
NLB = new SelectInst (C, StartValue, A, "lsplit.nlb", PHTerminator); NLB = SelectInst::Create(C, StartValue, A, "lsplit.nlb", PHTerminator);
} }
break; break;
default: default:
@ -1356,16 +1356,16 @@ void LoopIndexSplit::calculateLoopBounds(SplitInfo &SD) {
ExitCondition->getOperand(ExitValueNum), ExitCondition->getOperand(ExitValueNum),
"lsplit.ev", InsertPt); "lsplit.ev", InsertPt);
SD.A_ExitValue = new SelectInst(C1, AEV, SD.A_ExitValue = SelectInst::Create(C1, AEV,
ExitCondition->getOperand(ExitValueNum), ExitCondition->getOperand(ExitValueNum),
"lsplit.ev", InsertPt); "lsplit.ev", InsertPt);
Value *C2 = new ICmpInst(Sign ? Value *C2 = new ICmpInst(Sign ?
ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT, ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
BSV, StartValue, "lsplit.sv", BSV, StartValue, "lsplit.sv",
PHTerminator); PHTerminator);
SD.B_StartValue = new SelectInst(C2, StartValue, BSV, SD.B_StartValue = SelectInst::Create(C2, StartValue, BSV,
"lsplit.sv", PHTerminator); "lsplit.sv", PHTerminator);
} }
/// splitLoop - Split current loop L in two loops using split information /// splitLoop - Split current loop L in two loops using split information
@ -1508,7 +1508,7 @@ bool LoopIndexSplit::splitLoop(SplitInfo &SD) {
BI != BE; ++BI) { BI != BE; ++BI) {
if (PHINode *PN = dyn_cast<PHINode>(BI)) { if (PHINode *PN = dyn_cast<PHINode>(BI)) {
Value *V1 = PN->getIncomingValueForBlock(A_ExitBlock); 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); newPHI->addIncoming(V1, A_ExitingBlock);
A_ExitBlock->getInstList().push_front(newPHI); A_ExitBlock->getInstList().push_front(newPHI);
PN->removeIncomingValue(A_ExitBlock); PN->removeIncomingValue(A_ExitBlock);
@ -1598,7 +1598,7 @@ void LoopIndexSplit::moveExitCondition(BasicBlock *CondBB, BasicBlock *ActiveBB,
CurrentBR->eraseFromParent(); CurrentBR->eraseFromParent();
// Connect exiting block to original destination. // Connect exiting block to original destination.
new BranchInst(OrigDestBB, ExitingBB); BranchInst::Create(OrigDestBB, ExitingBB);
// Update PHINodes // Update PHINodes
updatePHINodes(ExitBB, ExitingBB, CondBB, IV, IVAdd, LP); updatePHINodes(ExitBB, ExitingBB, CondBB, IV, IVAdd, LP);

View File

@ -208,7 +208,7 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
// Create new PHI node with two incoming values for NewHeader. // Create new PHI node with two incoming values for NewHeader.
// One incoming value is from OrigLatch (through OrigHeader) and // One incoming value is from OrigLatch (through OrigHeader) and
// second incoming value is from original pre-header. // 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(PN->getIncomingValueForBlock(OrigLatch), OrigHeader);
NH->addIncoming(NPV, OrigPreHeader); NH->addIncoming(NPV, OrigPreHeader);
NewHeader->getInstList().push_front(NH); NewHeader->getInstList().push_front(NH);
@ -249,7 +249,7 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
// create new PHINode for this instruction. // create new PHINode for this instruction.
Instruction *NewHeaderReplacement = NULL; Instruction *NewHeaderReplacement = NULL;
if (usedOutsideOriginalHeader(In)) { 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(In, OrigHeader);
PN->addIncoming(C, OrigPreHeader); PN->addIncoming(C, OrigPreHeader);
NewHeader->getInstList().push_front(PN); NewHeader->getInstList().push_front(PN);
@ -336,7 +336,7 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
} else { } else {
// Used outside Exit block. Create a new PHI node from exit block // Used outside Exit block. Create a new PHI node from exit block
// to receive value from ne new header ane pre header. // 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(ILoopHeaderInfo.PreHeader, OrigPreHeader);
PN->addIncoming(OldPhi, OrigHeader); PN->addIncoming(OldPhi, OrigHeader);
Exit->getInstList().push_front(PN); 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 // Right now original pre-header has two successors, new header and
// exit block. Insert new block between original pre-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. // new header such that loop's new pre-header has only one successor.
BasicBlock *NewPreHeader = new BasicBlock("bb.nph", OrigHeader->getParent(), BasicBlock *NewPreHeader = BasicBlock::Create("bb.nph", OrigHeader->getParent(),
NewHeader); NewHeader);
LoopInfo &LI = LPM.getAnalysis<LoopInfo>(); LoopInfo &LI = LPM.getAnalysis<LoopInfo>();
if (Loop *PL = LI.getLoopFor(OrigPreHeader)) if (Loop *PL = LI.getLoopFor(OrigPreHeader))
PL->addBasicBlockToLoop(NewPreHeader, LI.getBase()); PL->addBasicBlockToLoop(NewPreHeader, LI.getBase());
new BranchInst(NewHeader, NewPreHeader); BranchInst::Create(NewHeader, NewPreHeader);
BranchInst *OrigPH_BI = cast<BranchInst>(OrigPreHeader->getTerminator()); BranchInst *OrigPH_BI = cast<BranchInst>(OrigPreHeader->getTerminator());
if (OrigPH_BI->getSuccessor(0) == NewHeader) if (OrigPH_BI->getSuccessor(0) == NewHeader)
@ -560,7 +560,7 @@ void LoopRotate::preserveCanonicalLoopForm(LPPassManager &LPM) {
BasicBlock::iterator I = Exit->begin(), E = Exit->end(); BasicBlock::iterator I = Exit->begin(), E = Exit->end();
PHINode *PN = NULL; PHINode *PN = NULL;
for (; (PN = dyn_cast<PHINode>(I)); ++I) { 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(); unsigned N = PN->getNumIncomingValues();
for (unsigned index = 0; index < N; ++index) for (unsigned index = 0; index < N; ++index)
if (PN->getIncomingBlock(index) == NExit) { if (PN->getIncomingBlock(index) == NExit) {

View File

@ -1271,7 +1271,7 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEVHandle &Stride,
if (RewriteFactor == 0) { if (RewriteFactor == 0) {
// Create a new Phi for this base, and stick it in the loop header. // 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; ++NumInserted;
// Add common base to the new Phi node. // Add common base to the new Phi node.

View File

@ -568,7 +568,7 @@ void LoopUnswitch::EmitPreheaderBranchOnCondition(Value *LIC, Constant *Val,
std::swap(TrueDest, FalseDest); std::swap(TrueDest, FalseDest);
// Insert the new branch. // 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(); for (BasicBlock::iterator I = EndBlock->begin();
(OldLCSSA = dyn_cast<PHINode>(I)); ++I) { (OldLCSSA = dyn_cast<PHINode>(I)); ++I) {
Value* OldValue = OldLCSSA->getIncomingValueForBlock(MiddleBlock); Value* OldValue = OldLCSSA->getIncomingValueForBlock(MiddleBlock);
PHINode* NewLCSSA = new PHINode(OldLCSSA->getType(), PHINode* NewLCSSA = PHINode::Create(OldLCSSA->getType(),
OldLCSSA->getName() + ".us-lcssa", OldLCSSA->getName() + ".us-lcssa",
MiddleBlock->getTerminator()); MiddleBlock->getTerminator());
NewLCSSA->addIncoming(OldValue, StartBlock); NewLCSSA->addIncoming(OldValue, StartBlock);
OldLCSSA->setIncomingValue(OldLCSSA->getBasicBlockIndex(MiddleBlock), OldLCSSA->setIncomingValue(OldLCSSA->getBasicBlockIndex(MiddleBlock),
NewLCSSA); NewLCSSA);
@ -687,9 +687,9 @@ void LoopUnswitch::SplitExitEdges(Loop *L, const SmallVector<BasicBlock *, 8> &E
for (BasicBlock::iterator I = MiddleBlock->begin(); for (BasicBlock::iterator I = MiddleBlock->begin();
(OldLCSSA = dyn_cast<PHINode>(I)) && InsertedPHIs.count(OldLCSSA) == 0; (OldLCSSA = dyn_cast<PHINode>(I)) && InsertedPHIs.count(OldLCSSA) == 0;
++I) { ++I) {
PHINode *NewLCSSA = new PHINode(OldLCSSA->getType(), PHINode *NewLCSSA = PHINode::Create(OldLCSSA->getType(),
OldLCSSA->getName() + ".us-lcssa", OldLCSSA->getName() + ".us-lcssa",
InsertPt); InsertPt);
OldLCSSA->replaceAllUsesWith(NewLCSSA); OldLCSSA->replaceAllUsesWith(NewLCSSA);
NewLCSSA->addIncoming(OldLCSSA, MiddleBlock); NewLCSSA->addIncoming(OldLCSSA, MiddleBlock);
} }
@ -1155,8 +1155,8 @@ void LoopUnswitch::RewriteLoopBodyWithConditionConstant(Loop *L, Value *LIC,
BasicBlock* Split = SplitBlock(Old, SI, this); BasicBlock* Split = SplitBlock(Old, SI, this);
Instruction* OldTerm = Old->getTerminator(); Instruction* OldTerm = Old->getTerminator();
new BranchInst(Split, SI->getSuccessor(i), BranchInst::Create(Split, SI->getSuccessor(i),
ConstantInt::getTrue(), OldTerm); ConstantInt::getTrue(), OldTerm);
LPM->deleteSimpleAnalysisValue(Old->getTerminator(), L); LPM->deleteSimpleAnalysisValue(Old->getTerminator(), L);
Old->getTerminator()->eraseFromParent(); Old->getTerminator()->eraseFromParent();
@ -1295,7 +1295,7 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist, Loop *L) {
BasicBlock *DeadSucc = BI->getSuccessor(CB->getZExtValue()); BasicBlock *DeadSucc = BI->getSuccessor(CB->getZExtValue());
BasicBlock *LiveSucc = BI->getSuccessor(!CB->getZExtValue()); BasicBlock *LiveSucc = BI->getSuccessor(!CB->getZExtValue());
DeadSucc->removePredecessor(BI->getParent(), true); DeadSucc->removePredecessor(BI->getParent(), true);
Worklist.push_back(new BranchInst(LiveSucc, BI)); Worklist.push_back(BranchInst::Create(LiveSucc, BI));
LPM->deleteSimpleAnalysisValue(BI, L); LPM->deleteSimpleAnalysisValue(BI, L);
BI->eraseFromParent(); BI->eraseFromParent();
RemoveFromWorklist(BI, Worklist); RemoveFromWorklist(BI, Worklist);

View File

@ -1740,7 +1740,7 @@ bool IPSCCP::runOnModule(Module &M) {
// Make this an uncond branch to the first successor. // Make this an uncond branch to the first successor.
TerminatorInst *TI = I->getParent()->getTerminator(); 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. // Remove entries in successor phi nodes to remove edges.
for (unsigned i = 1, e = TI->getNumSuccessors(); i != e; ++i) for (unsigned i = 1, e = TI->getNumSuccessors(); i != e; ++i)

View File

@ -323,8 +323,8 @@ void SROA::DoScalarReplacement(AllocationInst *AI,
SmallVector<Value*, 8> NewArgs; SmallVector<Value*, 8> NewArgs;
NewArgs.push_back(Constant::getNullValue(Type::Int32Ty)); NewArgs.push_back(Constant::getNullValue(Type::Int32Ty));
NewArgs.append(GEPI->op_begin()+3, GEPI->op_end()); NewArgs.append(GEPI->op_begin()+3, GEPI->op_end());
RepValue = new GetElementPtrInst(AllocaToUse, NewArgs.begin(), RepValue = GetElementPtrInst::Create(AllocaToUse, NewArgs.begin(),
NewArgs.end(), "", GEPI); NewArgs.end(), "", GEPI);
RepValue->takeName(GEPI); RepValue->takeName(GEPI);
} }
@ -634,9 +634,9 @@ void SROA::RewriteBitCastUserOfAlloca(Instruction *BCInst, AllocationInst *AI,
Value *Idx[2]; Value *Idx[2];
Idx[0] = Zero; Idx[0] = Zero;
Idx[1] = ConstantInt::get(Type::Int32Ty, i); Idx[1] = ConstantInt::get(Type::Int32Ty, i);
OtherElt = new GetElementPtrInst(OtherPtr, Idx, Idx + 2, OtherElt = GetElementPtrInst::Create(OtherPtr, Idx, Idx + 2,
OtherPtr->getNameStr()+"."+utostr(i), OtherPtr->getNameStr()+"."+utostr(i),
MI); MI);
} }
Value *EltPtr = NewElts[i]; Value *EltPtr = NewElts[i];
@ -716,7 +716,7 @@ void SROA::RewriteBitCastUserOfAlloca(Instruction *BCInst, AllocationInst *AI,
ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size
Zero // Align Zero // Align
}; };
new CallInst(TheFn, Ops, Ops + 4, "", MI); CallInst::Create(TheFn, Ops, Ops + 4, "", MI);
} else { } else {
assert(isa<MemSetInst>(MI)); assert(isa<MemSetInst>(MI));
Value *Ops[] = { Value *Ops[] = {
@ -724,7 +724,7 @@ void SROA::RewriteBitCastUserOfAlloca(Instruction *BCInst, AllocationInst *AI,
ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size ConstantInt::get(MI->getOperand(3)->getType(), EltSize), // Size
Zero // Align 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. // Insert the new GEP instructions, which are properly indexed.
SmallVector<Value*, 8> Indices(GEPI->op_begin()+1, GEPI->op_end()); SmallVector<Value*, 8> Indices(GEPI->op_begin()+1, GEPI->op_end());
Indices[1] = Constant::getNullValue(Type::Int32Ty); Indices[1] = Constant::getNullValue(Type::Int32Ty);
Value *ZeroIdx = new GetElementPtrInst(GEPI->getOperand(0), Value *ZeroIdx = GetElementPtrInst::Create(GEPI->getOperand(0),
Indices.begin(), Indices.begin(),
Indices.end(), Indices.end(),
GEPI->getName()+".0", GEPI); GEPI->getName()+".0", GEPI);
Indices[1] = ConstantInt::get(Type::Int32Ty, 1); Indices[1] = ConstantInt::get(Type::Int32Ty, 1);
Value *OneIdx = new GetElementPtrInst(GEPI->getOperand(0), Value *OneIdx = GetElementPtrInst::Create(GEPI->getOperand(0),
Indices.begin(), Indices.begin(),
Indices.end(), Indices.end(),
GEPI->getName()+".1", GEPI); GEPI->getName()+".1", GEPI);
// Replace all loads of the variable index GEP with loads from both // Replace all loads of the variable index GEP with loads from both
// indexes and a select. // indexes and a select.
while (!GEPI->use_empty()) { while (!GEPI->use_empty()) {
LoadInst *LI = cast<LoadInst>(GEPI->use_back()); LoadInst *LI = cast<LoadInst>(GEPI->use_back());
Value *Zero = new LoadInst(ZeroIdx, LI->getName()+".0", LI); Value *Zero = new LoadInst(ZeroIdx, LI->getName()+".0", LI);
Value *One = new LoadInst(OneIdx , LI->getName()+".1", 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->replaceAllUsesWith(R);
LI->eraseFromParent(); LI->eraseFromParent();
} }
@ -1261,9 +1261,9 @@ Value *SROA::ConvertUsesOfStoreToScalar(StoreInst *SI, AllocaInst *NewAI,
// Must be an element insertion. // Must be an element insertion.
const TargetData &TD = getAnalysis<TargetData>(); const TargetData &TD = getAnalysis<TargetData>();
unsigned Elt = Offset/TD.getABITypeSizeInBits(PTy->getElementType()); unsigned Elt = Offset/TD.getABITypeSizeInBits(PTy->getElementType());
SV = new InsertElementInst(Old, SV, SV = InsertElementInst::Create(Old, SV,
ConstantInt::get(Type::Int32Ty, Elt), ConstantInt::get(Type::Int32Ty, Elt),
"tmp", SI); "tmp", SI);
} }
} else if (isa<PointerType>(AllocaType)) { } else if (isa<PointerType>(AllocaType)) {
// If the alloca type is a pointer, then all the elements must be // If the alloca type is a pointer, then all the elements must be

View File

@ -78,15 +78,15 @@ static void ChangeToUnreachable(Instruction *I) {
static void ChangeToCall(InvokeInst *II) { static void ChangeToCall(InvokeInst *II) {
BasicBlock *BB = II->getParent(); BasicBlock *BB = II->getParent();
SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end()); SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
CallInst *NewCall = new CallInst(II->getCalledValue(), Args.begin(), CallInst *NewCall = CallInst::Create(II->getCalledValue(), Args.begin(),
Args.end(), "", II); Args.end(), "", II);
NewCall->takeName(II); NewCall->takeName(II);
NewCall->setCallingConv(II->getCallingConv()); NewCall->setCallingConv(II->getCallingConv());
NewCall->setParamAttrs(II->getParamAttrs()); NewCall->setParamAttrs(II->getParamAttrs());
II->replaceAllUsesWith(NewCall); II->replaceAllUsesWith(NewCall);
// Follow the call by a branch to the normal destination. // 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 // Update PHI nodes in the unwind destination
II->getUnwindDest()->removePredecessor(BB); II->getUnwindDest()->removePredecessor(BB);

View File

@ -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. // create the new entry block, allowing us to branch back to the old entry.
if (OldEntry == 0) { if (OldEntry == 0) {
OldEntry = &F->getEntryBlock(); OldEntry = &F->getEntryBlock();
BasicBlock *NewEntry = new BasicBlock("", F, OldEntry); BasicBlock *NewEntry = BasicBlock::Create("", F, OldEntry);
NewEntry->takeName(OldEntry); NewEntry->takeName(OldEntry);
OldEntry->setName("tailrecurse"); 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 // 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. // 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(); Instruction *InsertPos = OldEntry->begin();
for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end();
I != E; ++I) { 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! I->replaceAllUsesWith(PN); // Everyone use the PHI node now!
PN->addIncoming(I, NewEntry); PN->addIncoming(I, NewEntry);
ArgumentPHIs.push_back(PN); ArgumentPHIs.push_back(PN);
@ -430,8 +430,8 @@ bool TailCallElim::ProcessReturningBlock(ReturnInst *Ret, BasicBlock *&OldEntry,
if (AccumulatorRecursionEliminationInitVal) { if (AccumulatorRecursionEliminationInitVal) {
Instruction *AccRecInstr = AccumulatorRecursionInstr; Instruction *AccRecInstr = AccumulatorRecursionInstr;
// Start by inserting a new PHI node for the accumulator. // Start by inserting a new PHI node for the accumulator.
PHINode *AccPN = new PHINode(AccRecInstr->getType(), "accumulator.tr", PHINode *AccPN = PHINode::Create(AccRecInstr->getType(), "accumulator.tr",
OldEntry->begin()); OldEntry->begin());
// Loop over all of the predecessors of the tail recursion block. For the // 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, // 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 // Now that all of the PHI nodes are in place, remove the call and
// ret instructions, replacing them with an unconditional branch. // 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(Ret); // Remove return.
BB->getInstList().erase(CI); // Remove call. BB->getInstList().erase(CI); // Remove call.
++NumEliminated; ++NumEliminated;

View File

@ -98,7 +98,7 @@ void llvm::RemoveSuccessor(TerminatorInst *TI, unsigned SuccNum) {
RetVal = Constant::getNullValue(BB->getParent()->getReturnType()); RetVal = Constant::getNullValue(BB->getParent()->getReturnType());
// Create the return... // Create the return...
NewTI = new ReturnInst(RetVal); NewTI = ReturnInst::Create(RetVal);
} }
break; break;

View File

@ -122,10 +122,10 @@ bool llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum, Pass *P,
BasicBlock *DestBB = TI->getSuccessor(SuccNum); BasicBlock *DestBB = TI->getSuccessor(SuccNum);
// Create a new basic block, linking it into the CFG. // Create a new basic block, linking it into the CFG.
BasicBlock *NewBB = new BasicBlock(TIBB->getName() + "." + BasicBlock *NewBB = BasicBlock::Create(TIBB->getName() + "." +
DestBB->getName() + "_crit_edge"); DestBB->getName() + "_crit_edge");
// Create our unconditional branch... // Create our unconditional branch...
new BranchInst(DestBB, NewBB); BranchInst::Create(DestBB, NewBB);
// Branch to the new block, breaking the edge. // Branch to the new block, breaking the edge.
TI->setSuccessor(SuccNum, NewBB); TI->setSuccessor(SuccNum, NewBB);

View File

@ -31,7 +31,7 @@ BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB,
DenseMap<const Value*, Value*> &ValueMap, DenseMap<const Value*, Value*> &ValueMap,
const char *NameSuffix, Function *F, const char *NameSuffix, Function *F,
ClonedCodeInfo *CodeInfo) { ClonedCodeInfo *CodeInfo) {
BasicBlock *NewBB = new BasicBlock("", F); BasicBlock *NewBB = BasicBlock::Create("", F);
if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix); if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
NewBB->setUnwindDest(const_cast<BasicBlock*>(BB->getUnwindDest())); NewBB->setUnwindDest(const_cast<BasicBlock*>(BB->getUnwindDest()));
@ -144,7 +144,7 @@ Function *llvm::CloneFunction(const Function *F,
ArgTypes, F->getFunctionType()->isVarArg()); ArgTypes, F->getFunctionType()->isVarArg());
// Create the new function... // 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... // Loop over the arguments, copying the names of the mapped arguments over...
Function::arg_iterator DestI = NewF->arg_begin(); Function::arg_iterator DestI = NewF->arg_begin();
@ -208,7 +208,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
// Nope, clone it now. // Nope, clone it now.
BasicBlock *NewBB; BasicBlock *NewBB;
BBEntry = NewBB = new BasicBlock(); BBEntry = NewBB = BasicBlock::Create();
if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix); if (BB->hasName()) NewBB->setName(BB->getName()+NameSuffix);
bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false; bool hasCalls = false, hasDynamicAllocas = false, hasStaticAllocas = false;
@ -253,7 +253,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
// Constant fold to uncond branch! // Constant fold to uncond branch!
if (Cond) { if (Cond) {
BasicBlock *Dest = BI->getSuccessor(!Cond->getZExtValue()); BasicBlock *Dest = BI->getSuccessor(!Cond->getZExtValue());
ValueMap[OldTI] = new BranchInst(Dest, NewBB); ValueMap[OldTI] = BranchInst::Create(Dest, NewBB);
ToClone.push_back(Dest); ToClone.push_back(Dest);
TerminatorDone = true; TerminatorDone = true;
} }
@ -265,7 +265,7 @@ void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
Cond = dyn_cast_or_null<ConstantInt>(ValueMap[SI->getCondition()]); Cond = dyn_cast_or_null<ConstantInt>(ValueMap[SI->getCondition()]);
if (Cond) { // Constant fold to uncond branch! if (Cond) { // Constant fold to uncond branch!
BasicBlock *Dest = SI->getSuccessor(SI->findCaseValue(Cond)); BasicBlock *Dest = SI->getSuccessor(SI->findCaseValue(Cond));
ValueMap[OldTI] = new BranchInst(Dest, NewBB); ValueMap[OldTI] = BranchInst::Create(Dest, NewBB);
ToClone.push_back(Dest); ToClone.push_back(Dest);
TerminatorDone = true; TerminatorDone = true;
} }

View File

@ -63,8 +63,8 @@ Module *llvm::CloneModule(const Module *M,
// Loop over the functions in the module, making external functions as before // 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) { for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I) {
Function *NF = Function *NF =
new Function(cast<FunctionType>(I->getType()->getElementType()), Function::Create(cast<FunctionType>(I->getType()->getElementType()),
GlobalValue::ExternalLinkage, I->getName(), New); GlobalValue::ExternalLinkage, I->getName(), New);
NF->setCallingConv(I->getCallingConv()); NF->setCallingConv(I->getCallingConv());
NF->setParamAttrs(I->getParamAttrs()); NF->setParamAttrs(I->getParamAttrs());
if (I->hasCollector()) if (I->hasCollector())

View File

@ -161,8 +161,8 @@ void CodeExtractor::severSplitPHINodes(BasicBlock *&Header) {
PHINode *PN = cast<PHINode>(AfterPHIs); PHINode *PN = cast<PHINode>(AfterPHIs);
// Create a new PHI node in the new region, which has an incoming value // Create a new PHI node in the new region, which has an incoming value
// from OldPred of PN. // from OldPred of PN.
PHINode *NewPN = new PHINode(PN->getType(), PN->getName()+".ce", PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".ce",
NewBB->begin()); NewBB->begin());
NewPN->addIncoming(PN, OldPred); NewPN->addIncoming(PN, OldPred);
// Loop over all of the incoming value in PN, moving them to NewPN if they // 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); const FunctionType *funcType = FunctionType::get(RetTy, paramTy, false);
// Create the new function // Create the new function
Function *newFunction = new Function(funcType, Function *newFunction = Function::Create(funcType,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
oldFunction->getName() + "_" + oldFunction->getName() + "_" +
header->getName(), M); header->getName(), M);
newFunction->getBasicBlockList().push_back(newRootNode); newFunction->getBasicBlockList().push_back(newRootNode);
// Create an iterator to name all of the arguments we inserted. // 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); Idx[1] = ConstantInt::get(Type::Int32Ty, i);
std::string GEPname = "gep_" + inputs[i]->getName(); std::string GEPname = "gep_" + inputs[i]->getName();
TerminatorInst *TI = newFunction->begin()->getTerminator(); TerminatorInst *TI = newFunction->begin()->getTerminator();
GetElementPtrInst *GEP = new GetElementPtrInst(AI, Idx, Idx+2, GetElementPtrInst *GEP = GetElementPtrInst::Create(AI, Idx, Idx+2,
GEPname, TI); GEPname, TI);
RewriteVal = new LoadInst(GEP, "load" + GEPname, TI); RewriteVal = new LoadInst(GEP, "load" + GEPname, TI);
} else } else
RewriteVal = AI++; RewriteVal = AI++;
@ -386,8 +386,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty, i); Idx[1] = ConstantInt::get(Type::Int32Ty, i);
GetElementPtrInst *GEP = GetElementPtrInst *GEP =
new GetElementPtrInst(Struct, Idx, Idx + 2, GetElementPtrInst::Create(Struct, Idx, Idx + 2,
"gep_" + StructValues[i]->getName()); "gep_" + StructValues[i]->getName());
codeReplacer->getInstList().push_back(GEP); codeReplacer->getInstList().push_back(GEP);
StoreInst *SI = new StoreInst(StructValues[i], GEP); StoreInst *SI = new StoreInst(StructValues[i], GEP);
codeReplacer->getInstList().push_back(SI); codeReplacer->getInstList().push_back(SI);
@ -395,8 +395,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
} }
// Emit the call to the function // Emit the call to the function
CallInst *call = new CallInst(newFunction, params.begin(), params.end(), CallInst *call = CallInst::Create(newFunction, params.begin(), params.end(),
NumExitBlocks > 1 ? "targetBlock" : ""); NumExitBlocks > 1 ? "targetBlock" : "");
codeReplacer->getInstList().push_back(call); codeReplacer->getInstList().push_back(call);
Function::arg_iterator OutputArgBegin = newFunction->arg_begin(); Function::arg_iterator OutputArgBegin = newFunction->arg_begin();
@ -412,8 +412,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i); Idx[1] = ConstantInt::get(Type::Int32Ty, FirstOut + i);
GetElementPtrInst *GEP GetElementPtrInst *GEP
= new GetElementPtrInst(Struct, Idx, Idx + 2, = GetElementPtrInst::Create(Struct, Idx, Idx + 2,
"gep_reload_" + outputs[i]->getName()); "gep_reload_" + outputs[i]->getName());
codeReplacer->getInstList().push_back(GEP); codeReplacer->getInstList().push_back(GEP);
Output = GEP; Output = GEP;
} else { } else {
@ -431,8 +431,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// Now we can emit a switch statement using the call as a value. // Now we can emit a switch statement using the call as a value.
SwitchInst *TheSwitch = SwitchInst *TheSwitch =
new SwitchInst(ConstantInt::getNullValue(Type::Int16Ty), SwitchInst::Create(ConstantInt::getNullValue(Type::Int16Ty),
codeReplacer, 0, codeReplacer); codeReplacer, 0, codeReplacer);
// Since there may be multiple exits from the original region, make the new // Since there may be multiple exits from the original region, make the new
// function return an unsigned, switch on that number. This loop iterates // function return an unsigned, switch on that number. This loop iterates
@ -453,8 +453,8 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
if (!NewTarget) { if (!NewTarget) {
// If we don't already have an exit stub for this non-extracted // If we don't already have an exit stub for this non-extracted
// destination, create one now! // destination, create one now!
NewTarget = new BasicBlock(OldTarget->getName() + ".exitStub", NewTarget = BasicBlock::Create(OldTarget->getName() + ".exitStub",
newFunction); newFunction);
unsigned SuccNum = switchVal++; unsigned SuccNum = switchVal++;
Value *brVal = 0; Value *brVal = 0;
@ -469,7 +469,7 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
break; break;
} }
ReturnInst *NTRet = new ReturnInst(brVal, NewTarget); ReturnInst *NTRet = ReturnInst::Create(brVal, NewTarget);
// Update the switch instruction. // Update the switch instruction.
TheSwitch->addCase(ConstantInt::get(Type::Int16Ty, SuccNum), TheSwitch->addCase(ConstantInt::get(Type::Int16Ty, SuccNum),
@ -513,9 +513,9 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
Idx[0] = Constant::getNullValue(Type::Int32Ty); Idx[0] = Constant::getNullValue(Type::Int32Ty);
Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out); Idx[1] = ConstantInt::get(Type::Int32Ty,FirstOut+out);
GetElementPtrInst *GEP = GetElementPtrInst *GEP =
new GetElementPtrInst(OAI, Idx, Idx + 2, GetElementPtrInst::Create(OAI, Idx, Idx + 2,
"gep_" + outputs[out]->getName(), "gep_" + outputs[out]->getName(),
NTRet); NTRet);
new StoreInst(outputs[out], GEP, NTRet); new StoreInst(outputs[out], GEP, NTRet);
} else { } else {
new StoreInst(outputs[out], OAI, NTRet); new StoreInst(outputs[out], OAI, NTRet);
@ -541,14 +541,14 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
// Check if the function should return a value // Check if the function should return a value
if (OldFnRetTy == Type::VoidTy) { if (OldFnRetTy == Type::VoidTy) {
new ReturnInst(0, TheSwitch); // Return void ReturnInst::Create(0, TheSwitch); // Return void
} else if (OldFnRetTy == TheSwitch->getCondition()->getType()) { } else if (OldFnRetTy == TheSwitch->getCondition()->getType()) {
// return what we have // return what we have
new ReturnInst(TheSwitch->getCondition(), TheSwitch); ReturnInst::Create(TheSwitch->getCondition(), TheSwitch);
} else { } else {
// Otherwise we must have code extracted an unwind or something, just // Otherwise we must have code extracted an unwind or something, just
// return whatever we want. // return whatever we want.
new ReturnInst(Constant::getNullValue(OldFnRetTy), TheSwitch); ReturnInst::Create(Constant::getNullValue(OldFnRetTy), TheSwitch);
} }
TheSwitch->getParent()->getInstList().erase(TheSwitch); TheSwitch->getParent()->getInstList().erase(TheSwitch);
@ -556,12 +556,12 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
case 1: case 1:
// Only a single destination, change the switch into an unconditional // Only a single destination, change the switch into an unconditional
// branch. // branch.
new BranchInst(TheSwitch->getSuccessor(1), TheSwitch); BranchInst::Create(TheSwitch->getSuccessor(1), TheSwitch);
TheSwitch->getParent()->getInstList().erase(TheSwitch); TheSwitch->getParent()->getInstList().erase(TheSwitch);
break; break;
case 2: case 2:
new BranchInst(TheSwitch->getSuccessor(1), TheSwitch->getSuccessor(2), BranchInst::Create(TheSwitch->getSuccessor(1), TheSwitch->getSuccessor(2),
call, TheSwitch); call, TheSwitch);
TheSwitch->getParent()->getInstList().erase(TheSwitch); TheSwitch->getParent()->getInstList().erase(TheSwitch);
break; break;
default: default:
@ -641,12 +641,12 @@ ExtractCodeRegion(const std::vector<BasicBlock*> &code) {
Function *oldFunction = header->getParent(); Function *oldFunction = header->getParent();
// This takes place of the original loop // 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 // 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. // head of the region, but the entry node of a function cannot have preds.
BasicBlock *newFuncRoot = new BasicBlock("newFuncRoot"); BasicBlock *newFuncRoot = BasicBlock::Create("newFuncRoot");
newFuncRoot->getInstList().push_back(new BranchInst(header)); newFuncRoot->getInstList().push_back(BranchInst::Create(header));
// Find inputs to, outputs from the code region. // Find inputs to, outputs from the code region.
findInputsOutputs(inputs, outputs); findInputsOutputs(inputs, outputs);

View File

@ -84,9 +84,9 @@ static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock,
// of the old basic block. // of the old basic block.
SmallVector<Value*, 8> InvokeArgs(CI->op_begin()+1, CI->op_end()); SmallVector<Value*, 8> InvokeArgs(CI->op_begin()+1, CI->op_end());
InvokeInst *II = InvokeInst *II =
new InvokeInst(CI->getCalledValue(), Split, InvokeDest, InvokeInst::Create(CI->getCalledValue(), Split, InvokeDest,
InvokeArgs.begin(), InvokeArgs.end(), InvokeArgs.begin(), InvokeArgs.end(),
CI->getName(), BB->getTerminator()); CI->getName(), BB->getTerminator());
II->setCallingConv(CI->getCallingConv()); II->setCallingConv(CI->getCallingConv());
II->setParamAttrs(CI->getParamAttrs()); 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 // invoke site. Once this happens, we know that the unwind would cause
// a control transfer to the invoke exception destination, so we can // a control transfer to the invoke exception destination, so we can
// transform it into a direct branch to the exception destination. // transform it into a direct branch to the exception destination.
new BranchInst(InvokeDest, UI); BranchInst::Create(InvokeDest, UI);
// Delete the unwind instruction! // Delete the unwind instruction!
UI->getParent()->getInstList().pop_back(); 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) DestCast, SrcCast, Size, ConstantInt::get(Type::Int32Ty, 1)
}; };
CallInst *TheMemCpy = 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 we have a call graph, update it.
if (CG) { if (CG) {
@ -366,14 +366,14 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
} }
// Insert the llvm.stacksave. // Insert the llvm.stacksave.
CallInst *SavedPtr = new CallInst(StackSave, "savedstack", CallInst *SavedPtr = CallInst::Create(StackSave, "savedstack",
FirstNewBlock->begin()); FirstNewBlock->begin());
if (CG) CallerNode->addCalledFunction(SavedPtr, StackSaveCGN); if (CG) CallerNode->addCalledFunction(SavedPtr, StackSaveCGN);
// Insert a call to llvm.stackrestore before any return instructions in the // Insert a call to llvm.stackrestore before any return instructions in the
// inlined function. // inlined function.
for (unsigned i = 0, e = Returns.size(); i != e; ++i) { 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); 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(); for (Function::iterator BB = FirstNewBlock, E = Caller->end();
BB != E; ++BB) BB != E; ++BB)
if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->getTerminator())) { if (UnwindInst *UI = dyn_cast<UnwindInst>(BB->getTerminator())) {
new CallInst(StackRestore, SavedPtr, "", UI); CallInst::Create(StackRestore, SavedPtr, "", UI);
++NumStackRestores; ++NumStackRestores;
} }
} }
@ -428,7 +428,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
BB != E; ++BB) { BB != E; ++BB) {
TerminatorInst *Term = BB->getTerminator(); TerminatorInst *Term = BB->getTerminator();
if (isa<UnwindInst>(Term)) { if (isa<UnwindInst>(Term)) {
new BranchInst(UnwindBB, Term); BranchInst::Create(UnwindBB, Term);
BB->getInstList().erase(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 // If the call site was an invoke instruction, add a branch to the normal
// destination. // destination.
if (InvokeInst *II = dyn_cast<InvokeInst>(TheCall)) 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 // If the return instruction returned a value, replace uses of the call with
// uses of the returned value. // 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)) { if (InvokeInst *II = dyn_cast<InvokeInst>(TheCall)) {
// Add an unconditional branch to make this look like the CallInst case... // 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 // 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 // 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. // match corresponding return value operand number.
Instruction *InsertPt = AfterCallBB->begin(); Instruction *InsertPt = AfterCallBB->begin();
for (unsigned i = 0; i < NumRetVals; ++i) { for (unsigned i = 0; i < NumRetVals; ++i) {
PHINode *PHI = new PHINode(STy->getElementType(i), PHINode *PHI = PHINode::Create(STy->getElementType(i),
TheCall->getName() + "." + utostr(i), TheCall->getName() + "." + utostr(i),
InsertPt); InsertPt);
PHIs.push_back(PHI); PHIs.push_back(PHI);
} }
// TheCall results are used by GetResult instructions. // TheCall results are used by GetResult instructions.
@ -547,7 +547,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
GR->eraseFromParent(); GR->eraseFromParent();
} }
} else { } else {
PHINode *PHI = new PHINode(RTy, TheCall->getName(), AfterCallBB->begin()); PHINode *PHI = PHINode::Create(RTy, TheCall->getName(), AfterCallBB->begin());
PHIs.push_back(PHI); PHIs.push_back(PHI);
// Anything that used the result of the function call should now use the // Anything that used the result of the function call should now use the
// PHI node as their operand. // 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. // Add a branch to the merge points and remove retrun instructions.
for (unsigned i = 0, e = Returns.size(); i != e; ++i) { for (unsigned i = 0, e = Returns.size(); i != e; ++i) {
ReturnInst *RI = Returns[i]; ReturnInst *RI = Returns[i];
new BranchInst(AfterCallBB, RI); BranchInst::Create(AfterCallBB, RI);
RI->eraseFromParent(); RI->eraseFromParent();
} }
} else if (!Returns.empty()) { } else if (!Returns.empty()) {

View File

@ -155,8 +155,8 @@ void LCSSA::ProcessInstruction(Instruction *Instr,
DomTreeNode *ExitBBNode = DT->getNode(BB); DomTreeNode *ExitBBNode = DT->getNode(BB);
Value *&Phi = Phis[ExitBBNode]; Value *&Phi = Phis[ExitBBNode];
if (!Phi && DT->dominates(InstrNode, ExitBBNode)) { if (!Phi && DT->dominates(InstrNode, ExitBBNode)) {
PHINode *PN = new PHINode(Instr->getType(), Instr->getName()+".lcssa", PHINode *PN = PHINode::Create(Instr->getType(), Instr->getName()+".lcssa",
BB->begin()); BB->begin());
PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB))); PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB)));
// Remember that this phi makes the value alive in this block. // 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 // 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. // now, then get values to fill in the incoming values for the PHI.
PHINode *PN = new PHINode(OrigInst->getType(), OrigInst->getName()+".lcssa", PHINode *PN = PHINode::Create(OrigInst->getType(), OrigInst->getName()+".lcssa",
BBN->begin()); BBN->begin());
PN->reserveOperandSpace(std::distance(pred_begin(BBN), pred_end(BBN))); PN->reserveOperandSpace(std::distance(pred_begin(BBN), pred_end(BBN)));
V = PN; V = PN;

View File

@ -134,7 +134,7 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB) {
// now. // now.
if (TheOnlyDest) { if (TheOnlyDest) {
// Insert the new branch.. // Insert the new branch..
new BranchInst(TheOnlyDest, SI); BranchInst::Create(TheOnlyDest, SI);
BasicBlock *BB = SI->getParent(); BasicBlock *BB = SI->getParent();
// Remove entries from PHI nodes which we no longer branch to... // 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(), Value *Cond = new ICmpInst(ICmpInst::ICMP_EQ, SI->getCondition(),
SI->getSuccessorValue(1), "cond", SI); SI->getSuccessorValue(1), "cond", SI);
// Insert the new branch... // 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... // Delete the old switch...
SI->getParent()->getInstList().erase(SI); SI->getParent()->getInstList().erase(SI);

View File

@ -270,10 +270,10 @@ BasicBlock *LoopSimplify::SplitBlockPredecessors(BasicBlock *BB,
const std::vector<BasicBlock*> &Preds) { const std::vector<BasicBlock*> &Preds) {
// Create new basic block, insert right before the original block... // 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... // 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 // 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 // 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 the values coming into the block are not the same, we need a PHI.
if (InVal == 0) { if (InVal == 0) {
// Create the new PHI node, insert it into NewBB at the end of the block // 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); if (AA) AA->copyValue(PN, NewPHI);
// Move all of the edges from blocks outside the loop to the new PHI // 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); if (*I != Preheader) BackedgeBlocks.push_back(*I);
// Create and insert the new backedge block... // Create and insert the new backedge block...
BasicBlock *BEBlock = new BasicBlock(Header->getName()+".backedge", F); BasicBlock *BEBlock = BasicBlock::Create(Header->getName()+".backedge", F);
BranchInst *BETerminator = new BranchInst(Header, BEBlock); BranchInst *BETerminator = BranchInst::Create(Header, BEBlock);
// Move the new backedge block to right after the last backedge block. // Move the new backedge block to right after the last backedge block.
Function::iterator InsertPos = BackedgeBlocks.back(); ++InsertPos; 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. // the backedge block which correspond to any PHI nodes in the header block.
for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) { for (BasicBlock::iterator I = Header->begin(); isa<PHINode>(I); ++I) {
PHINode *PN = cast<PHINode>(I); PHINode *PN = cast<PHINode>(I);
PHINode *NewPN = new PHINode(PN->getType(), PN->getName()+".be", PHINode *NewPN = PHINode::Create(PN->getType(), PN->getName()+".be",
BETerminator); BETerminator);
NewPN->reserveOperandSpace(BackedgeBlocks.size()); NewPN->reserveOperandSpace(BackedgeBlocks.size());
if (AA) AA->copyValue(PN, NewPN); if (AA) AA->copyValue(PN, NewPN);

View File

@ -141,7 +141,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
} }
// Create the call to Malloc. // Create the call to Malloc.
CallInst *MCall = new CallInst(MallocFunc, MallocArg, "", I); CallInst *MCall = CallInst::Create(MallocFunc, MallocArg, "", I);
MCall->setTailCall(); MCall->setTailCall();
// Create a cast instruction to convert to the right type... // Create a cast instruction to convert to the right type...
@ -162,7 +162,7 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
PointerType::getUnqual(Type::Int8Ty), "", I); PointerType::getUnqual(Type::Int8Ty), "", I);
// Insert a call to the free function... // Insert a call to the free function...
(new CallInst(FreeFunc, PtrCast, "", I))->setTailCall(); CallInst::Create(FreeFunc, PtrCast, "", I)->setTailCall();
// Delete the old free instruction // Delete the old free instruction
I = --BBIL.erase(I); I = --BBIL.erase(I);

View File

@ -211,15 +211,15 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) { if (InvokeInst *II = dyn_cast<InvokeInst>(BB->getTerminator())) {
std::vector<Value*> CallArgs(II->op_begin()+3, II->op_end()); std::vector<Value*> CallArgs(II->op_begin()+3, II->op_end());
// Insert a normal call instruction... // Insert a normal call instruction...
CallInst *NewCall = new CallInst(II->getCalledValue(), CallInst *NewCall = CallInst::Create(II->getCalledValue(),
CallArgs.begin(), CallArgs.end(), "",II); CallArgs.begin(), CallArgs.end(), "",II);
NewCall->takeName(II); NewCall->takeName(II);
NewCall->setCallingConv(II->getCallingConv()); NewCall->setCallingConv(II->getCallingConv());
NewCall->setParamAttrs(II->getParamAttrs()); NewCall->setParamAttrs(II->getParamAttrs());
II->replaceAllUsesWith(NewCall); II->replaceAllUsesWith(NewCall);
// Insert an unconditional branch to the normal destination. // 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. // Remove any PHI node entries from the exception destination.
II->getUnwindDest()->removePredecessor(BB); II->getUnwindDest()->removePredecessor(BB);
@ -233,12 +233,12 @@ bool LowerInvoke::insertCheapEHSupport(Function &F) {
writeAbortMessage(UI); writeAbortMessage(UI);
// Insert a call to abort() // 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 // Insert a return instruction. This really should be a "barrier", as it
// is unreachable. // is unreachable.
new ReturnInst(F.getReturnType() == Type::VoidTy ? 0 : ReturnInst::Create(F.getReturnType() == Type::VoidTy ? 0 :
Constant::getNullValue(F.getReturnType()), UI); Constant::getNullValue(F.getReturnType()), UI);
// Remove the unwind instruction now. // Remove the unwind instruction now.
BB->getInstList().erase(UI); BB->getInstList().erase(UI);
@ -280,16 +280,16 @@ void LowerInvoke::rewriteExpensiveInvoke(InvokeInst *II, unsigned InvokeNo,
// Insert a normal call instruction. // Insert a normal call instruction.
std::vector<Value*> CallArgs(II->op_begin()+3, II->op_end()); std::vector<Value*> CallArgs(II->op_begin()+3, II->op_end());
CallInst *NewCall = new CallInst(II->getCalledValue(), CallInst *NewCall = CallInst::Create(II->getCalledValue(),
CallArgs.begin(), CallArgs.end(), "", CallArgs.begin(), CallArgs.end(), "",
II); II);
NewCall->takeName(II); NewCall->takeName(II);
NewCall->setCallingConv(II->getCallingConv()); NewCall->setCallingConv(II->getCallingConv());
NewCall->setParamAttrs(II->getParamAttrs()); NewCall->setParamAttrs(II->getParamAttrs());
II->replaceAllUsesWith(NewCall); II->replaceAllUsesWith(NewCall);
// Replace the invoke with an uncond branch. // Replace the invoke with an uncond branch.
new BranchInst(II->getNormalDest(), NewCall->getParent()); BranchInst::Create(II->getNormalDest(), NewCall->getParent());
II->eraseFromParent(); II->eraseFromParent();
} }
@ -463,8 +463,8 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
std::vector<Value*> Idx; std::vector<Value*> Idx;
Idx.push_back(Constant::getNullValue(Type::Int32Ty)); Idx.push_back(Constant::getNullValue(Type::Int32Ty));
Idx.push_back(ConstantInt::get(Type::Int32Ty, 1)); Idx.push_back(ConstantInt::get(Type::Int32Ty, 1));
OldJmpBufPtr = new GetElementPtrInst(JmpBuf, Idx.begin(), Idx.end(), OldJmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
"OldBuf", EntryBB->getTerminator()); "OldBuf", EntryBB->getTerminator());
// Copy the JBListHead to the alloca. // Copy the JBListHead to the alloca.
Value *OldBuf = new LoadInst(JBListHead, "oldjmpbufptr", true, 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 // Create the catch block. The catch block is basically a big switch
// statement that goes to all of the invoke catch blocks. // 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 // Create an alloca which keeps track of which invoke is currently
// executing. For normal calls it contains zero. // 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, // 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 // we go to a block that just does an unwind (which is the correct action
// for a standard call). // for a standard call).
BasicBlock *UnwindBB = new BasicBlock("unwindbb", &F); BasicBlock *UnwindBB = BasicBlock::Create("unwindbb", &F);
Unwinds.push_back(new UnwindInst(UnwindBB)); Unwinds.push_back(new UnwindInst(UnwindBB));
Value *CatchLoad = new LoadInst(InvokeNum, "invoke.num", true, CatchBB); Value *CatchLoad = new LoadInst(InvokeNum, "invoke.num", true, CatchBB);
SwitchInst *CatchSwitch = SwitchInst *CatchSwitch =
new SwitchInst(CatchLoad, UnwindBB, Invokes.size(), CatchBB); SwitchInst::Create(CatchLoad, UnwindBB, Invokes.size(), CatchBB);
// Now that things are set up, insert the setjmp call itself. // Now that things are set up, insert the setjmp call itself.
@ -502,11 +502,11 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
"setjmp.cont"); "setjmp.cont");
Idx[1] = ConstantInt::get(Type::Int32Ty, 0); Idx[1] = ConstantInt::get(Type::Int32Ty, 0);
Value *JmpBufPtr = new GetElementPtrInst(JmpBuf, Idx.begin(), Idx.end(), Value *JmpBufPtr = GetElementPtrInst::Create(JmpBuf, Idx.begin(), Idx.end(),
"TheJmpBuf", "TheJmpBuf",
EntryBB->getTerminator()); EntryBB->getTerminator());
Value *SJRet = new CallInst(SetJmpFn, JmpBufPtr, "sjret", Value *SJRet = CallInst::Create(SetJmpFn, JmpBufPtr, "sjret",
EntryBB->getTerminator()); EntryBB->getTerminator());
// Compare the return value to zero. // Compare the return value to zero.
Value *IsNormal = new ICmpInst(ICmpInst::ICMP_EQ, SJRet, Value *IsNormal = new ICmpInst(ICmpInst::ICMP_EQ, SJRet,
@ -516,7 +516,7 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
EntryBB->getTerminator()->eraseFromParent(); EntryBB->getTerminator()->eraseFromParent();
// Put in a new condbranch in its place. // 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. // At this point, we are all set up, rewrite each invoke instruction.
for (unsigned i = 0, e = Invokes.size(); i != e; ++i) 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 // 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 // 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. // is null. Add them at the end of the function because they are not hot.
BasicBlock *UnwindHandler = new BasicBlock("dounwind", &F); BasicBlock *UnwindHandler = BasicBlock::Create("dounwind", &F);
BasicBlock *UnwindBlock = new BasicBlock("unwind", &F); BasicBlock *UnwindBlock = BasicBlock::Create("unwind", &F);
BasicBlock *TermBlock = new BasicBlock("unwinderror", &F); BasicBlock *TermBlock = BasicBlock::Create("unwinderror", &F);
// If this function contains an invoke, restore the old jumpbuf ptr. // If this function contains an invoke, restore the old jumpbuf ptr.
Value *BufPtr; Value *BufPtr;
@ -546,17 +546,17 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
Value *NotNull = new ICmpInst(ICmpInst::ICMP_NE, BufPtr, Value *NotNull = new ICmpInst(ICmpInst::ICMP_NE, BufPtr,
Constant::getNullValue(BufPtr->getType()), Constant::getNullValue(BufPtr->getType()),
"notnull", UnwindHandler); "notnull", UnwindHandler);
new BranchInst(UnwindBlock, TermBlock, NotNull, UnwindHandler); BranchInst::Create(UnwindBlock, TermBlock, NotNull, UnwindHandler);
// Create the block to do the longjmp. // Create the block to do the longjmp.
// Get a pointer to the jmpbuf and longjmp. // Get a pointer to the jmpbuf and longjmp.
std::vector<Value*> Idx; std::vector<Value*> Idx;
Idx.push_back(Constant::getNullValue(Type::Int32Ty)); Idx.push_back(Constant::getNullValue(Type::Int32Ty));
Idx.push_back(ConstantInt::get(Type::Int32Ty, 0)); Idx.push_back(ConstantInt::get(Type::Int32Ty, 0));
Idx[0] = new GetElementPtrInst(BufPtr, Idx.begin(), Idx.end(), "JmpBuf", Idx[0] = GetElementPtrInst::Create(BufPtr, Idx.begin(), Idx.end(), "JmpBuf",
UnwindBlock); UnwindBlock);
Idx[1] = ConstantInt::get(Type::Int32Ty, 1); 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); new UnreachableInst(UnwindBlock);
// Set up the term block ("throw without a catch"). // Set up the term block ("throw without a catch").
@ -566,13 +566,13 @@ bool LowerInvoke::insertExpensiveEHSupport(Function &F) {
writeAbortMessage(TermBlock->getTerminator()); writeAbortMessage(TermBlock->getTerminator());
// Insert a call to abort() // Insert a call to abort()
(new CallInst(AbortFn, "", CallInst::Create(AbortFn, "",
TermBlock->getTerminator()))->setTailCall(); TermBlock->getTerminator())->setTailCall();
// Replace all unwinds with a branch to the unwind handler. // Replace all unwinds with a branch to the unwind handler.
for (unsigned i = 0, e = Unwinds.size(); i != e; ++i) { for (unsigned i = 0, e = Unwinds.size(); i != e; ++i) {
new BranchInst(UnwindHandler, Unwinds[i]); BranchInst::Create(UnwindHandler, Unwinds[i]);
Unwinds[i]->eraseFromParent(); Unwinds[i]->eraseFromParent();
} }

View File

@ -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 // Create a new node that checks if the value is < pivot. Go to the
// left branch if it is and right branch if not. // left branch if it is and right branch if not.
Function* F = OrigBlock->getParent(); Function* F = OrigBlock->getParent();
BasicBlock* NewNode = new BasicBlock("NodeBlock"); BasicBlock* NewNode = BasicBlock::Create("NodeBlock");
Function::iterator FI = OrigBlock; Function::iterator FI = OrigBlock;
F->getBasicBlockList().insert(++FI, NewNode); F->getBasicBlockList().insert(++FI, NewNode);
ICmpInst* Comp = new ICmpInst(ICmpInst::ICMP_SLT, Val, Pivot.Low, "Pivot"); ICmpInst* Comp = new ICmpInst(ICmpInst::ICMP_SLT, Val, Pivot.Low, "Pivot");
NewNode->getInstList().push_back(Comp); NewNode->getInstList().push_back(Comp);
new BranchInst(LBranch, RBranch, Comp, NewNode); BranchInst::Create(LBranch, RBranch, Comp, NewNode);
return NewNode; return NewNode;
} }
@ -179,7 +179,7 @@ BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val,
BasicBlock* Default) BasicBlock* Default)
{ {
Function* F = OrigBlock->getParent(); Function* F = OrigBlock->getParent();
BasicBlock* NewLeaf = new BasicBlock("LeafBlock"); BasicBlock* NewLeaf = BasicBlock::Create("LeafBlock");
Function::iterator FI = OrigBlock; Function::iterator FI = OrigBlock;
F->getBasicBlockList().insert(++FI, NewLeaf); F->getBasicBlockList().insert(++FI, NewLeaf);
@ -213,7 +213,7 @@ BasicBlock* LowerSwitch::newLeafBlock(CaseRange& Leaf, Value* Val,
// Make the conditional branch... // Make the conditional branch...
BasicBlock* Succ = Leaf.BB; 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 // If there were any PHI nodes in this successor, rewrite one entry
// from OrigBlock to come from NewLeaf. // 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 there is only the default destination, don't bother with the code below.
if (SI->getNumOperands() == 2) { if (SI->getNumOperands() == 2) {
new BranchInst(SI->getDefaultDest(), CurBlock); BranchInst::Create(SI->getDefaultDest(), CurBlock);
CurBlock->getInstList().erase(SI); CurBlock->getInstList().erase(SI);
return; return;
} }
// Create a new, empty default block so that the new hierarchy of // Create a new, empty default block so that the new hierarchy of
// if-then statements go to this and the PHI nodes are happy. // 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); 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 // If there is an entry in any PHI nodes for the default edge, make sure
// to update them as well. // to update them as well.
@ -317,7 +317,7 @@ void LowerSwitch::processSwitchInst(SwitchInst *SI) {
OrigBlock, NewDefault); OrigBlock, NewDefault);
// Branch to our shiny new if-then stuff... // 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. // We are now done with the switch instruction, delete it.
CurBlock->getInstList().erase(SI); CurBlock->getInstList().erase(SI);

View File

@ -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 // Create a PhiNode using the dereferenced type... and add the phi-node to the
// BasicBlock. // BasicBlock.
PN = new PHINode(Allocas[AllocaNo]->getAllocatedType(), PN = PHINode::Create(Allocas[AllocaNo]->getAllocatedType(),
Allocas[AllocaNo]->getName() + "." + Allocas[AllocaNo]->getName() + "." +
utostr(Version++), BB->begin()); utostr(Version++), BB->begin());
++NumPHIInsert; ++NumPHIInsert;
PhiToAllocaMap[PN] = AllocaNo; PhiToAllocaMap[PN] = AllocaNo;
PN->reserveOperandSpace(getNumPreds(BB)); PN->reserveOperandSpace(getNumPreds(BB));

View File

@ -619,7 +619,7 @@ static bool SimplifyEqualityComparisonWithOnlyPredecessor(TerminatorInst *TI,
assert(ThisCases.size() == 1 && "Branch can only have one case!"); assert(ThisCases.size() == 1 && "Branch can only have one case!");
Value *Cond = BTI->getCondition(); Value *Cond = BTI->getCondition();
// Insert the new branch. // Insert the new branch.
Instruction *NI = new BranchInst(ThisDef, TI); Instruction *NI = BranchInst::Create(ThisDef, TI);
// Remove PHI node entries for the dead edge. // Remove PHI node entries for the dead edge.
ThisCases[0].second->removePredecessor(TI->getParent()); ThisCases[0].second->removePredecessor(TI->getParent());
@ -689,7 +689,7 @@ static bool SimplifyEqualityComparisonWithOnlyPredecessor(TerminatorInst *TI,
CheckEdge = 0; CheckEdge = 0;
// Insert the new branch. // Insert the new branch.
Instruction *NI = new BranchInst(TheRealDest, TI); Instruction *NI = BranchInst::Create(TheRealDest, TI);
DOUT << "Threading pred instr: " << *Pred->getTerminator() DOUT << "Threading pred instr: " << *Pred->getTerminator()
<< "Through successor TI: " << *TI << "Leaving: " << *NI << "\n"; << "Through successor TI: " << *TI << "Leaving: " << *NI << "\n";
@ -802,7 +802,7 @@ static bool FoldValueComparisonIntoPredecessors(TerminatorInst *TI) {
AddPredecessorToBlock(NewSuccessors[i], Pred, BB); AddPredecessorToBlock(NewSuccessors[i], Pred, BB);
// Now that the successors are updated, create the new Switch instruction. // 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) for (unsigned i = 0, e = PredCases.size(); i != e; ++i)
NewSI->addCase(PredCases[i].first, PredCases[i].second); NewSI->addCase(PredCases[i].first, PredCases[i].second);
@ -824,8 +824,8 @@ static bool FoldValueComparisonIntoPredecessors(TerminatorInst *TI) {
if (InfLoopBlock == 0) { if (InfLoopBlock == 0) {
// Insert it at the end of the loop, because it's either code, // Insert it at the end of the loop, because it's either code,
// or it won't matter if it's hot. :) // or it won't matter if it's hot. :)
InfLoopBlock = new BasicBlock("infloop", BB->getParent()); InfLoopBlock = BasicBlock::Create("infloop", BB->getParent());
new BranchInst(InfLoopBlock, InfLoopBlock); BranchInst::Create(InfLoopBlock, InfLoopBlock);
} }
NewSI->setSuccessor(i, InfLoopBlock); NewSI->setSuccessor(i, InfLoopBlock);
} }
@ -902,8 +902,8 @@ HoistTerminator:
// that determines the right value. // that determines the right value.
SelectInst *&SI = InsertedSelects[std::make_pair(BB1V, BB2V)]; SelectInst *&SI = InsertedSelects[std::make_pair(BB1V, BB2V)];
if (SI == 0) if (SI == 0)
SI = new SelectInst(BI->getCondition(), BB1V, BB2V, SI = SelectInst::Create(BI->getCondition(), BB1V, BB2V,
BB1V->getName()+"."+BB2V->getName(), NT); BB1V->getName()+"."+BB2V->getName(), NT);
// Make the PHI node use the select for all incoming values for BB1/BB2 // Make the PHI node use the select for all incoming values for BB1/BB2
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
if (PN->getIncomingBlock(i) == BB1 || PN->getIncomingBlock(i) == BB2) 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 // difficult cases. Instead of being smart about this, just insert a new
// block that jumps to the destination block, effectively splitting // block that jumps to the destination block, effectively splitting
// the edge we are about to create. // the edge we are about to create.
BasicBlock *EdgeBB = new BasicBlock(RealDest->getName()+".critedge", BasicBlock *EdgeBB = BasicBlock::Create(RealDest->getName()+".critedge",
RealDest->getParent(), RealDest); RealDest->getParent(), RealDest);
new BranchInst(RealDest, EdgeBB); BranchInst::Create(RealDest, EdgeBB);
PHINode *PN; PHINode *PN;
for (BasicBlock::iterator BBI = RealDest->begin(); for (BasicBlock::iterator BBI = RealDest->begin();
(PN = dyn_cast<PHINode>(BBI)); ++BBI) { (PN = dyn_cast<PHINode>(BBI)); ++BBI) {
@ -1156,7 +1156,7 @@ static bool FoldTwoEntryPHINode(PHINode *PN) {
Value *FalseVal = Value *FalseVal =
PN->getIncomingValue(PN->getIncomingBlock(0) == IfTrue); 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); PN->replaceAllUsesWith(NV);
NV->takeName(PN); NV->takeName(PN);
@ -1307,7 +1307,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
if (RI->getNumOperands() == 0) { if (RI->getNumOperands() == 0) {
TrueSucc->removePredecessor(BI->getParent()); TrueSucc->removePredecessor(BI->getParent());
FalseSucc->removePredecessor(BI->getParent()); FalseSucc->removePredecessor(BI->getParent());
new ReturnInst(0, BI); ReturnInst::Create(0, BI);
BI->getParent()->getInstList().erase(BI); BI->getParent()->getInstList().erase(BI);
return true; return true;
} }
@ -1341,8 +1341,8 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
Value *NewRetVal; Value *NewRetVal;
Value *BrCond = BI->getCondition(); Value *BrCond = BI->getCondition();
if (TrueValue != FalseValue) if (TrueValue != FalseValue)
NewRetVal = new SelectInst(BrCond, TrueValue, NewRetVal = SelectInst::Create(BrCond, TrueValue,
FalseValue, "retval", BI); FalseValue, "retval", BI);
else else
NewRetVal = TrueValue; NewRetVal = TrueValue;
@ -1350,7 +1350,7 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
<< "\n " << *BI << "Select = " << *NewRetVal << "\n " << *BI << "Select = " << *NewRetVal
<< "TRUEBLOCK: " << *TrueSucc << "FALSEBLOCK: "<< *FalseSucc; << "TRUEBLOCK: " << *TrueSucc << "FALSEBLOCK: "<< *FalseSucc;
new ReturnInst(NewRetVal, BI); ReturnInst::Create(NewRetVal, BI);
BI->eraseFromParent(); BI->eraseFromParent();
if (Instruction *BrCondI = dyn_cast<Instruction>(BrCond)) if (Instruction *BrCondI = dyn_cast<Instruction>(BrCond))
if (isInstructionTriviallyDead(BrCondI)) if (isInstructionTriviallyDead(BrCondI))
@ -1386,13 +1386,13 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
if (II->getUnwindDest() == BB) { if (II->getUnwindDest() == BB) {
// Insert a new branch instruction before the invoke, because this // Insert a new branch instruction before the invoke, because this
// is now a fall through... // 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 Pred->getInstList().remove(II); // Take out of symbol table
// Insert the call now... // Insert the call now...
SmallVector<Value*,8> Args(II->op_begin()+3, II->op_end()); SmallVector<Value*,8> Args(II->op_begin()+3, II->op_end());
CallInst *CI = new CallInst(II->getCalledValue(), CallInst *CI = CallInst::Create(II->getCalledValue(),
Args.begin(), Args.end(), II->getName(), BI); Args.begin(), Args.end(), II->getName(), BI);
CI->setCallingConv(II->getCallingConv()); CI->setCallingConv(II->getCallingConv());
CI->setParamAttrs(II->getParamAttrs()); CI->setParamAttrs(II->getParamAttrs());
// If the invoke produced a value, the Call now does instead // 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 // Otherwise, if there are multiple predecessors, insert a PHI
// that merges in the constant and simplify the block result. // that merges in the constant and simplify the block result.
if (BlockIsSimpleEnoughToThreadThrough(BB)) { if (BlockIsSimpleEnoughToThreadThrough(BB)) {
PHINode *NewPN = new PHINode(Type::Int1Ty, PHINode *NewPN = PHINode::Create(Type::Int1Ty,
BI->getCondition()->getName()+".pr", BI->getCondition()->getName()+".pr",
BB->begin()); BB->begin());
for (PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) for (PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
if ((PBI = dyn_cast<BranchInst>((*PI)->getTerminator())) && if ((PBI = dyn_cast<BranchInst>((*PI)->getTerminator())) &&
PBI != BI && PBI->isConditional() && PBI != BI && PBI->isConditional() &&
@ -1661,8 +1661,8 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
Value *PBIV = PN->getIncomingValue(PBBIdx); Value *PBIV = PN->getIncomingValue(PBBIdx);
if (BIV != PBIV) { if (BIV != PBIV) {
// Insert a select in PBI to pick the right value. // Insert a select in PBI to pick the right value.
Value *NV = new SelectInst(PBICond, PBIV, BIV, Value *NV = SelectInst::Create(PBICond, PBIV, BIV,
PBIV->getName()+".mux", PBI); PBIV->getName()+".mux", PBI);
PN->setIncomingValue(PBBIdx, NV); PN->setIncomingValue(PBBIdx, NV);
} }
} }
@ -1705,10 +1705,10 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
} }
} else { } else {
if (BI->getSuccessor(0) == BB) { if (BI->getSuccessor(0) == BB) {
new BranchInst(BI->getSuccessor(1), BI); BranchInst::Create(BI->getSuccessor(1), BI);
BI->eraseFromParent(); BI->eraseFromParent();
} else if (BI->getSuccessor(1) == BB) { } else if (BI->getSuccessor(1) == BB) {
new BranchInst(BI->getSuccessor(0), BI); BranchInst::Create(BI->getSuccessor(0), BI);
BI->eraseFromParent(); BI->eraseFromParent();
Changed = true; Changed = true;
} }
@ -1761,14 +1761,14 @@ bool llvm::SimplifyCFG(BasicBlock *BB) {
if (II->getUnwindDest() == BB) { if (II->getUnwindDest() == BB) {
// Convert the invoke to a call instruction. This would be a good // Convert the invoke to a call instruction. This would be a good
// place to note that the call does not throw though. // 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 II->removeFromParent(); // Take out of symbol table
// Insert the call now... // Insert the call now...
SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end()); SmallVector<Value*, 8> Args(II->op_begin()+3, II->op_end());
CallInst *CI = new CallInst(II->getCalledValue(), CallInst *CI = CallInst::Create(II->getCalledValue(),
Args.begin(), Args.end(), Args.begin(), Args.end(),
II->getName(), BI); II->getName(), BI);
CI->setCallingConv(II->getCallingConv()); CI->setCallingConv(II->getCallingConv());
CI->setParamAttrs(II->getParamAttrs()); CI->setParamAttrs(II->getParamAttrs());
// If the invoke produced a value, the Call does now instead. // 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); if (!TrueWhenEqual) std::swap(DefaultBB, EdgeBB);
// Create the new switch instruction now. // 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. // Add all of the 'cases' to the switch instruction.
for (unsigned i = 0, e = Values.size(); i != e; ++i) for (unsigned i = 0, e = Values.size(); i != e; ++i)

View File

@ -69,14 +69,14 @@ bool UnifyFunctionExitNodes::runOnFunction(Function &F) {
} else if (UnwindingBlocks.size() == 1) { } else if (UnwindingBlocks.size() == 1) {
UnwindBlock = UnwindingBlocks.front(); UnwindBlock = UnwindingBlocks.front();
} else { } else {
UnwindBlock = new BasicBlock("UnifiedUnwindBlock", &F); UnwindBlock = BasicBlock::Create("UnifiedUnwindBlock", &F);
new UnwindInst(UnwindBlock); new UnwindInst(UnwindBlock);
for (std::vector<BasicBlock*>::iterator I = UnwindingBlocks.begin(), for (std::vector<BasicBlock*>::iterator I = UnwindingBlocks.begin(),
E = UnwindingBlocks.end(); I != E; ++I) { E = UnwindingBlocks.end(); I != E; ++I) {
BasicBlock *BB = *I; BasicBlock *BB = *I;
BB->getInstList().pop_back(); // Remove the unwind insn 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) { } else if (UnreachableBlocks.size() == 1) {
UnreachableBlock = UnreachableBlocks.front(); UnreachableBlock = UnreachableBlocks.front();
} else { } else {
UnreachableBlock = new BasicBlock("UnifiedUnreachableBlock", &F); UnreachableBlock = BasicBlock::Create("UnifiedUnreachableBlock", &F);
new UnreachableInst(UnreachableBlock); new UnreachableInst(UnreachableBlock);
for (std::vector<BasicBlock*>::iterator I = UnreachableBlocks.begin(), for (std::vector<BasicBlock*>::iterator I = UnreachableBlocks.begin(),
E = UnreachableBlocks.end(); I != E; ++I) { E = UnreachableBlocks.end(); I != E; ++I) {
BasicBlock *BB = *I; BasicBlock *BB = *I;
BB->getInstList().pop_back(); // Remove the unreachable inst. 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 // nodes (if the function returns values), and convert all of the return
// instructions into unconditional branches. // instructions into unconditional branches.
// //
BasicBlock *NewRetBlock = new BasicBlock("UnifiedReturnBlock", &F); BasicBlock *NewRetBlock = BasicBlock::Create("UnifiedReturnBlock", &F);
SmallVector<Value *, 4> Phis; SmallVector<Value *, 4> Phis;
unsigned NumRetVals = ReturningBlocks[0]->getTerminator()->getNumOperands(); unsigned NumRetVals = ReturningBlocks[0]->getTerminator()->getNumOperands();
if (NumRetVals == 0) if (NumRetVals == 0)
new ReturnInst(NULL, NewRetBlock); ReturnInst::Create(NULL, NewRetBlock);
else if (const StructType *STy = dyn_cast<StructType>(F.getReturnType())) { else if (const StructType *STy = dyn_cast<StructType>(F.getReturnType())) {
Instruction *InsertPt = NewRetBlock->getFirstNonPHI(); Instruction *InsertPt = NewRetBlock->getFirstNonPHI();
for (unsigned i = 0; i < NumRetVals; ++i) { for (unsigned i = 0; i < NumRetVals; ++i) {
PHINode *PN = new PHINode(STy->getElementType(i), "UnifiedRetVal." PHINode *PN = PHINode::Create(STy->getElementType(i), "UnifiedRetVal."
+ utostr(i), InsertPt); + utostr(i), InsertPt);
Phis.push_back(PN); Phis.push_back(PN);
} }
new ReturnInst(&Phis[0], NumRetVals); ReturnInst::Create(&Phis[0], NumRetVals);
} }
else { else {
// If the function doesn't return void... add a PHI node to the block... // 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); NewRetBlock->getInstList().push_back(PN);
Phis.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 // 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 BB->getInstList().pop_back(); // Remove the return insn
new BranchInst(NewRetBlock, BB); BranchInst::Create(NewRetBlock, BB);
} }
ReturnBlock = NewRetBlock; ReturnBlock = NewRetBlock;
return true; return true;

View File

@ -216,7 +216,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
return; return;
} }
switch(NewFn->getIntrinsicID()) { switch (NewFn->getIntrinsicID()) {
default: assert(0 && "Unknown function for CallInst upgrade."); default: assert(0 && "Unknown function for CallInst upgrade.");
case Intrinsic::x86_mmx_psll_d: case Intrinsic::x86_mmx_psll_d:
case Intrinsic::x86_mmx_psll_q: case Intrinsic::x86_mmx_psll_q:
@ -237,8 +237,8 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
Operands[1] = BC; Operands[1] = BC;
// Construct a new CallInst // Construct a new CallInst
CallInst *NewCI = new CallInst(NewFn, Operands, Operands+2, CallInst *NewCI = CallInst::Create(NewFn, Operands, Operands+2,
"upgraded."+CI->getName(), CI); "upgraded."+CI->getName(), CI);
NewCI->setTailCall(CI->isTailCall()); NewCI->setTailCall(CI->isTailCall());
NewCI->setCallingConv(CI->getCallingConv()); NewCI->setCallingConv(CI->getCallingConv());
@ -254,14 +254,14 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
} }
case Intrinsic::ctlz: case Intrinsic::ctlz:
case Intrinsic::ctpop: case Intrinsic::ctpop:
case Intrinsic::cttz: case Intrinsic::cttz: {
// Build a small vector of the 1..(N-1) operands, which are the // Build a small vector of the 1..(N-1) operands, which are the
// parameters. // parameters.
SmallVector<Value*, 8> Operands(CI->op_begin()+1, CI->op_end()); SmallVector<Value*, 8> Operands(CI->op_begin()+1, CI->op_end());
// Construct a new CallInst // Construct a new CallInst
CallInst *NewCI = new CallInst(NewFn, Operands.begin(), Operands.end(), CallInst *NewCI = CallInst::Create(NewFn, Operands.begin(), Operands.end(),
"upgraded."+CI->getName(), CI); "upgraded."+CI->getName(), CI);
NewCI->setTailCall(CI->isTailCall()); NewCI->setTailCall(CI->isTailCall());
NewCI->setCallingConv(CI->getCallingConv()); 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. // Clean up the old call now that it has been completely upgraded.
CI->eraseFromParent(); CI->eraseFromParent();
break; }
break;
} }
} }

View File

@ -35,6 +35,10 @@ namespace {
/// DummyInst - An instance of this class is used to mark the end of the /// DummyInst - An instance of this class is used to mark the end of the
/// instruction list. This is not a real instruction. /// instruction list. This is not a real instruction.
struct VISIBILITY_HIDDEN DummyInst : public 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) { DummyInst() : Instruction(Type::VoidTy, OtherOpsEnd, 0, 0) {
// This should not be garbage monitored. // This should not be garbage monitored.
LeakDetector::removeGarbageObject(this); LeakDetector::removeGarbageObject(this);
@ -71,7 +75,7 @@ template class SymbolTableListTraits<Instruction, BasicBlock>;
BasicBlock::BasicBlock(const std::string &Name, Function *NewParent, BasicBlock::BasicBlock(const std::string &Name, Function *NewParent,
BasicBlock *InsertBefore, BasicBlock *Dest) 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 // Make sure that we get added to a function
LeakDetector::addGarbageObject(this); LeakDetector::addGarbageObject(this);
@ -283,14 +287,14 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const std::string &BBName) {
assert(I != InstList.end() && assert(I != InstList.end() &&
"Trying to get me to create degenerate basic block!"); "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 // Move all of the specified instructions from the original basic block into
// the new basic block. // the new basic block.
New->getInstList().splice(New->end(), this->getInstList(), I, end()); New->getInstList().splice(New->end(), this->getInstList(), I, end());
// Add a branch instruction to the newly formed basic block. // 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 // 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 // _were_ the successors of the 'this' block), and update any PHI nodes in

View File

@ -410,8 +410,13 @@ namespace {
/// UnaryConstantExpr - This class is private to Constants.cpp, and is used /// UnaryConstantExpr - This class is private to Constants.cpp, and is used
/// behind the scenes to implement unary constant exprs. /// behind the scenes to implement unary constant exprs.
class VISIBILITY_HIDDEN UnaryConstantExpr : public ConstantExpr { class VISIBILITY_HIDDEN UnaryConstantExpr : public ConstantExpr {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Op; Use Op;
public: 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) UnaryConstantExpr(unsigned Opcode, Constant *C, const Type *Ty)
: ConstantExpr(Ty, Opcode, &Op, 1), Op(C, this) {} : ConstantExpr(Ty, Opcode, &Op, 1), Op(C, this) {}
}; };
@ -419,8 +424,13 @@ public:
/// BinaryConstantExpr - This class is private to Constants.cpp, and is used /// BinaryConstantExpr - This class is private to Constants.cpp, and is used
/// behind the scenes to implement binary constant exprs. /// behind the scenes to implement binary constant exprs.
class VISIBILITY_HIDDEN BinaryConstantExpr : public ConstantExpr { class VISIBILITY_HIDDEN BinaryConstantExpr : public ConstantExpr {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Ops[2]; Use Ops[2];
public: 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) BinaryConstantExpr(unsigned Opcode, Constant *C1, Constant *C2)
: ConstantExpr(C1->getType(), Opcode, Ops, 2) { : ConstantExpr(C1->getType(), Opcode, Ops, 2) {
Ops[0].init(C1, this); Ops[0].init(C1, this);
@ -431,8 +441,13 @@ public:
/// SelectConstantExpr - This class is private to Constants.cpp, and is used /// SelectConstantExpr - This class is private to Constants.cpp, and is used
/// behind the scenes to implement select constant exprs. /// behind the scenes to implement select constant exprs.
class VISIBILITY_HIDDEN SelectConstantExpr : public ConstantExpr { class VISIBILITY_HIDDEN SelectConstantExpr : public ConstantExpr {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Ops[3]; Use Ops[3];
public: 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) SelectConstantExpr(Constant *C1, Constant *C2, Constant *C3)
: ConstantExpr(C2->getType(), Instruction::Select, Ops, 3) { : ConstantExpr(C2->getType(), Instruction::Select, Ops, 3) {
Ops[0].init(C1, this); Ops[0].init(C1, this);
@ -445,8 +460,13 @@ public:
/// Constants.cpp, and is used behind the scenes to implement /// Constants.cpp, and is used behind the scenes to implement
/// extractelement constant exprs. /// extractelement constant exprs.
class VISIBILITY_HIDDEN ExtractElementConstantExpr : public ConstantExpr { class VISIBILITY_HIDDEN ExtractElementConstantExpr : public ConstantExpr {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Ops[2]; Use Ops[2];
public: public:
// allocate space for exactly two operands
void *operator new(size_t s) {
return User::operator new(s, 2);
}
ExtractElementConstantExpr(Constant *C1, Constant *C2) ExtractElementConstantExpr(Constant *C1, Constant *C2)
: ConstantExpr(cast<VectorType>(C1->getType())->getElementType(), : ConstantExpr(cast<VectorType>(C1->getType())->getElementType(),
Instruction::ExtractElement, Ops, 2) { Instruction::ExtractElement, Ops, 2) {
@ -459,8 +479,13 @@ public:
/// Constants.cpp, and is used behind the scenes to implement /// Constants.cpp, and is used behind the scenes to implement
/// insertelement constant exprs. /// insertelement constant exprs.
class VISIBILITY_HIDDEN InsertElementConstantExpr : public ConstantExpr { class VISIBILITY_HIDDEN InsertElementConstantExpr : public ConstantExpr {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Ops[3]; Use Ops[3];
public: 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) InsertElementConstantExpr(Constant *C1, Constant *C2, Constant *C3)
: ConstantExpr(C1->getType(), Instruction::InsertElement, : ConstantExpr(C1->getType(), Instruction::InsertElement,
Ops, 3) { Ops, 3) {
@ -474,8 +499,13 @@ public:
/// Constants.cpp, and is used behind the scenes to implement /// Constants.cpp, and is used behind the scenes to implement
/// shufflevector constant exprs. /// shufflevector constant exprs.
class VISIBILITY_HIDDEN ShuffleVectorConstantExpr : public ConstantExpr { class VISIBILITY_HIDDEN ShuffleVectorConstantExpr : public ConstantExpr {
void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
Use Ops[3]; Use Ops[3];
public: 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) ShuffleVectorConstantExpr(Constant *C1, Constant *C2, Constant *C3)
: ConstantExpr(C1->getType(), Instruction::ShuffleVector, : ConstantExpr(C1->getType(), Instruction::ShuffleVector,
Ops, 3) { Ops, 3) {
@ -487,7 +517,7 @@ public:
/// GetElementPtrConstantExpr - This class is private to Constants.cpp, and is /// GetElementPtrConstantExpr - This class is private to Constants.cpp, and is
/// used behind the scenes to implement getelementpr constant exprs. /// 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, GetElementPtrConstantExpr(Constant *C, const std::vector<Constant*> &IdxList,
const Type *DestTy) const Type *DestTy)
: ConstantExpr(DestTy, Instruction::GetElementPtr, : ConstantExpr(DestTy, Instruction::GetElementPtr,
@ -496,6 +526,11 @@ struct VISIBILITY_HIDDEN GetElementPtrConstantExpr : public ConstantExpr {
for (unsigned i = 0, E = IdxList.size(); i != E; ++i) for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
OperandList[i+1].init(IdxList[i], this); 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() { ~GetElementPtrConstantExpr() {
delete [] OperandList; delete [] OperandList;
} }
@ -505,6 +540,11 @@ struct VISIBILITY_HIDDEN GetElementPtrConstantExpr : public ConstantExpr {
// behind the scenes to implement ICmp and FCmp constant expressions. This is // behind the scenes to implement ICmp and FCmp constant expressions. This is
// needed in order to store the predicate value for these instructions. // needed in order to store the predicate value for these instructions.
struct VISIBILITY_HIDDEN CompareConstantExpr : public ConstantExpr { 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; unsigned short predicate;
Use Ops[2]; Use Ops[2];
CompareConstantExpr(Instruction::OtherOps opc, unsigned short pred, CompareConstantExpr(Instruction::OtherOps opc, unsigned short pred,
@ -771,7 +811,8 @@ namespace llvm {
template<class ConstantClass, class TypeClass, class ValType> template<class ConstantClass, class TypeClass, class ValType>
struct VISIBILITY_HIDDEN ConstantCreator { struct VISIBILITY_HIDDEN ConstantCreator {
static ConstantClass *create(const TypeClass *Ty, const ValType &V) { 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]); V.operands[2]);
if (V.opcode == Instruction::GetElementPtr) { if (V.opcode == Instruction::GetElementPtr) {
std::vector<Constant*> IdxList(V.operands.begin()+1, V.operands.end()); 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 // The compare instructions are weird. We have to encode the predicate

View File

@ -670,8 +670,8 @@ void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, int IsConstant) {
LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
LLVMTypeRef FunctionTy) { LLVMTypeRef FunctionTy) {
return wrap(new Function(unwrap<FunctionType>(FunctionTy), return wrap(Function::Create(unwrap<FunctionType>(FunctionTy),
GlobalValue::ExternalLinkage, Name, unwrap(M))); GlobalValue::ExternalLinkage, Name, unwrap(M)));
} }
LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) { LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) {
@ -864,14 +864,14 @@ LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) {
} }
LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) { 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, LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef InsertBeforeBBRef,
const char *Name) { const char *Name) {
BasicBlock *InsertBeforeBB = unwrap(InsertBeforeBBRef); BasicBlock *InsertBeforeBB = unwrap(InsertBeforeBBRef);
return wrap(new BasicBlock(Name, InsertBeforeBB->getParent(), return wrap(BasicBlock::Create(Name, InsertBeforeBB->getParent(),
InsertBeforeBB)); InsertBeforeBB));
} }
void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) { void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) {

View File

@ -24,7 +24,7 @@
using namespace llvm; using namespace llvm;
BasicBlock *ilist_traits<BasicBlock>::createSentinel() { BasicBlock *ilist_traits<BasicBlock>::createSentinel() {
BasicBlock *Ret = new BasicBlock(); BasicBlock *Ret = BasicBlock::Create();
// This should not be garbage monitored. // This should not be garbage monitored.
LeakDetector::removeGarbageObject(Ret); LeakDetector::removeGarbageObject(Ret);
return Ret; return Ret;

View File

@ -2710,7 +2710,7 @@ bool GetResultInst::isValidOperands(const Value *Aggregate, unsigned Index) {
// unit that uses these classes. // unit that uses these classes.
GetElementPtrInst *GetElementPtrInst::clone() const { GetElementPtrInst *GetElementPtrInst::clone() const {
return new GetElementPtrInst(*this); return new(getNumOperands()) GetElementPtrInst(*this);
} }
BinaryOperator *BinaryOperator::clone() const { 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 *PtrToIntInst::clone() const { return new PtrToIntInst(*this); }
CastInst *IntToPtrInst::clone() const { return new IntToPtrInst(*this); } CastInst *IntToPtrInst::clone() const { return new IntToPtrInst(*this); }
CastInst *BitCastInst::clone() const { return new BitCastInst(*this); } CastInst *BitCastInst::clone() const { return new BitCastInst(*this); }
CallInst *CallInst::clone() const { return new CallInst(*this); } CallInst *CallInst::clone() const { return new(getNumOperands()) CallInst(*this); }
SelectInst *SelectInst::clone() const { return new SelectInst(*this); } SelectInst *SelectInst::clone() const { return new(getNumOperands()) SelectInst(*this); }
VAArgInst *VAArgInst::clone() const { return new VAArgInst(*this); } VAArgInst *VAArgInst::clone() const { return new VAArgInst(*this); }
ExtractElementInst *ExtractElementInst::clone() const { ExtractElementInst *ExtractElementInst::clone() const {
return new ExtractElementInst(*this); return new ExtractElementInst(*this);
} }
InsertElementInst *InsertElementInst::clone() const { InsertElementInst *InsertElementInst::clone() const {
return new InsertElementInst(*this); return InsertElementInst::Create(*this);
} }
ShuffleVectorInst *ShuffleVectorInst::clone() const { ShuffleVectorInst *ShuffleVectorInst::clone() const {
return new ShuffleVectorInst(*this); return new ShuffleVectorInst(*this);
} }
PHINode *PHINode::clone() const { return new PHINode(*this); } PHINode *PHINode::clone() const { return new PHINode(*this); }
ReturnInst *ReturnInst::clone() const { return new ReturnInst(*this); } ReturnInst *ReturnInst::clone() const { return new(getNumOperands()) ReturnInst(*this); }
BranchInst *BranchInst::clone() const { return new BranchInst(*this); } BranchInst *BranchInst::clone() const { return new(getNumOperands()) BranchInst(*this); }
SwitchInst *SwitchInst::clone() const { return new SwitchInst(*this); } SwitchInst *SwitchInst::clone() const { return new(getNumOperands()) SwitchInst(*this); }
InvokeInst *InvokeInst::clone() const { return new InvokeInst(*this); } InvokeInst *InvokeInst::clone() const { return new(getNumOperands()) InvokeInst(*this); }
UnwindInst *UnwindInst::clone() const { return new UnwindInst(); } UnwindInst *UnwindInst::clone() const { return new UnwindInst(); }
UnreachableInst *UnreachableInst::clone() const { return new UnreachableInst();} UnreachableInst *UnreachableInst::clone() const { return new UnreachableInst();}
GetResultInst *GetResultInst::clone() const { return new GetResultInst(*this); } GetResultInst *GetResultInst::clone() const { return new GetResultInst(*this); }

View File

@ -32,7 +32,7 @@ using namespace llvm;
Function *ilist_traits<Function>::createSentinel() { Function *ilist_traits<Function>::createSentinel() {
FunctionType *FTy = FunctionType *FTy =
FunctionType::get(Type::VoidTy, std::vector<const Type*>(), false); 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. // This should not be garbage monitored.
LeakDetector::removeGarbageObject(Ret); LeakDetector::removeGarbageObject(Ret);
return Ret; return Ret;
@ -149,7 +149,7 @@ Constant *Module::getOrInsertFunction(const std::string &Name,
GlobalValue *F = dyn_cast_or_null<GlobalValue>(SymTab.lookup(Name)); GlobalValue *F = dyn_cast_or_null<GlobalValue>(SymTab.lookup(Name));
if (F == 0) { if (F == 0) {
// Nope, add it // Nope, add it
Function *New = new Function(Ty, GlobalVariable::ExternalLinkage, Name); Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name);
FunctionList.push_back(New); FunctionList.push_back(New);
return New; // Return the new prototype. return New; // Return the new prototype.
} }

View File

@ -309,8 +309,8 @@ bool ReduceCrashingBlocks::TestBlocks(std::vector<const BasicBlock*> &BBs) {
// Add a new return instruction of the appropriate type... // Add a new return instruction of the appropriate type...
const Type *RetTy = BB->getParent()->getReturnType(); const Type *RetTy = BB->getParent()->getReturnType();
new ReturnInst(RetTy == Type::VoidTy ? 0 : ReturnInst::Create(RetTy == Type::VoidTy ? 0 :
Constant::getNullValue(RetTy), BB); Constant::getNullValue(RetTy), BB);
} }
// The CFG Simplifier pass may delete one of the basic blocks we are // The CFG Simplifier pass may delete one of the basic blocks we are

View File

@ -644,14 +644,14 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
// Rename it // Rename it
oldMain->setName("llvm_bugpoint_old_main"); oldMain->setName("llvm_bugpoint_old_main");
// Create a NEW `main' function with same type in the test module. // Create a NEW `main' function with same type in the test module.
Function *newMain = new Function(oldMain->getFunctionType(), Function *newMain = Function::Create(oldMain->getFunctionType(),
GlobalValue::ExternalLinkage, GlobalValue::ExternalLinkage,
"main", Test); "main", Test);
// Create an `oldmain' prototype in the test module, which will // Create an `oldmain' prototype in the test module, which will
// corresponds to the real main function in the same module. // corresponds to the real main function in the same module.
Function *oldMainProto = new Function(oldMain->getFunctionType(), Function *oldMainProto = Function::Create(oldMain->getFunctionType(),
GlobalValue::ExternalLinkage, GlobalValue::ExternalLinkage,
oldMain->getName(), Test); oldMain->getName(), Test);
// Set up and remember the argument list for the main function. // Set up and remember the argument list for the main function.
std::vector<Value*> args; std::vector<Value*> args;
for (Function::arg_iterator for (Function::arg_iterator
@ -662,12 +662,12 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
} }
// Call the old main function and return its result // Call the old main function and return its result
BasicBlock *BB = new BasicBlock("entry", newMain); BasicBlock *BB = BasicBlock::Create("entry", newMain);
CallInst *call = new CallInst(oldMainProto, args.begin(), args.end(), CallInst *call = CallInst::Create(oldMainProto, args.begin(), args.end(),
"", BB); "", BB);
// If the type of old function wasn't void, return value of call // 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 // 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 // Construct a new stub function that will re-route calls to F
const FunctionType *FuncTy = F->getFunctionType(); const FunctionType *FuncTy = F->getFunctionType();
Function *FuncWrapper = new Function(FuncTy, Function *FuncWrapper = Function::Create(FuncTy,
GlobalValue::InternalLinkage, GlobalValue::InternalLinkage,
F->getName() + "_wrapper", F->getName() + "_wrapper",
F->getParent()); F->getParent());
BasicBlock *EntryBB = new BasicBlock("entry", FuncWrapper); BasicBlock *EntryBB = BasicBlock::Create("entry", FuncWrapper);
BasicBlock *DoCallBB = new BasicBlock("usecache", FuncWrapper); BasicBlock *DoCallBB = BasicBlock::Create("usecache", FuncWrapper);
BasicBlock *LookupBB = new BasicBlock("lookupfp", FuncWrapper); BasicBlock *LookupBB = BasicBlock::Create("lookupfp", FuncWrapper);
// Check to see if we already looked up the value. // Check to see if we already looked up the value.
Value *CachedVal = new LoadInst(Cache, "fpcache", EntryBB); Value *CachedVal = new LoadInst(Cache, "fpcache", EntryBB);
Value *IsNull = new ICmpInst(ICmpInst::ICMP_EQ, CachedVal, Value *IsNull = new ICmpInst(ICmpInst::ICMP_EQ, CachedVal,
NullPtr, "isNull", EntryBB); 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: // Resolve the call to function F via the JIT API:
// //
// call resolver(GetElementPtr...) // call resolver(GetElementPtr...)
CallInst *Resolver = new CallInst(resolverFunc, ResolverArgs.begin(), CallInst *Resolver = CallInst::Create(resolverFunc, ResolverArgs.begin(),
ResolverArgs.end(), ResolverArgs.end(),
"resolver", LookupBB); "resolver", LookupBB);
// cast the result from the resolver to correctly-typed function // cast the result from the resolver to correctly-typed function
CastInst *CastedResolver = new BitCastInst(Resolver, CastInst *CastedResolver = new BitCastInst(Resolver,
PointerType::getUnqual(F->getFunctionType()), "resolverCast", LookupBB); PointerType::getUnqual(F->getFunctionType()), "resolverCast", LookupBB);
// Save the value in our cache. // Save the value in our cache.
new StoreInst(CastedResolver, Cache, LookupBB); 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(CastedResolver, LookupBB);
FuncPtr->addIncoming(CachedVal, EntryBB); 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 // Pass on the arguments to the real function, return its result
if (F->getReturnType() == Type::VoidTy) { if (F->getReturnType() == Type::VoidTy) {
new CallInst(FuncPtr, Args.begin(), Args.end(), "", DoCallBB); CallInst::Create(FuncPtr, Args.begin(), Args.end(), "", DoCallBB);
new ReturnInst(DoCallBB); ReturnInst::Create(DoCallBB);
} else { } else {
CallInst *Call = new CallInst(FuncPtr, Args.begin(), Args.end(), CallInst *Call = CallInst::Create(FuncPtr, Args.begin(), Args.end(),
"retval", DoCallBB); "retval", DoCallBB);
new ReturnInst(Call, DoCallBB); ReturnInst::Create(Call, DoCallBB);
} }
// Use the wrapper function instead of the old function // Use the wrapper function instead of the old function