[−][src]Module llir::values
LLVM Values
LLVM Values has the following hierarchy
- Function
- Global
- Block
- Operand
- Instruction
- Alloca
- Binary
- Binary Opcode Opcode enum for binary instructions
- Branch
- Call
- CallBr
- ExtractValue
- FCmp
- FCmp Predicate Floating point comparison predicate for fcmp instructions
- Get Element Pointer
- ICmp
- ICmp Predicate Integer comparison predicate for icmp instructions
- IndirectBranch
- InsertValue
- Load
- PHI
- Return
- Select
- Store
- Switch
- Unary
- Unary Opcode Opcode enum for unary instructions
- Unreachable
- Constant
- Argument
- Inline Assembly
- Metadata
- Instruction
Function & Global
You can get Function
s & Global
s from Module:
for func in module.iter_functions() { // Do things to function } for glob in module.iter_globals() { // Do things to global }
Instruction
You can get instructions by iterating through blocks
for block in func.iter_blocks() { for instr in block.iter_instructions() { // Do things to instruction... } }
You can match the instruction with any particular kind of instruction by using pattern matching. From there you can access the instruction specific accessors. As an example, here's how you get the call instruction specific accessor:
match instr { Instruction::Call(call) => { let callee = call.callee_function(); // Do things to the callee function... } }
All instructions inherits methods like operand
, num_operands
, parent_block
,
next_instruction
and so. Checkout InstructionTrait.
Operand
You can get operand from instructions
let operand_0 = instr.operand(0).unwrap()
To check which type of operand this is, you do a pattern matching
match op { Operand::Constant(cons) => { // Do things to constant } Operand::Instruction(instr) => { // Do things to instruction } // ... }
Metadata is also a kind of operand, as its used in some intrinsic instructions.
Constant
Constant is also a enum, to get a specific kind of constant, you also do pattern matching
match my_constant { Constant::ConstExpr(const_expr) => { match const_expr { ConstExpr::GetElementPtr(gep_const_expr) => { // Get the integer constant indices from the GEP constant expression let indices = gep_const_expr.int_indices(); // ... } } }, Constant::Function(f) => { /* ... */ }, Constant::Global(g) => { /* ... */ }, // ... }
Constant expression is a kind of constant. There are only a limited amount of instruction opcode that can apply to constant expressions. To get each different kinds of constant expressions, you should do another pattern matching.
Functions & Globals are also constants.
Other constants involve integer, float, null and so on.
Structs
Enums
BinaryOpcode | Binary Opcode |
BranchInstruction | |
ConstExpr | |
Constant | |
FCmpPredicate | Floating point comparison predicate |
Global | Global container enum |
ICmpPredicate | Integer conparison predicate |
Instruction | |
Metadata | |
Opcode | |
Operand | Container class for operand |
UnaryOpcode | Unary opcode |
Traits
AsConstExpr | Turn constant expression subclass into a ConstExpr enum |
AsConstant | Turn constant subclass into a constant enum |
AsGenericValue | Turn the value into a GenericValue, implemented for every value class |
AsInstruction | Turn instructions into Instruction Container Enum |
AsMetadata | Turn metadata subclass into a Metadata enum |
AsOperand | Trait that turns a value into an operand |
ConstExprTrait | |
GetDebugLoc | GetDebugLoc trait is implemented when there's debug location with respect to a value |
GetDebugMetadata | Get debug metadata for any value |
GetType | GetType trait provides |
GlobalValueTrait | |
InstructionDebugLoc | InstructionDebugLoc is implemented whenever it is an instruction |
InstructionTrait | |
ValueOpcode |