[llvm-commits] [llvm] r48836 - in /llvm/branches/ggreif/use-diet/examples: BrainF/BrainF.cpp BrainF/BrainFDriver.cpp Fibonacci/fibonacci.cpp HowToUseJIT/HowToUseJIT.cpp ModuleMaker/ModuleMaker.cpp ParallelJIT/ParallelJIT.cpp

Gabor Greif ggreif at gmail.com
Wed Mar 26 12:28:00 PDT 2008


Author: ggreif
Date: Wed Mar 26 14:28:00 2008
New Revision: 48836

URL: http://llvm.org/viewvc/llvm-project?rev=48836&view=rev
Log:
Create-ify examples/

Modified:
    llvm/branches/ggreif/use-diet/examples/BrainF/BrainF.cpp
    llvm/branches/ggreif/use-diet/examples/BrainF/BrainFDriver.cpp
    llvm/branches/ggreif/use-diet/examples/Fibonacci/fibonacci.cpp
    llvm/branches/ggreif/use-diet/examples/HowToUseJIT/HowToUseJIT.cpp
    llvm/branches/ggreif/use-diet/examples/ModuleMaker/ModuleMaker.cpp
    llvm/branches/ggreif/use-diet/examples/ParallelJIT/ParallelJIT.cpp

Modified: llvm/branches/ggreif/use-diet/examples/BrainF/BrainF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/examples/BrainF/BrainF.cpp?rev=48836&r1=48835&r2=48836&view=diff

==============================================================================
--- llvm/branches/ggreif/use-diet/examples/BrainF/BrainF.cpp (original)
+++ llvm/branches/ggreif/use-diet/examples/BrainF/BrainF.cpp Wed Mar 26 14:28:00 2008
@@ -74,7 +74,7 @@
   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 @@
   //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 @@
                           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 @@
       };
 
       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 @@
               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 @@
       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 @@
                                       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);

Modified: llvm/branches/ggreif/use-diet/examples/BrainF/BrainFDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/examples/BrainF/BrainFDriver.cpp?rev=48836&r1=48835&r2=48836&view=diff

==============================================================================
--- llvm/branches/ggreif/use-diet/examples/BrainF/BrainFDriver.cpp (original)
+++ llvm/branches/ggreif/use-diet/examples/BrainF/BrainFDriver.cpp Wed Mar 26 14:28:00 2008
@@ -70,17 +70,17 @@
   }
 
   //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) {

Modified: llvm/branches/ggreif/use-diet/examples/Fibonacci/fibonacci.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/examples/Fibonacci/fibonacci.cpp?rev=48836&r1=48835&r2=48836&view=diff

==============================================================================
--- llvm/branches/ggreif/use-diet/examples/Fibonacci/fibonacci.cpp (original)
+++ llvm/branches/ggreif/use-diet/examples/Fibonacci/fibonacci.cpp Wed Mar 26 14:28:00 2008
@@ -43,7 +43,7 @@
                                           (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 @@
   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 @@
                                          "addresult", RecurseBB);
 
   // Create the return instruction and add it to the basic block
-  new ReturnInst(Sum, RecurseBB);
+  ReturnInst::Create(Sum, RecurseBB);
 
   return FibF;
 }

Modified: llvm/branches/ggreif/use-diet/examples/HowToUseJIT/HowToUseJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/examples/HowToUseJIT/HowToUseJIT.cpp?rev=48836&r1=48835&r2=48836&view=diff

==============================================================================
--- llvm/branches/ggreif/use-diet/examples/HowToUseJIT/HowToUseJIT.cpp (original)
+++ llvm/branches/ggreif/use-diet/examples/HowToUseJIT/HowToUseJIT.cpp Wed Mar 26 14:28:00 2008
@@ -58,7 +58,7 @@
 
   // 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 @@
   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 @@
     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);

Modified: llvm/branches/ggreif/use-diet/examples/ModuleMaker/ModuleMaker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/examples/ModuleMaker/ModuleMaker.cpp?rev=48836&r1=48835&r2=48836&view=diff

==============================================================================
--- llvm/branches/ggreif/use-diet/examples/ModuleMaker/ModuleMaker.cpp (original)
+++ llvm/branches/ggreif/use-diet/examples/ModuleMaker/ModuleMaker.cpp Wed Mar 26 14:28:00 2008
@@ -32,11 +32,11 @@
 
   // 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 @@
   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);

Modified: llvm/branches/ggreif/use-diet/examples/ParallelJIT/ParallelJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/ggreif/use-diet/examples/ParallelJIT/ParallelJIT.cpp?rev=48836&r1=48835&r2=48836&view=diff

==============================================================================
--- llvm/branches/ggreif/use-diet/examples/ParallelJIT/ParallelJIT.cpp (original)
+++ llvm/branches/ggreif/use-diet/examples/ParallelJIT/ParallelJIT.cpp Wed Mar 26 14:28:00 2008
@@ -39,7 +39,7 @@
 
   // 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 @@
   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 @@
                                           (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 @@
   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;
 }





More information about the llvm-commits mailing list