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

Implementations

Get name of the InstructionValue.

Set name of the InstructionValue.

Get type of the current InstructionValue

Returns whether or not a memory access instruction is volatile.

Sets whether or not a memory access instruction is volatile.

Returns alignment on a memory access instruction or alloca.

Sets alignment on a memory access instruction or alloca.

Returns atomic ordering on a memory access instruction.

Sets atomic ordering on a memory access instruction.

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.

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.

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

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

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

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.

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.

Determines whether or not this Instruction has any associated metadata.

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

Determines whether or not this Instruction has any associated metadata kind_id.

Trait Implementations

Returns an enum containing a typed version of AnyValue.

Prints a value to a LLVMString

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

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Feeds this value into the given Hasher. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.