[][src]Struct inkwell::values::InstructionValue

pub struct InstructionValue { /* fields omitted */ }

Methods

impl InstructionValue[src]

pub fn get_opcode(&self) -> InstructionOpcode[src]

pub fn get_previous_instruction(&self) -> Option<Self>[src]

pub fn get_next_instruction(&self) -> Option<Self>[src]

pub fn erase_from_basic_block(&self)[src]

pub fn remove_from_basic_block(&self)[src]

pub fn get_parent(&self) -> Option<BasicBlock>[src]

pub fn is_tail_call(&self) -> bool[src]

pub fn replace_all_uses_with(&self, other: &InstructionValue)[src]

pub fn get_volatile(&self) -> bool[src]

Returns whether or not a memory access instruction is volatile.

pub fn set_volatile(&self, volatile: bool)[src]

Sets whether or not a memory access instruction is volatile.

pub fn get_num_operands(&self) -> u32[src]

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::Generic);
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);
let free_instruction = builder.build_free(arg1);
let return_instruction = builder.build_return(None);

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.

pub fn get_operand(
    &self,
    index: u32
) -> Option<Either<BasicValueEnum, BasicBlock>>
[src]

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::Generic);
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);
let free_instruction = builder.build_free(arg1);
let return_instruction = builder.build_return(None);

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.

pub fn set_operand<BV: BasicValue>(&self, index: u32, val: BV) -> bool[src]

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::Generic);
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);
let free_instruction = builder.build_free(arg1);
let return_instruction = builder.build_return(None);

// This will produce invalid IR:
free_instruction.set_operand(0, f32_val);

assert_eq!(free_instruction.get_operand(0).unwrap().left().unwrap(), f32_val);

pub fn get_operand_use(&self, index: u32) -> Option<BasicValueUse>[src]

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::Generic);
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);
let free_instruction = builder.build_free(arg1);
let return_instruction = builder.build_return(None);

assert_eq!(store_instruction.get_operand_use(1), arg1.get_first_use());

pub fn get_first_use(&self) -> Option<BasicValueUse>[src]

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::Generic);
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);
let free_instruction = builder.build_free(arg1);
let return_instruction = builder.build_return(None);

assert!(arg1.get_first_use().is_some());

pub fn get_icmp_predicate(&self) -> Option<IntPredicate>[src]

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.

pub fn get_fcmp_predicate(&self) -> Option<FloatPredicate>[src]

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.

Trait Implementations

impl AnyValue for InstructionValue[src]

impl Eq for InstructionValue[src]

impl Clone for InstructionValue[src]

fn clone(&self) -> Self[src]

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

impl PartialEq<InstructionValue> for AnyValueEnum[src]

impl PartialEq<AnyValueEnum> for InstructionValue[src]

impl PartialEq<InstructionValue> for InstructionValue[src]

impl From<InstructionValue> for AnyValueEnum[src]

impl Copy for InstructionValue[src]

impl Hash for InstructionValue[src]

impl Debug for InstructionValue[src]

Auto Trait Implementations

impl !Sync for InstructionValue

impl !Send for InstructionValue

impl Unpin for InstructionValue

impl UnwindSafe for InstructionValue

impl RefUnwindSafe for InstructionValue

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]