[llvm-commits] [llvm] r90111 - in /llvm/trunk/docs/tutorial: JITTutorial1.html JITTutorial2-1.png JITTutorial2.html index.html

Nick Lewycky nicholas at mxc.ca
Sun Nov 29 20:23:18 PST 2009


Author: nicholas
Date: Sun Nov 29 22:23:17 2009
New Revision: 90111

URL: http://llvm.org/viewvc/llvm-project?rev=90111&view=rev
Log:
Remove the 'simple jit' tutorial as it wasn't really being maintained and its
material is covered by the Kaleidoscope tutorial.

Removed:
    llvm/trunk/docs/tutorial/JITTutorial1.html
    llvm/trunk/docs/tutorial/JITTutorial2-1.png
    llvm/trunk/docs/tutorial/JITTutorial2.html
Modified:
    llvm/trunk/docs/tutorial/index.html

Removed: llvm/trunk/docs/tutorial/JITTutorial1.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/tutorial/JITTutorial1.html?rev=90110&view=auto

==============================================================================
--- llvm/trunk/docs/tutorial/JITTutorial1.html (original)
+++ llvm/trunk/docs/tutorial/JITTutorial1.html (removed)
@@ -1,207 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
-                      "http://www.w3.org/TR/html4/strict.dtd">
-
-<html>
-<head>
-  <title>LLVM Tutorial 1: A First Function</title>
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-  <meta name="author" content="Owen Anderson">
-  <meta name="description" 
-  content="LLVM Tutorial 1: A First Function.">
-  <link rel="stylesheet" href="../llvm.css" type="text/css">
-</head>
-
-<body>
-
-<div class="doc_title"> LLVM Tutorial 1: A First Function </div>
-
-<div class="doc_author">
-  <p>Written by <a href="mailto:owen at apple.com">Owen Anderson</a></p>
-</div>
-
-<!-- *********************************************************************** -->
-<div class="doc_section"><a name="intro">A First Function</a></div>
-<!-- *********************************************************************** -->
-
-<div class="doc_text">
-
-<p>For starters, let's consider a relatively straightforward function that takes three integer parameters and returns an arithmetic combination of them.  This is nice and simple, especially since it involves no control flow:</p>
-
-<div class="doc_code">
-<pre>
-int mul_add(int x, int y, int z) {
-  return x * y + z;
-}
-</pre>
-</div>
-
-<p>As a preview, the LLVM IR we’re going to end up generating for this function will look like:</p>
-
-<div class="doc_code">
-<pre>
-define i32 @mul_add(i32 %x, i32 %y, i32 %z) {
-entry:
-  %tmp = mul i32 %x, %y
-  %tmp2 = add i32 %tmp, %z
-  ret i32 %tmp2
-}
-</pre>
-</div>
-
-<p>If you're unsure what the above code says, skim through the <a href="../LangRef.html">LLVM Language Reference Manual</a> and convince yourself that the above LLVM IR is actually equivalent to the original function.  Once you’re satisfied with that, let's move on to actually generating it programmatically!</p>
-
-<p>Of course, before we can start, we need to <code>#include</code> the appropriate LLVM header files:</p>
-
-<div class="doc_code">
-<pre>
-#include "llvm/Module.h"
-#include "llvm/Function.h"
-#include "llvm/PassManager.h"
-#include "llvm/CallingConv.h"
-#include "llvm/Analysis/Verifier.h"
-#include "llvm/Assembly/PrintModulePass.h"
-#include "llvm/Support/IRBuilder.h"
-#include "llvm/Support/raw_ostream.h"
-</pre>
-</div>
-
-<p>Now, let's get started on our real program.  Here's what our basic <code>main()</code> will look like:</p>
-
-<div class="doc_code">
-<pre>
-using namespace llvm;
-
-Module* makeLLVMModule();
-
-int main(int argc, char**argv) {
-  Module* Mod = makeLLVMModule();
-
-  verifyModule(*Mod, PrintMessageAction);
-
-  PassManager PM;
-  PM.add(createPrintModulePass(&outs()));
-  PM.run(*Mod);
-
-  delete Mod;
-  return 0;
-}
-</pre>
-</div>
-
-<p>The first segment is pretty simple: it creates an LLVM “module.”  In LLVM, a module represents a single unit of code that is to be processed together.  A module contains things like global variables, function declarations, and implementations.  Here we’ve declared a <code>makeLLVMModule()</code> function to do the real work of creating the module.  Don’t worry, we’ll be looking at that one next!</p>
-
-<p>The second segment runs the LLVM module verifier on our newly created module.  While this probably isn’t really necessary for a simple module like this one, it's always a good idea, especially if you’re generating LLVM IR based on some input.  The verifier will print an error message if your LLVM module is malformed in any way.</p>
-
-<p>Finally, we instantiate an LLVM <code>PassManager</code> and run
-the <code>PrintModulePass</code> on our module.  LLVM uses an explicit pass
-infrastructure to manage optimizations and various other things.
-A <code>PassManager</code>, as should be obvious from its name, manages passes:
-it is responsible for scheduling them, invoking them, and ensuring the proper
-disposal after we’re done with them.  For this example, we’re just using a
-trivial pass that prints out our module in textual form.</p>
-
-<p>Now onto the interesting part: creating and populating a module.  Here's the
-first chunk of our <code>makeLLVMModule()</code>:</p>
-
-<div class="doc_code">
-<pre>
-Module* makeLLVMModule() {
-  // Module Construction
-  Module* mod = new Module("test", getGlobalContext());
-</pre>
-</div>
-
-<p>Exciting, isn’t it!?  All we’re doing here is instantiating a module and giving it a name.  The name isn’t particularly important unless you’re going to be dealing with multiple modules at once.</p>
-
-<div class="doc_code">
-<pre>
-  Constant* c = mod->getOrInsertFunction("mul_add",
-  /*ret type*/                           IntegerType::get(32),
-  /*args*/                               IntegerType::get(32),
-                                         IntegerType::get(32),
-                                         IntegerType::get(32),
-  /*varargs terminated with null*/       NULL);
-  
-  Function* mul_add = cast<Function>(c);
-  mul_add->setCallingConv(CallingConv::C);
-</pre>
-</div>
-
-<p>We construct our <code>Function</code> by calling <code>getOrInsertFunction()</code> on our module, passing in the name, return type, and argument types of the function.  In the case of our <code>mul_add</code> function, that means one 32-bit integer for the return value and three 32-bit integers for the arguments.</p>
-
-<p>You'll notice that <code>getOrInsertFunction()</code> doesn't actually return a <code>Function*</code>.  This is because <code>getOrInsertFunction()</code> will return a cast of the existing function if the function already existed with a different prototype.  Since we know that there's not already a <code>mul_add</code> function, we can safely just cast <code>c</code> to a <code>Function*</code>.
-  
-<p>In addition, we set the calling convention for our new function to be the C
-calling convention.  This isn’t strictly necessary, but it ensures that our new
-function will interoperate properly with C code, which is a good thing.</p>
-
-<div class="doc_code">
-<pre>
-  Function::arg_iterator args = mul_add->arg_begin();
-  Value* x = args++;
-  x->setName("x");
-  Value* y = args++;
-  y->setName("y");
-  Value* z = args++;
-  z->setName("z");
-</pre>
-</div>
-
-<p>While we’re setting up our function, let's also give names to the parameters.  This also isn’t strictly necessary (LLVM will generate names for them if you don’t specify them), but it’ll make looking at our output somewhat more pleasant.  To name the parameters, we iterate over the arguments of our function and call <code>setName()</code> on them.  We’ll also keep the pointer to <code>x</code>, <code>y</code>, and <code>z</code> around, since we’ll need them when we get around to creating instructions.</p>
-
-<p>Great!  We have a function now.  But what good is a function if it has no body?  Before we start working on a body for our new function, we need to recall some details of the LLVM IR.  The IR, being an abstract assembly language, represents control flow using jumps (we call them branches), both conditional and unconditional.  The straight-line sequences of code between branches are called basic blocks, or just blocks.  To create a body for our function, we fill it with blocks:</p>
-
-<div class="doc_code">
-<pre>
-  BasicBlock* block = BasicBlock::Create(getGlobalContext(), "entry", mul_add);
-  IRBuilder<> builder(block);
-</pre>
-</div>
-
-<p>We create a new basic block, as you might expect, by calling its constructor.  All we need to tell it is its name and the function to which it belongs.  In addition, we’re creating an <code>IRBuilder</code> object, which is a convenience interface for creating instructions and appending them to the end of a block.  Instructions can be created through their constructors as well, but some of their interfaces are quite complicated.  Unless you need a lot of control, using <code>IRBuilder</code> will make your life simpler.</p>
-
-<div class="doc_code">
-<pre>
-  Value* tmp = builder.CreateBinOp(Instruction::Mul,
-                                   x, y, "tmp");
-  Value* tmp2 = builder.CreateBinOp(Instruction::Add,
-                                    tmp, z, "tmp2");
-
-  builder.CreateRet(tmp2);
-  
-  return mod;
-}
-</pre>
-</div>
-
-<p>The final step in creating our function is to create the instructions that make it up.  Our <code>mul_add</code> function is composed of just three instructions: a multiply, an add, and a return.  <code>IRBuilder</code> gives us a simple interface for constructing these instructions and appending them to the “entry” block.  Each of the calls to <code>IRBuilder</code> returns a <code>Value*</code> that represents the value yielded by the instruction.  You’ll also notice that, above, <code>x</code>, <code>y</code>, and <code>z</code> are also <code>Value*</code>'s, so it's clear that instructions operate on <code>Value*</code>'s.</p>
-
-<p>And that's it!  Now you can compile and run your code, and get a wonderful textual print out of the LLVM IR we saw at the beginning.  To compile, use the following command line as a guide:</p>
-
-<div class="doc_code">
-<pre>
-# c++ -g tut1.cpp `llvm-config --cxxflags --ldflags --libs core` -o tut1
-# ./tut1
-</pre>
-</div>
-
-<p>The <code>llvm-config</code> utility is used to obtain the necessary GCC-compatible compiler flags for linking with LLVM.  For this example, we only need the 'core' library.  We'll use others once we start adding optimizers and the JIT engine.</p>
-
-<a href="JITTutorial2.html">Next: A More Complicated Function</a>
-</div>
-
-<!-- *********************************************************************** -->
-<hr>
-<address>
-  <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
-  src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
-  <a href="http://validator.w3.org/check/referer"><img
-  src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
-
-  <a href="mailto:owen at apple.com">Owen Anderson</a><br>
-  <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
-  Last modified: $Date: 2009-07-21 11:05:13 -0700 (Tue, 21 Jul 2009) $
-</address>
-
-</body>
-</html>

Removed: llvm/trunk/docs/tutorial/JITTutorial2-1.png
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/tutorial/JITTutorial2-1.png?rev=90110&view=auto

==============================================================================
Binary file - no diff available.

Removed: llvm/trunk/docs/tutorial/JITTutorial2.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/tutorial/JITTutorial2.html?rev=90110&view=auto

==============================================================================
--- llvm/trunk/docs/tutorial/JITTutorial2.html (original)
+++ llvm/trunk/docs/tutorial/JITTutorial2.html (removed)
@@ -1,200 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
-                      "http://www.w3.org/TR/html4/strict.dtd">
-
-<html>
-<head>
-  <title>LLVM Tutorial 2: A More Complicated Function</title>
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-  <meta name="author" content="Owen Anderson">
-  <meta name="description" 
-  content="LLVM Tutorial 2: A More Complicated Function.">
-  <link rel="stylesheet" href="../llvm.css" type="text/css">
-</head>
-
-<body>
-
-<div class="doc_title"> LLVM Tutorial 2: A More Complicated Function </div>
-
-<div class="doc_author">
-  <p>Written by <a href="mailto:owen at apple.com">Owen Anderson</a></p>
-</div>
-
-<!-- *********************************************************************** -->
-<div class="doc_section"><a name="intro">A First Function</a></div>
-<!-- *********************************************************************** -->
-
-<div class="doc_text">
-
-<p>Now that we understand the basics of creating functions in LLVM, let's move on to a more complicated example: something with control flow.  As an example, let's consider Euclid's Greatest Common Denominator (GCD) algorithm:</p>
-
-<div class="doc_code">
-<pre>
-unsigned gcd(unsigned x, unsigned y) {
-  if(x == y) {
-    return x;
-  } else if(x < y) {
-    return gcd(x, y - x);
-  } else {
-    return gcd(x - y, y);
-  }
-}
-</pre>
-</div>
-
-<p>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.</p>
-
-<div style="text-align: center;"><img src="JITTutorial2-1.png" alt="GCD CFG" width="60%"></div>
-
-<p>This 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 <a href="../LangRef.html">LLVM Language Reference Manual</a> and convince yourself that it is, in fact, the GCD algorithm.</p>
-
-<p>The first part of our code is practically the same as from the first tutorial.  The same basic setup is required: creating a module, verifying it, and running the <code>PrintModulePass</code> on it.  Even the first segment of  <code>makeLLVMModule()</code> looks essentially the same, except that <code>gcd</code> takes one fewer parameter than <code>mul_add</code>.</p>
-
-<div class="doc_code">
-<pre>
-#include "llvm/Module.h"
-#include "llvm/Function.h"
-#include "llvm/PassManager.h"
-#include "llvm/Analysis/Verifier.h"
-#include "llvm/Assembly/PrintModulePass.h"
-#include "llvm/Support/IRBuilder.h"
-#include "llvm/Support/raw_ostream.h"
-
-using namespace llvm;
-
-Module* makeLLVMModule();
-
-int main(int argc, char**argv) {
-  Module* Mod = makeLLVMModule();
-  
-  verifyModule(*Mod, PrintMessageAction);
-  
-  PassManager PM;
-  PM.add(createPrintModulePass(&outs()));
-  PM.run(*Mod);
-
-  delete Mod;  
-  return 0;
-}
-
-Module* makeLLVMModule() {
-  Module* mod = new Module("tut2");
-  
-  Constant* c = mod->getOrInsertFunction("gcd",
-                                         IntegerType::get(32),
-                                         IntegerType::get(32),
-                                         IntegerType::get(32),
-                                         NULL);
-  Function* gcd = cast<Function>(c);
-  
-  Function::arg_iterator args = gcd->arg_begin();
-  Value* x = args++;
-  x->setName("x");
-  Value* y = args++;
-  y->setName("y");
-</pre>
-</div>
-
-<p>Here, however, is where our code begins to diverge from the first tutorial.  Because <code>gcd</code> has control flow, it is composed of multiple blocks interconnected by branching (<code>br</code>) instructions.  For those familiar with assembly language, a block is similar to a labeled set of instructions.  For those not familiar with assembly language, a block is basically a set of instructions that can be branched to and is executed linearly until the block is terminated by one of a small number of control flow instructions, such as <code>br</code> or <code>ret</code>.</p>
-
-<p>Blocks correspond to the nodes in the diagram we looked at in the beginning of this tutorial.  From the diagram, we can see that this function contains five blocks, so we'll go ahead and create them.  Note that we're making use of LLVM's automatic name uniquing in this code sample, since we're giving two blocks the same name.</p>
-
-<div class="doc_code">
-<pre>
-  BasicBlock* entry = BasicBlock::Create(getGlobalContext(), ("entry", gcd);
-  BasicBlock* ret = BasicBlock::Create(getGlobalContext(), ("return", gcd);
-  BasicBlock* cond_false = BasicBlock::Create(getGlobalContext(), ("cond_false", gcd);
-  BasicBlock* cond_true = BasicBlock::Create(getGlobalContext(), ("cond_true", gcd);
-  BasicBlock* cond_false_2 = BasicBlock::Create(getGlobalContext(), ("cond_false", gcd);
-</pre>
-</div>
-
-<p>Now we're ready to begin generating code!  We'll start with the <code>entry</code> block.  This block corresponds to the top-level if-statement in the original C code, so we need to compare <code>x</code> and <code>y</code>.  To achieve this, we perform an explicit comparison using <code>ICmpEQ</code>.  <code>ICmpEQ</code> stands for an <em>integer comparison for equality</em> and returns a 1-bit integer result.  This 1-bit result is then used as the input to a conditional branch, with <code>ret</code> as the <code>true</code> and <code>cond_false</code> as the <code>false</code> case.</p>
-
-<div class="doc_code">
-<pre>
-  IRBuilder<> builder(entry);
-  Value* xEqualsY = builder.CreateICmpEQ(x, y, "tmp");
-  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>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>
-  builder.SetInsertPoint(ret);
-  builder.CreateRet(x);
-</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 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>
-
-<div class="doc_code">
-<pre>
-  builder.SetInsertPoint(cond_false);
-  Value* xLessThanY = builder.CreateICmpULT(x, y, "tmp");
-  builder.CreateCondBr(xLessThanY, cond_true, cond_false_2);
-</pre>
-</div>
-
-<p>Our last two blocks are quite similar; they're both recursive calls to <code>gcd</code> with different parameters.  To create a call instruction, we have to create a <code>vector</code> (or any other container with <code>InputInterator</code>s) to hold the arguments.  We then pass in the beginning and ending iterators for this vector.</p>
-
-<div class="doc_code">
-<pre>
-  builder.SetInsertPoint(cond_true);
-  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");
-  builder.CreateRet(recur_1);
-  
-  builder.SetInsertPoint(cond_false_2);
-  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");
-  builder.CreateRet(recur_2);
-  
-  return mod;
-}
-</pre>
-</div>
-
-<p>And that's it!  You can compile and execute your code in the same way as before, by doing:</p>
-
-<div class="doc_code">
-<pre>
-# c++ -g tut2.cpp `llvm-config --cxxflags --ldflags --libs core` -o tut2
-# ./tut2
-</pre>
-</div>
-
-</div>
-
-<!-- *********************************************************************** -->
-<hr>
-<address>
-  <a href="http://jigsaw.w3.org/css-validator/check/referer"><img
-  src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
-  <a href="http://validator.w3.org/check/referer"><img
-  src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
-
-  <a href="mailto:owen at apple.com">Owen Anderson</a><br>
-  <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
-  Last modified: $Date: 2007-10-17 11:05:13 -0700 (Wed, 17 Oct 2007) $
-</address>
-
-</body>
-</html>

Modified: llvm/trunk/docs/tutorial/index.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/tutorial/index.html?rev=90111&r1=90110&r2=90111&view=diff

==============================================================================
--- llvm/trunk/docs/tutorial/index.html (original)
+++ llvm/trunk/docs/tutorial/index.html Sun Nov 29 22:23:17 2009
@@ -15,16 +15,6 @@
 <div class="doc_title"> LLVM Tutorial: Table of Contents </div>
 
 <ol>
-  <li><!--<a href="Introduction.html">-->An Introduction to LLVM: Basic Concepts and Design</li>
-  <li>Simple JIT Tutorials
-    <ol>
-      <li><a href="JITTutorial1.html">A First Function</a></li>
-      <li><a href="JITTutorial2.html">A More Complicated Function</a></li>
-      <li><!--<a href="Tutorial3.html">-->Running Optimizations</li>
-      <li><!--<a href="Tutorial4.html">-->Reading and Writing Bitcode</li>
-      <li><!--<a href="Tutorial5.html">-->Invoking the JIT</li>
-    </ol>
-  </li>
   <li>Kaleidoscope: Implementing a Language with LLVM
   <ol>
     <li><a href="LangImpl1.html">Tutorial Introduction and the Lexer</a></li>





More information about the llvm-commits mailing list