diff options
73 files changed, 972 insertions, 685 deletions
diff --git a/examples/BrainF/BrainF.cpp b/examples/BrainF/BrainF.cpp index a920793648..b2959f2000 100644 --- a/examples/BrainF/BrainF.cpp +++ b/examples/BrainF/BrainF.cpp @@ -74,7 +74,7 @@ void BrainF::header() { brainf_func = cast<Function>(module-> getOrInsertFunction("brainf", Type::VoidTy, NULL)); - builder = new LLVMBuilder(new BasicBlock(label, brainf_func)); + builder = new LLVMBuilder(BasicBlock::Create(label, brainf_func)); //%arr = malloc i8, i32 %d ConstantInt *val_mem = ConstantInt::get(APInt(32, memtotal)); @@ -110,13 +110,13 @@ void BrainF::header() { //Function footer //brainf.end: - endbb = new BasicBlock(label, brainf_func); + endbb = BasicBlock::Create(label, brainf_func); //free i8 *%arr new FreeInst(ptr_arr, endbb); //ret void - new ReturnInst(endbb); + ReturnInst::Create(endbb); @@ -141,7 +141,7 @@ void BrainF::header() { PointerType::getUnqual(IntegerType::Int8Ty), NULL)); //brainf.aberror: - aberrorbb = new BasicBlock(label, brainf_func); + aberrorbb = BasicBlock::Create(label, brainf_func); //call i32 @puts(i8 *getelementptr([%d x i8] *@aberrormsg, i32 0, i32 0)) { @@ -161,14 +161,14 @@ void BrainF::header() { }; CallInst *puts_call = - new CallInst(puts_func, - puts_params, array_endof(puts_params), - "", aberrorbb); + CallInst::Create(puts_func, + puts_params, array_endof(puts_params), + "", aberrorbb); puts_call->setTailCall(false); } //br label %brainf.end - new BranchInst(endbb, aberrorbb); + BranchInst::Create(endbb, aberrorbb); } } @@ -247,7 +247,7 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) { CreateOr(test_0, test_1, testreg); //br i1 %test.%d, label %main.%d, label %main.%d - BasicBlock *nextbb = new BasicBlock(label, brainf_func); + BasicBlock *nextbb = BasicBlock::Create(label, brainf_func); builder->CreateCondBr(test_2, aberrorbb, nextbb); //main.%d: @@ -273,16 +273,16 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) { case SYM_LOOP: { //br label %main.%d - BasicBlock *testbb = new BasicBlock(label, brainf_func); + BasicBlock *testbb = BasicBlock::Create(label, brainf_func); builder->CreateBr(testbb); //main.%d: BasicBlock *bb_0 = builder->GetInsertBlock(); - BasicBlock *bb_1 = new BasicBlock(label, brainf_func); + BasicBlock *bb_1 = BasicBlock::Create(label, brainf_func); builder->SetInsertPoint(bb_1); //Make part of PHI instruction now, wait until end of loop to finish - PHINode *phi_0 = new PHINode(PointerType::getUnqual(IntegerType::Int8Ty), + PHINode *phi_0 = PHINode::Create(PointerType::getUnqual(IntegerType::Int8Ty), headreg, testbb); phi_0->reserveOperandSpace(2); phi_0->addIncoming(curhead, bb_0); @@ -431,8 +431,8 @@ void BrainF::readloop(PHINode *phi, BasicBlock *oldbb, BasicBlock *testbb) { testbb); //br i1 %test.%d, label %main.%d, label %main.%d - BasicBlock *bb_0 = new BasicBlock(label, brainf_func); - new BranchInst(bb_0, oldbb, test_0, testbb); + BasicBlock *bb_0 = BasicBlock::Create(label, brainf_func); + BranchInst::Create(bb_0, oldbb, test_0, testbb); //main.%d: builder->SetInsertPoint(bb_0); diff --git a/examples/BrainF/BrainFDriver.cpp b/examples/BrainF/BrainFDriver.cpp index 2a3d546bde..0a24d7b665 100644 --- a/examples/BrainF/BrainFDriver.cpp +++ b/examples/BrainF/BrainFDriver.cpp @@ -70,17 +70,17 @@ void addMainFunction(Module *mod) { } //main.0: - BasicBlock *bb = new BasicBlock("main.0", main_func); + BasicBlock *bb = BasicBlock::Create("main.0", main_func); //call void @brainf() { - CallInst *brainf_call = new CallInst(mod->getFunction("brainf"), - "", bb); + CallInst *brainf_call = CallInst::Create(mod->getFunction("brainf"), + "", bb); brainf_call->setTailCall(false); } //ret i32 0 - new ReturnInst(ConstantInt::get(APInt(32, 0)), bb); + ReturnInst::Create(ConstantInt::get(APInt(32, 0)), bb); } int main(int argc, char **argv) { diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp index b028c4b794..f5ef0d02a8 100644 --- a/examples/Fibonacci/fibonacci.cpp +++ b/examples/Fibonacci/fibonacci.cpp @@ -43,7 +43,7 @@ static Function *CreateFibFunction(Module *M) { (Type *)0)); // Add a basic block to the function. - BasicBlock *BB = new BasicBlock("EntryBlock", FibF); + BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF); // Get pointers to the constants. Value *One = ConstantInt::get(Type::Int32Ty, 1); @@ -54,25 +54,25 @@ static Function *CreateFibFunction(Module *M) { ArgX->setName("AnArg"); // Give it a nice symbolic name for fun. // Create the true_block. - BasicBlock *RetBB = new BasicBlock("return", FibF); + BasicBlock *RetBB = BasicBlock::Create("return", FibF); // Create an exit block. - BasicBlock* RecurseBB = new BasicBlock("recurse", FibF); + BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF); // Create the "if (arg <= 2) goto exitbb" Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB); - new BranchInst(RetBB, RecurseBB, CondInst, BB); + BranchInst::Create(RetBB, RecurseBB, CondInst, BB); // Create: ret int 1 - new ReturnInst(One, RetBB); + ReturnInst::Create(One, RetBB); // create fib(x-1) Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB); - CallInst *CallFibX1 = new CallInst(FibF, Sub, "fibx1", RecurseBB); + CallInst *CallFibX1 = CallInst::Create(FibF, Sub, "fibx1", RecurseBB); CallFibX1->setTailCall(); // create fib(x-2) Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB); - CallInst *CallFibX2 = new CallInst(FibF, Sub, "fibx2", RecurseBB); + CallInst *CallFibX2 = CallInst::Create(FibF, Sub, "fibx2", RecurseBB); CallFibX2->setTailCall(); @@ -81,7 +81,7 @@ static Function *CreateFibFunction(Module *M) { "addresult", RecurseBB); // Create the return instruction and add it to the basic block - new ReturnInst(Sum, RecurseBB); + ReturnInst::Create(Sum, RecurseBB); return FibF; } diff --git a/examples/HowToUseJIT/HowToUseJIT.cpp b/examples/HowToUseJIT/HowToUseJIT.cpp index b79c6d42eb..2aba8e1128 100644 --- a/examples/HowToUseJIT/HowToUseJIT.cpp +++ b/examples/HowToUseJIT/HowToUseJIT.cpp @@ -58,7 +58,7 @@ int main() { // Add a basic block to the function. As before, it automatically inserts // because of the last argument. - BasicBlock *BB = new BasicBlock("EntryBlock", Add1F); + BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F); // Get pointers to the constant `1'. Value *One = ConstantInt::get(Type::Int32Ty, 1); @@ -72,7 +72,7 @@ int main() { Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB); // Create the return instruction and add it to the basic block - new ReturnInst(Add, BB); + ReturnInst::Create(Add, BB); // Now, function add1 is ready. @@ -83,17 +83,17 @@ int main() { cast<Function>(M->getOrInsertFunction("foo", Type::Int32Ty, (Type *)0)); // Add a basic block to the FooF function. - BB = new BasicBlock("EntryBlock", FooF); + BB = BasicBlock::Create("EntryBlock", FooF); // Get pointers to the constant `10'. Value *Ten = ConstantInt::get(Type::Int32Ty, 10); // Pass Ten to the call call: - CallInst *Add1CallRes = new CallInst(Add1F, Ten, "add1", BB); + CallInst *Add1CallRes = CallInst::Create(Add1F, Ten, "add1", BB); Add1CallRes->setTailCall(true); // Create the return instruction and add it to the basic block. - new ReturnInst(Add1CallRes, BB); + ReturnInst::Create(Add1CallRes, BB); // Now we create the JIT. ExistingModuleProvider* MP = new ExistingModuleProvider(M); diff --git a/examples/ModuleMaker/ModuleMaker.cpp b/examples/ModuleMaker/ModuleMaker.cpp index 1d630a4d77..40d2fa99f4 100644 --- a/examples/ModuleMaker/ModuleMaker.cpp +++ b/examples/ModuleMaker/ModuleMaker.cpp @@ -32,11 +32,11 @@ int main() { // By passing a module as the last parameter to the Function constructor, // it automatically gets appended to the Module. - Function *F = new Function(FT, Function::ExternalLinkage, "main", M); + Function *F = Function::Create(FT, Function::ExternalLinkage, "main", M); // Add a basic block to the function... again, it automatically inserts // because of the last argument. - BasicBlock *BB = new BasicBlock("EntryBlock", F); + BasicBlock *BB = BasicBlock::Create("EntryBlock", F); // Get pointers to the constant integers... Value *Two = ConstantInt::get(Type::Int32Ty, 2); @@ -50,7 +50,7 @@ int main() { BB->getInstList().push_back(Add); // Create the return instruction and add it to the basic block - BB->getInstList().push_back(new ReturnInst(Add)); + BB->getInstList().push_back(ReturnInst::Create(Add)); // Output the bitcode file to stdout WriteBitcodeToFile(M, std::cout); diff --git a/examples/ParallelJIT/ParallelJIT.cpp b/examples/ParallelJIT/ParallelJIT.cpp index 92d8f27f8b..300c432863 100644 --- a/examples/ParallelJIT/ParallelJIT.cpp +++ b/examples/ParallelJIT/ParallelJIT.cpp @@ -39,7 +39,7 @@ static Function* createAdd1(Module *M) { // Add a basic block to the function. As before, it automatically inserts // because of the last argument. - BasicBlock *BB = new BasicBlock("EntryBlock", Add1F); + BasicBlock *BB = BasicBlock::Create("EntryBlock", Add1F); // Get pointers to the constant `1'. Value *One = ConstantInt::get(Type::Int32Ty, 1); @@ -53,7 +53,7 @@ static Function* createAdd1(Module *M) { Instruction *Add = BinaryOperator::createAdd(One, ArgX, "addresult", BB); // Create the return instruction and add it to the basic block - new ReturnInst(Add, BB); + ReturnInst::Create(Add, BB); // Now, function add1 is ready. return Add1F; @@ -67,7 +67,7 @@ static Function *CreateFibFunction(Module *M) { (Type *)0)); // Add a basic block to the function. - BasicBlock *BB = new BasicBlock("EntryBlock", FibF); + BasicBlock *BB = BasicBlock::Create("EntryBlock", FibF); // Get pointers to the constants. Value *One = ConstantInt::get(Type::Int32Ty, 1); @@ -78,31 +78,31 @@ static Function *CreateFibFunction(Module *M) { ArgX->setName("AnArg"); // Give it a nice symbolic name for fun. // Create the true_block. - BasicBlock *RetBB = new BasicBlock("return", FibF); + BasicBlock *RetBB = BasicBlock::Create("return", FibF); // Create an exit block. - BasicBlock* RecurseBB = new BasicBlock("recurse", FibF); + BasicBlock* RecurseBB = BasicBlock::Create("recurse", FibF); // Create the "if (arg < 2) goto exitbb" Value *CondInst = new ICmpInst(ICmpInst::ICMP_SLE, ArgX, Two, "cond", BB); - new BranchInst(RetBB, RecurseBB, CondInst, BB); + BranchInst::Create(RetBB, RecurseBB, CondInst, BB); // Create: ret int 1 - new ReturnInst(One, RetBB); + ReturnInst::Create(One, RetBB); // create fib(x-1) Value *Sub = BinaryOperator::createSub(ArgX, One, "arg", RecurseBB); - Value *CallFibX1 = new CallInst(FibF, Sub, "fibx1", RecurseBB); + Value *CallFibX1 = CallInst::Create(FibF, Sub, "fibx1", RecurseBB); // create fib(x-2) Sub = BinaryOperator::createSub(ArgX, Two, "arg", RecurseBB); - Value *CallFibX2 = new CallInst(FibF, Sub, "fibx2", RecurseBB); + Value *CallFibX2 = CallInst::Create(FibF, Sub, "fibx2", RecurseBB); // fib(x-1)+fib(x-2) Value *Sum = BinaryOperator::createAdd(CallFibX1, CallFibX2, "addresult", RecurseBB); // Create the return instruction and add it to the basic block - new ReturnInst(Sum, RecurseBB); + ReturnInst::Create(Sum, RecurseBB); return FibF; } diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h index 253a8fa1a0..797f50e864 100644 --- a/include/llvm/BasicBlock.h +++ b/include/llvm/BasicBlock.h @@ -66,17 +66,22 @@ private : BasicBlock(const BasicBlock &); // Do not implement void operator=(const BasicBlock &); // Do not implement -public: - /// Instruction iterators... - typedef InstListType::iterator iterator; - typedef InstListType::const_iterator const_iterator; - /// BasicBlock ctor - If the function parameter is specified, the basic block /// is automatically inserted at either the end of the function (if /// InsertBefore is null), or before the specified basic block. /// explicit BasicBlock(const std::string &Name = "", Function *Parent = 0, - BasicBlock *InsertBefore = 0, BasicBlock *unwindDest = 0); + BasicBlock *InsertBefore = 0, BasicBlock *UnwindDest = 0); +public: + /// Instruction iterators... + typedef InstListType::iterator iterator; + typedef InstListType::const_iterator const_iterator; + + // allocate space for exactly zero operands + static BasicBlock *Create(const std::string &Name = "", Function *Parent = 0, + BasicBlock *InsertBefore = 0, BasicBlock *UnwindDest = 0) { + return new(!!UnwindDest) BasicBlock(Name, Parent, InsertBefore, UnwindDest); + } ~BasicBlock(); /// getUnwindDest - Returns the BasicBlock that flow will enter if an unwind diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h index f71c655455..13df601f41 100644 --- a/include/llvm/Constants.h +++ b/include/llvm/Constants.h @@ -43,9 +43,15 @@ struct ConvertConstantType; /// @brief Class for constant integers. class ConstantInt : public Constant { static ConstantInt *TheTrueVal, *TheFalseVal; + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT ConstantInt(const ConstantInt &); // DO NOT IMPLEMENT ConstantInt(const IntegerType *Ty, const APInt& V); APInt Val; +protected: + // allocate space for exactly zero operands + void *operator new(size_t s) { + return User::operator new(s, 0); + } public: /// Return the constant as an APInt value reference. This allows clients to /// obtain a copy of the value, with all its precision in tact. @@ -215,9 +221,15 @@ private: /// class ConstantFP : public Constant { APFloat Val; + void *operator new(size_t, unsigned);// DO NOT IMPLEMENT ConstantFP(const ConstantFP &); // DO NOT IMPLEMENT protected: ConstantFP(const Type *Ty, const APFloat& V); +protected: + // allocate space for exactly zero operands + void *operator new(size_t s) { + return User::operator new(s, 0); + } public: /// get() - Static factory methods - Return objects of the specified value static ConstantFP *get(const Type *Ty, const APFloat& V); @@ -262,10 +274,16 @@ public: /// class ConstantAggregateZero : public Constant { friend struct ConstantCreator<ConstantAggregateZero, Type, char>; + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT ConstantAggregateZero(const ConstantAggregateZero &); // DO NOT IMPLEMENT protected: explicit ConstantAggregateZero(const Type *Ty) : Constant(Ty, ConstantAggregateZeroVal, 0, 0) {} +protected: + // allocate space for exactly zero operands + void *operator new(size_t s) { + return User::operator new(s, 0); + } public: /// get() - static factory method for creating a null aggregate. It is /// illegal to call this method with a non-aggregate type. @@ -457,14 +475,19 @@ public: /// class ConstantPointerNull : public Constant { friend struct ConstantCreator<ConstantPointerNull, PointerType, char>; + void *operator new(size_t, unsigned); // DO NOT IMPLEMENT ConstantPointerNull(const ConstantPointerNull &); // DO NOT IMPLEMENT protected: explicit ConstantPointerNull(const PointerType *T) : Constant(reinterpret_cast<const Type*>(T), Value::ConstantPointerNullVal, 0, 0) {} +protected: + // allocate space for exactly zero operands + void *operator new(size_t s) { + return User::operator new(s |