[LLVMdev] Operand, instruction

John Criswell criswell at uiuc.edu
Tue Apr 13 13:31:39 PDT 2010


help__me_please wrote:
> Can you please give an example of creating an instruction (for example add
> instructions with two operand a and b)? I am trying instruction() for a
> while, but no success yet.
>   

You need to look for the appropriate subclass of llvm::Instruction and 
find the method for creating a new instruction.  The method is usually a 
static method and takes arguments pointing to the values to use as 
operands.  Doxygen is your best resource for finding these methods.

For example, if you look at 
http://llvm.org/doxygen/classllvm_1_1AllocaInst.html, you can see that 
the AllocaInst class (which represents an alloca instruction) has a 
standard constructor method that takes the type of object to allocate, 
the name of the new alloca instruction, an instruction before which to 
insert the alloca instruction, etc.

As another example, the CallInst class 
(http://llvm.org/doxygen/classllvm_1_1CallInst.html) represents a call 
instruction and has a static Create() method that you can use to create 
a new call instruction.

-- John T.





More information about the llvm-dev mailing list