2024-06-12 14:45:03 +08:00
|
|
|
use crate::codegen::CodeGenContext;
|
2024-02-22 01:47:26 +08:00
|
|
|
use inkwell::context::Context;
|
2024-06-04 17:11:28 +08:00
|
|
|
use inkwell::intrinsics::Intrinsic;
|
2024-02-22 01:47:26 +08:00
|
|
|
use inkwell::types::AnyTypeEnum::IntType;
|
|
|
|
use inkwell::types::FloatType;
|
|
|
|
use inkwell::values::{BasicValueEnum, CallSiteValue, FloatValue, IntValue, PointerValue};
|
2024-06-12 14:45:03 +08:00
|
|
|
use inkwell::AddressSpace;
|
2024-02-22 01:47:26 +08:00
|
|
|
use itertools::Either;
|
|
|
|
|
|
|
|
/// Returns the string representation for the floating-point type `ft` when used in intrinsic
|
|
|
|
/// functions.
|
|
|
|
fn get_float_intrinsic_repr(ctx: &Context, ft: FloatType) -> &'static str {
|
|
|
|
// Standard LLVM floating-point types
|
|
|
|
if ft == ctx.f16_type() {
|
2024-06-12 14:45:03 +08:00
|
|
|
return "f16";
|
2024-02-22 01:47:26 +08:00
|
|
|
}
|
|
|
|
if ft == ctx.f32_type() {
|
2024-06-12 14:45:03 +08:00
|
|
|
return "f32";
|
2024-02-22 01:47:26 +08:00
|
|
|
}
|
|
|
|
if ft == ctx.f64_type() {
|
2024-06-12 14:45:03 +08:00
|
|
|
return "f64";
|
2024-02-22 01:47:26 +08:00
|
|
|
}
|
|
|
|
if ft == ctx.f128_type() {
|
2024-06-12 14:45:03 +08:00
|
|
|
return "f128";
|
2024-02-22 01:47:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Non-standard floating-point types
|
|
|
|
if ft == ctx.x86_f80_type() {
|
2024-06-12 14:45:03 +08:00
|
|
|
return "f80";
|
2024-02-22 01:47:26 +08:00
|
|
|
}
|
|
|
|
if ft == ctx.ppc_f128_type() {
|
2024-06-12 14:45:03 +08:00
|
|
|
return "ppcf128";
|
2024-02-22 01:47:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unreachable!()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.stacksave`](https://llvm.org/docs/LangRef.html#llvm-stacksave-intrinsic)
|
|
|
|
/// intrinsic.
|
|
|
|
pub fn call_stacksave<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> PointerValue<'ctx> {
|
|
|
|
const FN_NAME: &str = "llvm.stacksave";
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_pointer_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the
|
|
|
|
/// [`llvm.stackrestore`](https://llvm.org/docs/LangRef.html#llvm-stackrestore-intrinsic) intrinsic.
|
2024-06-04 17:11:28 +08:00
|
|
|
///
|
|
|
|
/// - `ptr`: The pointer storing the address to restore the stack to.
|
2024-02-22 01:47:26 +08:00
|
|
|
pub fn call_stackrestore<'ctx>(ctx: &CodeGenContext<'ctx, '_>, ptr: PointerValue<'ctx>) {
|
|
|
|
const FN_NAME: &str = "llvm.stackrestore";
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_i8 = ctx.ctx.i8_type();
|
|
|
|
let llvm_p0i8 = llvm_i8.ptr_type(AddressSpace::default());
|
2024-02-22 01:47:26 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_p0i8.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
2024-06-12 14:45:03 +08:00
|
|
|
ctx.builder.build_call(intrinsic_fn, &[ptr.into()], "").unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.abs`](https://llvm.org/docs/LangRef.html#llvm-abs-intrinsic) intrinsic.
|
|
|
|
///
|
|
|
|
/// * `src` - The value for which the absolute value is to be returned.
|
|
|
|
/// * `is_int_min_poison` - Whether `poison` is to be returned if `src` is `INT_MIN`.
|
|
|
|
pub fn call_int_abs<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
src: IntValue<'ctx>,
|
|
|
|
is_int_min_poison: IntValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> IntValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.abs";
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
debug_assert_eq!(is_int_min_poison.get_type().get_bit_width(), 1);
|
|
|
|
debug_assert!(is_int_min_poison.is_const());
|
|
|
|
|
|
|
|
let llvm_src_t = src.get_type();
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_src_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[src.into(), is_int_min_poison.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_int_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.smax`](https://llvm.org/docs/LangRef.html#llvm-smax-intrinsic) intrinsic.
|
|
|
|
pub fn call_int_smax<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
a: IntValue<'ctx>,
|
|
|
|
b: IntValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> IntValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.smax";
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
debug_assert_eq!(a.get_type().get_bit_width(), b.get_type().get_bit_width());
|
|
|
|
|
|
|
|
let llvm_int_t = a.get_type();
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_int_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[a.into(), b.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_int_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.smin`](https://llvm.org/docs/LangRef.html#llvm-smin-intrinsic) intrinsic.
|
|
|
|
pub fn call_int_smin<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
a: IntValue<'ctx>,
|
|
|
|
b: IntValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> IntValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.smin";
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
debug_assert_eq!(a.get_type().get_bit_width(), b.get_type().get_bit_width());
|
|
|
|
|
|
|
|
let llvm_int_t = a.get_type();
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_int_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[a.into(), b.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_int_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.umax`](https://llvm.org/docs/LangRef.html#llvm-umax-intrinsic) intrinsic.
|
|
|
|
pub fn call_int_umax<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
a: IntValue<'ctx>,
|
|
|
|
b: IntValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> IntValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.umax";
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
debug_assert_eq!(a.get_type().get_bit_width(), b.get_type().get_bit_width());
|
|
|
|
|
|
|
|
let llvm_int_t = a.get_type();
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_int_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[a.into(), b.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_int_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.umin`](https://llvm.org/docs/LangRef.html#llvm-umin-intrinsic) intrinsic.
|
|
|
|
pub fn call_int_umin<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
a: IntValue<'ctx>,
|
|
|
|
b: IntValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> IntValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.umin";
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
debug_assert_eq!(a.get_type().get_bit_width(), b.get_type().get_bit_width());
|
|
|
|
|
|
|
|
let llvm_int_t = a.get_type();
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_int_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[a.into(), b.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_int_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.memcpy`](https://llvm.org/docs/LangRef.html#llvm-memcpy-intrinsic) intrinsic.
|
|
|
|
///
|
|
|
|
/// * `dest` - The pointer to the destination. Must be a pointer to an integer type.
|
|
|
|
/// * `src` - The pointer to the source. Must be a pointer to an integer type.
|
|
|
|
/// * `len` - The number of bytes to copy.
|
|
|
|
/// * `is_volatile` - Whether the `memcpy` operation should be `volatile`.
|
|
|
|
pub fn call_memcpy<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
dest: PointerValue<'ctx>,
|
|
|
|
src: PointerValue<'ctx>,
|
|
|
|
len: IntValue<'ctx>,
|
|
|
|
is_volatile: IntValue<'ctx>,
|
|
|
|
) {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.memcpy";
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
debug_assert!(dest.get_type().get_element_type().is_int_type());
|
|
|
|
debug_assert!(src.get_type().get_element_type().is_int_type());
|
|
|
|
debug_assert_eq!(
|
|
|
|
dest.get_type().get_element_type().into_int_type().get_bit_width(),
|
|
|
|
src.get_type().get_element_type().into_int_type().get_bit_width(),
|
|
|
|
);
|
|
|
|
debug_assert!(matches!(len.get_type().get_bit_width(), 32 | 64));
|
|
|
|
debug_assert_eq!(is_volatile.get_type().get_bit_width(), 1);
|
|
|
|
|
|
|
|
let llvm_dest_t = dest.get_type();
|
|
|
|
let llvm_src_t = src.get_type();
|
|
|
|
let llvm_len_t = len.get_type();
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
2024-06-12 14:45:03 +08:00
|
|
|
.and_then(|intrinsic| {
|
|
|
|
intrinsic.get_declaration(
|
|
|
|
&ctx.module,
|
|
|
|
&[llvm_dest_t.into(), llvm_src_t.into(), llvm_len_t.into()],
|
|
|
|
)
|
|
|
|
})
|
2024-06-04 17:11:28 +08:00
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[dest.into(), src.into(), len.into(), is_volatile.into()], "")
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the `llvm.memcpy` intrinsic.
|
|
|
|
///
|
|
|
|
/// Unlike [`call_memcpy`], this function accepts any type of pointer value. If `dest` or `src` is
|
|
|
|
/// not a pointer to an integer, the pointer(s) will be cast to `i8*` before invoking `memcpy`.
|
|
|
|
pub fn call_memcpy_generic<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
dest: PointerValue<'ctx>,
|
|
|
|
src: PointerValue<'ctx>,
|
|
|
|
len: IntValue<'ctx>,
|
|
|
|
is_volatile: IntValue<'ctx>,
|
|
|
|
) {
|
|
|
|
let llvm_i8 = ctx.ctx.i8_type();
|
|
|
|
let llvm_p0i8 = llvm_i8.ptr_type(AddressSpace::default());
|
|
|
|
|
|
|
|
let dest_elem_t = dest.get_type().get_element_type();
|
|
|
|
let src_elem_t = src.get_type().get_element_type();
|
|
|
|
|
|
|
|
let dest = if matches!(dest_elem_t, IntType(t) if t.get_bit_width() == 8) {
|
|
|
|
dest
|
|
|
|
} else {
|
|
|
|
ctx.builder
|
|
|
|
.build_bitcast(dest, llvm_p0i8, "")
|
|
|
|
.map(BasicValueEnum::into_pointer_value)
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
let src = if matches!(src_elem_t, IntType(t) if t.get_bit_width() == 8) {
|
|
|
|
src
|
|
|
|
} else {
|
|
|
|
ctx.builder
|
|
|
|
.build_bitcast(src, llvm_p0i8, "")
|
|
|
|
.map(BasicValueEnum::into_pointer_value)
|
|
|
|
.unwrap()
|
|
|
|
};
|
|
|
|
|
|
|
|
call_memcpy(ctx, dest, src, len, is_volatile);
|
|
|
|
}
|
|
|
|
|
2024-04-24 17:40:25 +08:00
|
|
|
/// Invokes the [`llvm.sqrt`](https://llvm.org/docs/LangRef.html#llvm-sqrt-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_sqrt<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.sqrt";
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_float_t = val.get_type();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
/// Invokes the [`llvm.powi`](https://llvm.org/docs/LangRef.html#llvm-powi-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_powi<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
power: IntValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.powi";
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
let llvm_val_t = val.get_type();
|
|
|
|
let llvm_power_t = power.get_type();
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
2024-06-12 14:45:03 +08:00
|
|
|
.and_then(|intrinsic| {
|
|
|
|
intrinsic.get_declaration(&ctx.module, &[llvm_val_t.into(), llvm_power_t.into()])
|
|
|
|
})
|
2024-06-04 17:11:28 +08:00
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into(), power.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
2024-04-24 17:40:25 +08:00
|
|
|
/// Invokes the [`llvm.sin`](https://llvm.org/docs/LangRef.html#llvm-sin-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_sin<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.sin";
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_float_t = val.get_type();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.cos`](https://llvm.org/docs/LangRef.html#llvm-cos-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_cos<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.cos";
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_float_t = val.get_type();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
/// Invokes the [`llvm.pow`](https://llvm.org/docs/LangRef.html#llvm-pow-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_pow<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
power: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.pow";
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
debug_assert_eq!(val.get_type(), power.get_type());
|
|
|
|
|
|
|
|
let llvm_float_t = val.get_type();
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into(), power.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
2024-04-24 17:40:25 +08:00
|
|
|
/// Invokes the [`llvm.exp`](https://llvm.org/docs/LangRef.html#llvm-exp-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_exp<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.exp";
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_float_t = val.get_type();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.exp2`](https://llvm.org/docs/LangRef.html#llvm-exp2-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_exp2<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.exp2";
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_float_t = val.get_type();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.log`](https://llvm.org/docs/LangRef.html#llvm-log-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_log<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.log";
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_float_t = val.get_type();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.log10`](https://llvm.org/docs/LangRef.html#llvm-log10-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_log10<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.log10";
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_float_t = val.get_type();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.log2`](https://llvm.org/docs/LangRef.html#llvm-log2-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_log2<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.log2";
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_float_t = val.get_type();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
/// Invokes the [`llvm.fabs`](https://llvm.org/docs/LangRef.html#llvm-fabs-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_fabs<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
src: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.fabs";
|
2024-02-22 01:47:26 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_src_t = src.get_type();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_src_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[src.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.minnum`](https://llvm.org/docs/LangRef.html#llvm-minnum-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_minnum<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val1: FloatValue<'ctx>,
|
|
|
|
val2: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.minnum";
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
debug_assert_eq!(val1.get_type(), val2.get_type());
|
|
|
|
|
|
|
|
let llvm_float_t = val1.get_type();
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val1.into(), val2.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.maxnum`](https://llvm.org/docs/LangRef.html#llvm-maxnum-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_maxnum<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val1: FloatValue<'ctx>,
|
|
|
|
val2: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.maxnum";
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
debug_assert_eq!(val1.get_type(), val2.get_type());
|
|
|
|
|
|
|
|
let llvm_float_t = val1.get_type();
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val1.into(), val2.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
2024-04-24 17:40:25 +08:00
|
|
|
/// Invokes the [`llvm.copysign`](https://llvm.org/docs/LangRef.html#llvm-copysign-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_copysign<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
mag: FloatValue<'ctx>,
|
|
|
|
sgn: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.copysign";
|
|
|
|
|
2024-04-24 17:40:25 +08:00
|
|
|
debug_assert_eq!(mag.get_type(), sgn.get_type());
|
|
|
|
|
|
|
|
let llvm_float_t = mag.get_type();
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-04-24 17:40:25 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[mag.into(), sgn.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
/// Invokes the [`llvm.floor`](https://llvm.org/docs/LangRef.html#llvm-floor-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_floor<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.floor";
|
2024-02-22 01:47:26 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_float_t = val.get_type();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.ceil`](https://llvm.org/docs/LangRef.html#llvm-ceil-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_ceil<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.ceil";
|
2024-02-22 01:47:26 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_float_t = val.get_type();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.round`](https://llvm.org/docs/LangRef.html#llvm-round-intrinsic) intrinsic.
|
|
|
|
pub fn call_float_round<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.round";
|
2024-02-22 01:47:26 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_float_t = val.get_type();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
2024-06-12 14:45:03 +08:00
|
|
|
/// Invokes the
|
2024-06-20 12:06:24 +08:00
|
|
|
/// [`llvm.nearbyint`](https://llvm.org/docs/LangRef.html#llvm-nearbyint-intrinsic)
|
|
|
|
/// Note [`llvm.roundeven`](https://llvm.org/docs/LangRef.html#llvm-roundeven-intrinsic) not supported on all platforms
|
2024-02-22 01:47:26 +08:00
|
|
|
pub fn call_float_roundeven<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: FloatValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> FloatValue<'ctx> {
|
2024-06-20 12:06:24 +08:00
|
|
|
const FN_NAME: &str = "llvm.nearbyint";
|
2024-02-22 01:47:26 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let llvm_float_t = val.get_type();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_float_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_float_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Invokes the [`llvm.expect`](https://llvm.org/docs/LangRef.html#llvm-expect-intrinsic) intrinsic.
|
|
|
|
pub fn call_expect<'ctx>(
|
|
|
|
ctx: &CodeGenContext<'ctx, '_>,
|
|
|
|
val: IntValue<'ctx>,
|
|
|
|
expected_val: IntValue<'ctx>,
|
|
|
|
name: Option<&str>,
|
|
|
|
) -> IntValue<'ctx> {
|
2024-06-04 17:11:28 +08:00
|
|
|
const FN_NAME: &str = "llvm.expect";
|
|
|
|
|
2024-02-22 01:47:26 +08:00
|
|
|
debug_assert_eq!(val.get_type().get_bit_width(), expected_val.get_type().get_bit_width());
|
|
|
|
|
|
|
|
let llvm_int_t = val.get_type();
|
|
|
|
|
2024-06-04 17:11:28 +08:00
|
|
|
let intrinsic_fn = Intrinsic::find(FN_NAME)
|
|
|
|
.and_then(|intrinsic| intrinsic.get_declaration(&ctx.module, &[llvm_int_t.into()]))
|
|
|
|
.unwrap();
|
2024-02-22 01:47:26 +08:00
|
|
|
|
|
|
|
ctx.builder
|
|
|
|
.build_call(intrinsic_fn, &[val.into(), expected_val.into()], name.unwrap_or_default())
|
|
|
|
.map(CallSiteValue::try_as_basic_value)
|
|
|
|
.map(|v| v.map_left(BasicValueEnum::into_int_value))
|
|
|
|
.map(Either::unwrap_left)
|
|
|
|
.unwrap()
|
|
|
|
}
|