pub struct InstructionValue<'ctx> { /* private fields */ }Implementations§
Source§impl<'ctx> InstructionValue<'ctx>
impl<'ctx> InstructionValue<'ctx>
Sourcepub unsafe fn new(instruction_value: LLVMValueRef) -> Self
pub unsafe fn new(instruction_value: LLVMValueRef) -> Self
Sourcepub fn explicit_clone(&self) -> Self
pub fn explicit_clone(&self) -> Self
Creates a clone of this InstructionValue, and returns it.
The clone will have no parent, and no name.
Sourcepub fn get_instruction_with_name(
&self,
name: &str,
) -> Option<InstructionValue<'ctx>>
pub fn get_instruction_with_name( &self, name: &str, ) -> Option<InstructionValue<'ctx>>
Get a instruction with it’s name Compares against all instructions after self, and self.
Sourcepub fn set_name(&self, name: &str) -> Result<(), InstructionValueError>
pub fn set_name(&self, name: &str) -> Result<(), InstructionValueError>
Set name of the InstructionValue.
Sourcepub fn get_type(self) -> AnyTypeEnum<'ctx>
pub fn get_type(self) -> AnyTypeEnum<'ctx>
Get type of the current InstructionValue
pub fn get_opcode(self) -> InstructionOpcode
pub fn get_previous_instruction(self) -> Option<Self>
pub fn get_next_instruction(self) -> Option<Self>
pub fn erase_from_basic_block(self)
pub fn remove_from_basic_block(self)
pub fn get_parent(self) -> Option<BasicBlock<'ctx>>
Sourcepub fn is_terminator(self) -> bool
pub fn is_terminator(self) -> bool
Returns if the instruction is a terminator
Sourcepub fn is_conditional(self) -> bool
pub fn is_conditional(self) -> bool
Returns if a terminator is conditional or not
pub fn is_tail_call(self) -> bool
pub fn replace_all_uses_with(self, other: &InstructionValue<'ctx>)
Sourcepub fn get_volatile(self) -> Result<bool, InstructionValueError>
pub fn get_volatile(self) -> Result<bool, InstructionValueError>
Returns whether or not a memory access instruction is volatile.
Sourcepub fn set_volatile(self, volatile: bool) -> Result<(), InstructionValueError>
pub fn set_volatile(self, volatile: bool) -> Result<(), InstructionValueError>
Sets whether or not a memory access instruction is volatile.
Sourcepub fn get_allocated_type(
self,
) -> Result<BasicTypeEnum<'ctx>, InstructionValueError>
pub fn get_allocated_type( self, ) -> Result<BasicTypeEnum<'ctx>, InstructionValueError>
Returns the type that is allocated by the alloca instruction.
Sourcepub fn get_gep_source_element_type(
self,
) -> Result<BasicTypeEnum<'ctx>, InstructionValueError>
pub fn get_gep_source_element_type( self, ) -> Result<BasicTypeEnum<'ctx>, InstructionValueError>
Returns the source element type of the given GEP.
Sourcepub fn get_alignment(self) -> Result<u32, InstructionValueError>
pub fn get_alignment(self) -> Result<u32, InstructionValueError>
Returns alignment on a memory access instruction or alloca.
Sourcepub fn set_alignment(self, alignment: u32) -> Result<(), InstructionValueError>
pub fn set_alignment(self, alignment: u32) -> Result<(), InstructionValueError>
Sets alignment on a memory access instruction or alloca.
Sourcepub fn get_atomic_ordering(
self,
) -> Result<AtomicOrdering, InstructionValueError>
pub fn get_atomic_ordering( self, ) -> Result<AtomicOrdering, InstructionValueError>
Returns atomic ordering on a memory access instruction.
Sourcepub fn set_atomic_ordering(
self,
ordering: AtomicOrdering,
) -> Result<(), InstructionValueError>
pub fn set_atomic_ordering( self, ordering: AtomicOrdering, ) -> Result<(), InstructionValueError>
Sets atomic ordering on a memory access instruction.
Sourcepub fn get_num_operands(self) -> u32
pub fn get_num_operands(self) -> u32
Obtains the number of operands an InstructionValue has.
An operand is a BasicValue used in an IR instruction.
The following example,
use inkwell::AddressSpace;
use inkwell::context::Context;
let context = Context::create();
let module = context.create_module("ivs");
let builder = context.create_builder();
let void_type = context.void_type();
let f32_type = context.f32_type();
#[cfg(feature = "typed-pointers")]
let f32_ptr_type = f32_type.ptr_type(AddressSpace::default());
#[cfg(not(feature = "typed-pointers"))]
let f32_ptr_type = context.ptr_type(AddressSpace::default());
let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false);
let function = module.add_function("take_f32_ptr", fn_type, None);
let basic_block = context.append_basic_block(function, "entry");
builder.position_at_end(basic_block);
let arg1 = function.get_first_param().unwrap().into_pointer_value();
let f32_val = f32_type.const_float(std::f64::consts::PI);
let store_instruction = builder.build_store(arg1, f32_val).unwrap();
let free_instruction = builder.build_free(arg1).unwrap();
let return_instruction = builder.build_return(None).unwrap();
assert_eq!(store_instruction.get_num_operands(), 2);
assert_eq!(free_instruction.get_num_operands(), 2);
assert_eq!(return_instruction.get_num_operands(), 0);will generate LLVM IR roughly like (varying slightly across LLVM versions):
; ModuleID = 'ivs'
source_filename = "ivs"
define void @take_f32_ptr(float* %0) {
entry:
store float 0x400921FB60000000, float* %0
%1 = bitcast float* %0 to i8*
tail call void @free(i8* %1)
ret void
}
declare void @free(i8*)which makes the number of instruction operands clear:
- Store has two: a const float and a variable float pointer %0
- Bitcast has one: a variable float pointer %0
- Function call has two: i8 pointer %1 argument, and the free function itself
- Void return has zero: void is not a value and does not count as an operand even though the return instruction can take values.
Sourcepub fn get_operand(self, index: u32) -> Option<Operand<'ctx>>
pub fn get_operand(self, index: u32) -> Option<Operand<'ctx>>
Obtains the operand an InstructionValue has at a given index if any.
An operand is a BasicValue used in an IR instruction.
The following example,
use inkwell::AddressSpace;
use inkwell::context::Context;
let context = Context::create();
let module = context.create_module("ivs");
let builder = context.create_builder();
let void_type = context.void_type();
let f32_type = context.f32_type();
#[cfg(feature = "typed-pointers")]
let f32_ptr_type = f32_type.ptr_type(AddressSpace::default());
#[cfg(not(feature = "typed-pointers"))]
let f32_ptr_type = context.ptr_type(AddressSpace::default());
let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false);
let function = module.add_function("take_f32_ptr", fn_type, None);
let basic_block = context.append_basic_block(function, "entry");
builder.position_at_end(basic_block);
let arg1 = function.get_first_param().unwrap().into_pointer_value();
let f32_val = f32_type.const_float(std::f64::consts::PI);
let store_instruction = builder.build_store(arg1, f32_val).unwrap();
let free_instruction = builder.build_free(arg1).unwrap();
let return_instruction = builder.build_return(None).unwrap();
assert!(store_instruction.get_operand(0).is_some());
assert!(store_instruction.get_operand(1).is_some());
assert!(store_instruction.get_operand(2).is_none());
assert!(free_instruction.get_operand(0).is_some());
assert!(free_instruction.get_operand(1).is_some());
assert!(free_instruction.get_operand(2).is_none());
assert!(return_instruction.get_operand(0).is_none());
assert!(return_instruction.get_operand(1).is_none());will generate LLVM IR roughly like (varying slightly across LLVM versions):
; ModuleID = 'ivs'
source_filename = "ivs"
define void @take_f32_ptr(float* %0) {
entry:
store float 0x400921FB60000000, float* %0
%1 = bitcast float* %0 to i8*
tail call void @free(i8* %1)
ret void
}
declare void @free(i8*)which makes the instruction operands clear:
- Store has two: a const float and a variable float pointer %0
- Bitcast has one: a variable float pointer %0
- Function call has two: i8 pointer %1 argument, and the free function itself
- Void return has zero: void is not a value and does not count as an operand even though the return instruction can take values.
Sourcepub unsafe fn get_operand_unchecked(self, index: u32) -> Option<Operand<'ctx>>
pub unsafe fn get_operand_unchecked(self, index: u32) -> Option<Operand<'ctx>>
Get the operand of an InstructionValue.
§Safety
The index must be less than InstructionValue::get_num_operands.
Sourcepub fn get_operands(self) -> OperandIter<'ctx> ⓘ
pub fn get_operands(self) -> OperandIter<'ctx> ⓘ
Get an instruction value operand iterator.
Sourcepub fn set_operand<BV: BasicValue<'ctx>>(self, index: u32, val: BV) -> bool
pub fn set_operand<BV: BasicValue<'ctx>>(self, index: u32, val: BV) -> bool
Sets the operand an InstructionValue has at a given index if possible.
An operand is a BasicValue used in an IR instruction.
use inkwell::AddressSpace;
use inkwell::context::Context;
let context = Context::create();
let module = context.create_module("ivs");
let builder = context.create_builder();
let void_type = context.void_type();
let f32_type = context.f32_type();
#[cfg(feature = "typed-pointers")]
let f32_ptr_type = f32_type.ptr_type(AddressSpace::default());
#[cfg(not(feature = "typed-pointers"))]
let f32_ptr_type = context.ptr_type(AddressSpace::default());
let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false);
let function = module.add_function("take_f32_ptr", fn_type, None);
let basic_block = context.append_basic_block(function, "entry");
builder.position_at_end(basic_block);
let arg1 = function.get_first_param().unwrap().into_pointer_value();
let f32_val = f32_type.const_float(std::f64::consts::PI);
let store_instruction = builder.build_store(arg1, f32_val).unwrap();
let free_instruction = builder.build_free(arg1).unwrap();
let return_instruction = builder.build_return(None).unwrap();
// This will produce invalid IR:
free_instruction.set_operand(0, f32_val);
assert_eq!(free_instruction.get_operand(0).unwrap().unwrap_value(), f32_val);Sourcepub fn get_operand_use(self, index: u32) -> Option<BasicValueUse<'ctx>>
pub fn get_operand_use(self, index: u32) -> Option<BasicValueUse<'ctx>>
Gets the use of an operand(BasicValue), if any.
use inkwell::AddressSpace;
use inkwell::context::Context;
use inkwell::values::BasicValue;
let context = Context::create();
let module = context.create_module("ivs");
let builder = context.create_builder();
let void_type = context.void_type();
let f32_type = context.f32_type();
#[cfg(feature = "typed-pointers")]
let f32_ptr_type = f32_type.ptr_type(AddressSpace::default());
#[cfg(not(feature = "typed-pointers"))]
let f32_ptr_type = context.ptr_type(AddressSpace::default());
let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false);
let function = module.add_function("take_f32_ptr", fn_type, None);
let basic_block = context.append_basic_block(function, "entry");
builder.position_at_end(basic_block);
let arg1 = function.get_first_param().unwrap().into_pointer_value();
let f32_val = f32_type.const_float(std::f64::consts::PI);
let store_instruction = builder.build_store(arg1, f32_val).unwrap();
let free_instruction = builder.build_free(arg1).unwrap();
let return_instruction = builder.build_return(None).unwrap();
assert_eq!(store_instruction.get_operand_use(1), arg1.get_first_use());Sourcepub unsafe fn get_operand_use_unchecked(
self,
index: u32,
) -> Option<BasicValueUse<'ctx>>
pub unsafe fn get_operand_use_unchecked( self, index: u32, ) -> Option<BasicValueUse<'ctx>>
Gets the use of an operand(BasicValue), if any.
§Safety
The index must be smaller than InstructionValue::get_num_operands.
Sourcepub fn get_operand_uses(self) -> OperandUseIter<'ctx> ⓘ
pub fn get_operand_uses(self) -> OperandUseIter<'ctx> ⓘ
Get an instruction value operand use iterator.
Sourcepub fn get_num_indices(self) -> u32
pub fn get_num_indices(self) -> u32
Obtains the number of indices an InstructionValue has.
An index is used in ExtractValue and InsertValue instructions to specify
which field or element to access in an aggregate type (struct or array).
Returns 0 for instructions that are not ExtractValue or InsertValue.
The following example,
use inkwell::context::Context;
use inkwell::values::BasicValue;
let context = Context::create();
let module = context.create_module("ivs");
let builder = context.create_builder();
let void_type = context.void_type();
let i32_type = context.i32_type();
let struct_type = context.struct_type(&[i32_type.into(), i32_type.into()], false);
let fn_type = void_type.fn_type(&[], false);
let function = module.add_function("test", fn_type, None);
let basic_block = context.append_basic_block(function, "entry");
builder.position_at_end(basic_block);
let struct_val = struct_type.get_undef();
let extract_instruction = builder.build_extract_value(struct_val, 0, "extract").unwrap()
.as_instruction_value().unwrap();
assert_eq!(extract_instruction.get_num_indices(), 1);Sourcepub fn get_indices(self) -> Vec<u32>
pub fn get_indices(self) -> Vec<u32>
Obtains the indices an InstructionValue has as a vector.
An index is used in ExtractValue and InsertValue instructions to specify
which field or element to access in an aggregate type (struct or array).
Returns an empty vector for instructions that are not ExtractValue or InsertValue.
The following example,
use inkwell::context::Context;
use inkwell::values::BasicValue;
let context = Context::create();
let module = context.create_module("ivs");
let builder = context.create_builder();
let void_type = context.void_type();
let i32_type = context.i32_type();
let struct_type = context.struct_type(&[i32_type.into(), i32_type.into()], false);
let fn_type = void_type.fn_type(&[], false);
let function = module.add_function("test", fn_type, None);
let basic_block = context.append_basic_block(function, "entry");
builder.position_at_end(basic_block);
let struct_val = struct_type.get_undef();
let extract_instruction = builder.build_extract_value(struct_val, 0, "extract").unwrap()
.as_instruction_value().unwrap();
assert_eq!(extract_instruction.get_indices(), vec![0]);Sourcepub fn get_first_use(self) -> Option<BasicValueUse<'ctx>>
pub fn get_first_use(self) -> Option<BasicValueUse<'ctx>>
Gets the first use of an InstructionValue if any.
The following example,
use inkwell::AddressSpace;
use inkwell::context::Context;
use inkwell::values::BasicValue;
let context = Context::create();
let module = context.create_module("ivs");
let builder = context.create_builder();
let void_type = context.void_type();
let f32_type = context.f32_type();
#[cfg(feature = "typed-pointers")]
let f32_ptr_type = f32_type.ptr_type(AddressSpace::default());
#[cfg(not(feature = "typed-pointers"))]
let f32_ptr_type = context.ptr_type(AddressSpace::default());
let fn_type = void_type.fn_type(&[f32_ptr_type.into()], false);
let function = module.add_function("take_f32_ptr", fn_type, None);
let basic_block = context.append_basic_block(function, "entry");
builder.position_at_end(basic_block);
let arg1 = function.get_first_param().unwrap().into_pointer_value();
let f32_val = f32_type.const_float(std::f64::consts::PI);
let store_instruction = builder.build_store(arg1, f32_val).unwrap();
let free_instruction = builder.build_free(arg1).unwrap();
let return_instruction = builder.build_return(None).unwrap();
assert!(arg1.get_first_use().is_some());Sourcepub fn get_icmp_predicate(self) -> Option<IntPredicate>
pub fn get_icmp_predicate(self) -> Option<IntPredicate>
Gets the predicate of an ICmp InstructionValue.
For instance, in the LLVM instruction
%3 = icmp slt i32 %0, %1
this gives the slt.
If the instruction is not an ICmp, this returns None.
Sourcepub fn get_fcmp_predicate(self) -> Option<FloatPredicate>
pub fn get_fcmp_predicate(self) -> Option<FloatPredicate>
Gets the predicate of an FCmp InstructionValue.
For instance, in the LLVM instruction
%3 = fcmp olt float %0, %1
this gives the olt.
If the instruction is not an FCmp, this returns None.
Sourcepub fn get_atomic_rmw_bin_op(self) -> Option<AtomicRMWBinOp>
pub fn get_atomic_rmw_bin_op(self) -> Option<AtomicRMWBinOp>
Gets the binary operation of an AtomicRMW InstructionValue.
For instance, in the LLVM instruction
%3 = atomicrmw add i32* %ptr, i32 %val monotonic
this gives the add.
If the instruction is not an AtomicRMW, this returns None.
Sourcepub fn has_metadata(self) -> bool
pub fn has_metadata(self) -> bool
Determines whether or not this Instruction has any associated metadata.
Sourcepub fn get_metadata(self, kind_id: u32) -> Option<MetadataValue<'ctx>>
pub fn get_metadata(self, kind_id: u32) -> Option<MetadataValue<'ctx>>
Gets the MetadataValue associated with this Instruction at a specific
kind_id.
Sourcepub fn set_metadata(
self,
metadata: MetadataValue<'ctx>,
kind_id: u32,
) -> Result<(), InstructionValueError>
pub fn set_metadata( self, metadata: MetadataValue<'ctx>, kind_id: u32, ) -> Result<(), InstructionValueError>
Determines whether or not this Instruction has any associated metadata
kind_id.
Sourcepub fn get_debug_location(self) -> Option<DILocation<'ctx>>
pub fn get_debug_location(self) -> Option<DILocation<'ctx>>
Get the debug location for this instruction.
Sourcepub fn set_debug_location(self, location: Option<DILocation<'_>>)
pub fn set_debug_location(self, location: Option<DILocation<'_>>)
Set the debug location for this instruction.
Trait Implementations§
Source§impl<'ctx> AnyValue<'ctx> for InstructionValue<'ctx>
impl<'ctx> AnyValue<'ctx> for InstructionValue<'ctx>
Source§fn as_any_value_enum(&self) -> AnyValueEnum<'ctx>
fn as_any_value_enum(&self) -> AnyValueEnum<'ctx>
AnyValue.Source§fn print_to_string(&self) -> LLVMString
fn print_to_string(&self) -> LLVMString
LLVMStringSource§impl AsValueRef for InstructionValue<'_>
impl AsValueRef for InstructionValue<'_>
fn as_value_ref(&self) -> LLVMValueRef
Source§impl<'ctx> Clone for InstructionValue<'ctx>
impl<'ctx> Clone for InstructionValue<'ctx>
Source§fn clone(&self) -> InstructionValue<'ctx>
fn clone(&self) -> InstructionValue<'ctx>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more