From bad82d8c94202f03bbc127a685d423396afd8a63 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Tue, 23 Oct 2007 06:22:21 +0000 Subject: [PATCH] Now with valid HTML 4.01! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43244 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/tutorial/JITTutorial2.html | 44 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/docs/tutorial/JITTutorial2.html b/docs/tutorial/JITTutorial2.html index 047579735e0..1f9bef886a3 100644 --- a/docs/tutorial/JITTutorial2.html +++ b/docs/tutorial/JITTutorial2.html @@ -51,9 +51,9 @@ unsigned gcd(unsigned x, unsigned y) {

With this example, we'll learn how to create functions with multiple blocks and control flow, and how to make function calls within your LLVM code. For starters, consider the diagram below.

-
GCD CFG
+
GCD CFG
-

The above is a graphical representation of a program in LLVM IR. It places each basic block on a node of a graph, and uses directed edges to indicate flow control. These blocks will be serialized when written to a text or bitcode file, but it is often useful conceptually to think of them as a graph. Again, if you are unsure about the code in the diagram, you should skim through the LLVM Language Reference Manual and convince yourself that it is, in fact, the GCD algorithm.

+

The above is a graphical representation of a program in LLVM IR. It places each basic block on a node of a graph, and uses directed edges to indicate flow control. These blocks will be serialized when written to a text or bitcode file, but it is often useful conceptually to think of them as a graph. Again, if you are unsure about the code in the diagram, you should skim through the LLVM Language Reference Manual and convince yourself that it is, in fact, the GCD algorithm.

The first part of our code is the same as from first tutorial. The same basic setup is required: creating a module, verifying it, and running the PrintModulePass on it. Even the first segment of makeLLVMModule() looks the same, because gcd happens the have the same prototype as our mul_add function.

@@ -76,27 +76,27 @@ int main(int argc, char**argv) { verifyModule(*Mod, PrintMessageAction); PassManager PM; - PM.add(new PrintModulePass(&llvm::cout)); + PM.add(new PrintModulePass(&llvm::cout)); PM.run(*Mod); return 0; } Module* makeLLVMModule() { - Module* mod = new Module("tut2"); + Module* mod = new Module("tut2"); - Constant* c = mod->getOrInsertFunction("gcd", + Constant* c = mod->getOrInsertFunction("gcd", IntegerType::get(32), IntegerType::get(32), IntegerType::get(32), NULL); - Function* gcd = cast(c); + Function* gcd = cast<Function>(c); - Function::arg_iterator args = gcd->arg_begin(); + Function::arg_iterator args = gcd->arg_begin(); Value* x = args++; - x->setName("x"); + x->setName("x"); Value* y = args++; - y->setName("y"); + y->setName("y"); @@ -106,11 +106,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 = 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);
 
@@ -119,7 +119,7 @@ Module* makeLLVMModule() {
   LLVMBuilder builder(entry);
-  Value* xEqualsY = builder.CreateICmpEQ(x, y, "tmp");
+  Value* xEqualsY = builder.CreateICmpEQ(x, y, "tmp");
   builder.CreateCondBr(xEqualsY, ret, cond_false);
 
@@ -140,7 +140,7 @@ Module* makeLLVMModule() {
   builder.SetInsertPoint(cond_false);
-  Value* xLessThanY = builder.CreateICmpULT(x, y, "tmp");
+  Value* xLessThanY = builder.CreateICmpULT(x, y, "tmp");
   builder.CreateCondBr(xLessThanY, cond_true, cond_false_2);
 
@@ -150,19 +150,19 @@ Module* makeLLVMModule() {
   builder.SetInsertPoint(cond_true);
-  Value* yMinusX = builder.CreateSub(y, x, "tmp");
-  std::vector args1;
+  Value* yMinusX = builder.CreateSub(y, x, "tmp");
+  std::vector<Value*> args1;
   args1.push_back(x);
   args1.push_back(yMinusX);
-  Value* recur_1 = builder.CreateCall(gcd, args1.begin(), args1.end(), "tmp");
+  Value* recur_1 = builder.CreateCall(gcd, args1.begin(), args1.end(), "tmp");
   builder.CreateRet(recur_1);
   
   builder.SetInsertPoint(cond_false_2);
-  Value* xMinusY = builder.CreateSub(x, y, "tmp");
-  std::vector args2;
+  Value* xMinusY = builder.CreateSub(x, y, "tmp");
+  std::vector<Value*> args2;
   args2.push_back(xMinusY);
   args2.push_back(y);
-  Value* recur_2 = builder.CreateCall(gcd, args2.begin(), args2.end(), "tmp");
+  Value* recur_2 = builder.CreateCall(gcd, args2.begin(), args2.end(), "tmp");
   builder.CreateRet(recur_2);
   
   return mod;