summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDan Liew <dan@su-root.co.uk>2014-06-06 17:25:47 +0000
committerDan Liew <dan@su-root.co.uk>2014-06-06 17:25:47 +0000
commit64d39d3281aaabc09ee792312a48251fd3114a3b (patch)
tree449a00091f2575471d33e1f350baddff73db6f6f /docs
parentf4f9c6bfc1ab0d7d9e6126e2f0cdd0c8a06ae400 (diff)
downloadllvm-64d39d3281aaabc09ee792312a48251fd3114a3b.tar.gz
llvm-64d39d3281aaabc09ee792312a48251fd3114a3b.tar.bz2
llvm-64d39d3281aaabc09ee792312a48251fd3114a3b.tar.xz
Mention the IRBuilder in Programmer's Manual with a few small examples.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210354 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs')
-rw-r--r--docs/ProgrammersManual.rst37
1 files changed, 36 insertions, 1 deletions
diff --git a/docs/ProgrammersManual.rst b/docs/ProgrammersManual.rst
index 9838ba2ecc..2ec02964e1 100644
--- a/docs/ProgrammersManual.rst
+++ b/docs/ProgrammersManual.rst
@@ -1918,7 +1918,7 @@ which is a pointer to an integer on the run time stack.
*Inserting instructions*
-There are essentially two ways to insert an ``Instruction`` into an existing
+There are essentially three ways to insert an ``Instruction`` into an existing
sequence of instructions that form a ``BasicBlock``:
* Insertion into an explicit instruction list
@@ -1988,6 +1988,41 @@ sequence of instructions that form a ``BasicBlock``:
which is much cleaner, especially if you're creating a lot of instructions and
adding them to ``BasicBlock``\ s.
+* Insertion using an instance of ``IRBuilder``
+
+ Inserting several ``Instuction``\ s can be quite laborious using the previous
+ methods. The ``IRBuilder`` is a convenience class that can be used to add
+ several instructions to the end of a ``BasicBlock`` or before a particular
+ ``Instruction``. It also supports constant folding and renaming named
+ registers (see ``IRBuilder``'s template arguments).
+
+ The example below demonstrates a very simple use of the ``IRBuilder`` where
+ three instructions are inserted before the instruction ``pi``. The first two
+ instructions are Call instructions and third instruction multiplies the return
+ value of the two calls.
+
+ .. code-block:: c++
+
+ Instruction *pi = ...;
+ IRBuilder<> Builder(pi);
+ CallInst* callOne = Builder.CreateCall(...);
+ CallInst* callTwo = Builder.CreateCall(...);
+ Value* result = Builder.CreateMul(callOne, callTwo);
+
+ The example below is similar to the above example except that the created
+ ``IRBuilder`` inserts instructions at the end of the ``BasicBlock`` ``pb``.
+
+ .. code-block:: c++
+
+ BasicBlock *pb = ...;
+ IRBuilder<> Builder(pb);
+ CallInst* callOne = Builder.CreateCall(...);
+ CallInst* callTwo = Builder.CreateCall(...);
+ Value* result = Builder.CreateMul(callOne, callTwo);
+
+ See :doc:`tutorial/LangImpl3` for a practical use of the ``IRBuilder``.
+
+
.. _schanges_deleting:
Deleting Instructions