Skip to content

Commit c6ab58f

Browse files
committedJun 6, 2014
Mention the IRBuilder in Programmer's Manual with a few small examples.
llvm-svn: 210354
1 parent fc9b5d6 commit c6ab58f

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed
 

‎llvm/docs/ProgrammersManual.rst

+36-1
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,7 @@ which is a pointer to an integer on the run time stack.
19181918

19191919
*Inserting instructions*
19201920

1921-
There are essentially two ways to insert an ``Instruction`` into an existing
1921+
There are essentially three ways to insert an ``Instruction`` into an existing
19221922
sequence of instructions that form a ``BasicBlock``:
19231923

19241924
* Insertion into an explicit instruction list
@@ -1988,6 +1988,41 @@ sequence of instructions that form a ``BasicBlock``:
19881988
which is much cleaner, especially if you're creating a lot of instructions and
19891989
adding them to ``BasicBlock``\ s.
19901990

1991+
* Insertion using an instance of ``IRBuilder``
1992+
1993+
Inserting several ``Instuction``\ s can be quite laborious using the previous
1994+
methods. The ``IRBuilder`` is a convenience class that can be used to add
1995+
several instructions to the end of a ``BasicBlock`` or before a particular
1996+
``Instruction``. It also supports constant folding and renaming named
1997+
registers (see ``IRBuilder``'s template arguments).
1998+
1999+
The example below demonstrates a very simple use of the ``IRBuilder`` where
2000+
three instructions are inserted before the instruction ``pi``. The first two
2001+
instructions are Call instructions and third instruction multiplies the return
2002+
value of the two calls.
2003+
2004+
.. code-block:: c++
2005+
2006+
Instruction *pi = ...;
2007+
IRBuilder<> Builder(pi);
2008+
CallInst* callOne = Builder.CreateCall(...);
2009+
CallInst* callTwo = Builder.CreateCall(...);
2010+
Value* result = Builder.CreateMul(callOne, callTwo);
2011+
2012+
The example below is similar to the above example except that the created
2013+
``IRBuilder`` inserts instructions at the end of the ``BasicBlock`` ``pb``.
2014+
2015+
.. code-block:: c++
2016+
2017+
BasicBlock *pb = ...;
2018+
IRBuilder<> Builder(pb);
2019+
CallInst* callOne = Builder.CreateCall(...);
2020+
CallInst* callTwo = Builder.CreateCall(...);
2021+
Value* result = Builder.CreateMul(callOne, callTwo);
2022+
2023+
See :doc:`tutorial/LangImpl3` for a practical use of the ``IRBuilder``.
2024+
2025+
19912026
.. _schanges_deleting:
19922027

19932028
Deleting Instructions

0 commit comments

Comments
 (0)
Please sign in to comment.