Struct inkwell::values::InstructionValue
source · 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 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<(), &'static str>
pub fn set_name(&self, name: &str) -> Result<(), &'static str>
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
sourcepub fn get_tail_call_kind(self) -> Option<LLVMTailCallKind>
pub fn get_tail_call_kind(self) -> Option<LLVMTailCallKind>
Returns the tail call kind on call instructions.
Other instructions return None
.
sourcepub fn can_use_fast_math_flags(self) -> bool
pub fn can_use_fast_math_flags(self) -> bool
Check whether this instructions supports fast math flags.
sourcepub fn get_fast_math_flags(self) -> Option<u32>
pub fn get_fast_math_flags(self) -> Option<u32>
Get fast math flags of supported instructions.
Calling this on unsupported instructions is safe and returns None
.
sourcepub fn set_fast_math_flags(self, flags: u32)
pub fn set_fast_math_flags(self, flags: u32)
Set fast math flags on supported instructions.
Calling this on unsupported instructions is safe and results in a no-op.
sourcepub fn get_non_negative_flag(self) -> Option<bool>
pub fn get_non_negative_flag(self) -> Option<bool>
Check if a zext
instruction has the non-negative flag set.
Calling this function on other instructions is safe and returns None
.
sourcepub fn set_non_negative_flag(self, flag: bool)
pub fn set_non_negative_flag(self, flag: bool)
Set the non-negative flag on zext
instructions.
Calling this function on other instructions is safe and results in a no-op.
sourcepub fn get_disjoint_flag(self) -> Option<bool>
pub fn get_disjoint_flag(self) -> Option<bool>
Checks if an or
instruction has the disjoint
flag set.
Calling this function on other instructions is safe and returns None
.
sourcepub fn set_disjoint_flag(self, flag: bool)
pub fn set_disjoint_flag(self, flag: bool)
Set the disjoint
flag on or
instructions.
Calling this function on other instructions is safe and results in a no-op.
pub fn replace_all_uses_with(self, other: &InstructionValue<'ctx>)
sourcepub fn get_volatile(self) -> Result<bool, &'static str>
pub fn get_volatile(self) -> Result<bool, &'static str>
Returns whether or not a memory access instruction is volatile.
sourcepub fn set_volatile(self, volatile: bool) -> Result<(), &'static str>
pub fn set_volatile(self, volatile: bool) -> Result<(), &'static str>
Sets whether or not a memory access instruction is volatile.
sourcepub fn get_allocated_type(self) -> Result<BasicTypeEnum<'ctx>, &'static str>
pub fn get_allocated_type(self) -> Result<BasicTypeEnum<'ctx>, &'static str>
Returns the type that is allocated by the alloca instruction.
sourcepub fn get_alignment(self) -> Result<u32, &'static str>
pub fn get_alignment(self) -> Result<u32, &'static str>
Returns alignment on a memory access instruction or alloca.
sourcepub fn set_alignment(self, alignment: u32) -> Result<(), &'static str>
pub fn set_alignment(self, alignment: u32) -> Result<(), &'static str>
Sets alignment on a memory access instruction or alloca.
sourcepub fn get_atomic_ordering(self) -> Result<AtomicOrdering, &'static str>
pub fn get_atomic_ordering(self) -> Result<AtomicOrdering, &'static str>
Returns atomic ordering on a memory access instruction.
sourcepub fn set_atomic_ordering(
self,
ordering: AtomicOrdering
) -> Result<(), &'static str>
pub fn set_atomic_ordering( self, ordering: AtomicOrdering ) -> Result<(), &'static str>
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();
let f32_ptr_type = f32_type.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<Either<BasicValueEnum<'ctx>, BasicBlock<'ctx>>>
pub fn get_operand( self, index: u32 ) -> Option<Either<BasicValueEnum<'ctx>, BasicBlock<'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();
let f32_ptr_type = f32_type.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<Either<BasicValueEnum<'ctx>, BasicBlock<'ctx>>>
pub unsafe fn get_operand_unchecked( self, index: u32 ) -> Option<Either<BasicValueEnum<'ctx>, BasicBlock<'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();
let f32_ptr_type = f32_type.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().left().unwrap(), 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();
let f32_ptr_type = f32_type.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_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();
let f32_ptr_type = f32_type.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 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<(), &'static str>
pub fn set_metadata( self, metadata: MetadataValue<'ctx>, kind_id: u32 ) -> Result<(), &'static str>
Determines whether or not this Instruction
has any associated metadata
kind_id
.
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
LLVMString
source§impl AsValueRef for InstructionValue<'_>
impl AsValueRef for InstructionValue<'_>
fn as_value_ref(&self) -> LLVMValueRef
source§impl Clone for InstructionValue<'_>
impl Clone for InstructionValue<'_>
source§impl<'ctx> Debug for InstructionValue<'ctx>
impl<'ctx> Debug for InstructionValue<'ctx>
source§impl Display for InstructionValue<'_>
impl Display for InstructionValue<'_>
source§impl<'ctx> From<InstructionValue<'ctx>> for AnyValueEnum<'ctx>
impl<'ctx> From<InstructionValue<'ctx>> for AnyValueEnum<'ctx>
source§fn from(value: InstructionValue<'_>) -> AnyValueEnum<'_>
fn from(value: InstructionValue<'_>) -> AnyValueEnum<'_>
source§impl<'ctx> Hash for InstructionValue<'ctx>
impl<'ctx> Hash for InstructionValue<'ctx>
source§impl<'ctx> PartialEq<AnyValueEnum<'ctx>> for InstructionValue<'ctx>
impl<'ctx> PartialEq<AnyValueEnum<'ctx>> for InstructionValue<'ctx>
source§fn eq(&self, other: &AnyValueEnum<'ctx>) -> bool
fn eq(&self, other: &AnyValueEnum<'ctx>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'ctx> PartialEq<InstructionValue<'ctx>> for AnyValueEnum<'ctx>
impl<'ctx> PartialEq<InstructionValue<'ctx>> for AnyValueEnum<'ctx>
source§fn eq(&self, other: &InstructionValue<'ctx>) -> bool
fn eq(&self, other: &InstructionValue<'ctx>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'ctx> PartialEq for InstructionValue<'ctx>
impl<'ctx> PartialEq for InstructionValue<'ctx>
source§fn eq(&self, other: &InstructionValue<'ctx>) -> bool
fn eq(&self, other: &InstructionValue<'ctx>) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'ctx> TryFrom<AnyValueEnum<'ctx>> for InstructionValue<'ctx>
impl<'ctx> TryFrom<AnyValueEnum<'ctx>> for InstructionValue<'ctx>
source§impl<'ctx> TryFrom<InstructionValue<'ctx>> for FloatValue<'ctx>
impl<'ctx> TryFrom<InstructionValue<'ctx>> for FloatValue<'ctx>
source§impl<'ctx> TryFrom<InstructionValue<'ctx>> for IntValue<'ctx>
impl<'ctx> TryFrom<InstructionValue<'ctx>> for IntValue<'ctx>
source§impl<'ctx> TryFrom<InstructionValue<'ctx>> for PhiValue<'ctx>
impl<'ctx> TryFrom<InstructionValue<'ctx>> for PhiValue<'ctx>
source§impl<'ctx> TryFrom<InstructionValue<'ctx>> for PointerValue<'ctx>
impl<'ctx> TryFrom<InstructionValue<'ctx>> for PointerValue<'ctx>
impl<'ctx> Copy for InstructionValue<'ctx>
impl<'ctx> Eq for InstructionValue<'ctx>
impl<'ctx> StructuralPartialEq for InstructionValue<'ctx>
Auto Trait Implementations§
impl<'ctx> RefUnwindSafe for InstructionValue<'ctx>
impl<'ctx> !Send for InstructionValue<'ctx>
impl<'ctx> !Sync for InstructionValue<'ctx>
impl<'ctx> Unpin for InstructionValue<'ctx>
impl<'ctx> UnwindSafe for InstructionValue<'ctx>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more