Move TargetData to DataLayout.
[oota-llvm.git] / docs / tutorial / LangImpl5.html
index e46ded13ae53cd1a10fa5ac1ac6d1c3bd91df2e2..768d9a0e11536b0446bdf156b9b13945b6982097 100644 (file)
@@ -6,7 +6,7 @@
   <title>Kaleidoscope: Extending the Language: Control Flow</title>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <meta name="author" content="Chris Lattner">
-  <link rel="stylesheet" href="../llvm.css" type="text/css">
+  <link rel="stylesheet" href="../_static/llvm.css" type="text/css">
 </head>
 
 <body>
@@ -259,20 +259,20 @@ declare double @bar()
 
 define double @baz(double %x) {
 entry:
-       %ifcond = fcmp one double %x, 0.000000e+00
-       br i1 %ifcond, label %then, label %else
+  %ifcond = fcmp one double %x, 0.000000e+00
+  br i1 %ifcond, label %then, label %else
 
 then:          ; preds = %entry
-       %calltmp = call double @foo()
-       br label %ifcont
+  %calltmp = call double @foo()
+  br label %ifcont
 
 else:          ; preds = %entry
-       %calltmp1 = call double @bar()
-       br label %ifcont
+  %calltmp1 = call double @bar()
+  br label %ifcont
 
 ifcont:                ; preds = %else, %then
-       %iftmp = phi double [ %calltmp, %then ], [ %calltmp1, %else ]
-       ret double %iftmp
+  %iftmp = phi double [ %calltmp, %then ], [ %calltmp1, %else ]
+  ret double %iftmp
 }
 </pre>
 </div>
@@ -660,25 +660,25 @@ declare double @putchard(double)
 
 define double @printstar(double %n) {
 entry:
-        ; initial value = 1.0 (inlined into phi)
-       br label %loop
+  ; initial value = 1.0 (inlined into phi)
+  br label %loop
 
 loop:          ; preds = %loop, %entry
-       %i = phi double [ 1.000000e+00, %entry ], [ %nextvar, %loop ]
-        ; body
-       %calltmp = call double @putchard(double 4.200000e+01)
-        ; increment
-       %nextvar = fadd double %i, 1.000000e+00
-
-        ; termination test
-       %cmptmp = fcmp ult double %i, %n
-       %booltmp = uitofp i1 %cmptmp to double
-       %loopcond = fcmp one double %booltmp, 0.000000e+00
-       br i1 %loopcond, label %loop, label %afterloop
+  %i = phi double [ 1.000000e+00, %entry ], [ %nextvar, %loop ]
+  ; body
+  %calltmp = call double @putchard(double 4.200000e+01)
+  ; increment
+  %nextvar = fadd double %i, 1.000000e+00
+
+  ; termination test
+  %cmptmp = fcmp ult double %i, %n
+  %booltmp = uitofp i1 %cmptmp to double
+  %loopcond = fcmp one double %booltmp, 0.000000e+00
+  br i1 %loopcond, label %loop, label %afterloop
 
 afterloop:             ; preds = %loop
-        ; loop always returns 0.0
-       ret double 0.000000e+00
+  ; loop always returns 0.0
+  ret double 0.000000e+00
 }
 </pre>
 </div>
@@ -829,10 +829,11 @@ statement.</p>
 </div>
 
 <p>With the code for the body of the loop complete, we just need to finish up
-the control flow for it.  This code remembers the end block (for the phi node), then creates the block for the loop exit ("afterloop").  Based on the value of the
-exit condition, it creates a conditional branch that chooses between executing
-the loop again and exiting the loop.  Any future code is emitted in the
-"afterloop" block, so it sets the insertion position to it.</p>
+the control flow for it.  This code remembers the end block (for the phi node),
+then creates the block for the loop exit ("afterloop").  Based on the value of
+the exit condition, it creates a conditional branch that chooses between
+executing the loop again and exiting the loop.  Any future code is emitted in
+the "afterloop" block, so it sets the insertion position to it.</p>
   
 <div class="doc_code">
 <pre>
@@ -880,10 +881,10 @@ if/then/else and for expressions..  To build this example, use:
 
 <div class="doc_code">
 <pre>
-   # Compile
-   g++ -g toy.cpp `llvm-config --cppflags --ldflags --libs core jit native` -O3 -o toy
-   # Run
-   ./toy
+# Compile
+clang++ -g toy.cpp `llvm-config --cppflags --ldflags --libs core jit native` -O3 -o toy
+# Run
+./toy
 </pre>
 </div>
 
@@ -894,15 +895,15 @@ if/then/else and for expressions..  To build this example, use:
 #include "llvm/DerivedTypes.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/ExecutionEngine/JIT.h"
+#include "llvm/IRBuilder.h"
 #include "llvm/LLVMContext.h"
 #include "llvm/Module.h"
 #include "llvm/PassManager.h"
 #include "llvm/Analysis/Verifier.h"
 #include "llvm/Analysis/Passes.h"
-#include "llvm/Target/TargetData.h"
-#include "llvm/Target/TargetSelect.h"
+#include "llvm/DataLayout.h"
 #include "llvm/Transforms/Scalar.h"
-#include "llvm/Support/IRBuilder.h"
+#include "llvm/Support/TargetSelect.h"
 #include &lt;cstdio&gt;
 #include &lt;string&gt;
 #include &lt;map&gt;
@@ -1397,7 +1398,7 @@ Value *CallExprAST::Codegen() {
     if (ArgsV.back() == 0) return 0;
   }
   
-  return Builder.CreateCall(CalleeF, ArgsV.begin(), ArgsV.end(), "calltmp");
+  return Builder.CreateCall(CalleeF, ArgsV, "calltmp");
 }
 
 Value *IfExprAST::Codegen() {
@@ -1546,8 +1547,8 @@ Value *ForExprAST::Codegen() {
 
 Function *PrototypeAST::Codegen() {
   // Make the function type:  double(double,double) etc.
-  std::vector&lt;const Type*&gt; Doubles(Args.size(),
-                                   Type::getDoubleTy(getGlobalContext()));
+  std::vector&lt;Type*&gt; Doubles(Args.size(),
+                             Type::getDoubleTy(getGlobalContext()));
   FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()),
                                        Doubles, false);
   
@@ -1722,7 +1723,7 @@ int main() {
 
   // Set up the optimizer pipeline.  Start with registering info about how the
   // target lays out data structures.
-  OurFPM.add(new TargetData(*TheExecutionEngine-&gt;getTargetData()));
+  OurFPM.add(new DataLayout(*TheExecutionEngine-&gt;getDataLayout()));
   // Provide basic AliasAnalysis support for GVN.
   OurFPM.add(createBasicAliasAnalysisPass());
   // Do simple "peephole" optimizations and bit-twiddling optzns.