llvm.org GIT mirror llvm / 051a950
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 Gabor Greif 11 years ago
73 changed file(s) with 976 addition(s) and 689 deletion(s). Raw diff Collapse all Expand all
7373 brainf_func = cast(module->
7474 getOrInsertFunction("brainf", Type::VoidTy, NULL));
7575
76 builder = new LLVMBuilder(new BasicBlock(label, brainf_func));
76 builder = new LLVMBuilder(BasicBlock::Create(label, brainf_func));
7777
7878 //%arr = malloc i8, i32 %d
7979 ConstantInt *val_mem = ConstantInt::get(APInt(32, memtotal));
109109 //Function footer
110110
111111 //brainf.end:
112 endbb = new BasicBlock(label, brainf_func);
112 endbb = BasicBlock::Create(label, brainf_func);
113113
114114 //free i8 *%arr
115115 new FreeInst(ptr_arr, endbb);
116116
117117 //ret void
118 new ReturnInst(endbb);
118 ReturnInst::Create(endbb);
119119
120120
121121
140140 PointerType::getUnqual(IntegerType::Int8Ty), NULL));
141141
142142 //brainf.aberror:
143 aberrorbb = new BasicBlock(label, brainf_func);
143 aberrorbb = BasicBlock::Create(label, brainf_func);
144144
145145 //call i32 @puts(i8 *getelementptr([%d x i8] *@aberrormsg, i32 0, i32 0))
146146 {
160160 };
161161
162162 CallInst *puts_call =
163 new CallInst(puts_func,
164 puts_params, array_endof(puts_params),
165 "", aberrorbb);
163 CallInst::Create(puts_func,
164 puts_params, array_endof(puts_params),
165 "", aberrorbb);
166166 puts_call->setTailCall(false);
167167 }
168168
169169 //br label %brainf.end
170 new BranchInst(endbb, aberrorbb);
170 BranchInst::Create(endbb, aberrorbb);
171171 }
172172 }
173173
246246 CreateOr(test_0, test_1, testreg);
247247
248248 //br i1 %test.%d, label %main.%d, label %main.%d
249 BasicBlock *nextbb = new BasicBlock(label, brainf_func);
249 BasicBlock *nextbb = BasicBlock::Create(label, brainf_func);
250250 builder->CreateCondBr(test_2, aberrorbb, nextbb);
251251
252252 //main.%d:
272272 case SYM_LOOP:
273273 {
274274 //br label %main.%d
275 BasicBlock *testbb = new BasicBlock(label, brainf_func);
275 BasicBlock *testbb = BasicBlock::Create(label, brainf_func);
276276 builder->CreateBr(testbb);
277277
278278 //main.%d:
279279 BasicBlock *bb_0 = builder->GetInsertBlock();
280 BasicBlock *bb_1 = new BasicBlock(label, brainf_func);
280 BasicBlock *bb_1 = BasicBlock::Create(label, brainf_func);
281281 builder->SetInsertPoint(bb_1);
282282
283283 //Make part of PHI instruction now, wait until end of loop to finish
284 PHINode *phi_0 = new PHINode(PointerType::getUnqual(IntegerType::Int8Ty),
284 PHINode *phi_0 = PHINode::Create(PointerType::getUnqual(IntegerType::Int8Ty),
285285 headreg, testbb);
286286 phi_0->reserveOperandSpace(2);
287287 phi_0->addIncoming(curhead, bb_0);
430430 testbb);
431431
432432 //br i1 %test.%d, label %main.%d, label %main.%d
433 BasicBlock *bb_0 = new BasicBlock(label, brainf_func);
434 new BranchInst(bb_0, oldbb, test_0, testbb);
433 BasicBlock *bb_0 = BasicBlock::Create(label, brainf_func);
434 BranchInst::Create(bb_0, oldbb, test_0, testbb);
435435
436436 //main.%d:
437437 builder->SetInsertPoint(bb_0);
6969 }
7070
7171 //main.0:
72 BasicBlock *bb = new BasicBlock("main.0", main_func);
72 BasicBlock *bb = BasicBlock::Create("main.0", main_func);
7373
7474 //call void @brainf()
7575 {
76 CallInst *brainf_call = new CallInst(mod->getFunction("brainf"),
77 "", bb);
76 CallInst *brainf_call = CallInst::Create(mod->getFunction("brainf"),
77 "", bb);
7878 brainf_call->setTailCall(false);
7979 }
8080
8181 //ret i32 0
82 new ReturnInst(ConstantInt::get(APInt(32, 0)), bb);
82 ReturnInst::Create(ConstantInt::get(APInt(32, 0)), bb);
8383 }
8484
8585 int main(int argc, char **argv) {
4242 (Type *)0));
4343
4444 // Add a basic block to the function.
45 BasicBlock *BB = new BasicBlock("EntryBlock", FibF);
45 BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF);
4646
4747 // Get pointers to the constants.
4848 Value *One = ConstantInt::get(Type::Int32Ty, 1);
5353 ArgX->setName("AnArg"); // Give it a nice symbolic name for fun.
5454
5555 // Create the true_block.
56 BasicBlock *RetBB = new BasicBlock("return", FibF);
56 BasicBlock *RetBB = BasicBlock::Create("return", FibF);
5757 // Create an exit block.
58 BasicBlock* RecurseBB = new BasicBlock("recurse", FibF);
58 BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);
5959
6060 // Create the "if (arg <= 2) goto exitbb"
6161 Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB);
62 new BranchInst(RetBB, RecurseBB, CondInst, BB);
62 BranchInst::Create(RetBB, RecurseBB, CondInst, BB);
6363
6464 // Create: ret int 1
65 new ReturnInst(One, RetBB);
65 ReturnInst::Create(One, RetBB);
6666
6767 // create fib(x-1)
6868 Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB);
69 CallInst *CallFibX1 = new CallInst(FibF, Sub, "fibx1", RecurseBB);
69 CallInst *CallFibX1 = CallInst::Create(FibF, Sub, "fibx1", RecurseBB);
7070 CallFibX1->setTailCall();
7171
7272 // create fib(x-2)
7373 Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB);
74 CallInst *CallFibX2 = new CallInst(FibF, Sub, "fibx2", RecurseBB);
74 CallInst *CallFibX2 = CallInst::Create(FibF, Sub, "fibx2", RecurseBB);
7575 CallFibX2->setTailCall();
7676
7777
8080 "addresult", RecurseBB);
8181
8282 // Create the return instruction and add it to the basic block
83 new ReturnInst(Sum, RecurseBB);
83 ReturnInst::Create(Sum, RecurseBB);
8484
8585 return FibF;
8686 }
5757
5858 // Add a basic block to the function. As before, it automatically inserts
5959 // because of the last argument.
60 BasicBlock *BB = new BasicBlock("EntryBlock", Add1F);
60 BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F);
6161
6262 // Get pointers to the constant `1'.
6363 Value *One = ConstantInt::get(Type::Int32Ty, 1);
7171 Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB);
7272
7373 // Create the return instruction and add it to the basic block
74 new ReturnInst(Add, BB);
74 ReturnInst::Create(Add, BB);
7575
7676 // Now, function add1 is ready.
7777
8282 cast(M->getOrInsertFunction("foo", Type::Int32Ty, (Type *)0));
8383
8484 // Add a basic block to the FooF function.
85 BB = new BasicBlock("EntryBlock", FooF);
85 BB = BasicBlock::Create("EntryBlock", FooF);
8686
8787 // Get pointers to the constant `10'.
8888 Value *Ten = ConstantInt::get(Type::Int32Ty, 10);
8989
9090 // Pass Ten to the call call:
91 CallInst *Add1CallRes = new CallInst(Add1F, Ten, "add1", BB);
91 CallInst *Add1CallRes = CallInst::Create(Add1F, Ten, "add1", BB);
9292 Add1CallRes->setTailCall(true);
9393
9494 // Create the return instruction and add it to the basic block.
95 new ReturnInst(Add1CallRes, BB);
95 ReturnInst::Create(Add1CallRes, BB);
9696
9797 // Now we create the JIT.
9898 ExistingModuleProvider* MP = new ExistingModuleProvider(M);
3131
3232 // By passing a module as the last parameter to the Function constructor,
3333 // it automatically gets appended to the Module.
34 Function *F = new Function(FT, Function::ExternalLinkage, "main", M);
34 Function *F = Function::Create(FT, Function::ExternalLinkage, "main", M);
3535
3636 // Add a basic block to the function... again, it automatically inserts
3737 // because of the last argument.
38 BasicBlock *BB = new BasicBlock("EntryBlock", F);
38 BasicBlock *BB = BasicBlock::Create("EntryBlock", F);
3939
4040 // Get pointers to the constant integers...
4141 Value *Two = ConstantInt::get(Type::Int32Ty, 2);
4949 BB->getInstList().push_back(Add);
5050
5151 // Create the return instruction and add it to the basic block
52 BB->getInstList().push_back(new ReturnInst(Add));
52 BB->getInstList().push_back(ReturnInst::Create(Add));
5353
5454 // Output the bitcode file to stdout
5555 WriteBitcodeToFile(M, std::cout);
3838
3939 // Add a basic block to the function. As before, it automatically inserts
4040 // because of the last argument.
41 BasicBlock *BB = new BasicBlock("EntryBlock", Add1F);
41 BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F);
4242
4343 // Get pointers to the constant `1'.
4444 Value *One = ConstantInt::get(Type::Int32Ty, 1);
5252 Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB);
5353
5454 // Create the return instruction and add it to the basic block
55 new ReturnInst(Add, BB);
55 ReturnInst::Create(Add, BB);
5656
5757 // Now, function add1 is ready.
5858 return Add1F;
6666 (Type *)0));
6767
6868 // Add a basic block to the function.
69 BasicBlock *BB = new BasicBlock("EntryBlock", FibF);
69 BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF);
7070
7171 // Get pointers to the constants.
7272 Value *One = ConstantInt::get(Type::Int32Ty, 1);
7777 ArgX->setName("AnArg"); // Give it a nice symbolic name for fun.
7878
7979 // Create the true_block.
80 BasicBlock *RetBB = new BasicBlock("return", FibF);
80 BasicBlock *RetBB = BasicBlock::Create("return", FibF);
8181 // Create an exit block.
82 BasicBlock* RecurseBB = new BasicBlock("recurse", FibF);
82 BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF);
8383
8484 // Create the "if (arg < 2) goto exitbb"
8585 Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB);
86 new BranchInst(RetBB, RecurseBB, CondInst, BB);
86 BranchInst::Create(RetBB, RecurseBB, CondInst, BB);
8787
8888 // Create: ret int 1
89 new ReturnInst(One, RetBB);
89 ReturnInst::Create(One, RetBB);
9090
9191 // create fib(x-1)
9292 Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB);
93 Value *CallFibX1 = new CallInst(FibF, Sub, "fibx1", RecurseBB);
93 Value *CallFibX1 = CallInst::Create(FibF, Sub, "fibx1", RecurseBB);
9494
9595 // create fib(x-2)
9696 Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB);
97 Value *CallFibX2 = new CallInst(FibF, Sub, "fibx2", RecurseBB);
97 Value *CallFibX2 = CallInst::Create(FibF, Sub, "fibx2", RecurseBB);
9898
9999 // fib(x-1)+fib(x-2)
100100 Value *Sum =
101101 BinaryOperator::createAdd(CallFibX1, CallFibX2, "addresult", RecurseBB);
102102
103103 // Create the return instruction and add it to the basic block
104 new ReturnInst(Sum, RecurseBB);
104 ReturnInst::Create(Sum, RecurseBB);
105105
106106 return FibF;
107107 }
6565 BasicBlock(const BasicBlock &); // Do not implement
6666 void operator=(const BasicBlock &); // Do not implement
6767
68 /// BasicBlock ctor - If the function parameter is specified, the basic block
69 /// is automatically inserted at either the end of the function (if
70 /// InsertBefore is null), or before the specified basic block.
71 ///
72 explicit BasicBlock(const std::string &Name = "", Function *Parent = 0,
73 BasicBlock *InsertBefore = 0, BasicBlock *UnwindDest = 0);
6874 public:
6975 /// Instruction iterators...
7076 typedef InstListType::iterator iterator;
7177 typedef InstListType::const_iterator const_iterator;
7278
73 /// BasicBlock ctor - If the function parameter is specified, the basic block
74 /// is automatically inserted at either the end of the function (if
75 /// InsertBefore is null), or before the specified basic block.
76 ///
77 explicit BasicBlock(const std::string &Name = "", Function *Parent = 0,
78 BasicBlock *InsertBefore = 0, BasicBlock *unwindDest = 0);
79 // allocate space for exactly zero operands
80 static BasicBlock *Create(const std::string &Name = "", Function *Parent = 0,
81 BasicBlock *InsertBefore = 0, BasicBlock *UnwindDest = 0) {
82 return new(!!UnwindDest) BasicBlock(Name, Parent, InsertBefore, UnwindDest);
83 }
7984 ~BasicBlock();
8085
8186 /// getUnwindDest - Returns the BasicBlock that flow will enter if an unwind
4242 /// @brief Class for constant integers.
4343 class ConstantInt : public Constant {
4444 static ConstantInt *TheTrueVal, *TheFalseVal;
45 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
4546 ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT
4647 ConstantInt(const IntegerType *Ty, const APInt& V);
4748 APInt Val;
49 protected:
50 // allocate space for exactly zero operands
51 void *operator new(size_t s) {
52 return User::operator new(s, 0);
53 }
4854 public:
4955 /// Return the constant as an APInt value reference. This allows clients to
5056 /// obtain a copy of the value, with all its precision in tact.
214220 ///
215221 class ConstantFP : public Constant {
216222 APFloat Val;
223 void *operator new(size_t, unsigned);// DO NOT IMPLEMENT
217224 ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT
218225 protected:
219226 ConstantFP(const Type *Ty, const APFloat& V);
227 protected:
228 // allocate space for exactly zero operands
229 void *operator new(size_t s) {
230 return User::operator new(s, 0);
231 }
220232 public:
221233 /// get() - Static factory methods - Return objects of the specified value
222234 static ConstantFP *get(const Type *Ty, const APFloat& V);
261273 ///
262274 class ConstantAggregateZero : public Constant {
263275 friend struct ConstantCreator;
276 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
264277 ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT
265278 protected:
266279 explicit ConstantAggregateZero(const Type *Ty)
267280 : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {}
281 protected:
282 // allocate space for exactly zero operands
283 void *operator new(size_t s) {
284 return User::operator new(s, 0);
285 }
268286 public:
269287 /// get() - static factory method for creating a null aggregate. It is
270288 /// illegal to call this method with a non-aggregate type.
456474 ///
457475 class ConstantPointerNull : public Constant {
458476 friend struct ConstantCreator;
477 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
459478 ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT
460479 protected:
461480 explicit ConstantPointerNull(const PointerType *T)
462481 : Constant(reinterpret_cast(T),
463482 Value::ConstantPointerNullVal, 0, 0) {}
464483
465 public:
466
484 protected:
485 // allocate space for exactly zero operands
486 void *operator new(size_t s) {
487 return User::operator new(s, 0);
488 }
489 public:
467490 /// get() - Static factory methods - Return objects of the specified value
468491 static ConstantPointerNull *get(const PointerType *T);
469492
705728 ///
706729 class UndefValue : public Constant {
707730 friend struct ConstantCreator;
731 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
708732 UndefValue(const UndefValue &); // DO NOT IMPLEMENT
709733 protected:
710734 explicit UndefValue(const Type *T) : Constant(T, UndefValueVal, 0, 0) {}
735 protected:
736 // allocate space for exactly zero operands
737 void *operator new(size_t s) {
738 return User::operator new(s, 0);
739 }
711740 public:
712741 /// get() - Static factory methods - Return an 'undef' object of the specified
713742 /// type.
103103
104104 Function(const Function&); // DO NOT IMPLEMENT
105105 void operator=(const Function&); // DO NOT IMPLEMENT
106 public:
106
107107 /// Function ctor - If the (optional) Module argument is specified, the
108108 /// function is automatically inserted into the end of the function list for
109109 /// the module.
110110 ///
111111 Function(const FunctionType *Ty, LinkageTypes Linkage,
112112 const std::string &N = "", Module *M = 0);
113
114 public:
115 static Function *Create(const FunctionType *Ty, LinkageTypes Linkage,
116 const std::string &N = "", Module *M = 0) {
117 return new(0) Function(Ty, Linkage, N, M);
118 }
119
113120 ~Function();
114121
115122 const Type *getReturnType() const; // Return the type of the ret val
4343
4444 Use Aliasee;
4545 public:
46 // allocate space for exactly zero operands
47 void *operator new(size_t s) {
48 return User::operator new(s, 0);
49 }
4650 /// GlobalAlias ctor - If a parent module is specified, the alias is
4751 /// automatically inserted into the end of the specified module's alias list.
4852 GlobalAlias(const Type *Ty, LinkageTypes Linkage, const std::string &Name = "",
3131
3232 class GlobalVariable : public GlobalValue {
3333 friend class SymbolTableListTraits;
34 void *operator new(size_t, unsigned); // Do not implement
3435 void operator=(const GlobalVariable &); // Do not implement
3536 GlobalVariable(const GlobalVariable &); // Do not implement
3637
4546 Use Initializer;
4647
4748 public:
49 // allocate space for exactly zero operands
50 void *operator new(size_t s) {
51 return User::operator new(s, 0);
52 }
4853 /// GlobalVariable ctor - If a parent module is specified, the global is
4954 /// automatically inserted into the end of the specified modules global list.
5055 GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage,
8282 //===----------------------------------------------------------------------===//
8383
8484 class UnaryInstruction : public Instruction {
85 void *operator new(size_t, unsigned); // Do not implement
8586 Use Op;
8687
8788 // avoiding warning: 'this' : used in base member initializer list
9495 : Instruction(Ty, iType, &Op, 1, IAE), Op(V, this_()) {
9596 }
9697 public:
98 // allocate space for exactly one operand
99 void *operator new(size_t s) {
100 return User::operator new(s, 1);
101 }
102
97103 // Out of line virtual method, so the vtable, etc has a home.
98104 ~UnaryInstruction();
99105
128134 //===----------------------------------------------------------------------===//
129135
130136 class BinaryOperator : public Instruction {
137 void *operator new(size_t, unsigned); // Do not implement
131138 Use Ops[2];
132139 protected:
133140 void init(BinaryOps iType);
136143 BinaryOperator(BinaryOps iType, Value *S1, Value *S2, const Type *Ty,
137144 const std::string &Name, BasicBlock *InsertAtEnd);
138145 public:
146 // allocate space for exactly two operands
147 void *operator new(size_t s) {
148 return User::operator new(s, 2);
149 }
139150
140151 /// Transparently provide more efficient getOperand methods.
141152 Value *getOperand(unsigned i) const {
488499 /// This class is the base class for the comparison instructions.
489500 /// @brief Abstract base class of comparison instructions.
490501 class CmpInst: public Instruction {
502 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
491503 CmpInst(); // do not implement
492504 protected:
493505 CmpInst(Instruction::OtherOps op, unsigned short pred, Value *LHS, Value *RHS,
499511 Use Ops[2]; // CmpInst instructions always have 2 operands, optimize
500512
501513 public:
514 // allocate space for exactly two operands
515 void *operator new(size_t s) {
516 return User::operator new(s, 2);
517 }
502518 /// Construct a compare instruction, given the opcode, the predicate and
503519 /// the two operands. Optionally (if InstBefore is specified) insert the
504520 /// instruction into a BasicBlock right before the specified instruction.
4444 AllocationInst(const Type *Ty, Value *ArraySize, unsigned iTy, unsigned Align,
4545 const std::string &Name, BasicBlock *InsertAtEnd);
4646 public:
47 // Out of line virtual method, so the vtable, etc has a home.
47 // Out of line virtual method, so the vtable, etc. has a home.
4848 virtual ~AllocationInst();
4949
5050 /// isArrayAllocation - Return true if there is an allocation size parameter
286286 /// StoreInst - an instruction for storing to memory
287287 ///
288288 class StoreInst : public Instruction {
289 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
289290 Use Ops[2];
290291
291292 StoreInst(const StoreInst &SI) : Instruction(SI.getType(), Store, Ops, 2) {
300301 }
301302 void AssertOK();
302303 public:
304 // allocate space for exactly two operands
305 void *operator new(size_t s) {
306 return User::operator new(s, 2);
307 }
303308 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
304309 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
305310 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
437442 }
438443 }
439444
440 public:
441445 /// Constructors - Create a getelementptr instruction with a base pointer an
442446 /// list of indices. The first ctor can optionally insert before an existing
443447 /// instruction, the second appends the new instruction to the specified
446450 GetElementPtrInst(Value *Ptr, InputIterator IdxBegin,
447451 InputIterator IdxEnd,
448452 const std::string &Name = "",
449 Instruction *InsertBefore =0)
453 Instruction *InsertBefore = 0)
450454 : Instruction(PointerType::get(
451455 checkType(getIndexedType(Ptr->getType(),
452456 IdxBegin, IdxEnd, true)),
470474 /// Constructors - These two constructors are convenience methods because one
471475 /// and two index getelementptr instructions are so common.
472476 GetElementPtrInst(Value *Ptr, Value *Idx,
473 const std::string &Name = "", Instruction *InsertBefore =0);
477 const std::string &Name = "", Instruction *InsertBefore = 0);
474478 GetElementPtrInst(Value *Ptr, Value *Idx,
475479 const std::string &Name, BasicBlock *InsertAtEnd);
480 public:
481 template
482 static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin,
483 InputIterator IdxEnd,
484 const std::string &Name = "",
485 Instruction *InsertBefore = 0) {
486 return new(0/*FIXME*/) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name, InsertBefore);
487 }
488 template
489 static GetElementPtrInst *Create(Value *Ptr, InputIterator IdxBegin, InputIterator IdxEnd,
490 const std::string &Name, BasicBlock *InsertAtEnd) {
491 return new(0/*FIXME*/) GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name, InsertAtEnd);
492 }
493
494 /// Constructors - These two constructors are convenience methods because one
495 /// and two index getelementptr instructions are so common.
496 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
497 const std::string &Name = "", Instruction *InsertBefore = 0) {
498 return new(2/*FIXME*/) GetElementPtrInst(Ptr, Idx, Name, InsertBefore);
499 }
500 static GetElementPtrInst *Create(Value *Ptr, Value *Idx,
501 const std::string &Name, BasicBlock *InsertAtEnd) {
502 return new(2/*FIXME*/) GetElementPtrInst(Ptr, Idx, Name, InsertAtEnd);
503 }
476504 ~GetElementPtrInst();
477505
478506 virtual GetElementPtrInst *clone() const;
865893 setName(Name);
866894 }
867895
868 public:
869896 /// Construct a CallInst given a range of arguments. InputIterator
870897 /// must be a random-access iterator pointing to contiguous storage
871898 /// (e.g. a std::vector<>::iterator). Checks are made for
905932 explicit CallInst(Value *F, const std::string &Name = "",
906933 Instruction *InsertBefore = 0);
907934 CallInst(Value *F, const std::string &Name, BasicBlock *InsertAtEnd);
935 public:
936 template
937 static CallInst *Create(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
938 const std::string &Name = "", Instruction *InsertBefore = 0) {
939 return new(ArgEnd - ArgBegin + 1) CallInst(Func, ArgBegin, ArgEnd, Name, InsertBefore);
940 }
941 template
942 static CallInst *Create(Value *Func, InputIterator ArgBegin, InputIterator ArgEnd,
943 const std::string &Name, BasicBlock *InsertAtEnd) {
944 return new(ArgEnd - ArgBegin + 1) CallInst(Func, ArgBegin, ArgEnd, Name, InsertAtEnd);
945 }
946 static CallInst *Create(Value *F, Value *Actual, const std::string& Name = "",
947 Instruction *InsertBefore = 0) {
948 return new(2) CallInst(F, Actual, Name, InsertBefore);
949 }
950 static CallInst *Create(Value *F, Value *Actual, const std::string& Name,
951 BasicBlock *InsertAtEnd) {
952 return new(2) CallInst(F, Actual, Name, InsertAtEnd);
953 }
954 static CallInst *Create(Value *F, const std::string &Name = "",
955 Instruction *InsertBefore = 0) {
956 return new(1) CallInst(F, Name, InsertBefore);
957 }
958 static CallInst *Create(Value *F, const std::string &Name, BasicBlock *InsertAtEnd) {
959 return new(1) CallInst(F, Name, InsertAtEnd);
960 }
961
908962 ~CallInst();
909963
910964 virtual CallInst *clone() const;
10101064 : Instruction(SI.getType(), SI.getOpcode(), Ops, 3) {
10111065 init(SI.Ops[0], SI.Ops[1], SI.Ops[2]);
10121066 }
1013 public:
10141067 SelectInst(Value *C, Value *S1, Value *S2, const std::string &Name = "",
10151068 Instruction *InsertBefore = 0)
10161069 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertBefore) {
10221075 : Instruction(S1->getType(), Instruction::Select, Ops, 3, InsertAtEnd) {
10231076 init(C, S1, S2);
10241077 setName(Name);
1078 }
1079 public:
1080 static SelectInst *Create(Value *C, Value *S1, Value *S2, const std::string &Name = "",
1081 Instruction *InsertBefore = 0) {
1082 return new(3) SelectInst(C, S1, S2, Name, InsertBefore);
1083 }
1084 static SelectInst *Create(Value *C, Value *S1, Value *S2, const std::string &Name,
1085 BasicBlock *InsertAtEnd) {
1086 return new(3) SelectInst(C, S1, S2, Name, InsertAtEnd);
10251087 }
10261088
10271089 Value *getCondition() const { return Ops[0]; }
11051167 }
11061168
11071169 public:
1170 // allocate space for exactly two operands
1171 void *operator new(size_t s) {
1172 return User::operator new(s, 2); // FIXME: unsigned Idx forms of constructor?
1173 }
11081174 ExtractElementInst(Value *Vec, Value *Idx, const std::string &Name = "",
11091175 Instruction *InsertBefore = 0);
11101176 ExtractElementInst(Value *Vec, unsigned Idx, const std::string &Name = "",
11511217 class InsertElementInst : public Instruction {
11521218 Use Ops[3];
11531219 InsertElementInst(const InsertElementInst &IE);
1154 public:
11551220 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
11561221 const std::string &Name = "",Instruction *InsertBefore = 0);
11571222 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
11601225 const std::string &Name, BasicBlock *InsertAtEnd);
11611226 InsertElementInst(Value *Vec, Value *NewElt, unsigned Idx,
11621227 const std::string &Name, BasicBlock *InsertAtEnd);
1228 public:
1229 static InsertElementInst *Create(const InsertElementInst &IE) {
1230 return new(IE.getNumOperands()) InsertElementInst(IE);
1231 }
1232 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1233 const std::string &Name = "",Instruction *InsertBefore = 0) {
1234 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
1235 }
1236 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
1237 const std::string &Name = "",Instruction *InsertBefore = 0) {
1238 return new(3/*FIXME*/) InsertElementInst(Vec, NewElt, Idx, Name, InsertBefore);
1239 }
1240 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
1241 const std::string &Name, BasicBlock *InsertAtEnd) {
1242 return new(3) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
1243 }
1244 static InsertElementInst *Create(Value *Vec, Value *NewElt, unsigned Idx,
1245 const std::string &Name, BasicBlock *InsertAtEnd) {
1246 return new(3/*FIXME*/) InsertElementInst(Vec, NewElt, Idx, Name, InsertAtEnd);
1247 }
11631248
11641249 /// isValidOperands - Return true if an insertelement instruction can be
11651250 /// formed with the specified operands.
12061291 Use Ops[3];
12071292 ShuffleVectorInst(const ShuffleVectorInst &IE);
12081293 public:
1294 // allocate space for exactly three operands
1295 void *operator new(size_t s) {
1296 return User::operator new(s, 3);
1297 }
12091298 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
12101299 const std::string &Name = "", Instruction *InsertBefor = 0);
12111300 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
12641353 // scientist's overactive imagination.
12651354 //
12661355 class PHINode : public Instruction {
1356 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
12671357 /// ReservedSpace - The number of operands actually allocated. NumOperands is
12681358 /// the number actually in use.
12691359 unsigned ReservedSpace;
12701360 PHINode(const PHINode &PN);
1271 public:
1361 // allocate space for exactly zero operands
1362 void *operator new(size_t s) {
1363 return User::operator new(s, 0);
1364 }
12721365 explicit PHINode(const Type *Ty, const std::string &Name = "",
12731366 Instruction *InsertBefore = 0)
12741367 : Instruction(Ty, Instruction::PHI, 0, 0, InsertBefore),
12811374 ReservedSpace(0) {
12821375 setName(Name);
12831376 }
1284
1377 public:
1378 static PHINode *Create(const Type *Ty, const std::string &Name = "",
1379 Instruction *InsertBefore = 0) {
1380 return new PHINode(Ty, Name, InsertBefore);
1381 }
1382 static PHINode *Create(const Type *Ty, const std::string &Name, BasicBlock *InsertAtEnd) {
1383 return new PHINode(Ty, Name, InsertAtEnd);
1384 }
12851385 ~PHINode();
12861386
12871387 /// reserveOperandSpace - This method can be used to avoid repeated
14001500 ReturnInst(const ReturnInst &RI);
14011501 void init(Value * const* retVals, unsigned N);
14021502
1403 public:
1503 private:
14041504 // ReturnInst constructors:
14051505 // ReturnInst() - 'ret void' instruction
14061506 // ReturnInst( null) - 'ret void' instruction
14211521 ReturnInst(Value * const* retVals, unsigned N, Instruction *InsertBefore);
14221522 ReturnInst(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd);
14231523 explicit ReturnInst(BasicBlock *InsertAtEnd);
1524 public:
1525 static ReturnInst* Create(Value *retVal = 0, Instruction *InsertBefore = 0) {
1526 return new(!!retVal) ReturnInst(retVal, InsertBefore);
1527 }
1528 static ReturnInst* Create(Value *retVal, BasicBlock *InsertAtEnd) {
1529 return new(!!retVal) ReturnInst(retVal, InsertAtEnd);
1530 }
1531 static ReturnInst* Create(Value * const* retVals, unsigned N) {
1532 return new(N) ReturnInst(retVals, N);
1533 }
1534 static ReturnInst* Create(Value * const* retVals, unsigned N, Instruction *InsertBefore) {
1535 return new(N) ReturnInst(retVals, N, InsertBefore);
1536 }
1537 static ReturnInst* Create(Value * const* retVals, unsigned N, BasicBlock *InsertAtEnd) {
1538 return new(N) ReturnInst(retVals, N, InsertAtEnd);
1539 }
1540 static ReturnInst* Create(BasicBlock *InsertAtEnd) {
1541 return new(0) ReturnInst(InsertAtEnd);
1542 }
14241543 virtual ~ReturnInst();
14251544
14261545 virtual ReturnInst *clone() const;
14661585 Use Ops[3];
14671586 BranchInst(const BranchInst &BI);
14681587 void AssertOK();
1469 public:
14701588 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
14711589 // BranchInst(BB *B) - 'br B'
14721590 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
14801598 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
14811599 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
14821600 BasicBlock *InsertAtEnd);
1601 public:
1602 static BranchInst *Create(BasicBlock *IfTrue, Instruction *InsertBefore = 0) {
1603 return new(1) BranchInst(IfTrue, InsertBefore);
1604 }
1605 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1606 Instruction *InsertBefore = 0) {
1607 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
1608 }
1609 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
1610 return new(1) BranchInst(IfTrue, InsertAtEnd);
1611 }
1612 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
1613 BasicBlock *InsertAtEnd) {
1614 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
1615 }
14831616
14841617 /// Transparently provide more efficient getOperand methods.
14851618 Value *getOperand(unsigned i) const {
15601693 SwitchInst(const SwitchInst &RI);
15611694 void init(Value *Value, BasicBlock *Default, unsigned NumCases);
15621695 void resizeOperands(unsigned No);
1563 public:
15641696 /// SwitchInst ctor - Create a new switch instruction, specifying a value to
15651697 /// switch on and a default destination. The number of additional cases can
15661698 /// be specified here to make memory allocation more efficient. This
15741706 /// constructor also autoinserts at the end of the specified BasicBlock.
15751707 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
15761708 BasicBlock *InsertAtEnd);
1709 public:
1710 static SwitchInst *Create(Value *Value, BasicBlock *Default, unsigned NumCases,
1711 Instruction *InsertBefore = 0) {
1712 return new(NumCases/*FIXME*/) SwitchInst(Value, Default, NumCases, InsertBefore);
1713 }
1714 static SwitchInst *Create(Value *Value, BasicBlock *Default, unsigned NumCases,
1715 BasicBlock *InsertAtEnd) {
1716 return new(NumCases/*FIXME*/) SwitchInst(Value, Default, NumCases, InsertAtEnd);
1717 }
15771718 ~SwitchInst();
1578
15791719
15801720 // Accessor Methods for Switch stmt
15811721 Value *getCondition() const { return getOperand(0); }
17021842 setName(Name);
17031843 }
17041844
1705 public:
17061845 /// Construct an InvokeInst given a range of arguments.
17071846 /// InputIterator must be a random-access iterator pointing to
17081847 /// contiguous storage (e.g. a std::vector<>::iterator). Checks are
17381877 init(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name,
17391878 typename std::iterator_traits::iterator_category());
17401879 }
1880 public:
1881 template
1882 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1883 InputIterator ArgBegin, InputIterator ArgEnd,
1884 const std::string &Name = "", Instruction *InsertBefore = 0) {
1885 return new(ArgEnd - ArgBegin + 3) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, InsertBefore);
1886 }
1887 template
1888 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
1889 InputIterator ArgBegin, InputIterator ArgEnd,
1890 const std::string &Name, BasicBlock *InsertAtEnd) {
1891 return new(ArgEnd - ArgBegin + 3) InvokeInst(Func, IfNormal, IfException, ArgBegin, ArgEnd, Name, InsertAtEnd);
1892 }
17411893
17421894 ~InvokeInst();
17431895
18552007 /// until an invoke instruction is found.
18562008 ///
18572009 class UnwindInst : public TerminatorInst {
1858 public:
2010 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2011 public:
2012 // allocate space for exactly zero operands
2013 void *operator new(size_t s) {
2014 return User::operator new(s, 0);
2015 }
18592016 explicit UnwindInst(Instruction *InsertBefore = 0);
18602017 explicit UnwindInst(BasicBlock *InsertAtEnd);
18612018
18872044 /// end of the block cannot be reached.
18882045 ///
18892046 class UnreachableInst : public TerminatorInst {
1890 public:
2047 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
2048 public:
2049 // allocate space for exactly zero operands
2050 void *operator new(size_t s) {
2051 return User::operator new(s, 0);
2052 }
18912053 explicit UnreachableInst(Instruction *InsertBefore = 0);
18922054 explicit UnreachableInst(BasicBlock *InsertAtEnd);
18932055
23872549 /// GetResultInst - This instruction extracts individual result value from
23882550 /// aggregate value, where aggregate value is returned by CallInst.
23892551 ///
2390 class GetResultInst : public Instruction {
2552 class GetResultInst : public /*FIXME: Unary*/Instruction {
2553 void *operator new(size_t, unsigned); // DO NOT IMPLEMENT
23912554 Use Aggr;
23922555 unsigned Idx;
23932556 GetResultInst(const GetResultInst &GRI) :
23972560 }
23982561
23992562 public:
2563 // allocate space for exactly one operand
2564 void *operator new(size_t s) {
2565 return User::operator new(s, 1);
2566 }
24002567 explicit GetResultInst(Value *Aggr, unsigned index,
24012568 const std::string &Name = "",
24022569 Instruction *InsertBefore = 0);
8686
8787 /// CreateRetVoid - Create a 'ret void' instruction.
8888 ReturnInst *CreateRetVoid() {
89 return Insert(new ReturnInst());
89 return Insert(ReturnInst::Create());
9090 }
9191
9292 /// @verbatim
9393 /// CreateRet - Create a 'ret ' instruction.
9494 /// @endverbatim
9595 ReturnInst *CreateRet(Value *V) {
96 return Insert(new ReturnInst(V));
96 return Insert(ReturnInst::Create(V));
9797 }
9898
9999 /// CreateBr - Create an unconditional 'br label X' instruction.
100100 BranchInst *CreateBr(BasicBlock *Dest) {
101 return Insert(new BranchInst(Dest));
101 return Insert(BranchInst::Create(Dest));
102102 }
103103
104104 /// CreateCondBr - Create a conditional 'br Cond, TrueDest, FalseDest'
105105 /// instruction.
106106 BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False) {
107 return Insert(new BranchInst(True, False, Cond));
107 return Insert(BranchInst::Create(True, False, Cond));
108108 }
109109
110110 /// CreateSwitch - Create a switch instruction with the specified value,
111111 /// default dest, and with a hint for the number of cases that will be added
112112 /// (for efficient allocation).
113113 SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10) {
114 return Insert(new SwitchInst(V, Dest, NumCases));
114 return Insert(SwitchInst::Create(V, Dest, NumCases));
115115 }
116116
117117 /// CreateInvoke - Create an invoke instruction.
119119 InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
120120 BasicBlock *UnwindDest, InputIterator ArgBegin,
121121 InputIterator ArgEnd, const char *Name = "") {
122 return(Insert(new InvokeInst(Callee, NormalDest, UnwindDest,
123 ArgBegin, ArgEnd, Name)));
122 return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest,
123 ArgBegin, ArgEnd, Name));
124124 }
125125
126126 UnwindInst *CreateUnwind() {
220220 template
221221 GetElementPtrInst *CreateGEP(Value *Ptr, InputIterator IdxBegin,
222222 InputIterator IdxEnd, const char *Name = "") {
223 return(Insert(new GetElementPtrInst(Ptr, IdxBegin, IdxEnd, Name)));
223 return(Insert(GetElementPtrInst::Create(Ptr, IdxBegin, IdxEnd, Name)));
224224 }
225225 GetElementPtrInst *CreateGEP(Value *Ptr, Value *Idx, const char *Name = "") {
226 return Insert(new GetElementPtrInst(Ptr, Idx, Name));
226 return Insert(GetElementPtrInst::Create(Ptr, Idx, Name));
227227 }
228228 GetElementPtrInst *CreateStructGEP(Value *Ptr, unsigned Idx,
229229 const char *Name = "") {
231231 ConstantInt::get(llvm::Type::Int32Ty, 0),
232232 ConstantInt::get(llvm::Type::Int32Ty, Idx)
233233 };
234 return Insert(new GetElementPtrInst(Ptr, Idxs, Idxs+2, Name));
234 return Insert(GetElementPtrInst::Create(Ptr, Idxs, Idxs+2, Name));
235235 }
236236
237237 //===--------------------------------------------------------------------===//
383383 //===--------------------------------------------------------------------===//
384384
385385 PHINode *CreatePHI(const Type *Ty, const char *Name = "") {
386 return Insert(new PHINode(Ty, Name));
386 return Insert(PHINode::Create(Ty, Name));
387387 }
388388
389389 CallInst *CreateCall(Value *Callee, const char *Name = "") {
390 return Insert(new CallInst(Callee, Name));
390 return Insert(CallInst::Create(Callee, Name));
391391 }
392392 CallInst *CreateCall(Value *Callee, Value *Arg, const char *Name = "") {
393 return Insert(new CallInst(Callee, Arg, Name));
393 return Insert(CallInst::Create(Callee, Arg, Name));
394394 }
395395
396396 template
397397 CallInst *CreateCall(Value *Callee, InputIterator ArgBegin,
398398 InputIterator ArgEnd, const char *Name = "") {
399 return(Insert(new CallInst(Callee, ArgBegin, ArgEnd, Name)));
399 return Insert(CallInst::Create(Callee, ArgBegin, ArgEnd, Name));
400400 }
401401
402402 SelectInst *CreateSelect(Value *C, Value *True, Value *False,
403403 const char *Name = "") {
404 return Insert(new SelectInst(C, True, False, Name));
404 return Insert(SelectInst::Create(C, True, False, Name));
405405 }
406406
407407 VAArgInst *CreateVAArg(Value *List, const Type *Ty, const char *Name = "") {
415415
416416 InsertElementInst *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx,
417417 const char *Name = "") {
418 return Insert(new InsertElementInst(Vec, NewElt, Idx, Name));
418 return Insert(InsertElementInst::Create(Vec, NewElt, Idx, Name));
419419 }
420420
421421 ShuffleVectorInst *CreateShuffleVector(Value *V1, Value *V2, Value *Mask,
2424
2525 class User : public Value {
2626 User(const User &); // Do not implement
27 void *operator new(size_t); // Do not implement
2728 protected:
2829 /// OperandList - This is a pointer to the array of Users for this operand.
2930 /// For nodes of fixed arity (e.g. a binary operator) this array will live
3738 ///
3839 unsigned NumOperands;
3940
40 public:
41 void *operator new(size_t s, unsigned) {
42 return ::operator new(s);
43 }
4144 User(const Type *Ty, unsigned vty, Use *OpList, unsigned NumOps)
4245 : Value(Ty, vty), OperandList(OpList), NumOperands(NumOps) {}
4346
47 public:
4448 Value *getOperand(unsigned i) const {
4549 assert(i < NumOperands && "getOperand() out of range!");
4650 return OperandList[i];
142142 // Create and insert the PHI node for the induction variable in the
143143 // specified loop.
144144 BasicBlock *Header = L->getHeader();
145 PHINode *PN = new PHINode(Ty, "indvar", Header->begin());
145 PHINode *PN = PHINode::Create(Ty, "indvar", Header->begin());
146146 PN->addIncoming(Constant::getNullValue(Ty), L->getLoopPreheader());
147147
148148 pred_iterator HPI = pred_begin(Header);
214214 for (unsigned i = 1; i < S->getNumOperands(); ++i) {
215215 Value *RHS = expand(S->getOperand(i));
216216 Value *ICmp = new ICmpInst(ICmpInst::ICMP_SGT, LHS, RHS, "tmp", InsertPt);
217 LHS = new SelectInst(ICmp, LHS, RHS, "smax", InsertPt);
217 LHS = SelectInst::Create(ICmp, LHS, RHS, "smax", InsertPt);
218218 }
219219 return LHS;
220220 }
224224 for (unsigned i = 1; i < S->getNumOperands(); ++i) {
225225 Value *RHS = expand(S->getOperand(i));
226226 Value *ICmp = new ICmpInst(ICmpInst::ICMP_UGT, LHS, RHS, "tmp", InsertPt);
227 LHS = new SelectInst(ICmp, LHS, RHS, "umax", InsertPt);
227 LHS = SelectInst::Create(ICmp, LHS, RHS, "umax", InsertPt);
228228 }
229229 return LHS;
230230 }
492492 }
493493 const Type* ElTy = PTy->getElementType();
494494 if (const FunctionType *FTy = dyn_cast(ElTy))
495 V = new Function(FTy, GlobalValue::ExternalLinkage);
495 V = Function::Create(FTy, GlobalValue::ExternalLinkage);
496496 else
497497 V = new GlobalVariable(ElTy, false, GlobalValue::ExternalLinkage, 0, "",
498498 (Module*)0, false, PTy->getAddressSpace());
550550 // We haven't seen this BB before and its first mention is a definition.
551551 // Just create it and return it.
552552 std::string Name (ID.Type == ValID::LocalName ? ID.getName() : "");
553 BB = new BasicBlock(Name, CurFun.CurrentFunction);
553 BB = BasicBlock::Create(Name, CurFun.CurrentFunction);
554554 if (ID.Type == ValID::LocalID) {
555555 assert(ID.Num == CurFun.NextValNum && "Invalid new block number");
556556 InsertValue(BB);
606606 std::string Name;
607607 if (ID.Type == ValID::LocalName)
608608 Name = ID.getName();
609 BB = new BasicBlock(Name, CurFun.CurrentFunction);
609 BB = BasicBlock::Create(Name, CurFun.CurrentFunction);
610610
611611 // Insert it in the forward refs map.
612612 CurFun.BBForwardRefs[ID] = BB;
17781778 GlobalValue *GV;
17791779 if (const FunctionType *FTy =
17801780 dyn_cast(PT->getElementType())) {
1781 GV = new Function(FTy, GlobalValue::ExternalWeakLinkage, Name,
1782 CurModule.CurrentModule);
1781 GV = Function::Create(FTy, GlobalValue::ExternalWeakLinkage, Name,
1782 CurModule.CurrentModule);
17831783 } else {
17841784 GV = new GlobalVariable(PT->getElementType(), false,
17851785 GlobalValue::ExternalWeakLinkage, 0,
23182318 AI->setName("");
23192319 }
23202320 } else { // Not already defined?
2321 Fn = new Function(FT, GlobalValue::ExternalWeakLinkage, FunctionName,
2322 CurModule.CurrentModule);
2321 Fn = Function::Create(FT, GlobalValue::ExternalWeakLinkage, FunctionName,
2322 CurModule.CurrentModule);
23232323 InsertValue(Fn, CurModule.Values);
23242324 }
23252325
25782578 RET ReturnedVal { // Return with a result...
25792579 ValueList &VL = *$2;
25802580 assert(!VL.empty() && "Invalid ret operands!");
2581 $$ = new ReturnInst(&VL[0], VL.size());
2581 $$ = ReturnInst::Create(&VL[0], VL.size());
25822582 delete $2;
25832583 CHECK_FOR_ERROR
25842584 }
25852585 | RET VOID { // Return with no result...
2586 $$ = new ReturnInst();
2586 $$ = ReturnInst::Create();
25872587 CHECK_FOR_ERROR
25882588 }
25892589 | BR LABEL ValueRef { // Unconditional Branch...
25902590 BasicBlock* tmpBB = getBBVal($3);
25912591 CHECK_FOR_ERROR
2592 $$ = new BranchInst(tmpBB);
2592 $$ = BranchInst::Create(tmpBB);
25932593 } // Conditional Branch...
25942594 | BR INTTYPE ValueRef ',' LABEL ValueRef ',' LABEL ValueRef {
25952595 assert(cast($2)->getBitWidth() == 1 && "Not Bool?");
25992599 CHECK_FOR_ERROR
26002600 Value* tmpVal = getVal(Type::Int1Ty, $3);
26012601 CHECK_FOR_ERROR
2602 $$ = new BranchInst(tmpBBA, tmpBBB, tmpVal);
2602 $$ = BranchInst::Create(tmpBBA, tmpBBB, tmpVal);
26032603 }
26042604 | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' {
26052605 Value* tmpVal = getVal($2, $3);
26062606 CHECK_FOR_ERROR
26072607 BasicBlock* tmpBB = getBBVal($6);
26082608 CHECK_FOR_ERROR
2609 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, $8->size());
2609 SwitchInst *S = SwitchInst::Create(tmpVal, tmpBB, $8->size());
26102610 $$ = S;
26112611
26122612 std::vector >::iterator I = $8->begin(),
26252625 CHECK_FOR_ERROR
26262626 BasicBlock* tmpBB = getBBVal($6);
26272627 CHECK_FOR_ERROR
2628 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0);
2628 SwitchInst *S = SwitchInst::Create(tmpVal, tmpBB, 0);
26292629 $$ = S;
26302630 CHECK_FOR_ERROR
26312631 }
27032703 PAL = PAListPtr::get(Attrs.begin(), Attrs.end());
27042704
27052705 // Create the InvokeInst
2706 InvokeInst *II = new InvokeInst(V, Normal, Except, Args.begin(),Args.end());
2706 InvokeInst *II = InvokeInst::Create(V, Normal, Except, Args.begin(),Args.end());
27072707 II->setCallingConv($2);
27082708 II->setParamAttrs(PAL);
27092709 $$ = II;
29102910 GEN_ERROR("select condition must be boolean");
29112911 if ($4->getType() != $6->getType())
29122912 GEN_ERROR("select value types should match");
2913 $$ = new SelectInst($2, $4, $6);
2913 $$ = SelectInst::Create($2, $4, $6);
29142914 CHECK_FOR_ERROR
29152915 }
29162916 | VAARG ResolvedVal ',' Types {
29292929 | INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
29302930 if (!InsertElementInst::isValidOperands($2, $4, $6))
29312931 GEN_ERROR("Invalid insertelement operands");
2932 $$ = new InsertElementInst($2, $4, $6);
2932 $$ = InsertElementInst::Create($2, $4, $6);
29332933 CHECK_FOR_ERROR
29342934 }
29352935 | SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal {
29422942 const Type *Ty = $2->front().first->getType();
29432943 if (!Ty->isFirstClassType())
29442944 GEN_ERROR("PHI node operands must be of first class type");
2945 $$ = new PHINode(Ty);
2945 $$ = PHINode::Create(Ty);
29462946 ((PHINode*)$$)->reserveOperandSpace($2->size());
29472947 while ($2->begin() != $2->end()) {
29482948 if ($2->front().first->getType() != Ty)
30303030 PAL = PAListPtr::get(Attrs.begin(), Attrs.end());
30313031
30323032 // Create the call node
3033 CallInst *CI = new CallInst(V, Args.begin(), Args.end());
3033 CallInst *CI = CallInst::Create(V, Args.begin(), Args.end());
30343034 CI->setTailCall($1);
30353035 CI->setCallingConv($2);
30363036 CI->setParamAttrs(PAL);
31433143 (*$2)->getDescription()+ "'");
31443144 Value* tmpVal = getVal(*$2, $3);
31453145 CHECK_FOR_ERROR
3146 $$ = new GetElementPtrInst(tmpVal, $4->begin(), $4->end());
3146 $$ = GetElementPtrInst::Create(tmpVal, $4->begin(), $4->end());
31473147 delete $2;
31483148 delete $4;
31493149 };
121121 class ConstantPlaceHolder : public ConstantExpr {
122122 ConstantPlaceHolder(); // DO NOT IMPLEMENT
123123 void operator=(const ConstantPlaceHolder &); // DO NOT IMPLEMENT
124 Use Op;
124125 public:
125 Use Op;
126 // allocate space for exactly one operand
127 void *operator new(size_t s) {
128 return User::operator new(s, 1);
129 }
126130 explicit ConstantPlaceHolder(const Type *Ty)
127131 : ConstantExpr(Ty, Instruction::UserOp1, &Op, 1),
128132 Op(UndefValue::get(Type::Int32Ty), this) {
10451049 if (!FTy)
10461050 return Error("Function not a pointer to function type!");
10471051
1048 Function *Func = new Function(FTy, GlobalValue::ExternalLinkage,
1049 "", TheModule);
1052 Function *Func = Function::Create(FTy, GlobalValue::ExternalLinkage,
1053 "", TheModule);
10501054
10511055 Func->setCallingConv(Record[1]);
10521056 bool isProto = Record[2];
12151219 // Create all the basic blocks for the function.
12161220 FunctionBBs.resize(Record[0]);
12171221 for (unsigned i = 0, e = FunctionBBs.size(); i != e; ++i)
1218 FunctionBBs[i] = new BasicBlock("", F);
1222 FunctionBBs[i] = BasicBlock::Create("", F);
12191223 CurBB = FunctionBBs[0];
12201224 continue;
12211225
12691273 GEPIdx.push_back(Op);
12701274 }
12711275
1272 I = new GetElementPtrInst(BasePtr, GEPIdx.begin(), GEPIdx.end());
1276 I = GetElementPtrInst::Create(BasePtr, GEPIdx.begin(), GEPIdx.end());
12731277 break;
12741278 }
12751279
12811285 getValue(Record, OpNum, Type::Int1Ty, Cond))
12821286 return Error("Invalid SELECT record");
12831287
1284 I = new SelectInst(Cond, TrueVal, FalseVal);
1288 I = SelectInst::Create(Cond, TrueVal, FalseVal);
12851289 break;
12861290 }
12871291
13031307 cast(Vec->getType())->getElementType(), Elt) ||
13041308 getValue(Record, OpNum, Type::Int32Ty, Idx))
13051309 return Error("Invalid INSERTELT record");
1306 I = new InsertElementInst(Vec, Elt, Idx);
1310 I = InsertElementInst::Create(Vec, Elt, Idx);
13071311 break;
13081312 }
13091313
13531357 {
13541358 unsigned Size = Record.size();
13551359 if (Size == 0) {
1356 I = new ReturnInst();
1360 I = ReturnInst::Create();
13571361 break;
13581362 } else {
13591363 unsigned OpNum = 0;
13661370 } while(OpNum != Record.size());
13671371
13681372 // SmallVector Vs has at least one element.
1369 I = new ReturnInst(&Vs[0], Vs.size());
1373 I = ReturnInst::Create(&Vs[0], Vs.size());
13701374 break;
13711375 }
13721376 }
13781382 return Error("Invalid BR record");
13791383
13801384 if (Record.size() == 1)
1381 I = new BranchInst(TrueDest);
1385 I = BranchInst::Create(TrueDest);
13821386 else {
13831387 BasicBlock *FalseDest = getBasicBlock(Record[1]);
13841388 Value *Cond = getFnValueByID(Record[2], Type::Int1Ty);
13851389 if (FalseDest == 0 || Cond == 0)
13861390 return Error("Invalid BR record");
1387 I = new BranchInst(TrueDest, FalseDest, Cond);
1391 I = BranchInst::Create(TrueDest, FalseDest, Cond);
13881392 }
13891393 break;
13901394 }
13971401 if (OpTy == 0 || Cond == 0 || Default == 0)
13981402 return Error("Invalid SWITCH record");
13991403 unsigned NumCases = (Record.size()-3)/2;
1400 SwitchInst *SI = new SwitchInst(Cond, Default, NumCases);
1404 SwitchInst *SI = SwitchInst::Create(Cond, Default, NumCases);
14011405 for (unsigned i = 0, e = NumCases; i != e; ++i) {
14021406 ConstantInt *CaseVal =
14031407 dyn_cast_or_null(getFnValueByID(Record[3+i*2], OpTy));
14531457 }
14541458 }
14551459
1456 I = new InvokeInst(Callee, NormalBB, UnwindBB, Ops.begin(), Ops.end());
1460 I = InvokeInst::Create(Callee, NormalBB, UnwindBB, Ops.begin(), Ops.end());
14571461 cast(I)->setCallingConv(CCInfo);
14581462 cast(I)->setParamAttrs(PAL);
14591463 break;
14701474 const Type *Ty = getTypeByID(Record[0]);
14711475 if (!Ty) return Error("Invalid PHI record");
14721476
1473 PHINode *PN = new PHINode(Ty);
1477 PHINode *PN = PHINode::Create(Ty);
14741478 PN->reserveOperandSpace(Record.size()-1);
14751479
14761480 for (unsigned i = 0, e = Record.size()-1; i != e; i += 2) {
15901594 }
15911595 }
15921596
1593 I = new CallInst(Callee, Args.begin(), Args.end());
1597 I = CallInst::Create(Callee, Args.begin(), Args.end());
15941598 cast(I)->setCallingConv(CCInfo>>1);
15951599 cast(I)->setTailCall(CCInfo & 1);
15961600 cast(I)->setParamAttrs(PAL);
5454 }
5555
5656 SmallVector Args(ArgBegin, ArgEnd);
57 CallInst *NewCI = new CallInst(FCache, Args.begin(), Args.end(),
58 CI->getName(), CI);
57 CallInst *NewCI = CallInst::Create(FCache, Args.begin(), Args.end(),
58 CI->getName(), CI);
5959 if (!CI->use_empty())
6060 CI->replaceAllUsesWith(NewCI);
6161 return NewCI;
338338 Function::arg_iterator args = F->arg_begin();
339339 Value* Val = args++; Val->setName("Val");
340340 Value* Lo = args++; Lo->setName("Lo");
341 Value* Hi = args++; Hi->setName("High");
341 Value* Hi = args++; Hi->setName("High");
342342
343343 // We want to select a range of bits here such that [Hi, Lo] is shifted
344344 // down to the low bits. However, it is quite possible that Hi is smaller
345345 // than Lo in which case the bits have to be reversed.
346346
347347 // Create the blocks we will need for the two cases (forward, reverse)
348 BasicBlock* CurBB = new BasicBlock("entry", F);
349 BasicBlock *RevSize = new BasicBlock("revsize", CurBB->getParent());
350 BasicBlock *FwdSize = new BasicBlock("fwdsize", CurBB->getParent());
351 BasicBlock *Compute = new BasicBlock("compute", CurBB->getParent());
352 BasicBlock *Reverse = new BasicBlock("reverse", CurBB->getParent());
353 BasicBlock *RsltBlk = new BasicBlock("result", CurBB->getParent());
348 BasicBlock* CurBB = BasicBlock::Create("entry", F);
349 BasicBlock *RevSize = BasicBlock::Create("revsize", CurBB->getParent());
350 BasicBlock *FwdSize = BasicBlock::Create("fwdsize", CurBB->getParent());
351 BasicBlock *Compute = BasicBlock::Create("compute", CurBB->getParent());
352 BasicBlock *Reverse = BasicBlock::Create("reverse", CurBB->getParent());
353 BasicBlock *RsltBlk = BasicBlock::Create("result", CurBB->getParent());
354354
355355 // Cast Hi and Lo to the size of Val so the widths are all the same
356356 if (Hi->getType() != Val->getType())
368368 // Compare the Hi and Lo bit positions. This is used to determine
369369 // which case we have (forward or reverse)
370370 ICmpInst *Cmp = new ICmpInst(ICmpInst::ICMP_ULT, Hi, Lo, "less",CurBB);
371 new BranchInst(RevSize, FwdSize, Cmp, CurBB);
371 BranchInst::Create(RevSize, FwdSize, Cmp, CurBB);
372372
373373 // First, copmute the number of bits in the forward case.
374374 Instruction* FBitSize =
375375 BinaryOperator::createSub(Hi, Lo,"fbits", FwdSize);
376 new BranchInst(Compute, FwdSize);
376 BranchInst::Create(Compute, FwdSize);
377377
378378 // Second, compute the number of bits in the reverse case.
379379 Instruction* RBitSize =
380380 BinaryOperator::createSub(Lo, Hi, "rbits", RevSize);
381 new BranchInst(Compute, RevSize);
381 BranchInst::Create(Compute, RevSize);
382382
383383 // Now, compute the bit range. Start by getting the bitsize and the shift
384384 // amount (either Hi or Lo) from PHI nodes. Then we compute a mask for
388388 // reversed.
389389
390390 // Get the BitSize from one of the two subtractions
391 PHINode *BitSize = new PHINode(Val->getType(), "bits", Compute);
391 PHINode *BitSize = PHINode::Create(Val->getType(), "bits", Compute);
392392 BitSize->reserveOperandSpace(2);
393393 BitSize->addIncoming(FBitSize, FwdSize);
394394 BitSize->addIncoming(RBitSize, RevSize);
395395
396396 // Get the ShiftAmount as the smaller of Hi/Lo
397 PHINode *ShiftAmt = new PHINode(Val->getType(), "shiftamt", Compute);
397 PHINode *ShiftAmt = PHINode::Create(Val->getType(), "shiftamt", Compute);
398398 ShiftAmt->reserveOperandSpace(2);
399399 ShiftAmt->addIncoming(Lo, FwdSize);
400400 ShiftAmt->addIncoming(Hi, RevSize);
412412 Instruction* FRes =
413413 BinaryOperator::createLShr(Val, ShiftAmt, "fres", Compute);
414414 FRes = BinaryOperator::createAnd(FRes, Mask, "fres", Compute);
415 new BranchInst(Reverse, RsltBlk, Cmp, Compute);
415 BranchInst::Create(Reverse, RsltBlk, Cmp, Compute);
416416
417417 // In the Reverse block we have the mask already in FRes but we must reverse
418418 // it by shifting FRes bits right and putting them in RRes by shifting them
419419 // in from left.
420420
421421 // First set up our loop counters
422 PHINode *Count = new PHINode(Val->getType(), "count", Reverse);
422 PHINode *Count = PHINode::Create(Val->getType(), "count", Reverse);
423423 Count->reserveOperandSpace(2);
424424 Count->addIncoming(BitSizePlusOne, Compute);
425425
426426 // Next, get the value that we are shifting.
427 PHINode *BitsToShift = new PHINode(Val->getType(), "val", Reverse);
427 PHINode *BitsToShift = PHINode::Create(Val->getType(), "val", Reverse);
428428 BitsToShift->reserveOperandSpace(2);
429429 BitsToShift->addIncoming(FRes, Compute);
430430
431431 // Finally, get the result of the last computation
432 PHINode *RRes = new PHINode(Val->getType(), "rres", Reverse);
432 PHINode *RRes = PHINode::Create(Val->getType(), "rres", Reverse);
433433 RRes->reserveOperandSpace(2);
434434 RRes->addIncoming(Zero, Compute);
435435
455455 // Terminate loop if we've moved all the bits.
456456 ICmpInst *Cond =
457457 new ICmpInst(ICmpInst::ICMP_EQ, Decr, Zero, "cond", Reverse);
458 new BranchInst(RsltBlk, Reverse, Cond, Reverse);
458 BranchInst::Create(RsltBlk, Reverse, Cond, Reverse);
459459
460460 // Finally, in the result block, select one of the two results with a PHI
461461 // node and return the result;
462462 CurBB = RsltBlk;
463 PHINode *BitSelect = new PHINode(Val->getType(), "part_select", CurBB);
463 PHINode *BitSelect = PHINode::Create(Val->getType(), "part_select", CurBB);
464464 BitSelect->reserveOperandSpace(2);
465465 BitSelect->addIncoming(FRes, Compute);
466466 BitSelect->addIncoming(NewRes, Reverse);
467 new ReturnInst(BitSelect, CurBB);
467 ReturnInst::Create(BitSelect, CurBB);
468468 }
469469
470470 // Return a call to the implementation function
473473 CI->getOperand(2),
474474 CI->getOperand(3)
475475 };
476 return new CallInst(F, Args, array_endof(Args), CI->getName(), CI);
476 return CallInst::Create(F, Args, array_endof(Args), CI->getName(), CI);
477477 }
478478
479479 /// Convert the llvm.part.set.iX.iY.iZ intrinsic. This intrinsic takes
530530 ConstantInt* ValZero = ConstantInt::get(ValTy, 0);
531531
532532 // Basic blocks we fill in below.
533 BasicBlock* entry = new BasicBlock("entry", F, 0);
534 BasicBlock* large = new BasicBlock("large", F, 0);
535 BasicBlock* small = new BasicBlock("small", F, 0);
536 BasicBlock* reverse = new BasicBlock("reverse", F, 0);
537 BasicBlock* result = new BasicBlock("result", F, 0);
533 BasicBlock* entry = BasicBlock::Create("entry", F, 0);
534 BasicBlock* large = BasicBlock::Create("large", F, 0);
535 BasicBlock* small = BasicBlock::Create("small", F, 0);
536 BasicBlock* reverse = BasicBlock::Create("reverse", F, 0);
537 BasicBlock* result = BasicBlock::Create("result", F, 0);
538538
539539 // BASIC BLOCK: entry
540540 // First, get the number of bits that we're placing as an i32
541541 ICmpInst* is_forward =
542542 new ICmpInst(ICmpInst::ICMP_ULT, Lo, Hi, "", entry);
543 SelectInst* Hi_pn = new SelectInst(is_forward, Hi, Lo, "", entry);
544 SelectInst* Lo_pn = new SelectInst(is_forward, Lo, Hi, "", entry);
543 SelectInst* Hi_pn = SelectInst::Create(is_forward, Hi, Lo, "", entry);
544 SelectInst* Lo_pn = SelectInst::Create(is_forward, Lo, Hi, "", entry);
545545 BinaryOperator* NumBits = BinaryOperator::createSub(Hi_pn, Lo_pn, "",entry);
546546 NumBits = BinaryOperator::createAdd(NumBits, One, "", entry);
547547 // Now, convert Lo and Hi to ValTy bit width
554554 // are replacing and deal with it.
555555 ICmpInst* is_large =
556556 new ICmpInst(ICmpInst::ICMP_ULT, NumBits, RepBitWidth, "", entry);
557 new BranchInst(large, small, is_large, entry);
557 BranchInst::Create(large, small, is_large, entry);
558558
559559 // BASIC BLOCK: large
560560 Instruction* MaskBits =
564564 BinaryOperator* Mask1 =
565565 BinaryOperator::createLShr(RepMask, MaskBits, "", large);
566566 BinaryOperator* Rep2 = BinaryOperator::createAnd(Mask1, Rep, "", large);
567 new BranchInst(small, large);
567 BranchInst::Create(small, large);
568568
569569 // BASIC BLOCK: small
570 PHINode* Rep3 = new PHINode(RepTy, "", small);
570 PHINode* Rep3 = PHINode::Create(RepTy, "", small);
571571 Rep3->reserveOperandSpace(2);
572572 Rep3->addIncoming(Rep2, large);
573573 Rep3->addIncoming(Rep, entry);
576576 Rep4 = new ZExtInst(Rep3, ValTy, "", small);
577577 else if (ValBits < RepBits)
578578 Rep4 = new TruncInst(Rep3, ValTy, "", small);
579 new BranchInst(result, reverse, is_forward, small);
579 BranchInst::Create(result, reverse, is_forward, small);
580580
581581 // BASIC BLOCK: reverse (reverses the bits of the replacement)
582582 // Set up our loop counter as a PHI so we can decrement on each iteration.
583583 // We will loop for the number of bits in the replacement value.
584 PHINode *Count = new PHINode(Type::Int32Ty, "count", reverse);
584 PHINode *Count = PHINode::Create(Type::Int32Ty, "count", reverse);
585585 Count->reserveOperandSpace(2);
586586 Count->addIncoming(NumBits, small);
587587
588588 // Get the value that we are shifting bits out of as a PHI because
589589 // we'll change this with each iteration.
590 PHINode *BitsToShift = new PHINode(Val->getType(), "val", reverse);
590 PHINode *BitsToShift = PHINode::Create(Val->getType(), "val", reverse);
591591 BitsToShift->reserveOperandSpace(2);
592592 BitsToShift->addIncoming(Rep4, small);
593593
594594 // Get the result of the last computation or zero on first iteration
595 PHINode *RRes = new PHINode(Val->getType(), "rres", reverse);
595 PHINode *RRes = PHINode::Create(Val->getType(), "rres", reverse);
596596 RRes->reserveOperandSpace(2);
597597 RRes->addIncoming(ValZero, small);
598598
614614
615615 // Terminate loop if we've moved all the bits.
616616 ICmpInst *Cond = new ICmpInst(ICmpInst::ICMP_EQ, Decr, Zero, "", reverse);
617 new BranchInst(result, reverse, Cond, reverse);
617 BranchInst::Create(result, reverse, Cond, reverse);
618618
619619 // BASIC BLOCK: result
620 PHINode *Rplcmnt = new PHINode(Val->getType(), "", result);
620 PHINode *Rplcmnt = PHINode::Create(Val->getType(), "", result);
621621 Rplcmnt->reserveOperandSpace(2);
622622 Rplcmnt->addIncoming(NewRes, reverse);
623623 Rplcmnt->addIncoming(Rep4, small);
629629 Value* t5 = BinaryOperator::createAnd(t4, Val, "", result);
630630 Value* t6 = BinaryOperator::createShl(Rplcmnt, Lo, "", result);
631631 Value* Rslt = BinaryOperator::createOr(t5, t6, "part_set", result);
632 new ReturnInst(Rslt, result);
632 ReturnInst::Create(Rslt, result);
633633 }
634634
635635 // Return a call to the implementation function
639639 CI->getOperand(3),
640640 CI->getOperand(4)
641641 };
642 return new CallInst(F, Args, array_endof(Args), CI->getName(), CI);
642 return CallInst::Create(F, Args, array_endof(Args), CI->getName(), CI);
643643 }
644644
645645
704704 // cttz(x) -> ctpop(~X & (X-1))
705705 Value *Src = CI->getOperand(1);
706706 Value *NotSrc = BinaryOperator::createNot(Src, Src->getName()+".not", CI);
707 Value *SrcM1 = ConstantInt::get(Src->getType(), 1);
707 Value *SrcM1 = ConstantInt::get(Src->getType(), 1);
708708 SrcM1 = BinaryOperator::createSub(Src, SrcM1, "", CI);
709709 Src = LowerCTPOP(BinaryOperator::createAnd(NotSrc, SrcM1, "", CI), CI);
710710 CI->replaceAllUsesWith(Src);
132132 return 0;
133133
134134 // Create a cleanup block.
135 BasicBlock *CleanupBB = new BasicBlock(CleanupBBName, &F);
135 BasicBlock *CleanupBB = BasicBlock::Create(CleanupBBName, &F);
136136 UnwindInst *UI = new UnwindInst(CleanupBB);
137137
138138 // Transform the 'call' instructions into 'invoke's branching to the
154154 Args.clear();
155155 Args.append(CI->op_begin() + 1, CI->op_end());
156156
157 InvokeInst *II = new InvokeInst(CI->getOperand(0),
158 NewBB, CleanupBB,
159 Args.begin(), Args.end(),
160 CI->getName(), CallBB);
157 InvokeInst *II = InvokeInst::Create(CI->getOperand(0),
158 NewBB, CleanupBB,
159 Args.begin(), Args.end(),
160 CI->getName(), CallBB);
161161 II->setCallingConv(CI->getCallingConv());
162162 II->setParamAttrs(CI->getParamAttrs());
163163 CI->replaceAllUsesWith(II);
219219
220220 // First, create the function.
221221 FunctionType *STy=FunctionType::get(RetTy, std::vector(), false);
222 Function *Stub = new Function(STy, Function::InternalLinkage, "",
223 F->getParent());
222 Function *Stub = Function::Create(STy, Function::InternalLinkage, "",
223 F->getParent());
224224
225225 // Insert a basic block.
226 BasicBlock *StubBB = new BasicBlock("", Stub);
226 BasicBlock *StubBB = BasicBlock::Create("", Stub);
227227
228228 // Convert all of the GenericValue arguments over to constants. Note that we
229229 // currently don't support varargs.
256256 Args.push_back(C);
257257 }
258258
259 CallInst *TheCall = new CallInst(F, Args.begin(), Args.end(), "", StubBB);
259 CallInst *TheCall = CallInst::Create(F, Args.begin(), Args.end(), "", StubBB);
260260 TheCall->setTailCall();
261261 if (TheCall->getType() != Type::VoidTy)
262 new ReturnInst(TheCall, StubBB); // Return result of the call.
262 ReturnInst::Create(TheCall, StubBB); // Return result of the call.
263263 else
264 new ReturnInst(StubBB); // Just return void.
264 ReturnInst::Create(StubBB); // Just return void.
265265
266266 // Finally, return the value returned by our nullary stub function.
267267 return runFunction(Stub, std::vector());
821821 // We have a definition of the same name but different type in the
822822 // source module. Copy the prototype to the destination and replace
823823 // uses of the destination's prototype with the new prototype.
824 Function *NewDF = new Function(SF->getFunctionType(), SF->getLinkage(),
825 SF->getName(), Dest);
824 Function *NewDF = Function::Create(SF->getFunctionType(), SF->getLinkage(),
825 SF->getName(), Dest);
826826 CopyGVAttributes(NewDF, SF);
827827
828828 // Any uses of DF need to change to NewDF, with cast
857857 } else if (!DF || SF->hasInternalLinkage() || DF->hasInternalLinkage()) {
858858 // Function does not already exist, simply insert an function signature
859859 // identical to SF into the dest module.
860 Function *NewDF = new Function(SF->getFunctionType(), SF->getLinkage(),
861 SF->getName(), Dest);
860 Function *NewDF = Function::Create(SF->getFunctionType(), SF->getLinkage(),
861 SF->getName(), Dest);
862862 CopyGVAttributes(NewDF, SF);
863863
864864 // If the LLVM runtime renamed the function, but it is an externally
253253 Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
254254
255255 Value *Op = CI->getOperand(1);
256 Op = new CallInst(Int, Op, CI->getName(), CI);
256 Op = CallInst::Create(Int, Op, CI->getName(), CI);
257257
258258 CI->replaceAllUsesWith(Op);
259259 CI->eraseFromParent();
468468 FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg());
469469
470470 // Create the new function body and insert it into the module...
471 Function *NF = new Function(NFTy, F->getLinkage(), F->getName());
471 Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName());
472472 NF->setCallingConv(F->getCallingConv());
473473
474474 // Recompute the parameter attributes list based on the new arguments for
517517 Value *Idxs[2] = { ConstantInt::get(Type::Int32Ty, 0), 0 };
518518 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
519519 Idxs[1] = ConstantInt::get(Type::Int32Ty, i);
520 Value *Idx = new GetElementPtrInst(*AI, Idxs, Idxs+2,
521 (*AI)->getName()+"."+utostr(i),
522 Call);
520 Value *Idx = GetElementPtrInst::Create(*AI, Idxs, Idxs+2,
521 (*AI)->getName()+"."+utostr(i),
522 Call);
523523 // TODO: Tell AA about the new values?
524524 Args.push_back(new LoadInst(Idx, Idx->getName()+".val", Call));
525525 }
531531 Value *V = *AI;
532532 LoadInst *OrigLoad = OriginalLoads[*SI];
533533 if (!SI->empty()) {
534 V = new GetElementPtrInst(V, SI->begin(), SI->end(),
535 V->getName()+".idx", Call);
534 V = GetElementPtrInst::Create(V, SI->begin(), SI->end(),
535 V->getName()+".idx", Call);
536536 AA.copyValue(OrigLoad->getOperand(0), V);
537537 }
538538 Args.push_back(new LoadInst(V, V->getName()+".val", Call));
552552
553553 Instruction *New;
554554 if (InvokeInst *II = dyn_cast(Call)) {
555 New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
556 Args.begin(), Args.end(), "", Call);
555 New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
556 Args.begin(), Args.end(), "", Call);
557557 cast(New)->setCallingConv(CS.getCallingConv());
558558 cast(New)->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(),
559559 ParamAttrsVec.end()));
560560 } else {
561 New = new CallInst(NF, Args.begin(), Args.end(), "", Call);
561 New = CallInst::Create(NF, Args.begin(), Args.end(), "", Call);
562562 cast(New)->setCallingConv(CS.getCallingConv());
563563 cast(New)->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(),
564564 ParamAttrsVec.end()));
615615
616616 for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i) {
617617 Idxs[1] = ConstantInt::get(Type::Int32Ty, i);
618 Value *Idx = new GetElementPtrInst(TheAlloca, Idxs, Idxs+2,
619 TheAlloca->getName()+"."+utostr(i),
620 InsertPt);
618 Value *Idx = GetElementPtrInst::Create(TheAlloca, Idxs, Idxs+2,
619 TheAlloca->getName()+"."+utostr(i),
620 InsertPt);
621621 I2->setName(I->getName()+"."+utostr(i));
622622 new StoreInst(I2++, Idx, InsertPt);
623623 }
156156 unsigned NumArgs = Params.size();
157157
158158 // Create the new function body and insert it into the module...
159 Function *NF = new Function(NFTy, Fn.getLinkage());
159 Function *NF = Function::Create(NFTy, Fn.getLinkage());
160160 NF->setCallingConv(Fn.getCallingConv());
161161 NF->setParamAttrs(Fn.getParamAttrs());
162162 if (Fn.hasCollector())
186186
187187 Instruction *New;
188188 if (InvokeInst *II = dyn_cast(Call)) {
189 New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
190 Args.begin(), Args.end(), "", Call);
189 New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
190 Args.begin(), Args.end(), "", Call);
191191 cast(New)->setCallingConv(CS.getCallingConv());
192192 cast(New)->setParamAttrs(PAL);
193193 } else {
194 New = new CallInst(NF, Args.begin(), Args.end(), "", Call);
194 New = CallInst::Create(NF, Args.begin(), Args.end(), "", Call);
195195 cast(New)->setCallingConv(CS.getCallingConv());
196196 cast(New)->setParamAttrs(PAL);
197197 if (cast(Call)->isTailCall())
549549 FunctionType *NFTy = FunctionType::get(RetTy, Params, FTy->isVarArg());
550550
551551 // Create the new function body and insert it into the module...
552 Function *NF = new Function(NFTy, F->getLinkage());
552 Function *NF = Function::Create(NFTy, F->getLinkage());
553553 NF->setCallingConv(F->getCallingConv());
554554 NF->setParamAttrs(NewPAL);
555555 if (F->hasCollector())
601601
602602 Instruction *New;
603603 if (InvokeInst *II = dyn_cast(Call)) {
604 New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
605 Args.begin(), Args.end(), "", Call);
604 New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
605 Args.begin(), Args.end(), "", Call);
606606 cast(New)->setCallingConv(CS.getCallingConv());
607607 cast(New)->setParamAttrs(NewCallPAL);
608608 } else {
609 New = new CallInst(NF, Args.begin(), Args.end(), "", Call);
609 New = CallInst::Create(NF, Args.begin(), Args.end(), "", Call);
610610 cast(New)->setCallingConv(CS.getCallingConv());
611611 cast(New)->setParamAttrs(NewCallPAL);
612612 if (cast(Call)->isTailCall())
659659 if (F->getReturnType() != NF->getReturnType())
660660 for (Function::iterator BB = NF->begin(), E = NF->end(); BB != E; ++BB)
661661 if (ReturnInst *RI = dyn_cast(BB->getTerminator())) {
662 new ReturnInst(0, RI);
662 ReturnInst::Create(0, RI);
663663 BB->getInstList().erase(RI);
664664 }
665665
120120
121121 for (Module::iterator I = M.begin(); ; ++I) {
122122 if (std::find(Named.begin(), Named.end(), &*I) == Named.end()) {
123 Function *New = new Function(I->getFunctionType(),
124 GlobalValue::ExternalLinkage);
123 Function *New = Function::Create(I->getFunctionType(),
124 GlobalValue::ExternalLinkage);
125125 New->setCallingConv(I->getCallingConv());
126126 New->setParamAttrs(I->getParamAttrs());
127127 if (I->hasCollector())
545545 Idxs.push_back(NullInt);
546546 for (unsigned i = 3, e = GEPI->getNumOperands(); i != e; ++i)
547547 Idxs.push_back(GEPI->getOperand(i));
548 NewPtr = new GetElementPtrInst(NewPtr, Idxs.begin(), Idxs.end(),
549 GEPI->getName()+"."+utostr(Val), GEPI);
548 NewPtr = GetElementPtrInst::Create(NewPtr, Idxs.begin(), Idxs.end(),
549 GEPI->getName()+"."+utostr(Val), GEPI);
550550 }
551551 }
552552 GEP->replaceAllUsesWith(NewPtr);
788788 MI->getAlignment(), MI->getName(), MI);
789789 Value* Indices[2];
790790 Indices[0] = Indices[1] = Constant::getNullValue(Type::Int32Ty);
791 Value *NewGEP = new GetElementPtrInst(NewMI, Indices, Indices + 2,
792 NewMI->getName()+".el0", MI);
791 Value *NewGEP = GetElementPtrInst::Create(NewMI, Indices, Indices + 2,
792 NewMI->getName()+".el0", MI);
793793 MI->replaceAllUsesWith(NewGEP);
794794 MI->eraseFromParent();
795795 MI = NewMI;
10531053 GEPIdx.push_back(GEPI->getOperand(1));
10541054 GEPIdx.append(GEPI->op_begin()+3, GEPI->op_end());
10551055
1056 Value *NGEPI = new GetElementPtrInst(NewPtr, GEPIdx.begin(), GEPIdx.end(),
1057 GEPI->getName(), GEPI);
1056 Value *NGEPI = GetElementPtrInst::Create(NewPtr, GEPIdx.begin(), GEPIdx.end(),
1057 GEPI->getName(), GEPI);
10581058 GEPI->replaceAllUsesWith(NGEPI);
10591059 GEPI->eraseFromParent();
10601060 return;
10691069 for (unsigned i = 0, e = FieldGlobals.size(); i != e; ++i) {
10701070 Value *LoadV = GetHeapSROALoad(Load, i, FieldGlobals, InsertedLoadsForPtr);
10711071
1072 PHINode *FieldPN = new PHINode(LoadV->getType(),
1073 PN->getName()+"."+utostr(i), PN);
1072 PHINode *FieldPN = PHINode::Create(LoadV->getType(),
1073 PN->getName()+"."+utostr(i), PN);
10741074 // Fill in the predecessor values.
10751075 for (unsigned pred = 0, e = PN->getNumIncomingValues(); pred != e; ++pred) {
10761076 // Each predecessor either uses the load or the original malloc.
11721172
11731173 // Create the block to check the first condition. Put all these blocks at the
11741174 // end of the function as they are unlikely to be executed.
1175 BasicBlock *NullPtrBlock = new BasicBlock("malloc_ret_null",
1176 OrigBB->getParent());
1175 BasicBlock *NullPtrBlock = BasicBlock::Create("malloc_ret_null",
1176 OrigBB->getParent());
11771177
11781178 // Remove the uncond branch from OrigBB to ContBB, turning it into a cond
11791179 // branch on RunningOr.
11801180 OrigBB->getTerminator()->eraseFromParent();
1181 new BranchInst(NullPtrBlock, ContBB, RunningOr, OrigBB);
1181 BranchInst::Create(NullPtrBlock, ContBB, RunningOr, OrigBB);
11821182
11831183 // Within the NullPtrBlock, we need to emit a comparison and branch for each
11841184 // pointer, because some may be null while others are not.
11871187 Value *Cmp = new ICmpInst(ICmpInst::ICMP_NE, GVVal,
11881188 Constant::getNullValue(GVVal->getType()),
11891189 "tmp", NullPtrBlock);
1190 BasicBlock *FreeBlock = new BasicBlock("free_it", OrigBB->getParent());
1191 BasicBlock *NextBlock = new BasicBlock("next", OrigBB->getParent());
1192 new BranchInst(FreeBlock, NextBlock, Cmp, NullPtrBlock);
1190 BasicBlock *FreeBlock = BasicBlock::Create("free_it", OrigBB->getParent());
1191 BasicBlock *NextBlock = BasicBlock::Create("next", OrigBB->getParent());
1192 BranchInst::Create(FreeBlock, NextBlock, Cmp, NullPtrBlock);
11931193
11941194 // Fill in FreeBlock.
11951195 new FreeInst(GVVal, FreeBlock);
11961196 new StoreInst(Constant::getNullValue(GVVal->getType()), FieldGlobals[i],
11971197 FreeBlock);
1198 new BranchInst(NextBlock, FreeBlock);
1198 BranchInst::Create(NextBlock, FreeBlock);
11991199
12001200 NullPtrBlock = NextBlock;
12011201 }
12021202
1203 new BranchInst(ContBB, NullPtrBlock);
1204
1203 BranchInst::Create(ContBB, NullPtrBlock);
12051204
12061205 // MI is no longer needed, remove it.
12071206 MI->eraseFromParent();
14101409 if (IsOneZero)
14111410 NSI = new ZExtInst(NLI, LI->getType(), "", LI);
14121411 else
1413 NSI = new SelectInst(NLI, OtherVal, InitVal, "", LI);
1412 NSI = SelectInst::Create(NLI, OtherVal, InitVal, "", LI);
14141413 NSI->takeName(LI);
14151414 LI->replaceAllUsesWith(NSI);
14161415 }
5151 if (Function* F = M.getFunction("free")) {
5252 assert(F->isDeclaration() && "free not external?");
5353 if (!F->use_empty()) {
54 Function* FN = new Function(F->getFunctionType(),
55 GlobalValue::LinkOnceLinkage,
56 "free_llvm_bounce", &M);
57 BasicBlock* bb = new BasicBlock("entry",FN);
58 Instruction* R = new ReturnInst(bb);
54 Function* FN = Function::Create(F->getFunctionType(),
55 GlobalValue::LinkOnceLinkage,
56 "free_llvm_bounce", &M);
57 BasicBlock* bb = BasicBlock::Create("entry",FN);
58 Instruction* R = ReturnInst::Create(bb);
5959 new FreeInst(FN->arg_begin(), R);
6060 ++NumBounce;
6161 NumBounceSites += F->getNumUses();
6666 if (Function* F = M.getFunction("malloc")) {
6767 assert(F->isDeclaration() && "malloc not external?");
6868 if (!F->use_empty()) {
69 Function* FN = new Function(F->getFunctionType(),
70 GlobalValue::LinkOnceLinkage,
71 "malloc_llvm_bounce", &M);
72 BasicBlock* bb = new BasicBlock("entry",FN);
69 Function* FN = Function::Create(F->getFunctionType(),
70 GlobalValue::LinkOnceLinkage,
71 "malloc_llvm_bounce", &M);
72 BasicBlock* bb = BasicBlock::Create("entry",FN);
7373 Instruction* c = CastInst::createIntegerCast(
7474 FN->arg_begin(), Type::Int32Ty, false, "c", bb);
7575 Instruction* a = new MallocInst(Type::Int8Ty, c, "m", bb);
76 new ReturnInst(a, bb);
76 ReturnInst::Create(a, bb);
7777 ++NumBounce;
7878 NumBounceSites += F->getNumUses();
7979 F->replaceAllUsesWith(FN);
267267 SmallVector Args;
268268 Args.push_back(CI);
269269 Args.push_back(Inst->getOperand(2));
270 new CallInst(ThrowLongJmp, Args.begin(), Args.end(), "", Inst);
270 CallInst::Create(ThrowLongJmp, Args.begin(), Args.end(), "", Inst);
271271
272272 SwitchValuePair& SVP = SwitchValMap[Inst->getParent()->getParent()];
273273
275275 // we should branch to the basic block that determines if this longjmp
276276 // is applicable here. Otherwise, issue an unwind.
277277 if (SVP.first)
278 new BranchInst(SVP.first->getParent(), Inst);
278 BranchInst::Create(SVP.first->getParent(), Inst);
279279 else
280280 new UnwindInst(Inst);
281281
310310 // Fill in the alloca and call to initialize the SJ map.
311311 const Type *SBPTy = PointerType::getUnqual(Type::Int8Ty);
312312 AllocaInst* Map = new AllocaInst(SBPTy, 0, "SJMap", Inst);
313 new CallInst(InitSJMap, Map, "", Inst);
313 CallInst::Create(InitSJMap, Map, "", Inst);
314314 return SJMap[Func] = Map;
315315 }
316316
323323
324324 // The basic block we're going to jump to if we need to rethrow the
325325 // exception.
326 BasicBlock* Rethrow = new BasicBlock("RethrowExcept", Func);
326 BasicBlock* Rethrow = BasicBlock::Create("RethrowExcept", Func);
327327
328328 // Fill in the "Rethrow" BB with a call to rethrow the exception. This
329329 // is the last instruction in the BB since at this point the runtime
339339 {
340340 if (SwitchValMap[Func].first) return SwitchValMap[Func];
341341
342 BasicBlock* LongJmpPre = new BasicBlock("LongJmpBlkPre", Func);
342 BasicBlock* LongJmpPre = BasicBlock::Create("LongJmpBlkPre", Func);
343343 BasicBlock::InstListType& LongJmpPreIL = LongJmpPre->getInstList();
344344
345345 // Keep track of the preliminary basic block for some of the other
347347 PrelimBBMap[Func] = LongJmpPre;
348348
349349 // Grab the exception.
350 CallInst* Cond = new CallInst(IsLJException, "IsLJExcept");
350 CallInst* Cond = CallInst::Create(IsLJException, "IsLJExcept");
351351 LongJmpPreIL.push_back(Cond);
352352
353353 // The "decision basic block" gets the number associated with the
354354 // setjmp call returning to switch on and the value returned by
355355 // longjmp.
356 BasicBlock* DecisionBB = new BasicBlock("LJDecisionBB", Func);
356 BasicBlock* DecisionBB = BasicBlock::Create("LJDecisionBB", Func);
357357 BasicBlock::InstListType& DecisionBBIL = DecisionBB->getInstList();
358358
359 new BranchInst(DecisionBB, Rethrow, Cond, LongJmpPre);
359 BranchInst::Create(DecisionBB, Rethrow, Cond, LongJmpPre);
360360
361361 // Fill in the "decision" basic block.
362 CallInst* LJVal = new CallInst(GetLJValue, "LJVal");
362 CallInst* LJVal = CallInst::Create(GetLJValue, "LJVal");
363363 DecisionBBIL.push_back(LJVal);
364 CallInst* SJNum = new CallInst(TryCatchLJ, GetSetJmpMap(Func), "SJNum");
364 CallInst* SJNum = CallInst::Create(TryCatchLJ, GetSetJmpMap(Func), "SJNum");
365365 DecisionBBIL.push_back(SJNum);
366366
367 SwitchInst* SI = new SwitchInst(SJNum, Rethrow, 0, DecisionBB);
367 SwitchInst* SI = SwitchInst::Create(SJNum, Rethrow, 0, DecisionBB);
368368 return SwitchValMap[Func] = SwitchValuePair(SI, LJVal);
369369 }
370370
385385 make_vector(GetSetJmpMap(Func), BufPtr,
386386 ConstantInt::get(Type::Int32Ty,
387387 SetJmpIDMap[Func]++), 0);
388 new CallInst(AddSJToMap, Args.begin(), Args.end(), "", Inst);
388 CallInst::Create(AddSJToMap, Args.begin(), Args.end(), "", Inst);
389389
390390 // We are guaranteed that there are no values live across basic blocks
391391 // (because we are "not in SSA form" yet), but there can still be values live
427427
428428 // This PHI node will be in the new block created from the
429429 // splitBasicBlock call.
430 PHINode* PHI = new PHINode(Type::Int32Ty, "SetJmpReturn", Inst);
430 PHINode* PHI = PHINode::Create(Type::Int32Ty, "SetJmpReturn", Inst);
431431
432432 // Coming from a call to setjmp, the return is 0.
433433 PHI->addIncoming(ConstantInt::getNullValue(Type::Int32Ty), ABlock);
473473 // Construct the new "invoke" instruction.
474474 TerminatorInst* Term = OldBB->getTerminator();
475475 std::vector Params(CI.op_begin() + 1, CI.op_end());
476 InvokeInst* II = new
477 InvokeInst(CI.getCalledValue(), NewBB, PrelimBBMap[Func],
478 Params.begin(), Params.end(), CI.getName(), Term);
476 InvokeInst* II =
477 InvokeInst::Create(CI.getCalledValue(), NewBB, PrelimBBMap[Func],
478 Params.begin(), Params.end(), CI.getName(), Term);
479479 II->setCallingConv(CI.getCallingConv());
480480 II->setParamAttrs(CI.getParamAttrs());
481481
506506 BasicBlock* ExceptBB = II.getUnwindDest();
507507
508508 Function* Func = BB->getParent();
509 BasicBlock* NewExceptBB = new BasicBlock("InvokeExcept", Func);
509 BasicBlock* NewExceptBB = BasicBlock::Create("InvokeExcept", Func);
510510 BasicBlock::InstListType& InstList = NewExceptBB->getInstList();
511511
512512 // If this is a longjmp exception, then branch to the preliminary BB of
513513 // the longjmp exception handling. Otherwise, go to the old exception.
514 CallInst* IsLJExcept = new CallInst(IsLJException, "IsLJExcept");
514 CallInst* IsLJExcept = CallInst::Create(IsLJException, "IsLJExcept");
515515 InstList.push_back(IsLJExcept);
516516
517 new BranchInst(PrelimBBMap[Func], ExceptBB, IsLJExcept, NewExceptBB);
517 BranchInst::Create(PrelimBBMap[Func], ExceptBB, IsLJExcept, NewExceptBB);
518518
519519 II.setUnwindDest(NewExceptBB);
520520 ++InvokesTransformed;
524524 // function.
525525 void LowerSetJmp::visitReturnInst(ReturnInst &RI) {
526526 Function* Func = RI.getParent()->getParent();
527 new CallInst(DestroySJMap, GetSetJmpMap(Func), "", &RI);
527 CallInst::Create(DestroySJMap, GetSetJmpMap(Func), "", &RI);
528528 }
529529
530530 // visitUnwindInst - We want to destroy the setjmp map upon exit from the
531531 // function.
532532 void LowerSetJmp::visitUnwindInst(UnwindInst &UI) {
533533 Function* Func = UI.getParent()->getParent();
534 new CallInst(DestroySJMap, GetSetJmpMap(Func), "", &UI);
534 CallInst::Create(DestroySJMap, GetSetJmpMap(Func), "", &UI);
535535 }
536536
537537 ModulePass *llvm::createLowerSetJmpPass() {
157157 if (II->doesNotThrow()) {
158158 SmallVector Args(II->op_begin()+3, II->op_end());
159159 // Insert a call instruction before the invoke.
160 CallInst *Call = new CallInst(II->getCalledValue(),
161 Args.begin(), Args.end(), "", II);
160 CallInst *Call = CallInst::Create(II->getCalledValue(),
161 Args.begin(), Args.end(), "", II);
162162 Call->takeName(II);
163163 Call->setCallingConv(II->getCallingConv());
164164 Call->setParamAttrs(II->getParamAttrs());
171171
172172 // Insert a branch to the normal destination right before the
173173 // invoke.
174 new BranchInst(II->getNormalDest(), II);
174 BranchInst::Create(II->getNormalDest(), II);
175175
176176 // Finally, delete the invoke instruction!
177177 BB->getInstList().pop_back();
174174 // If the old instruction was an invoke, add an unconditional branch
175175 // before the invoke, which will become the new terminator.
176176 if (InvokeInst *II = dyn_cast(I))
177 new BranchInst(II->getNormalDest(), I);
177 BranchInst::Create(II->getNormalDest(), I);
178178
179179 // Delete the old call site
180180 MI->getParent()->getInstList().erase(I);
226226 // If the old instruction was an invoke, add an unconditional branch
227227 // before the invoke, which will become the new terminator.
228228 if (InvokeInst *II = dyn_cast(I))
229 new BranchInst(II->getNormalDest(), I);
229 BranchInst::Create(II->getNormalDest(), I);
230230
231231 // Delete the old call site
232232 if (I->getType() != Type::VoidTy)
429429 // Create a return instruction that we'll replace the call with.
430430 // Note that the argument of the return is the argument of the call
431431 // instruction.
432 new ReturnInst(ci->getOperand(1), ci);
432 ReturnInst::Create(ci->getOperand(1), ci);
433433
434434 // Split the block at the call instruction which places it in a new
435435 // basic block.
495495
496496 // We need to find the end of the destination string. That's where the
497497 // memory is to be moved to. We just generate a call to strlen.
498 CallInst *DstLen = new CallInst(SLC.get_strlen(), Dst,
499 Dst->getName()+".len", CI);
498 CallInst *DstLen = CallInst::Create(SLC.get_strlen(), Dst,
499 Dst->getName()+".len", CI);
500500
501501 // Now that we have the destination's length, we must index into the
502502 // destination's pointer to get the actual memcpy destination (end of
503503 // the string .. we're concatenating).
504 Dst = new GetElementPtrInst(Dst, DstLen, Dst->getName()+".indexed", CI);
504 Dst = GetElementPtrInst::Create(Dst, DstLen, Dst->getName()+".indexed", CI);
505505
506506 // We have enough information to now generate the memcpy call to
507507 // do the concatenation for us.
510510 ConstantInt::get(SLC.getIntPtrType(), SrcStr.size()+1), // copy nul byte.
511511 ConstantInt::get(Type::Int32Ty, 1) // alignment
512512 };
513 new CallInst(SLC.get_memcpy(), Vals, Vals + 4, "", CI);
513 CallInst::Create(SLC.get_memcpy(), Vals, Vals + 4, "", CI);
514514
515515 return ReplaceCallWith(CI, Dst);
516516 }
550550 CI->getOperand(2),
551551 ConstantInt::get(SLC.getIntPtrType(), Str.size()+1)
552552 };
553 return ReplaceCallWith(CI, new CallInst(SLC.get_memchr(), Args, Args + 3,
554 CI->getName(), CI));
553 return ReplaceCallWith(CI, CallInst::Create(SLC.get_memchr(), Args, Args + 3,
554 CI->getName(), CI));
555555 }
556556
557557 // strchr can find the nul character.
574574 // strchr(s+n,c) -> gep(s+n+i,c)
575575 // (if c is a constant integer and s is a constant string)
576576 Value *Idx = ConstantInt::get(Type::Int64Ty, i);
577 Value *GEP = new GetElementPtrInst(CI->getOperand(1), Idx,
578 CI->getOperand(1)->getName() +
579 ".strchr", CI);
577 Value *GEP = GetElementPtrInst::Create(CI->getOperand(1), Idx,
578 CI->getOperand(1)->getName() +
579 ".strchr", CI);
580580 return ReplaceCallWith(CI, GEP);
581581 }
582582 } StrChrOptimizer;
753753 ConstantInt::get(SLC.getIntPtrType(), SrcStr.size()+1),
754754 ConstantInt::get(Type::Int32Ty, 1) // alignment
755755 };
756 new CallInst(SLC.get_memcpy(), MemcpyOps, MemcpyOps + 4, "", CI);
756 CallInst::Create(SLC.get_memcpy(), MemcpyOps, MemcpyOps + 4, "", CI);
757757
758758 return ReplaceCallWith(CI, Dst);
759759 }
899899 Value *D1 = BinaryOperator::createSub(S1V1, S2V1,
900900 CI->getName()+".d1", CI);
901901 Constant *One = ConstantInt::get(Type::Int32Ty, 1);
902 Value *G1 = new GetElementPtrInst(Op1Cast, One, "next1v", CI);
903 Value *G2 = new GetElementPtrInst(Op2Cast, One, "next2v", CI);
902 Value *G1 = GetElementPtrInst::Create(Op1Cast, One, "next1v", CI);
903 Value *G2 = GetElementPtrInst::Create(Op2Cast, One, "next2v", CI);
904904 Value *S1V2 = new LoadInst(G1, LHS->getName()+".val2", CI);
905905 Value *S2V2 = new LoadInst(G2, RHS->getName()+".val2", CI);
906906 Value *D2 = BinaryOperator::createSub(S1V2, S2V2,
945945 CI->getOperand(1), CI->getOperand(2), CI->getOperand(3),
946946 ConstantInt::get(Type::Int32Ty, 1) // align = 1 always.
947947 };
948 new CallInst(SLC.get_memcpy(), MemcpyOps, MemcpyOps + 4, "", CI);
948 CallInst::Create(SLC.get_memcpy(), MemcpyOps, MemcpyOps + 4, "", CI);
949949 // memcpy always returns the destination
950950 return ReplaceCallWith(CI, CI->getOperand(1));
951951 }
11611161 Ty==Type::FloatTy ? APFloat(1.0f) : APFloat(1.0)));
11621162 } else if (Op2->isExactlyValue(0.5)) {
11631163 // pow(x,0.5) -> sqrt(x)
1164 CallInst* sqrt_inst = new CallInst(SLC.get_sqrt(), base,
1165 ci->getName()+".pow",ci);
1164 CallInst* sqrt_inst = CallInst::Create(SLC.get_sqrt(), base,
1165 ci->getName()+".pow",ci);
11661166 return ReplaceCallWith(ci, sqrt_inst);
11671167 } else if (Op2->isExactlyValue(1.0)) {
11681168 // pow(x,1.0) -> x
12191219 if (FormatStr.size() == 1) {
12201220 // Turn this into a putchar call, even if it is a %.
12211221 Value *V = ConstantInt::get(Type::Int32Ty, FormatStr[0]);
1222 new CallInst(SLC.get_putchar(), V, "", CI);
1222 CallInst::Create(SLC.get_putchar(), V, "", CI);
12231223 if (CI->use_empty()) return ReplaceCallWith(CI, 0);
12241224 return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1));
12251225 }
12391239 CI->getParent()->getParent()->getParent());
12401240 // Cast GV to be a pointer to char.
12411241 GV = ConstantExpr::getBitCast(GV, PointerType::getUnqual(Type::Int8Ty));
1242 new CallInst(SLC.get_puts(), GV, "", CI);
1242 CallInst::Create(SLC.get_puts(), GV, "", CI);
12431243
12441244 if (CI->use_empty()) return ReplaceCallWith(CI, 0);
12451245 // The return value from printf includes the \n we just removed, so +1.
12631263 return false;
12641264
12651265 // printf("%s\n",str) -> puts(str)
1266 new CallInst(SLC.get_puts(), CastToCStr(CI->getOperand(2), CI),
1267 CI->getName(), CI);
1266 CallInst::Create(SLC.get_puts(), CastToCStr(CI->getOperand(2), CI),
1267 CI->getName(), CI);
12681268 return ReplaceCallWith(CI, 0);
12691269 case 'c': {
12701270 // printf("%c",c) -> putchar(c)
12781278
12791279 V = CastInst::createZExtOrBitCast(V, Type::Int32Ty, CI->getName()+".int",
12801280 CI);
1281 new CallInst(SLC.get_putchar(), V, "", CI);
1281 CallInst::Create(SLC.get_putchar(), V, "", CI);
12821282 return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1));
12831283 }
12841284 }
13301330 ConstantInt::get(SLC.getIntPtrType(), 1),
13311331 CI->getOperand(1)
13321332 };
1333 new CallInst(SLC.get_fwrite(FILEty), FWriteArgs, FWriteArgs + 4, CI->getName(), CI);
1333 CallInst::Create(SLC.get_fwrite(FILEty), FWriteArgs, FWriteArgs + 4, CI->getName(), CI);
13341334 return ReplaceCallWith(CI, ConstantInt::get(CI->getType(),
13351335 FormatStr.size()));
13361336 }
13501350 SmallVector Args;
13511351 Args.push_back(C);
13521352 Args.push_back(CI->getOperand(1));
1353 new CallInst(SLC.get_fputc(FILETy), Args.begin(), Args.end(), "", CI);
1353 CallInst::Create(SLC.get_fputc(FILETy), Args.begin(), Args.end(), "", CI);
13541354 return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1));
13551355 }
13561356 case 's': {
13651365 SmallVector Args;
13661366 Args.push_back(CastToCStr(CI->getOperand(3), CI));
13671367 Args.push_back(CI->getOperand(1));
1368 new CallInst(SLC.get_fputs(FILETy), Args.begin(),
1369 Args.end(), CI->getName(), CI);
1368 CallInst::Create(SLC.get_fputs(FILETy), Args.begin(),
1369 Args.end(), CI->getName(), CI);
13701370 return ReplaceCallWith(CI, 0);
13711371 }
13721372 default:
14171417 FormatStr.size()+1), // Copy the nul byte.
14181418 ConstantInt::get(Type::Int32Ty, 1)
14191419 };
1420 new CallInst(SLC.get_memcpy(), MemCpyArgs, MemCpyArgs + 4, "", CI);
1420 CallInst::Create(SLC.get_memcpy(), MemCpyArgs, MemCpyArgs + 4, "", CI);
14211421 return ReplaceCallWith(CI, ConstantInt::get(CI->getType(),
14221422 FormatStr.size()));
14231423 }
14331433 Value *V = CastInst::createTruncOrBitCast(CI->getOperand(3),
14341434 Type::Int8Ty, "char", CI);
14351435 new StoreInst(V, CI->getOperand(1), CI);
1436 Value *Ptr = new GetElementPtrInst(CI->getOperand(1),
1437 ConstantInt::get(Type::Int32Ty, 1),
1438 CI->getOperand(1)->getName()+".end",
1439 CI);
1436 Value *Ptr = GetElementPtrInst::Create(CI->getOperand(1),
1437 ConstantInt::get(Type::Int32Ty, 1),
1438 CI->getOperand(1)->getName()+".end",
1439 CI);
14401440 new StoreInst(ConstantInt::get(Type::Int8Ty,0), Ptr, CI);
14411441 return ReplaceCallWith(CI, ConstantInt::get(Type::Int32Ty, 1));
14421442 }
14431443 case 's': {
14441444 // sprintf(dest,"%s",str) -> llvm.memcpy(dest, str, strlen(str)+1, 1)
1445 Value *Len = new CallInst(SLC.get_strlen(),
1446 CastToCStr(CI->getOperand(3), CI),
1447 CI->getOperand(3)->getName()+".len", CI);
1445 Value *Len = CallInst::Create(SLC.get_strlen(),
1446 CastToCStr(CI->getOperand(3), CI),
1447 CI->getOperand(3)->getName()+".len", CI);
14481448 Value *UnincLen = Len;
14491449 Len = BinaryOperator::createAdd(Len, ConstantInt::get(Len->getType(), 1),
14501450 Len->getName()+"1", CI);
14541454 Len,
14551455 ConstantInt::get(Type::Int32Ty, 1)
14561456 };
1457 new CallInst(SLC.get_memcpy(), MemcpyArgs, MemcpyArgs + 4, "", CI);
1457 CallInst::Create(SLC.get_memcpy(), MemcpyArgs, MemcpyArgs + 4, "", CI);
14581458
14591459 // The strlen result is the unincremented number of bytes in the string.
14601460 if (!CI->use_empty()) {
15061506 ConstantInt::get(SLC.getIntPtrType(), 1),
15071507 CI->getOperand(2)
15081508 };
1509 new CallInst(SLC.get_fwrite(FILETy), FWriteParms, FWriteParms + 4, "", CI);
1509 CallInst::Create(SLC.get_fwrite(FILETy), FWriteParms, FWriteParms + 4, "", CI);
15101510 return ReplaceCallWith(CI, 0); // Known to have no uses (see above).
15111511 }
15121512 } FPutsOptimizer;
15541554 Args.push_back(new ZExtInst(Val, Type::Int32Ty, Val->getName()+".int", CI));
15551555 Args.push_back(CI->getOperand(4));
15561556 const Type *FILETy = CI->getOperand(4)->getType();
1557 new CallInst(SLC.get_fputc(FILETy), Args.begin(), Args.end(), "", CI);
1557 CallInst::Create(SLC.get_fputc(FILETy), Args.begin(), Args.end(), "", CI);
15581558 return ReplaceCallWith(CI, ConstantInt::get(CI->getType(), 1));
15591559 }
15601560 return false;
17141714 ArgType, NULL);
17151715 Value *V = CastInst::createIntegerCast(TheCall->getOperand(1), ArgType,
17161716 false/*ZExt*/, "tmp", TheCall);
1717 Value *V2 = new CallInst(F, V, "tmp", TheCall);
1717 Value *V2 = CallInst::Create(F, V, "tmp", TheCall);
17181718 V2 = CastInst::createIntegerCast(V2, Type::Int32Ty, false/*ZExt*/,
17191719 "tmp", TheCall);
17201720 V2 = BinaryOperator::createAdd(V2, ConstantInt::get(Type::Int32Ty, 1),
17221722 Value *Cond = new ICmpInst(ICmpInst::ICMP_EQ, V,
17231723 Constant::getNullValue(V->getType()), "tmp",
17241724 TheCall);
1725 V2 = new SelectInst(Cond, ConstantInt::get(Type::Int32Ty, 0), V2,
1726 TheCall->getName(), TheCall);
1725 V2 = SelectInst::Create(Cond, ConstantInt::get(Type::Int32Ty, 0), V2,
1726 TheCall->getName(), TheCall);
17271727 return ReplaceCallWith(TheCall, V2);
17281728 }
17291729 } FFSOptimizer;
17721772 Constant *(SimplifyLibCalls::*FP)()){
17731773 if (FPExtInst *Cast = dyn_cast(CI->getOperand(1)))
17741774 if (Cast->getOperand(0)->getType() == Type::FloatTy) {
1775 Value *New = new CallInst((SLC.*FP)(), Cast->getOperand(0),
1776 CI->getName(), CI);
1775 Value *New = CallInst::Create((SLC.*FP)(), Cast->getOperand(0),
1776 CI->getName(), CI);
17771777 New = new FPExtInst(New, Type::DoubleTy, CI->getName(), CI);
17781778 CI->replaceAllUsesWith(New);
17791779 CI->eraseFromParent();
115115 SmallVector GEPIdx;
116116 GEPIdx.push_back(ConstantInt::get(Type::Int32Ty, 0));
117117 GEPIdx.push_back(ConstantInt::get(Type::Int32Ty, idx));
118 Value *NGEPI = new GetElementPtrInst(TheAlloca, GEPIdx.begin(),
119 GEPIdx.end(),
120 "mrv.gep", I);
118 Value *NGEPI = GetElementPtrInst::Create(TheAlloca, GEPIdx.begin(),
119 GEPIdx.end(),
120 "mrv.gep", I);
121121 Value *NV = new LoadInst(NGEPI, "mrv.ld", I);
122122 RetVals.push_back(NV);
123123 }
124124
125 ReturnInst *NR = new ReturnInst(&RetVals[0], RetVals.size(), I);
125 ReturnInst *NR = ReturnInst::Create(&RetVals[0], RetVals.size(), I);
126126 I->replaceAllUsesWith(NR);
127127 I->eraseFromParent();
128128 }
221221 }
222222
223223 FunctionType *NFTy = FunctionType::get(STy, Params, FTy->isVarArg());
224 Function *NF = new Function(NFTy, F->getLinkage(), F->getName());
224 Function *NF = Function::Create(NFTy, F->getLinkage(), F->getName());
225225 NF->setCallingConv(F->getCallingConv());
226226 NF->setParamAttrs(PAListPtr::get(ParamAttrsVec.begin(), ParamAttrsVec.end()));
227227 F->getParent()->getFunctionList().insert(F, NF);
282282 // Build new call instruction.
283283 Instruction *New;
284284 if (InvokeInst *II = dyn_cast(Call)) {
285 New = new InvokeInst(NF, II->getNormalDest(), II->getUnwindDest(),
286 Args.begin(), Args.end(), "", Call);
285 New = InvokeInst::Create(NF, II->getNormalDest(), II->getUnwindDest(),
286 Args.begin(), Args.end(), "", Call);
287287 cast(New)->setCallingConv(CS.getCallingConv());
288288 cast(New)->setParamAttrs(NewPAL);
289289 } else {
290 New = new CallInst(NF, Args.begin(), Args.end(), "", Call);
290 New = CallInst::Create(NF, Args.begin(), Args.end(), "", Call);
291291 cast(New)->setCallingConv(CS.getCallingConv());
292292 cast(New)->setParamAttrs(NewPAL);
293293 if (cast(Call)->isTailCall())
5454 }
5555 Args[3] = ConstantInt::get(Type::Int32Ty, NumElements);
5656
57 Instruction *InitCall = new CallInst(InitFn, Args.begin(), Args.end(),
58 "newargc", InsertPos);
57 Instruction *InitCall = CallInst::Create(InitFn, Args.begin(), Args.end(),
58 "newargc", InsertPos);
5959
6060 // If argc or argv are not available in main, just pass null values in.
6161 Function::arg_iterator AI;
215215
216216 //reset counter
217217 BasicBlock* oldnext = t->getSuccessor(0);
218 BasicBlock* resetblock = new BasicBlock("reset", oldnext->getParent(),
219 oldnext);
220 TerminatorInst* t2 = new BranchInst(oldnext, resetblock);
218 BasicBlock* resetblock = BasicBlock::Create("reset", oldnext->getParent(),
219 oldnext);
220 TerminatorInst* t2 = BranchInst::Create(oldnext, resetblock);
221221 t->setSuccessor(0, resetblock);
222222 new StoreInst(ResetValue, Counter, t2);
223223 ReplacePhiPred(oldnext, bb, resetblock);
290290
291291 //reset counter
292292 BasicBlock* oldnext = t->getSuccessor(0);
293 BasicBlock* resetblock = new BasicBlock("reset", oldnext->getParent(),
294 oldnext);
295 TerminatorInst* t2 = new BranchInst(oldnext, resetblock);
293 BasicBlock* resetblock = BasicBlock::Create("reset", oldnext->getParent(),
294 oldnext);
295 TerminatorInst* t2 = BranchInst::Create(oldnext, resetblock);
296296 t->setSuccessor(0, resetblock);
297297 new StoreInst(ResetValue, AI, t2);
298298 ReplacePhiPred(oldnext, bb, resetblock);
310310 void CycleCounter::ProcessChoicePoint(BasicBlock* bb) {
311311 BranchInst* t = cast(bb->getTerminator());
312312
313 CallInst* c = new CallInst(F, "rdcc", t);
313 CallInst* c = CallInst::Create(F, "rdcc", t);
314314 BinaryOperator* b =
315315 BinaryOperator::createAnd(c, ConstantInt::get(Type::Int64Ty, rm),
316316 "mrdcc", t);
374374 if (bb == &bb->getParent()->getEntryBlock())
375375 TransCache[bb] = bb; //don't translate entry block
376376 else
377 TransCache[bb] = new BasicBlock("dup_" + bb->getName(), bb->getParent(),
378 NULL);
377 TransCache[bb] = BasicBlock::Create("dup_" + bb->getName(), bb->getParent(),
378 NULL);
379379 return TransCache[bb];
380380 } else if (Instruction* i = dyn_cast(v)) {
381381 //we have already translated this
463463
464464 //a:
465465 Function::iterator BBN = src; ++BBN;
466 BasicBlock* bbC = new BasicBlock("choice", &F, BBN);
466 BasicBlock* bbC = BasicBlock::Create("choice", &F, BBN);
467467 //ChoicePoints.insert(bbC);
468468 BBN = cast(Translate(src));
469 BasicBlock* bbCp = new BasicBlock("choice", &F, ++BBN);
469 BasicBlock* bbCp = BasicBlock::Create("choice", &F, ++BBN);
470470 ChoicePoints.insert(bbCp);
471471
472472 //b:
473 new BranchInst(cast(Translate(dst)), bbC);
474 new BranchInst(dst, cast(Translate(dst)),
475 ConstantInt::get(Type::Int1Ty, true), bbCp);
473 BranchInst::Create(cast(Translate(dst)), bbC);
474 BranchInst::Create(dst, cast(Translate(dst)),
475 ConstantInt::get(Type::Int1Ty, true), bbCp);
476476 //c:
477477 {
478478 TerminatorInst* iB = src->getTerminator();
526526 //oh, and add the edge from the reg2mem created entry node to the
527527 //duplicated second node
528528 TerminatorInst* T = F.getEntryBlock().getTerminator();
529 ReplaceInstWithInst(T, new BranchInst(T->getSuccessor(0),
530 cast(
531 Translate(T->getSuccessor(0))),
532 ConstantInt::get(Type::Int1Ty, true)));
529 ReplaceInstWithInst(T, BranchInst::Create(T->getSuccessor(0),
530 cast(
531 Translate(T->getSuccessor(0))),
532 ConstantInt::get(Type::Int1Ty,
533 true)));
533534
534535 //do whatever is needed now that the function is duplicated
535536 c->PrepFunction(&F);
162162 /// successors it goes to. This eliminate a use of the condition as well.
163163 ///
164164 TerminatorInst *ADCE::convertToUnconditionalBranch(TerminatorInst *TI) {
165 BranchInst *NB = new BranchInst(TI->getSuccessor(0), TI);
165 BranchInst *NB = BranchInst::Create(TI->getSuccessor(0), TI);
166166 BasicBlock *BB = TI->getParent();
167167
168168 // Remove entries from PHI nodes to avoid confusing ourself later...
324324 // node as a special case.
325325 //
326326 if (!AliveBlocks.count(&Func->front())) {
327 BasicBlock *NewEntry = new BasicBlock();
328 new BranchInst(&Func->front(), NewEntry);
327 BasicBlock *NewEntry = BasicBlock::Create();
328 BranchInst::Create(&Func->front(), NewEntry);
329329 Func->getBasicBlockList().push_front(NewEntry);
330330 AliveBlocks.insert(NewEntry); // This block is always alive!
331331 LiveSet.insert(NewEntry->getTerminator()); // The branch is live
191191 if (InvokeInst *II = dyn_cast(I)) {
192192 // Removing an invoke instruction requires adding a branch to the normal
193193 // destination and removing PHI node entries in the exception destination.
194 new BranchInst(II->getNormalDest(), II);
194 BranchInst::Create(II->getNormalDest(), II);
195195 II->getUnwindDest()->removePredecessor(II->getParent());
196196 }
197197
792792
793793 // Otherwise, the idom is the loop, so we need to insert a PHI node. Do so
794794 // now, then get values to fill in the incoming values for the PHI.
795 PHINode *PN = new PHINode(orig->getType(), orig->getName()+".rle",
796 BB->begin());
795 PHINode *PN = PHINode::Create(orig->getType(), orig->getName()+".rle",
796 BB->begin());
797797 PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB)));
798798
799799 if (Phis.count(BB) == 0)
13691369 ConstantInt::get(Type::Int64Ty, Range.End-Range.Start), // size
13701370 ConstantInt::get(Type::Int32Ty, Range.Alignment) // align
13711371 };
1372 Value *C = new CallInst(MemSetF, Ops, Ops+4, "", InsertPt);
1372 Value *C = CallInst::Create(MemSetF, Ops, Ops+4, "", InsertPt);
13731373 DEBUG(cerr << "Replace stores:\n";
13741374 for (unsigned i = 0, e = Range.TheStores.size(); i != e; ++i)
13751375 cerr << *Range.TheStores[i];
15671567 args.push_back(M->getLength());
15681568 args.push_back(M->getAlignment());
15691569
1570 CallInst* C = new CallInst(MemCpyFun, args.begin(), args.end(), "", M);
1570 CallInst* C = CallInst::Create(MemCpyFun, args.begin(), args.end(), "", M);
15711571
15721572 MemoryDependenceAnalysis& MD = getAnalysis();
15731573 if (MD.getDependency(C) == MDep) {
903903 newVal = new ShuffleVectorInst(newOp1, newOp2, newOp3,
904904 S->getName()+".expr");
905905 else if (InsertElementInst* I = dyn_cast(U))
906 newVal = new InsertElementInst(newOp1, newOp2, newOp3,
907 I->getName()+".expr");
906 newVal = InsertElementInst::Create(newOp1, newOp2, newOp3,
907 I->getName()+".expr");
908908 else if (SelectInst* I = dyn_cast(U))
909 newVal = new SelectInst(newOp1, newOp2, newOp3, I->getName()+".expr");
909 newVal = SelectInst::Create(newOp1, newOp2, newOp3, I->getName()+".expr");
910910
911911 uint32_t v = VN.lookup_or_add(newVal);
912912
946946 }
947947
948948 if (newOp1 != U->getPointerOperand() || changed_idx) {
949 Instruction* newVal = new GetElementPtrInst(newOp1,
950 newIdx.begin(), newIdx.end(),
951 U->getName()+".expr");
949 Instruction* newVal =
950 GetElementPtrInst::Create(newOp1,
951 newIdx.begin(), newIdx.end(),
952 U->getName()+".expr");
952953
953954 uint32_t v = VN.lookup_or_add(newVal);
954955
16661667 newVal = new ShuffleVectorInst(s1, s2, s3, S->getName()+".gvnpre",
16671668 (*PI)->getTerminator());
16681669 else if (InsertElementInst* S = dyn_cast(U))
1669 newVal = new InsertElementInst(s1, s2, s3, S->getName()+".gvnpre",
1670 (*PI)->getTerminator());
1670 newVal = InsertElementInst::Create(s1, s2, s3, S->getName()+".gvnpre",
1671 (*PI)->getTerminator());
16711672 else if (ExtractElementInst* S = dyn_cast(U))
16721673 newVal = new ExtractElementInst(s1, s2, S->getName()+".gvnpre",
16731674 (*PI)->getTerminator());
16741675 else if (SelectInst* S = dyn_cast(U))
1675 newVal = new SelectInst(s1, s2, s3, S->getName()+".gvnpre",
1676 (*PI)->getTerminator());
1676 newVal = SelectInst::Create(s1, s2, s3, S->getName()+".gvnpre",
1677 (*PI)->getTerminator());
16771678 else if (CastInst* C = dyn_cast(U))
16781679 newVal = CastInst::create(C->getOpcode(), s1, C->getType(),
16791680 C->getName()+".gvnpre",
16801681 (*PI)->getTerminator());
16811682 else if (GetElementPtrInst* G = dyn_cast(U))
1682 newVal = new GetElementPtrInst(s1, sVarargs.begin(), sVarargs.end(),
1683 G->getName()+".gvnpre",
1684 (*PI)->getTerminator());
1685
1686
1683 newVal = GetElementPtrInst::Create(s1, sVarargs.begin(), sVarargs.end(),
1684 G->getName()+".gvnpre",
1685 (*PI)->getTerminator());
1686
16871687 VN.add(newVal, VN.lookup(U));
16881688
16891689 ValueNumberedSet& predAvail = availableOut[*PI];
17041704
17051705 for (pred_iterator PI = pred_begin(BB), PE = pred_end(BB); PI != PE; ++PI) {
17061706 if (p == 0)
1707 p = new PHINode(avail[*PI]->getType(), "gvnpre-join", BB->begin());
1707 p = PHINode::Create(avail[*PI]->getType(), "gvnpre-join", BB->begin());
17081708
17091709 p->addIncoming(avail[*PI], *PI);
17101710 }
144144 Value *AddedVal = GEPI->getOperand(1);
145145
146146 // Insert a new integer PHI node into the top of the block.
147 PHINode *NewPhi = new PHINode(AddedVal->getType(),
148 PN->getName()+".rec", PN);
147 PHINode *NewPhi = PHINode::Create(AddedVal->getType(),
148 PN->getName()+".rec", PN);
149149 NewPhi->addIncoming(Constant::getNullValue(NewPhi->getType()), Preheader);
150150
151151 // Create the new add instruction.
180180 Value *Idx[2];
181181 Idx[0] = Constant::getNullValue(Type::Int32Ty);
182182 Idx[1] = NewAdd;
183 GetElementPtrInst *NGEPI = new GetElementPtrInst(
183 GetElementPtrInst *NGEPI = GetElementPtrInst::Create(
184184 NCE, Idx, Idx + 2,
185185 GEPI->getName(), GEPI);
186186 SE->deleteValueFromRecords(GEPI);
199199 BasicBlock::iterator InsertPos = PN; ++InsertPos;
200200 while (isa(InsertPos)) ++InsertPos;
201201 Value *PreInc =
202 new GetElementPtrInst(PN->getIncomingValue(PreheaderIdx),
203 NewPhi, "", InsertPos);
202 GetElementPtrInst::Create(PN->getIncomingValue(PreheaderIdx),
203 NewPhi, "", InsertPos);
204204 PreInc->takeName(PN);
205205 PN->replaceAllUsesWith(PreInc);
206206 }
18101810 }
18111811
18121812 Instruction *New =
1813 new InsertElementInst(UndefValue::get(II->getType()), TmpV, 0U,
1814 II->getName());
1813 InsertElementInst::Create(UndefValue::get(II->getType()), TmpV, 0U,
1814 II->getName());
18151815 InsertNewInstBefore(New, *II);
18161816 AddSoonDeadInstToWorklist(*II, 0);
18171817 return New;
20062006 Value *SelectTrueVal = FoldOperationIntoSelectOperand(Op, TV, IC);
20072007 Value *SelectFalseVal = FoldOperationIntoSelectOperand(Op, FV, IC);
20082008
2009 return new SelectInst(SI->getCondition(), SelectTrueVal,
2010 SelectFalseVal);
2009 return SelectInst::Create(SI->getCondition(), SelectTrueVal,
2010 SelectFalseVal);
20112011 }
20122012 return 0;
20132013 }
20472047 }
20482048
20492049 // Okay, we can do the transformation: create the new PHI node.
2050 PHINode *NewPN = new PHINode(I.getType(), "");
2050 PHINode *NewPN = PHINode::Create(I.getType(), "");
20512051 NewPN->reserveOperandSpace(PN->getNumOperands()/2);
20522052 InsertNewInstBefore(NewPN, *PN);
20532053 NewPN->takeName(PN);
23652365 cast(CI->getOperand(0)->getType())->getAddressSpace();
23662366 Value *I2 = InsertBitCastBefore(CI->getOperand(0),
23672367 PointerType::get(Type::Int8Ty, AS), I);
2368 I2 = InsertNewInstBefore(new GetElementPtrInst(I2, Other, "ctg2"), I);
2368 I2 = InsertNewInstBefore(GetElementPtrInst::Create(I2, Other, "ctg2"), I);
23692369 return new PtrToIntInst(I2, CI->getType());
23702370 }
23712371 }
23872387 // We check both true and false select arguments for a matching subtract.
23882388 if (match(FV, m_Zero()) && match(TV, m_Sub(m_Value(N), m_Value(A))) &&
23892389 A == Other) // Fold the add into the true select value.
2390 return new SelectInst(SI->getCondition(), N, A);
2390 return SelectInst::Create(SI->getCondition(), N, A);
23912391 if (match(TV, m_Zero()) && match(FV, m_Sub(m_Value(N), m_Value(A))) &&
23922392 A == Other) // Fold the add into the false select value.
2393 return new SelectInst(SI->getCondition(), A, N);
2393 return SelectInst::Create(SI->getCondition(), A, N);
23942394 }
23952395 }
23962396
28742874 FSI = InsertNewInstBefore(FSI, I);
28752875
28762876 // construct the select instruction and return it.
2877 return new SelectInst(SI->getOperand(0), TSI, FSI, SI->getName());
2877 return SelectInst::Create(SI->getOperand(0), TSI, FSI, SI->getName());
28782878 }
28792879 }
28802880 return 0;
30483048 BinaryOperator::createAnd(Op0, SubOne(STO), SI->getName()+".t"), I);
30493049 Value *FalseAnd = InsertNewInstBefore(
30503050 BinaryOperator::createAnd(Op0, SubOne(SFO), SI->getName()+".f"), I);
3051 return new SelectInst(SI->getOperand(0), TrueAnd, FalseAnd);
3051 return SelectInst::Create(SI->getOperand(0), TrueAnd, FalseAnd);
30523052 }
30533053 }
30543054 }
40204020 const Type *Tys[] = { ITy };
40214021 Module *M = I.getParent()->getParent()->getParent();
40224022 Function *F = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
4023 return new CallInst(F, V);
4023 return CallInst::Create(F, V);
40244024 }
40254025
40264026
49564956 }
49574957
49584958 if (Op1)
4959 return new SelectInst(LHSI->getOperand(0), Op1, Op2);
4959 return SelectInst::Create(LHSI->getOperand(0), Op1, Op2);
49604960 break;
49614961 }
49624962 }
52565256 }
52575257
52585258 if (Op1)
5259 return new SelectInst(LHSI->getOperand(0), Op1, Op2);
5259 return SelectInst::Create(LHSI->getOperand(0), Op1, Op2);
52605260 break;
52615261 }
52625262 case Instruction::Malloc:
69526952 // If we were able to index down into an element, create the GEP
69536953 // and bitcast the result. This eliminates one bitcast, potentially
69546954 // two.
6955 Instruction *NGEP = new GetElementPtrInst(OrigBase,
6956 NewIndices.begin(),
6957 NewIndices.end(), "");
6955 Instruction *NGEP = GetElementPtrInst::Create(OrigBase,
6956 NewIndices.begin(),
6957 NewIndices.end(), "");
69586958 InsertNewInstBefore(NGEP, CI);
69596959 NGEP->takeName(GEP);
69606960
75167516 // If Offset is evenly divisible by Size, we can do this xform.
75177517 if (Size && !APIntOps::srem(Offset, APInt(Offset.getBitWidth(), Size))){
75187518 Offset = APIntOps::sdiv(Offset, APInt(Offset.getBitWidth(), Size));
7519 return new GetElementPtrInst(X, ConstantInt::get(Offset));
7519 return GetElementPtrInst::Create(X, ConstantInt::get(Offset));
75207520 }
75217521 }
75227522 // TODO: Could handle other cases, e.g. where add is indexing into field of
75397539
75407540 Instruction *P = InsertNewInstBefore(new IntToPtrInst(X, CI.getType(),
75417541 "tmp"), CI);
7542 return new GetElementPtrInst(P, ConstantInt::get(Offset), "tmp");
7542 return GetElementPtrInst::Create(P, ConstantInt::get(Offset), "tmp");
75437543 }
75447544 }
75457545 return 0;
76007600 // If we found a path from the src to dest, create the getelementptr now.
76017601 if (SrcElTy == DstElTy) {
76027602 SmallVector Idxs(NumZeros+1, ZeroUInt);
7603 return new GetElementPtrInst(Src, Idxs.begin(), Idxs.end(), "",
7604 ((Instruction*) NULL));
7603 return GetElementPtrInst::Create(Src, Idxs.begin(), Idxs.end(), "",
7604 ((Instruction*) NULL));
76057605 }
76067606 }
76077607
76987698 }
76997699
77007700 // Fold this by inserting a select from the input values.
7701 SelectInst *NewSI = new SelectInst(SI.getCondition(), TI->getOperand(0),
7702 FI->getOperand(0), SI.getName()+".v");
7701 SelectInst *NewSI = SelectInst::Create(SI.getCondition(), TI->getOperand(0),
7702 FI->getOperand(0), SI.getName()+".v");
77037703 InsertNewInstBefore(NewSI, SI);
77047704 return CastInst::create(Instruction::CastOps(TI->getOpcode()), NewSI,
77057705 TI->getType());
77397739 }
77407740
77417741 // If we reach here, they do have operations in common.
7742 SelectInst *NewSI = new SelectInst(SI.getCondition(), OtherOpT,
7743 OtherOpF, SI.getName()+".v");
7742 SelectInst *NewSI = SelectInst::Create(SI.getCondition(), OtherOpT,
7743 OtherOpF, SI.getName()+".v");
77447744 InsertNewInstBefore(NewSI, SI);
77457745
77467746 if (BinaryOperator *BO = dyn_cast(TI)) {
79897989 if (AddOp != TI)
79907990 std::swap(NewTrueOp, NewFalseOp);
79917991 Instruction *NewSel =
7992 new SelectInst(CondVal, NewTrueOp,NewFalseOp,SI.getName()+".p");
7992 SelectInst::Create(CondVal, NewTrueOp,NewFalseOp,SI.getName()+".p");
79937993
79947994 NewSel = InsertNewInstBefore(NewSel, SI);
79957995 return BinaryOperator::createAdd(SubOp->getOperand(0), NewSel);
80158015 if (OpToFold) {
80168016 Constant *C = GetSelectFoldableConstant(TVI);
80178017 Instruction *NewSel =
8018 new SelectInst(SI.getCondition(), TVI->getOperand(2-OpToFold), C);
8018 SelectInst::Create(SI.getCondition(), TVI->getOperand(2-OpToFold), C);
80198019 InsertNewInstBefore(NewSel, SI);
80208020 NewSel->takeName(TVI);
80218021 if (BinaryOperator *BO = dyn_cast(TVI))
80408040 if (OpToFold) {
80418041 Constant *C = GetSelectFoldableConstant(FVI);
80428042 Instruction *NewSel =
8043 new SelectInst(SI.getCondition(), C, FVI->getOperand(2-OpToFold));
8043 SelectInst::Create(SI.getCondition(), C, FVI->getOperand(2-OpToFold));
80448044 InsertNewInstBefore(NewSel, SI);
80458045 NewSel->takeName(FVI);
80468046 if (BinaryOperator *BO = dyn_cast(FVI))
83688368 }
83698369
83708370 // Insert this value into the result vector.
8371 Result = new InsertElementInst(Result, ExtractedElts[Idx], i,"tmp");
8371 Result = InsertElementInst::Create(Result, ExtractedElts[Idx], i, "tmp");
83728372 InsertNewInstBefore(cast(Result), CI);
83738373 }
83748374 return CastInst::create(Instruction::BitCast, Result, CI.getType());
84658465
84668466 if (InvokeInst *II = dyn_cast(CS.getInstruction())) {
84678467 // Don't break the CFG, insert a dummy cond branch.
8468 new BranchInst(II->getNormalDest(), II->getUnwindDest(),
8469 ConstantInt::getTrue(), II);
8468 BranchInst::Create(II->getNormalDest(), II->getUnwindDest(),
8469 ConstantInt::getTrue(), II);
84708470 }
84718471 return EraseInstFromFunction(*CS.getInstruction());
84728472 }
86778677
86788678 Instruction *NC;
86798679 if (InvokeInst *II = dyn_cast(Caller)) {
8680 NC = new InvokeInst(Callee, II->getNormalDest(), II->getUnwindDest(),
8681 Args.begin(), Args.end(), Caller->getName(), Caller);
8680 NC = InvokeInst::Create(Callee, II->getNormalDest(), II->getUnwindDest(),
8681 Args.begin(), Args.end(), Caller->getName(), Caller);
86828682 cast(NC)->setCallingConv(II->getCallingConv());
86838683 cast(NC)->setParamAttrs(NewCallerPAL);
86848684 } else {
8685 NC = new CallInst(Callee, Args.begin(), Args.end(),
8686 Caller->getName(), Caller);
8685 NC = CallInst::Create(Callee, Args.begin(), Args.end(),
8686 Caller->getName(), Caller);
86878687 CallInst *CI = cast(Caller);
86888688 if (CI->isTailCall())
86898689 cast(NC)->setTailCall();
88408840
88418841 Instruction *NewCaller;
88428842 if (InvokeInst *II = dyn_cast(Caller)) {
8843 NewCaller = new InvokeInst(NewCallee,
8844 II->getNormalDest(), II->getUnwindDest(),
8845 NewArgs.begin(), NewArgs.end(),
8846 Caller->getName(), Caller);
8843 NewCaller = InvokeInst::Create(NewCallee,
8844 II->getNormalDest(), II->getUnwindDest(),
8845 NewArgs.begin(), NewArgs.end(),
8846 Caller->getName(), Caller);
88478847 cast(NewCaller)->setCallingConv(II->getCallingConv());
88488848 cast(NewCaller)->setParamAttrs(NewPAL);
88498849 } else {
8850 NewCaller = new CallInst(NewCallee, NewArgs.begin(), NewArgs.end(),
8851 Caller->getName(), Caller);
8850 NewCaller = CallInst::Create(NewCallee, NewArgs.begin(), NewArgs.end(),
8851 Caller->getName(), Caller);
88528852 if (cast(Caller)->isTailCall())
88538853 cast(NewCaller)->setTailCall();
88548854 cast(NewCaller)->
89208920 Value *InRHS = FirstInst->getOperand(1);
89218921 PHINode *NewLHS = 0, *NewRHS = 0;
89228922 if (LHSVal == 0) {
8923 NewLHS = new PHINode(LHSType, FirstInst->getOperand(0)->getName()+".pn");
8923 NewLHS = PHINode::Create(LHSType, FirstInst->getOperand(0)->getName()+".pn");
89248924 NewLHS->reserveOperandSpace(PN.getNumOperands()/2);
89258925 NewLHS->addIncoming(InLHS, PN.getIncomingBlock(0));
89268926 InsertNewInstBefore(NewLHS, PN);
89288928 }
89298929
89308930 if (RHSVal == 0) {
8931 NewRHS = new PHINode(RHSType, FirstInst->getOperand(1)->getName()+".pn");
8931 NewRHS = PHINode::Create(RHSType, FirstInst->getOperand(1)->getName()+".pn");
89328932 NewRHS->reserveOperandSpace(PN.getNumOperands()/2);
89338933 NewRHS->addIncoming(InRHS, PN.getIncomingBlock(0));
89348934 InsertNewInstBefore(NewRHS, PN);
89548954 RHSVal);
89558955 else {
89568956 assert(isa(FirstInst));
8957 return new GetElementPtrInst(LHSVal, RHSVal);
8957 return GetElementPtrInst::Create(LHSVal, RHSVal);
89588958 }
89598959 }
89608960
90569056
90579057 // Okay, they are all the same operation. Create a new PHI node of the
90589058 // correct type, and PHI together all of the LHS's of the instructions.
9059 PHINode *NewPN = new PHINode(FirstInst->getOperand(0)->getType(),
9060 PN.getName()+".in");
9059 PHINode *NewPN = PHINode::Create(FirstInst->getOperand(0)->getType(),
9060 PN.getName()+".in");
90619061 NewPN->reserveOperandSpace(PN.getNumOperands()/2);
90629062
90639063 Value *InVal = FirstInst->getOperand(0);
94049404 }
94059405
94069406 if (!Indices.empty())
9407 return new GetElementPtrInst(SrcGEPOperands[0], Indices.begin(),
9408 Indices.end(), GEP.getName());
9407 return GetElementPtrInst::Create(SrcGEPOperands[0], Indices.begin(),
9408 Indices.end(), GEP.getName());
94099409
94109410 } else if (GlobalValue *GV = dyn_cast(PtrOp)) {
94119411 // GEP of global variable. If all of the indices for this GEP are
94609460 Idx[0] = Constant::getNullValue(Type::Int32Ty);
94619461 Idx[1] = GEP.getOperand(1);
94629462 Value *V = InsertNewInstBefore(
9463 new GetElementPtrInst(X, Idx, Idx + 2, GEP.getName()), GEP);
9463 GetElementPtrInst::Create(X, Idx, Idx + 2, GEP.getName()), GEP);
94649464 // V and GEP are both pointer types --> BitCast
94659465 return new BitCastInst(V, GEP.getType());
94669466 }
95189518 Idx[0] = Constant::getNullValue(Type::Int32Ty);
95199519 Idx[1] = NewIdx;
95209520 Instruction *NewGEP =
9521 new GetElementPtrInst(X, Idx, Idx + 2, GEP.getName());
9521 GetElementPtrInst::Create(X, Idx, Idx + 2, GEP.getName());
95229522 NewGEP = InsertNewInstBefore(NewGEP, GEP);
95239523 // The NewGEP must be pointer typed, so must the old one -> BitCast
95249524 return new BitCastInst(NewGEP, GEP.getType());
95619561 Value *Idx[2];
95629562 Idx[0] = NullIdx;
95639563 Idx[1] = NullIdx;
9564 Value *V = new GetElementPtrInst(New, Idx, Idx + 2,
9565 New->getName()+".sub", It);
9564 Value *V = GetElementPtrInst::Create(New, Idx, Idx + 2,
9565 New->getName()+".sub", It);
95669566
95679567 // Now make everything use the getelementptr instead of the original
95689568 // allocation.
98739873 SI->getOperand(1)->getName()+".val"), LI);
98749874 Value *V2 = InsertNewInstBefore(new LoadInst(SI->getOperand(2),
98759875 SI->getOperand(2)->getName()+".val"), LI);
9876 return new SelectInst(SI->getCondition(), V1, V2);
9876 return SelectInst::Create(SI->getCondition(), V1, V2);
98779877 }
98789878
98799879 // load (select (cond, null, P)) -> load P
1015010150 // Insert a PHI node now if we need it.
1015110151 Value *MergedVal = OtherStore->getOperand(0);
1015210152 if (MergedVal != SI.getOperand(0)) {
10153 PHINode *PN = new PHINode(MergedVal->getType(), "storemerge");
10153 PHINode *PN = PHINode::Create(MergedVal->getType(), "storemerge");
1015410154 PN->reserveOperandSpace(2);
1015510155 PN->addIncoming(SI.getOperand(0), SI.getParent());
1015610156 PN->addIncoming(OtherStore->getOperand(0), OtherBB);
1043610436 Value *Ptr = InsertBitCastBefore(I->getOperand(0),
1043710437 PointerType::get(EI.getType(), AS),EI);
1043810438 GetElementPtrInst *GEP =
10439 new GetElementPtrInst(Ptr, EI.getOperand(1), I->getName() + ".gep");
10439 GetElementPtrInst::Create(Ptr, EI.getOperand(1), I->getName() + ".gep");
1044010440 InsertNewInstBefore(GEP, EI);
1044110441 return new LoadInst(GEP);
1044210442 }
771771 "lsplit.add", PHTerminator);
772772 Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
773773 A, UB,"lsplit,c", PHTerminator);
774 NUB = new SelectInst (C, A, UB, "lsplit.nub", PHTerminator);
774 NUB = SelectInst::Create(C, A, UB, "lsplit.nub", PHTerminator);
775775 }
776776
777777 // for (i = LB; i <= UB; ++i)
787787 || ExitCondition->getPredicate() == ICmpInst::ICMP_ULE) {
788788 Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
789789 NV, UB, "lsplit.c", PHTerminator);
790 NUB = new SelectInst (C, NV, UB, "lsplit.nub", PHTerminator);
790 NUB = SelectInst::Create(C, NV, UB, "lsplit.nub", PHTerminator);
791791 }
792792 break;
793793 case ICmpInst::ICMP_ULT:
805805 || ExitCondition->getPredicate() == ICmpInst::ICMP_ULT) {
806806 Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
807807 NV, UB, "lsplit.c", PHTerminator);
808 NUB = new SelectInst (C, NV, UB, "lsplit.nub", PHTerminator);
808 NUB = SelectInst::Create(C, NV, UB, "lsplit.nub", PHTerminator);
809809 }
810810
811811 // for (i = LB; i <= UB; ++i)
823823 "lsplit.add", PHTerminator);
824824 Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
825825 S, UB, "lsplit.c", PHTerminator);
826 NUB = new SelectInst (C, S, UB, "lsplit.nub", PHTerminator);
826 NUB = SelectInst::Create(C, S, UB, "lsplit.nub", PHTerminator);
827827 }
828828 break;
829829 case ICmpInst::ICMP_UGE:
840840 {
841841 Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
842842 NV, StartValue, "lsplit.c", PHTerminator);
843 NLB = new SelectInst (C, StartValue, NV, "lsplit.nlb", PHTerminator);
843 NLB = SelectInst::Create(C, StartValue, NV, "lsplit.nlb", PHTerminator);
844844 }
845845 break;
846846 case ICmpInst::ICMP_UGT:
859859 "lsplit.add", PHTerminator);
860860 Value *C = new ICmpInst(Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
861861 A, StartValue, "lsplit.c", PHTerminator);
862 NLB = new SelectInst (C, StartValue, A, "lsplit.nlb", PHTerminator);
862 NLB = SelectInst::Create(C, StartValue, A, "lsplit.nlb", PHTerminator);
863863 }
864864 break;
865865 default:
13551355 ExitCondition->getOperand(ExitValueNum),
13561356 "lsplit.ev", InsertPt);
13571357
1358 SD.A_ExitValue = new SelectInst(C1, AEV,
1359 ExitCondition->getOperand(ExitValueNum),
1360 "lsplit.ev", InsertPt);
1358 SD.A_ExitValue = SelectInst::Create(C1, AEV,
1359 ExitCondition->getOperand(ExitValueNum),
1360 "lsplit.ev", InsertPt);
13611361
13621362 Value *C2 = new ICmpInst(Sign ?
13631363 ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT,
13641364 BSV, StartValue, "lsplit.sv",
13651365 PHTerminator);
1366 SD.B_StartValue = new SelectInst(C2, StartValue, BSV,
1367 "lsplit.sv", PHTerminator);
1366 SD.B_StartValue = SelectInst::Create(C2, StartValue, BSV,
1367 "lsplit.sv", PHTerminator);
13681368 }
13691369
13701370 /// splitLoop - Split current loop L in two loops using split information
15071507 BI != BE; ++BI) {
15081508 if (PHINode *PN = dyn_cast(BI)) {
15091509 Value *V1 = PN->getIncomingValueForBlock(A_ExitBlock);
1510 PHINode *newPHI = new PHINode(PN->getType(), PN->getName());
1510 PHINode *newPHI = PHINode::Create(PN->getType(), PN->getName());
15111511 newPHI->addIncoming(V1, A_ExitingBlock);
15121512 A_ExitBlock->getInstList().push_front(newPHI);
15131513 PN->removeIncomingValue(A_ExitBlock);
15971597 CurrentBR->eraseFromParent();
15981598
15991599 // Connect exiting block to original destination.
1600 new BranchInst(OrigDestBB, ExitingBB);
1600 BranchInst::Create(OrigDestBB, ExitingBB);
16011601
16021602 // Update PHINodes
16031603 updatePHINodes(ExitBB, ExitingBB, CondBB, IV, IVAdd, LP);
207207 // Create new PHI node with two incoming values for NewHeader.
208208 // One incoming value is from OrigLatch (through OrigHeader) and
209209 // second incoming value is from original pre-header.
210 PHINode *NH = new PHINode(In->getType(), In->getName());
210 PHINode *NH = PHINode::Create(In->getType(), In->getName());
211211 NH->addIncoming(PN->getIncomingValueForBlock(OrigLatch), OrigHeader);
212212 NH->addIncoming(NPV, OrigPreHeader);
213213 NewHeader->getInstList().push_front(NH);
248248 // create new PHINode for this instruction.
249249 Instruction *NewHeaderReplacement = NULL;
250250 if (usedOutsideOriginalHeader(In)) {
251 PHINode *PN = new PHINode(In->getType(), In->getName());
251 PHINode *PN = PHINode::Create(In->getType(), In->getName());
252252 PN->addIncoming(In, OrigHeader);
253253 PN->addIncoming(C, OrigPreHeader);
254254 NewHeader->getInstList().push_front(PN);
335335 } else {
336336 // Used outside Exit block. Create a new PHI node from exit block
337337 // to receive value from ne new header ane pre header.
338 PHINode *PN = new PHINode(U->getType(), U->getName());
338 PHINode *PN = PHINode::Create(U->getType(), U->getName());
339339 PN->addIncoming(ILoopHeaderInfo.PreHeader, OrigPreHeader);
340340 PN->addIncoming(OldPhi, OrigHeader);
341341 Exit->getInstList().push_front(PN);
446446 // Right now original pre-header has two successors, new header and