@@ -1918,7 +1918,7 @@ which is a pointer to an integer on the run time stack.
1918
1918
1919
1919
*Inserting instructions *
1920
1920
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
1922
1922
sequence of instructions that form a ``BasicBlock ``:
1923
1923
1924
1924
* Insertion into an explicit instruction list
@@ -1988,6 +1988,41 @@ sequence of instructions that form a ``BasicBlock``:
1988
1988
which is much cleaner, especially if you're creating a lot of instructions and
1989
1989
adding them to ``BasicBlock ``\ s.
1990
1990
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
+
1991
2026
.. _schanges_deleting :
1992
2027
1993
2028
Deleting Instructions
0 commit comments