layout: page |
title: Instruction (llvm.core) |
An llvm.core.Instruction object represents an LLVM instruction. This class is the root of a small hierarchy:
Instruction
CallOrInvokeInstruction
PHINode
SwitchInstruction
CompareInstruction
Instructions are not created directly, but via a builder. The builder both creates instructions and adds them to a basic block at the same time. One way of getting instruction objects are from basic blocks.
Being derived from llvm.core.User, the instruction is-a user, i.e., an instruction in turn uses other values. The values an instruction uses are its operands. These may be accessed using operands property from the llvm.core.User base.
The name of the instruction (like add, mul etc) can be got via the opcode_name property. The basic_block property gives the basic block to which the instruction belongs to. Note that llvmpy does not allow free-standing instruction objects (i.e., all instructions are created contained within a basic block).
Classes of instructions can be got via the properties is_terminator, is_binary_op, is_shift etc. See below for the full list.
[read-only] The basic block to which this instruction belongs to.
[read-only] True if the instruction is a terminator instruction.
[read-only] True if the instruction is a binary operator.
[read-only] True if the instruction is a shift instruction.
[read-only] True if the instruction is a cast instruction.
[read-only] True if the instruction is a logical shift instruction.
[read-only] True if the instruction is an arithmetic shift instruction.
[read-only] True if the instruction is associative.
[read-only] True if the instruction is commutative.
[read-only] True if the instruction is a volatile load or store.
[read-only] The numeric opcode value of the instruction. Do not rely on the absolute value of this number, it may change with LLVM version.
[read-only] The name of the instruction, like add, sub etc.
The llvm.core.CallOrInvokeInstruction is a subclass of llvm.core.Instruction, and represents either a call or an invoke instruction.
calling_convention Get or set the calling convention. See here for possible values.
Add an attribute attr to the idx-th argument. See here for possible values of attr.
Remove an attribute attr from the idx-th argument. See here for possible values of attr.
Set the alignment of the idx-th argument to align. align should be a power of two.
The llvm.core.PHINode is a subclass of llvm.core.Instruction, and represents the phi instruction. When created (using Builder.phi) the phi node contains no incoming blocks (nor their corresponding values). To add an incoming arc to the phi node, use the add_incoming method, which takes a source block ( llvm.core.BasicBlock object) and a value (object of llvm.core.Value or of a class derived from it) that the phi node will take on if control branches in from that block.
incoming_count [read-only] The number of incoming arcs for this phi node.
Add an incoming arc, from the llvm.core.BasicBlock object block, with the corresponding value value. value should be an object of llvm.core.Value (or of a descendent class).
Returns the idx-th incoming arc’s value.
Returns the idx-th incoming arc’s block.
(TODO describe)
Add another case to the switch statement. When the expression being evaluated equals const, then control branches to block. Here const must be of type llvm.core.ConstantInt.
(TODO describe)
[read-only]
The predicate of the compare instruction, one of the ICMP_* or FCMP_* constants.
True if this is a volatile load or store.