inkwell::values

Struct CallSiteValue

Source
pub struct CallSiteValue<'ctx>(/* private fields */);
Expand description

A value resulting from a function call. It may have function attributes applied to it.

This struct may be removed in the future in favor of an InstructionValue<CallSite> type.

Implementations§

Source§

impl<'ctx> CallSiteValue<'ctx>

Source

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

Get a value from an LLVMValueRef.

§Safety

The ref must be valid and of type call site.

Source

pub fn set_tail_call(self, tail_call: bool)

Sets whether or not this call is a tail call.

§Example
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.set_tail_call(true);
Source

pub fn is_tail_call(self) -> bool

Determines whether or not this call is a tail call.

§Example
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.set_tail_call(true);

assert!(call_site_value.is_tail_call());
Source

pub fn get_tail_call_kind(self) -> LLVMTailCallKind

Available on crate feature llvm18-0 only.

Returns tail, musttail, and notail attributes.

§Example
use inkwell::values::LLVMTailCallKind::*;

let context = inkwell::context::Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site = builder.build_call(fn_value, &[], "my_fn").unwrap();

assert_eq!(call_site.get_tail_call_kind(), LLVMTailCallKindNone);
Source

pub fn set_tail_call_kind(self, kind: LLVMTailCallKind)

Available on crate feature llvm18-0 only.

Sets tail, musttail, and notail attributes.

§Example
use inkwell::values::LLVMTailCallKind::*;

let context = inkwell::context::Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site.set_tail_call_kind(LLVMTailCallKindTail);
assert_eq!(call_site.get_tail_call_kind(), LLVMTailCallKindTail);
Source

pub fn try_as_basic_value( self, ) -> Either<BasicValueEnum<'ctx>, InstructionValue<'ctx>>

Try to convert this CallSiteValue to a BasicValueEnum if not a void return type.

§Example
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

assert!(call_site_value.try_as_basic_value().is_right());
Source

pub fn add_attribute(self, loc: AttributeLoc, attribute: Attribute)

Adds an Attribute to this CallSiteValue.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.add_attribute(AttributeLoc::Return, string_attribute);
call_site_value.add_attribute(AttributeLoc::Return, enum_attribute);
Source

pub fn get_called_fn_value(self) -> FunctionValue<'ctx>

Gets the FunctionValue this CallSiteValue is based on.

§Example
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

assert_eq!(call_site_value.get_called_fn_value(), fn_value);
Source

pub fn count_attributes(self, loc: AttributeLoc) -> u32

Counts the number of Attributes on this CallSiteValue at an index.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.add_attribute(AttributeLoc::Return, string_attribute);
call_site_value.add_attribute(AttributeLoc::Return, enum_attribute);

assert_eq!(call_site_value.count_attributes(AttributeLoc::Return), 2);
Source

pub fn attributes(self, loc: AttributeLoc) -> Vec<Attribute>

Get all Attributes on this CallSiteValue at an index.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.add_attribute(AttributeLoc::Return, string_attribute);
call_site_value.add_attribute(AttributeLoc::Return, enum_attribute);

assert_eq!(call_site_value.attributes(AttributeLoc::Return), vec![ string_attribute, enum_attribute ]);
Source

pub fn get_enum_attribute( self, loc: AttributeLoc, kind_id: u32, ) -> Option<Attribute>

Gets an enum Attribute on this CallSiteValue at an index and kind id.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.add_attribute(AttributeLoc::Return, string_attribute);
call_site_value.add_attribute(AttributeLoc::Return, enum_attribute);

assert_eq!(call_site_value.get_enum_attribute(AttributeLoc::Return, 1).unwrap(), enum_attribute);
Source

pub fn get_string_attribute( self, loc: AttributeLoc, key: &str, ) -> Option<Attribute>

Gets a string Attribute on this CallSiteValue at an index and key.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.add_attribute(AttributeLoc::Return, string_attribute);
call_site_value.add_attribute(AttributeLoc::Return, enum_attribute);

assert_eq!(call_site_value.get_string_attribute(AttributeLoc::Return, "my_key").unwrap(), string_attribute);
Source

pub fn remove_enum_attribute(self, loc: AttributeLoc, kind_id: u32)

Removes an enum Attribute on this CallSiteValue at an index and kind id.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.add_attribute(AttributeLoc::Return, string_attribute);
call_site_value.add_attribute(AttributeLoc::Return, enum_attribute);
call_site_value.remove_enum_attribute(AttributeLoc::Return, 1);

assert_eq!(call_site_value.get_enum_attribute(AttributeLoc::Return, 1), None);
Source

pub fn remove_string_attribute(self, loc: AttributeLoc, key: &str)

Removes a string Attribute on this CallSiteValue at an index and key.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.add_attribute(AttributeLoc::Return, string_attribute);
call_site_value.add_attribute(AttributeLoc::Return, enum_attribute);
call_site_value.remove_string_attribute(AttributeLoc::Return, "my_key");

assert_eq!(call_site_value.get_string_attribute(AttributeLoc::Return, "my_key"), None);
Source

pub fn count_arguments(self) -> u32

Counts the number of arguments this CallSiteValue was called with.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let string_attribute = context.create_string_attribute("my_key", "my_val");
let enum_attribute = context.create_enum_attribute(1, 1);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

assert_eq!(call_site_value.count_arguments(), 0);
Source

pub fn get_call_convention(self) -> u32

Gets the calling convention for this CallSiteValue.

§Example
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

assert_eq!(call_site_value.get_call_convention(), 0);
Source

pub fn set_call_convention(self, conv: u32)

Sets the calling convention for this CallSiteValue.

§Example
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.set_call_convention(2);

assert_eq!(call_site_value.get_call_convention(), 2);
Source

pub fn set_alignment_attribute(self, loc: AttributeLoc, alignment: u32)

Shortcut for setting the alignment Attribute for this CallSiteValue.

§Panics

When the alignment is not a power of 2.

§Example
use inkwell::attributes::AttributeLoc;
use inkwell::context::Context;

let context = Context::create();
let builder = context.create_builder();
let module = context.create_module("my_mod");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("my_fn", fn_type, None);
let entry_bb = context.append_basic_block(fn_value, "entry");

builder.position_at_end(entry_bb);

let call_site_value = builder.build_call(fn_value, &[], "my_fn").unwrap();

call_site_value.set_alignment_attribute(AttributeLoc::Param(0), 2);
Source

pub fn get_operand_bundles(&self) -> OperandBundleIter<'_, 'ctx>

Available on crate feature llvm18-0 only.

Iterate over operand bundles.

§Example
use inkwell::context::Context;
use inkwell::values::OperandBundle;

let context = Context::create();
let module = context.create_module("op_bundles");
let builder = context.create_builder();

let void_type = context.void_type();
let i32_type = context.i32_type();
let fn_type = void_type.fn_type(&[], false);
let fn_value = module.add_function("func", fn_type, None);

let basic_block = context.append_basic_block(fn_value, "entry");
builder.position_at_end(basic_block);

// Recursive call
let callinst = builder.build_direct_call_with_operand_bundles(
  fn_value,
  &[],
  &[OperandBundle::create("tag0", &[i32_type.const_zero().into()]), OperandBundle::create("tag1", &[])],
  "call"
).unwrap();

builder.build_return(None).unwrap();

let mut op_bundles_iter = callinst.get_operand_bundles();
assert_eq!(op_bundles_iter.len(), 2);
let tags: Vec<String> = op_bundles_iter.map(|ob| ob.get_tag().unwrap().into()).collect();
assert_eq!(tags, vec!["tag0", "tag1"]);

Trait Implementations§

Source§

impl<'ctx> AnyValue<'ctx> for CallSiteValue<'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

Available on crate features llvm12-0 or llvm13-0 or llvm14-0 or llvm15-0 or llvm16-0 or llvm17-0 or llvm18-0 only.
Returns whether the value is poison
Source§

impl AsValueRef for CallSiteValue<'_>

Source§

impl<'ctx> Clone for CallSiteValue<'ctx>

Source§

fn clone(&self) -> CallSiteValue<'ctx>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<'ctx> Debug for CallSiteValue<'ctx>

Source§

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

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

impl Display for CallSiteValue<'_>

Source§

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

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

impl<'ctx> Hash for CallSiteValue<'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 for CallSiteValue<'ctx>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

Source§

type Error = ()

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

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

Performs the conversion.
Source§

impl<'ctx> Copy for CallSiteValue<'ctx>

Source§

impl<'ctx> Eq for CallSiteValue<'ctx>

Source§

impl<'ctx> StructuralPartialEq for CallSiteValue<'ctx>

Auto Trait Implementations§

§

impl<'ctx> Freeze for CallSiteValue<'ctx>

§

impl<'ctx> RefUnwindSafe for CallSiteValue<'ctx>

§

impl<'ctx> !Send for CallSiteValue<'ctx>

§

impl<'ctx> !Sync for CallSiteValue<'ctx>

§

impl<'ctx> Unpin for CallSiteValue<'ctx>

§

impl<'ctx> UnwindSafe for CallSiteValue<'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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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,

Source§

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>,

Source§

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>,

Source§

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.