X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=docs%2Ftutorial%2FJITTutorial2.html;h=262457274d08d504205e40ddf0d13c91e0f02bd3;hb=317bd709bdd119a286e4c2e10b59202dc7e81a13;hp=ba72ea2abb014c1f19e8fb765b778c0f7242a89a;hpb=729eb14ae8b1a1002a212a99cdc411659670fbd4;p=oota-llvm.git diff --git a/docs/tutorial/JITTutorial2.html b/docs/tutorial/JITTutorial2.html index ba72ea2abb0..262457274d0 100644 --- a/docs/tutorial/JITTutorial2.html +++ b/docs/tutorial/JITTutorial2.html @@ -56,7 +56,7 @@ unsigned gcd(unsigned x, unsigned y) { #include <llvm/PassManager.h> #include <llvm/Analysis/Verifier.h> #include <llvm/Assembly/PrintModulePass.h> -#include <llvm/Support/LLVMBuilder.h> +#include <llvm/Support/IRBuilder.h> using namespace llvm; @@ -70,7 +70,8 @@ int main(int argc, char**argv) { PassManager PM; PM.add(new PrintModulePass(&llvm::cout)); PM.run(*Mod); - + + delete Mod; return 0; } @@ -98,11 +99,11 @@ Module* makeLLVMModule() {
- BasicBlock* entry = new BasicBlock("entry", gcd); - BasicBlock* ret = new BasicBlock("return", gcd); - BasicBlock* cond_false = new BasicBlock("cond_false", gcd); - BasicBlock* cond_true = new BasicBlock("cond_true", gcd); - BasicBlock* cond_false_2 = new BasicBlock("cond_false", gcd); + BasicBlock* entry = BasicBlock::Create("entry", gcd); + BasicBlock* ret = BasicBlock::Create("return", gcd); + BasicBlock* cond_false = BasicBlock::Create("cond_false", gcd); + BasicBlock* cond_true = BasicBlock::Create("cond_true", gcd); + BasicBlock* cond_false_2 = BasicBlock::Create("cond_false", gcd);
- LLVMBuilder builder(entry); + IRBuilder builder(entry); Value* xEqualsY = builder.CreateICmpEQ(x, y, "tmp"); builder.CreateCondBr(xEqualsY, ret, cond_false);
Our next block, ret
, is pretty simple: it just returns the value of x
. Recall that this block is only reached if x == y
, so this is the correct behavior. Notice that instead of creating a new LLVMBuilder
for each block, we can use SetInsertPoint
to retarget our existing one. This saves on construction and memory allocation costs.
Our next block, ret
, is pretty simple: it just returns the value of x
. Recall that this block is only reached if x == y
, so this is the correct behavior. Notice that instead of creating a new IRBuilder
for each block, we can use SetInsertPoint
to retarget our existing one. This saves on construction and memory allocation costs.
@@ -125,7 +126,15 @@ Module* makeLLVMModule() {
cond_false
is a more interesting block: we now know that x != y
, so we must branch again to determine which of x
and y
is larger. This is achieved using the ICmpULT
instruction, which stands for integer comparison for unsigned less-than. In LLVM, integer types do not carry sign; a 32-bit integer pseudo-register can interpreted as signed or unsigned without casting. Whether a signed or unsigned interpretation is desired is specified in the instruction. This is why several instructions in the LLVM IR, such as integer less-than, include a specifier for signed or unsigned.
cond_false
is a more interesting block: we now know that x
+!= y
, so we must branch again to determine which of x
+and y
is larger. This is achieved using the ICmpULT
+instruction, which stands for integer comparison for unsigned
+less-than. In LLVM, integer types do not carry sign; a 32-bit integer
+pseudo-register can be interpreted as signed or unsigned without casting.
+Whether a signed or unsigned interpretation is desired is specified in the
+instruction. This is why several instructions in the LLVM IR, such as integer
+less-than, include a specifier for signed or unsigned.
Also note that we're again making use of LLVM's automatic name uniquing, this time at a register level. We've deliberately chosen to name every instruction "tmp" to illustrate that LLVM will give them all unique names without getting confused.
@@ -166,7 +175,7 @@ Module* makeLLVMModule() {-# c++ -g tut2.cpp `llvm-config --cppflags --ldflags --libs core` -o tut2 +# c++ -g tut2.cpp `llvm-config --cxxflags --ldflags --libs core` -o tut2 # ./tut2