Propagate debug loc info for XOR and MatchRotate.
[oota-llvm.git] / docs / tutorial / JITTutorial2.html
index ba72ea2abb014c1f19e8fb765b778c0f7242a89a..262457274d08d504205e40ddf0d13c91e0f02bd3 100644 (file)
@@ -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() {
 
 <div class="doc_code">
 <pre>
-  BasicBlock* entry = new BasicBlock(&quot;entry&quot;, gcd);
-  BasicBlock* ret = new BasicBlock(&quot;return&quot;, gcd);
-  BasicBlock* cond_false = new BasicBlock(&quot;cond_false&quot;, gcd);
-  BasicBlock* cond_true = new BasicBlock(&quot;cond_true&quot;, gcd);
-  BasicBlock* cond_false_2 = new BasicBlock(&quot;cond_false&quot;, gcd);
+  BasicBlock* entry = BasicBlock::Create(&quot;entry&quot;, gcd);
+  BasicBlock* ret = BasicBlock::Create(&quot;return&quot;, gcd);
+  BasicBlock* cond_false = BasicBlock::Create(&quot;cond_false&quot;, gcd);
+  BasicBlock* cond_true = BasicBlock::Create(&quot;cond_true&quot;, gcd);
+  BasicBlock* cond_false_2 = BasicBlock::Create(&quot;cond_false&quot;, gcd);
 </pre>
 </div>
 
@@ -110,13 +111,13 @@ Module* makeLLVMModule() {
 
 <div class="doc_code">
 <pre>
-  LLVMBuilder builder(entry);
+  IRBuilder builder(entry);
   Value* xEqualsY = builder.CreateICmpEQ(x, y, &quot;tmp&quot;);
   builder.CreateCondBr(xEqualsY, ret, cond_false);
 </pre>
 </div>
 
-<p>Our next block, <code>ret</code>, is pretty simple: it just returns the value of <code>x</code>.  Recall that this block is only reached if <code>x == y</code>, so this is the correct behavior.  Notice that instead of creating a new <code>LLVMBuilder</code> for each block, we can use <code>SetInsertPoint</code> to retarget our existing one.  This saves on construction and memory allocation costs.</p>
+<p>Our next block, <code>ret</code>, is pretty simple: it just returns the value of <code>x</code>.  Recall that this block is only reached if <code>x == y</code>, so this is the correct behavior.  Notice that instead of creating a new <code>IRBuilder</code> for each block, we can use <code>SetInsertPoint</code> to retarget our existing one.  This saves on construction and memory allocation costs.</p>
 
 <div class="doc_code">
 <pre>
@@ -125,7 +126,15 @@ Module* makeLLVMModule() {
 </pre>
 </div>
 
-<p><code>cond_false</code> is a more interesting block: we now know that <code>x != y</code>, so we must branch again to determine which of <code>x</code> and <code>y</code> is larger.  This is achieved using the <code>ICmpULT</code> instruction, which stands for <em>integer comparison for unsigned less-than</em>.  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.</p>
+<p><code>cond_false</code> is a more interesting block: we now know that <code>x
+!= y</code>, so we must branch again to determine which of <code>x</code>
+and <code>y</code> is larger.  This is achieved using the <code>ICmpULT</code>
+instruction, which stands for <em>integer comparison for unsigned
+less-than</em>.  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.</p>
 
 <p>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.</p>
 
@@ -166,7 +175,7 @@ Module* makeLLVMModule() {
 
 <div class="doc_code">
 <pre>
-# 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
 </pre>
 </div>