Merge LLVMBuilder and FoldingBuilder, calling

the result IRBuilder.  Patch by Dominic Hamon.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49604 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan Sands
2008-04-13 06:22:09 +00:00
parent 86941611c9
commit 89f6d88db3
18 changed files with 295 additions and 493 deletions
+4 -4
View File
@@ -60,7 +60,7 @@ entry:
#include <llvm/CallingConv.h>
#include <llvm/Analysis/Verifier.h>
#include <llvm/Assembly/PrintModulePass.h>
#include <llvm/Support/LLVMBuilder.h>
#include <llvm/Support/IRBuilder.h>
</pre>
</div>
@@ -143,11 +143,11 @@ Module* makeLLVMModule() {
<div class="doc_code">
<pre>
BasicBlock* block = new BasicBlock("entry", mul_add);
LLVMBuilder builder(block);
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, were creating an <code>LLVMBuilder</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>LLVMBuilder</code> will make your life simpler.</p>
<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, were 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>
@@ -163,7 +163,7 @@ Module* makeLLVMModule() {
</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>LLVMBuilder</code> gives us a simple interface for constructing these instructions and appending them to the “entry” block. Each of the calls to <code>LLVMBuilder</code> returns a <code>Value*</code> that represents the value yielded by the instruction. Youll also notice that, above, <code>x</code>, <code>y</code>, and <code>z</code> are also <code>Value*</code>s, so its clear that instructions operate on <code>Value*</code>s.</p>
<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. Youll also notice that, above, <code>x</code>, <code>y</code>, and <code>z</code> are also <code>Value*</code>s, so its clear that instructions operate on <code>Value*</code>s.</p>
<p>And thats 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>