pub struct InstructionValue<'ctx> { /* private fields */ }

Implementations§

source§

impl<'ctx> InstructionValue<'ctx>

source

pub unsafe fn new(instruction_value: LLVMValueRef) -> Self

Get a value from an LLVMValueRef.

§Safety

The ref must be valid and of type instruction.

source

pub fn get_name(&self) -> Option<&CStr>

Get name of the InstructionValue.

source

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.

source

pub fn set_name(&self, name: &str) -> Result<(), &'static str>

Set name of the InstructionValue.

source

pub fn get_type(self) -> AnyTypeEnum<'ctx>

Get type of the current InstructionValue

source

pub fn get_opcode(self) -> InstructionOpcode

source

pub fn get_previous_instruction(self) -> Option<Self>

source

pub fn get_next_instruction(self) -> Option<Self>

source

pub fn erase_from_basic_block(self)

source

pub fn remove_from_basic_block(self)

source

pub fn get_parent(self) -> Option<BasicBlock<'ctx>>

source

pub fn is_terminator(self) -> bool

Returns if the instruction is a terminator

source

pub fn is_conditional(self) -> bool

Returns if a terminator is conditional or not

source

pub fn is_tail_call(self) -> bool

source

pub fn get_tail_call_kind(self) -> Option<LLVMTailCallKind>

Returns the tail call kind on call instructions.

Other instructions return None.

source

pub fn can_use_fast_math_flags(self) -> bool

Check whether this instructions supports fast math flags.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn replace_all_uses_with(self, other: &InstructionValue<'ctx>)

source

pub fn get_volatile(self) -> Result<bool, &'static str>

Returns whether or not a memory access instruction is volatile.

source

pub fn set_volatile(self, volatile: bool) -> Result<(), &'static str>

Sets whether or not a memory access instruction is volatile.

source

pub fn get_allocated_type(self) -> Result<BasicTypeEnum<'ctx>, &'static str>

Returns the type that is allocated by the alloca instruction.

source

pub fn get_alignment(self) -> Result<u32, &'static str>

Returns alignment on a memory access instruction or alloca.

source

pub fn set_alignment(self, alignment: u32) -> Result<(), &'static str>

Sets alignment on a memory access instruction or alloca.

source

pub fn get_atomic_ordering(self) -> Result<AtomicOrdering, &'static str>

Returns atomic ordering on a memory access instruction.

source

pub fn set_atomic_ordering( self, ordering: AtomicOrdering ) -> Result<(), &'static str>

Sets atomic ordering on a memory access instruction.

source

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:

  1. Store has two: a const float and a variable float pointer %0
  2. Bitcast has one: a variable float pointer %0
  3. Function call has two: i8 pointer %1 argument, and the free function itself
  4. Void return has zero: void is not a value and does not count as an operand even though the return instruction can take values.
source

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:

  1. Store has two: a const float and a variable float pointer %0
  2. Bitcast has one: a variable float pointer %0
  3. Function call has two: i8 pointer %1 argument, and the free function itself
  4. Void return has zero: void is not a value and does not count as an operand even though the return instruction can take values.
source

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.

source

pub fn get_operands(self) -> OperandIter<'ctx>

Get an instruction value operand iterator.

source

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);
source

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());
source

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.

source

pub fn get_operand_uses(self) -> OperandUseIter<'ctx>

Get an instruction value operand use iterator.

source

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());
source

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.

source

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.

source

pub fn has_metadata(self) -> bool

Determines whether or not this Instruction has any associated metadata.

source

pub fn get_metadata(self, kind_id: u32) -> Option<MetadataValue<'ctx>>

Gets the MetadataValue associated with this Instruction at a specific kind_id.

source

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>

source§

fn as_any_value_enum(&self) -> AnyValueEnum<'ctx>

Returns an enum containing a typed version of AnyValue.
source§

fn print_to_string(&self) -> LLVMString

Prints a value to a LLVMString
source§

fn is_poison(&self) -> bool

Returns whether the value is poison
source§

impl AsValueRef for InstructionValue<'_>

source§

impl Clone for InstructionValue<'_>

source§

fn clone(&self) -> Self

Creates a clone of this InstructionValue, and returns it. The clone will have no parent, and no name.

1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'ctx> Debug for InstructionValue<'ctx>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for InstructionValue<'_>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'ctx> From<InstructionValue<'ctx>> for AnyValueEnum<'ctx>

source§

fn from(value: InstructionValue<'_>) -> AnyValueEnum<'_>

Converts to this type from the input type.
source§

impl<'ctx> Hash for InstructionValue<'ctx>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'ctx> PartialEq<AnyValueEnum<'ctx>> for InstructionValue<'ctx>

source§

fn eq(&self, other: &AnyValueEnum<'ctx>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'ctx> PartialEq<InstructionValue<'ctx>> for AnyValueEnum<'ctx>

source§

fn eq(&self, other: &InstructionValue<'ctx>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'ctx> PartialEq for InstructionValue<'ctx>

source§

fn eq(&self, other: &InstructionValue<'ctx>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'ctx> TryFrom<AnyValueEnum<'ctx>> for InstructionValue<'ctx>

§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(value: AnyValueEnum<'ctx>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'ctx> TryFrom<InstructionValue<'ctx>> for FloatValue<'ctx>

§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(value: InstructionValue<'_>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'ctx> TryFrom<InstructionValue<'ctx>> for IntValue<'ctx>

§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(value: InstructionValue<'_>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'ctx> TryFrom<InstructionValue<'ctx>> for PhiValue<'ctx>

§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(value: InstructionValue<'_>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'ctx> TryFrom<InstructionValue<'ctx>> for PointerValue<'ctx>

§

type Error = ()

The type returned in the event of a conversion error.
source§

fn try_from(value: InstructionValue<'_>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'ctx> Copy for InstructionValue<'ctx>

source§

impl<'ctx> Eq for InstructionValue<'ctx>

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.