2020-09-23 15:13:49 +02:00
|
|
|
//! Codegen of intrinsics. This includes `extern "rust-intrinsic"`, `extern "platform-intrinsic"`
|
|
|
|
//! and LLVM intrinsics that have symbol names starting with `llvm.`.
|
|
|
|
|
2022-07-26 18:53:46 +02:00
|
|
|
macro_rules! intrinsic_args {
|
|
|
|
($fx:expr, $args:expr => ($($arg:tt),*); $intrinsic:expr) => {
|
|
|
|
#[allow(unused_parens)]
|
|
|
|
let ($($arg),*) = if let [$($arg),*] = $args {
|
2024-01-12 08:21:42 +01:00
|
|
|
($(codegen_operand($fx, &($arg).node)),*)
|
2022-07-26 18:53:46 +02:00
|
|
|
} else {
|
|
|
|
$crate::intrinsics::bug_on_incorrect_arg_count($intrinsic);
|
|
|
|
};
|
2020-07-03 16:52:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-20 16:55:21 +01:00
|
|
|
mod llvm;
|
2022-12-14 19:30:46 +01:00
|
|
|
mod llvm_aarch64;
|
|
|
|
mod llvm_x86;
|
2022-03-20 16:55:21 +01:00
|
|
|
mod simd;
|
|
|
|
|
2023-10-09 08:52:46 +00:00
|
|
|
use cranelift_codegen::ir::AtomicRmwOp;
|
2023-02-22 20:51:29 +00:00
|
|
|
use rustc_middle::ty;
|
2023-02-26 21:50:19 +00:00
|
|
|
use rustc_middle::ty::layout::{HasParamEnv, ValidityRequirement};
|
2023-03-15 14:41:48 +00:00
|
|
|
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
|
2023-07-11 22:35:29 +01:00
|
|
|
use rustc_middle::ty::GenericArgsRef;
|
2024-01-12 08:21:42 +01:00
|
|
|
use rustc_span::source_map::Spanned;
|
2024-02-25 18:51:22 +01:00
|
|
|
use rustc_span::symbol::{sym, Symbol};
|
2022-03-20 16:55:21 +01:00
|
|
|
|
2023-10-09 08:52:46 +00:00
|
|
|
pub(crate) use self::llvm::codegen_llvm_intrinsic_call;
|
2024-04-19 18:45:25 +00:00
|
|
|
use crate::cast::clif_intcast;
|
2022-03-20 16:55:21 +01:00
|
|
|
use crate::prelude::*;
|
|
|
|
|
2022-07-26 18:53:46 +02:00
|
|
|
fn bug_on_incorrect_arg_count(intrinsic: impl std::fmt::Display) -> ! {
|
|
|
|
bug!("wrong number of args for intrinsic {}", intrinsic);
|
|
|
|
}
|
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
fn report_atomic_type_validation_error<'tcx>(
|
|
|
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
|
|
|
intrinsic: Symbol,
|
|
|
|
span: Span,
|
|
|
|
ty: Ty<'tcx>,
|
|
|
|
) {
|
2023-12-18 22:21:37 +11:00
|
|
|
fx.tcx.dcx().span_err(
|
2022-02-23 11:49:34 +01:00
|
|
|
span,
|
Restrict `From<S>` for `{D,Subd}iagnosticMessage`.
Currently a `{D,Subd}iagnosticMessage` can be created from any type that
impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static,
str>`, which are reasonable. It also includes `&String`, which is pretty
weird, and results in many places making unnecessary allocations for
patterns like this:
```
self.fatal(&format!(...))
```
This creates a string with `format!`, takes a reference, passes the
reference to `fatal`, which does an `into()`, which clones the
reference, doing a second allocation. Two allocations for a single
string, bleh.
This commit changes the `From` impls so that you can only create a
`{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static,
str>`. This requires changing all the places that currently create one
from a `&String`. Most of these are of the `&format!(...)` form
described above; each one removes an unnecessary static `&`, plus an
allocation when executed. There are also a few places where the existing
use of `&String` was more reasonable; these now just use `clone()` at
the call site.
As well as making the code nicer and more efficient, this is a step
towards possibly using `Cow<'static, str>` in
`{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing
the `From<&'a str>` impls to `From<&'static str>`, which is doable, but
I'm not yet sure if it's worthwhile.
2023-04-20 13:26:58 +10:00
|
|
|
format!(
|
2022-02-23 11:49:34 +01:00
|
|
|
"`{}` intrinsic: expected basic integer or raw pointer type, found `{:?}`",
|
|
|
|
intrinsic, ty
|
|
|
|
),
|
|
|
|
);
|
|
|
|
// Prevent verifier error
|
2022-08-24 18:40:58 +02:00
|
|
|
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
|
2020-07-03 16:52:37 +02:00
|
|
|
}
|
|
|
|
|
2023-04-29 12:00:43 +00:00
|
|
|
pub(crate) fn clif_vector_type<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> Type {
|
2021-08-29 11:06:55 +02:00
|
|
|
let (element, count) = match layout.abi {
|
|
|
|
Abi::Vector { element, count } => (element, count),
|
2020-03-27 16:41:05 +01:00
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
2023-04-29 12:00:43 +00:00
|
|
|
scalar_to_clif_type(tcx, element).by(u32::try_from(count).unwrap()).unwrap()
|
2020-03-27 16:41:05 +01:00
|
|
|
}
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
fn simd_for_each_lane<'tcx>(
|
|
|
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
2019-11-18 21:29:34 +01:00
|
|
|
val: CValue<'tcx>,
|
|
|
|
ret: CPlace<'tcx>,
|
2022-02-23 11:49:34 +01:00
|
|
|
f: &dyn Fn(&mut FunctionCx<'_, '_, 'tcx>, Ty<'tcx>, Ty<'tcx>, Value) -> Value,
|
2019-11-18 21:29:34 +01:00
|
|
|
) {
|
|
|
|
let layout = val.layout();
|
|
|
|
|
2020-12-27 10:30:38 +01:00
|
|
|
let (lane_count, lane_ty) = layout.ty.simd_size_and_type(fx.tcx);
|
|
|
|
let lane_layout = fx.layout_of(lane_ty);
|
|
|
|
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
|
|
|
|
let ret_lane_layout = fx.layout_of(ret_lane_ty);
|
2019-11-18 21:29:34 +01:00
|
|
|
assert_eq!(lane_count, ret_lane_count);
|
|
|
|
|
|
|
|
for lane_idx in 0..lane_count {
|
2021-08-06 16:26:56 +02:00
|
|
|
let lane = val.value_lane(fx, lane_idx).load_scalar(fx);
|
2019-11-18 21:29:34 +01:00
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
let res_lane = f(fx, lane_layout.ty, ret_lane_layout.ty, lane);
|
|
|
|
let res_lane = CValue::by_val(res_lane, ret_lane_layout);
|
2019-11-18 21:29:34 +01:00
|
|
|
|
2021-08-06 16:26:56 +02:00
|
|
|
ret.place_lane(fx, lane_idx).write_cvalue(fx, res_lane);
|
2019-11-18 21:29:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-23 16:22:55 +02:00
|
|
|
fn simd_pair_for_each_lane_typed<'tcx>(
|
|
|
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
|
|
|
x: CValue<'tcx>,
|
|
|
|
y: CValue<'tcx>,
|
|
|
|
ret: CPlace<'tcx>,
|
|
|
|
f: &dyn Fn(&mut FunctionCx<'_, '_, 'tcx>, CValue<'tcx>, CValue<'tcx>) -> CValue<'tcx>,
|
|
|
|
) {
|
|
|
|
assert_eq!(x.layout(), y.layout());
|
|
|
|
let layout = x.layout();
|
|
|
|
|
|
|
|
let (lane_count, _lane_ty) = layout.ty.simd_size_and_type(fx.tcx);
|
|
|
|
let (ret_lane_count, _ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
|
|
|
|
assert_eq!(lane_count, ret_lane_count);
|
|
|
|
|
|
|
|
for lane_idx in 0..lane_count {
|
|
|
|
let x_lane = x.value_lane(fx, lane_idx);
|
|
|
|
let y_lane = y.value_lane(fx, lane_idx);
|
|
|
|
|
|
|
|
let res_lane = f(fx, x_lane, y_lane);
|
|
|
|
|
|
|
|
ret.place_lane(fx, lane_idx).write_cvalue(fx, res_lane);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
fn simd_pair_for_each_lane<'tcx>(
|
|
|
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
2019-07-27 17:48:24 +02:00
|
|
|
x: CValue<'tcx>,
|
|
|
|
y: CValue<'tcx>,
|
|
|
|
ret: CPlace<'tcx>,
|
2022-02-23 11:49:34 +01:00
|
|
|
f: &dyn Fn(&mut FunctionCx<'_, '_, 'tcx>, Ty<'tcx>, Ty<'tcx>, Value, Value) -> Value,
|
2019-07-27 17:48:24 +02:00
|
|
|
) {
|
|
|
|
assert_eq!(x.layout(), y.layout());
|
|
|
|
let layout = x.layout();
|
|
|
|
|
2020-12-27 10:30:38 +01:00
|
|
|
let (lane_count, lane_ty) = layout.ty.simd_size_and_type(fx.tcx);
|
|
|
|
let lane_layout = fx.layout_of(lane_ty);
|
|
|
|
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
|
|
|
|
let ret_lane_layout = fx.layout_of(ret_lane_ty);
|
2019-07-27 17:48:24 +02:00
|
|
|
assert_eq!(lane_count, ret_lane_count);
|
|
|
|
|
2021-08-06 16:26:56 +02:00
|
|
|
for lane_idx in 0..lane_count {
|
|
|
|
let x_lane = x.value_lane(fx, lane_idx).load_scalar(fx);
|
|
|
|
let y_lane = y.value_lane(fx, lane_idx).load_scalar(fx);
|
2019-07-27 17:48:24 +02:00
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
let res_lane = f(fx, lane_layout.ty, ret_lane_layout.ty, x_lane, y_lane);
|
|
|
|
let res_lane = CValue::by_val(res_lane, ret_lane_layout);
|
2019-07-27 17:48:24 +02:00
|
|
|
|
2021-08-06 16:26:56 +02:00
|
|
|
ret.place_lane(fx, lane_idx).write_cvalue(fx, res_lane);
|
2019-07-27 17:48:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-10 11:30:51 +00:00
|
|
|
fn simd_horizontal_pair_for_each_lane<'tcx>(
|
|
|
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
|
|
|
x: CValue<'tcx>,
|
|
|
|
y: CValue<'tcx>,
|
|
|
|
ret: CPlace<'tcx>,
|
|
|
|
f: &dyn Fn(&mut FunctionCx<'_, '_, 'tcx>, Ty<'tcx>, Ty<'tcx>, Value, Value) -> Value,
|
|
|
|
) {
|
|
|
|
assert_eq!(x.layout(), y.layout());
|
|
|
|
let layout = x.layout();
|
|
|
|
|
|
|
|
let (lane_count, lane_ty) = layout.ty.simd_size_and_type(fx.tcx);
|
|
|
|
let lane_layout = fx.layout_of(lane_ty);
|
|
|
|
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
|
|
|
|
let ret_lane_layout = fx.layout_of(ret_lane_ty);
|
|
|
|
assert_eq!(lane_count, ret_lane_count);
|
|
|
|
|
|
|
|
for lane_idx in 0..lane_count {
|
|
|
|
let src = if lane_idx < (lane_count / 2) { x } else { y };
|
|
|
|
let src_idx = lane_idx % (lane_count / 2);
|
|
|
|
|
|
|
|
let lhs_lane = src.value_lane(fx, src_idx * 2).load_scalar(fx);
|
|
|
|
let rhs_lane = src.value_lane(fx, src_idx * 2 + 1).load_scalar(fx);
|
|
|
|
|
|
|
|
let res_lane = f(fx, lane_layout.ty, ret_lane_layout.ty, lhs_lane, rhs_lane);
|
|
|
|
let res_lane = CValue::by_val(res_lane, ret_lane_layout);
|
|
|
|
|
|
|
|
ret.place_lane(fx, lane_idx).write_cvalue(fx, res_lane);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn simd_trio_for_each_lane<'tcx>(
|
|
|
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
|
|
|
x: CValue<'tcx>,
|
|
|
|
y: CValue<'tcx>,
|
|
|
|
z: CValue<'tcx>,
|
|
|
|
ret: CPlace<'tcx>,
|
|
|
|
f: &dyn Fn(&mut FunctionCx<'_, '_, 'tcx>, Ty<'tcx>, Ty<'tcx>, Value, Value, Value) -> Value,
|
|
|
|
) {
|
|
|
|
assert_eq!(x.layout(), y.layout());
|
|
|
|
let layout = x.layout();
|
|
|
|
|
|
|
|
let (lane_count, lane_ty) = layout.ty.simd_size_and_type(fx.tcx);
|
|
|
|
let lane_layout = fx.layout_of(lane_ty);
|
|
|
|
let (ret_lane_count, ret_lane_ty) = ret.layout().ty.simd_size_and_type(fx.tcx);
|
|
|
|
let ret_lane_layout = fx.layout_of(ret_lane_ty);
|
|
|
|
assert_eq!(lane_count, ret_lane_count);
|
|
|
|
|
|
|
|
for lane_idx in 0..lane_count {
|
|
|
|
let x_lane = x.value_lane(fx, lane_idx).load_scalar(fx);
|
|
|
|
let y_lane = y.value_lane(fx, lane_idx).load_scalar(fx);
|
|
|
|
let z_lane = z.value_lane(fx, lane_idx).load_scalar(fx);
|
|
|
|
|
|
|
|
let res_lane = f(fx, lane_layout.ty, ret_lane_layout.ty, x_lane, y_lane, z_lane);
|
|
|
|
let res_lane = CValue::by_val(res_lane, ret_lane_layout);
|
|
|
|
|
|
|
|
ret.place_lane(fx, lane_idx).write_cvalue(fx, res_lane);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
fn simd_reduce<'tcx>(
|
|
|
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
2020-11-27 20:48:53 +01:00
|
|
|
val: CValue<'tcx>,
|
2021-08-06 16:26:56 +02:00
|
|
|
acc: Option<Value>,
|
2020-11-27 20:48:53 +01:00
|
|
|
ret: CPlace<'tcx>,
|
2022-02-23 11:49:34 +01:00
|
|
|
f: &dyn Fn(&mut FunctionCx<'_, '_, 'tcx>, Ty<'tcx>, Value, Value) -> Value,
|
2020-11-27 20:48:53 +01:00
|
|
|
) {
|
2020-12-27 10:30:38 +01:00
|
|
|
let (lane_count, lane_ty) = val.layout().ty.simd_size_and_type(fx.tcx);
|
|
|
|
let lane_layout = fx.layout_of(lane_ty);
|
2020-11-27 20:48:53 +01:00
|
|
|
assert_eq!(lane_layout, ret.layout());
|
|
|
|
|
2021-08-06 16:26:56 +02:00
|
|
|
let (mut res_val, start_lane) =
|
|
|
|
if let Some(acc) = acc { (acc, 0) } else { (val.value_lane(fx, 0).load_scalar(fx), 1) };
|
|
|
|
for lane_idx in start_lane..lane_count {
|
|
|
|
let lane = val.value_lane(fx, lane_idx).load_scalar(fx);
|
2022-02-23 11:49:34 +01:00
|
|
|
res_val = f(fx, lane_layout.ty, res_val, lane);
|
2020-11-27 20:48:53 +01:00
|
|
|
}
|
|
|
|
let res = CValue::by_val(res_val, lane_layout);
|
|
|
|
ret.write_cvalue(fx, res);
|
|
|
|
}
|
|
|
|
|
2021-08-06 16:26:56 +02:00
|
|
|
// FIXME move all uses to `simd_reduce`
|
2021-03-05 19:12:59 +01:00
|
|
|
fn simd_reduce_bool<'tcx>(
|
|
|
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
2020-11-27 20:48:53 +01:00
|
|
|
val: CValue<'tcx>,
|
|
|
|
ret: CPlace<'tcx>,
|
2022-02-23 11:49:34 +01:00
|
|
|
f: &dyn Fn(&mut FunctionCx<'_, '_, 'tcx>, Value, Value) -> Value,
|
2020-11-27 20:48:53 +01:00
|
|
|
) {
|
2020-12-27 10:30:38 +01:00
|
|
|
let (lane_count, _lane_ty) = val.layout().ty.simd_size_and_type(fx.tcx);
|
2020-11-27 20:48:53 +01:00
|
|
|
assert!(ret.layout().ty.is_bool());
|
|
|
|
|
2021-08-06 16:26:56 +02:00
|
|
|
let res_val = val.value_lane(fx, 0).load_scalar(fx);
|
2020-11-27 20:48:53 +01:00
|
|
|
let mut res_val = fx.bcx.ins().band_imm(res_val, 1); // mask to boolean
|
|
|
|
for lane_idx in 1..lane_count {
|
2021-08-06 16:26:56 +02:00
|
|
|
let lane = val.value_lane(fx, lane_idx).load_scalar(fx);
|
2020-11-27 20:48:53 +01:00
|
|
|
let lane = fx.bcx.ins().band_imm(lane, 1); // mask to boolean
|
|
|
|
res_val = f(fx, res_val, lane);
|
|
|
|
}
|
2021-08-06 16:26:56 +02:00
|
|
|
let res_val = if fx.bcx.func.dfg.value_type(res_val) != types::I8 {
|
|
|
|
fx.bcx.ins().ireduce(types::I8, res_val)
|
|
|
|
} else {
|
|
|
|
res_val
|
|
|
|
};
|
2020-11-27 20:48:53 +01:00
|
|
|
let res = CValue::by_val(res_val, ret.layout());
|
|
|
|
ret.write_cvalue(fx, res);
|
|
|
|
}
|
|
|
|
|
2019-11-18 20:45:32 +01:00
|
|
|
fn bool_to_zero_or_max_uint<'tcx>(
|
2021-03-05 19:12:59 +01:00
|
|
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
2022-02-23 11:49:34 +01:00
|
|
|
ty: Ty<'tcx>,
|
2019-07-28 09:45:01 +02:00
|
|
|
val: Value,
|
2022-02-23 11:49:34 +01:00
|
|
|
) -> Value {
|
|
|
|
let ty = fx.clif_type(ty).unwrap();
|
2019-07-28 09:45:01 +02:00
|
|
|
|
2019-07-30 14:37:20 +02:00
|
|
|
let int_ty = match ty {
|
|
|
|
types::F32 => types::I32,
|
|
|
|
types::F64 => types::I64,
|
|
|
|
ty => ty,
|
|
|
|
};
|
|
|
|
|
2022-12-14 19:30:46 +01:00
|
|
|
let mut res = fx.bcx.ins().bmask(int_ty, val);
|
2019-07-30 14:37:20 +02:00
|
|
|
|
|
|
|
if ty.is_float() {
|
2023-01-24 18:56:42 +01:00
|
|
|
res = codegen_bitcast(fx, ty, res);
|
2019-07-30 14:37:20 +02:00
|
|
|
}
|
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
res
|
2019-07-30 14:37:20 +02:00
|
|
|
}
|
|
|
|
|
2020-03-27 12:14:45 +01:00
|
|
|
pub(crate) fn codegen_intrinsic_call<'tcx>(
|
2021-03-05 19:12:59 +01:00
|
|
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
2019-09-21 11:30:29 +02:00
|
|
|
instance: Instance<'tcx>,
|
2024-01-12 08:21:42 +01:00
|
|
|
args: &[Spanned<mir::Operand<'tcx>>],
|
2022-04-16 09:27:54 -04:00
|
|
|
destination: CPlace<'tcx>,
|
|
|
|
target: Option<BasicBlock>,
|
2022-05-15 12:32:19 +02:00
|
|
|
source_info: mir::SourceInfo,
|
2024-01-31 20:39:59 +00:00
|
|
|
) -> Result<(), Instance<'tcx>> {
|
2021-10-12 05:06:37 +00:00
|
|
|
let intrinsic = fx.tcx.item_name(instance.def_id());
|
2023-07-11 22:35:29 +01:00
|
|
|
let instance_args = instance.args;
|
2019-09-21 11:30:29 +02:00
|
|
|
|
2021-04-30 14:49:58 +02:00
|
|
|
if intrinsic.as_str().starts_with("simd_") {
|
2022-04-16 09:27:54 -04:00
|
|
|
self::simd::codegen_simd_intrinsic_call(
|
|
|
|
fx,
|
|
|
|
intrinsic,
|
2023-07-11 22:35:29 +01:00
|
|
|
instance_args,
|
2022-04-16 09:27:54 -04:00
|
|
|
args,
|
|
|
|
destination,
|
2023-02-09 12:38:16 +01:00
|
|
|
target.expect("target for simd intrinsic"),
|
2022-04-16 09:27:54 -04:00
|
|
|
source_info.span,
|
|
|
|
);
|
|
|
|
} else if codegen_float_intrinsic_call(fx, intrinsic, args, destination) {
|
2023-02-09 12:38:16 +01:00
|
|
|
let ret_block = fx.get_block(target.expect("target for float intrinsic"));
|
2022-02-23 11:49:34 +01:00
|
|
|
fx.bcx.ins().jump(ret_block, &[]);
|
|
|
|
} else {
|
|
|
|
codegen_regular_intrinsic_call(
|
|
|
|
fx,
|
|
|
|
instance,
|
|
|
|
intrinsic,
|
2023-07-11 22:35:29 +01:00
|
|
|
instance_args,
|
2022-02-23 11:49:34 +01:00
|
|
|
args,
|
|
|
|
destination,
|
2023-02-09 12:38:16 +01:00
|
|
|
target,
|
2022-04-16 09:27:54 -04:00
|
|
|
source_info,
|
2024-01-31 14:29:12 +00:00
|
|
|
)?;
|
2019-11-18 20:58:33 +01:00
|
|
|
}
|
2024-01-31 14:29:12 +00:00
|
|
|
Ok(())
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
2019-11-18 20:58:33 +01:00
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
fn codegen_float_intrinsic_call<'tcx>(
|
|
|
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
|
|
|
intrinsic: Symbol,
|
2024-01-12 08:21:42 +01:00
|
|
|
args: &[Spanned<mir::Operand<'tcx>>],
|
2022-02-23 11:49:34 +01:00
|
|
|
ret: CPlace<'tcx>,
|
|
|
|
) -> bool {
|
2023-03-15 14:41:48 +00:00
|
|
|
let (name, arg_count, ty, clif_ty) = match intrinsic {
|
|
|
|
sym::expf32 => ("expf", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::expf64 => ("exp", 1, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::exp2f32 => ("exp2f", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::exp2f64 => ("exp2", 1, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::sqrtf32 => ("sqrtf", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::sqrtf64 => ("sqrt", 1, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::powif32 => ("__powisf2", 2, fx.tcx.types.f32, types::F32), // compiler-builtins
|
|
|
|
sym::powif64 => ("__powidf2", 2, fx.tcx.types.f64, types::F64), // compiler-builtins
|
|
|
|
sym::powf32 => ("powf", 2, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::powf64 => ("pow", 2, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::logf32 => ("logf", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::logf64 => ("log", 1, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::log2f32 => ("log2f", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::log2f64 => ("log2", 1, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::log10f32 => ("log10f", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::log10f64 => ("log10", 1, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::fabsf32 => ("fabsf", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::fabsf64 => ("fabs", 1, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::fmaf32 => ("fmaf", 3, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::fmaf64 => ("fma", 3, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::copysignf32 => ("copysignf", 2, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::copysignf64 => ("copysign", 2, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::floorf32 => ("floorf", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::floorf64 => ("floor", 1, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::ceilf32 => ("ceilf", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::ceilf64 => ("ceil", 1, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::truncf32 => ("truncf", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::truncf64 => ("trunc", 1, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::rintf32 => ("rintf", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::rintf64 => ("rint", 1, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::roundf32 => ("roundf", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::roundf64 => ("round", 1, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::roundevenf32 => ("roundevenf", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::roundevenf64 => ("roundeven", 1, fx.tcx.types.f64, types::F64),
|
2024-03-26 10:18:44 +00:00
|
|
|
sym::nearbyintf32 => ("nearbyintf", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::nearbyintf64 => ("nearbyint", 1, fx.tcx.types.f64, types::F64),
|
2023-03-15 14:41:48 +00:00
|
|
|
sym::sinf32 => ("sinf", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::sinf64 => ("sin", 1, fx.tcx.types.f64, types::F64),
|
|
|
|
sym::cosf32 => ("cosf", 1, fx.tcx.types.f32, types::F32),
|
|
|
|
sym::cosf64 => ("cos", 1, fx.tcx.types.f64, types::F64),
|
2022-02-23 11:49:34 +01:00
|
|
|
_ => return false,
|
|
|
|
};
|
2018-10-03 18:21:52 +02:00
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
if args.len() != arg_count {
|
|
|
|
bug!("wrong number of args for intrinsic {:?}", intrinsic);
|
2019-07-27 16:51:48 +02:00
|
|
|
}
|
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
let (a, b, c);
|
|
|
|
let args = match args {
|
|
|
|
[x] => {
|
2024-01-12 08:21:42 +01:00
|
|
|
a = [codegen_operand(fx, &x.node).load_scalar(fx)];
|
2022-02-23 11:49:34 +01:00
|
|
|
&a as &[_]
|
|
|
|
}
|
|
|
|
[x, y] => {
|
2024-01-12 08:21:42 +01:00
|
|
|
b = [
|
|
|
|
codegen_operand(fx, &x.node).load_scalar(fx),
|
|
|
|
codegen_operand(fx, &y.node).load_scalar(fx),
|
|
|
|
];
|
2022-02-23 11:49:34 +01:00
|
|
|
&b
|
|
|
|
}
|
|
|
|
[x, y, z] => {
|
2023-03-15 14:41:48 +00:00
|
|
|
c = [
|
2024-01-12 08:21:42 +01:00
|
|
|
codegen_operand(fx, &x.node).load_scalar(fx),
|
|
|
|
codegen_operand(fx, &y.node).load_scalar(fx),
|
|
|
|
codegen_operand(fx, &z.node).load_scalar(fx),
|
2023-03-15 14:41:48 +00:00
|
|
|
];
|
2022-02-23 11:49:34 +01:00
|
|
|
&c
|
|
|
|
}
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
2022-08-24 18:40:58 +02:00
|
|
|
let layout = fx.layout_of(ty);
|
|
|
|
let res = match intrinsic {
|
|
|
|
sym::fmaf32 | sym::fmaf64 => {
|
2023-03-15 14:41:48 +00:00
|
|
|
CValue::by_val(fx.bcx.ins().fma(args[0], args[1], args[2]), layout)
|
2022-08-24 18:40:58 +02:00
|
|
|
}
|
|
|
|
sym::copysignf32 | sym::copysignf64 => {
|
2023-03-15 14:41:48 +00:00
|
|
|
CValue::by_val(fx.bcx.ins().fcopysign(args[0], args[1]), layout)
|
2022-08-24 18:40:58 +02:00
|
|
|
}
|
|
|
|
sym::fabsf32
|
|
|
|
| sym::fabsf64
|
|
|
|
| sym::floorf32
|
|
|
|
| sym::floorf64
|
|
|
|
| sym::ceilf32
|
|
|
|
| sym::ceilf64
|
|
|
|
| sym::truncf32
|
2024-03-08 20:41:29 +00:00
|
|
|
| sym::truncf64
|
2024-03-26 10:18:44 +00:00
|
|
|
| sym::nearbyintf32
|
|
|
|
| sym::nearbyintf64
|
2024-03-08 20:41:29 +00:00
|
|
|
| sym::sqrtf32
|
|
|
|
| sym::sqrtf64 => {
|
2022-08-24 18:40:58 +02:00
|
|
|
let val = match intrinsic {
|
2023-03-15 14:41:48 +00:00
|
|
|
sym::fabsf32 | sym::fabsf64 => fx.bcx.ins().fabs(args[0]),
|
|
|
|
sym::floorf32 | sym::floorf64 => fx.bcx.ins().floor(args[0]),
|
|
|
|
sym::ceilf32 | sym::ceilf64 => fx.bcx.ins().ceil(args[0]),
|
|
|
|
sym::truncf32 | sym::truncf64 => fx.bcx.ins().trunc(args[0]),
|
2024-03-26 10:18:44 +00:00
|
|
|
sym::nearbyintf32 | sym::nearbyintf64 => fx.bcx.ins().nearest(args[0]),
|
2024-03-08 20:41:29 +00:00
|
|
|
sym::sqrtf32 | sym::sqrtf64 => fx.bcx.ins().sqrt(args[0]),
|
2022-08-24 18:40:58 +02:00
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
|
|
|
|
|
|
|
CValue::by_val(val, layout)
|
|
|
|
}
|
2023-03-15 14:41:48 +00:00
|
|
|
|
2022-08-24 18:40:58 +02:00
|
|
|
// These intrinsics aren't supported natively by Cranelift.
|
|
|
|
// Lower them to a libcall.
|
2023-03-15 14:41:48 +00:00
|
|
|
sym::powif32 | sym::powif64 => {
|
|
|
|
let input_tys: Vec<_> = vec![AbiParam::new(clif_ty), AbiParam::new(types::I32)];
|
|
|
|
let ret_val = fx.lib_call(name, input_tys, vec![AbiParam::new(clif_ty)], &args)[0];
|
|
|
|
CValue::by_val(ret_val, fx.layout_of(ty))
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
let input_tys: Vec<_> = args.iter().map(|_| AbiParam::new(clif_ty)).collect();
|
|
|
|
let ret_val = fx.lib_call(name, input_tys, vec![AbiParam::new(clif_ty)], &args)[0];
|
|
|
|
CValue::by_val(ret_val, fx.layout_of(ty))
|
|
|
|
}
|
2022-08-24 18:40:58 +02:00
|
|
|
};
|
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
ret.write_cvalue(fx, res);
|
|
|
|
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
fn codegen_regular_intrinsic_call<'tcx>(
|
|
|
|
fx: &mut FunctionCx<'_, '_, 'tcx>,
|
|
|
|
instance: Instance<'tcx>,
|
|
|
|
intrinsic: Symbol,
|
2023-07-11 22:35:29 +01:00
|
|
|
generic_args: GenericArgsRef<'tcx>,
|
2024-01-12 08:21:42 +01:00
|
|
|
args: &[Spanned<mir::Operand<'tcx>>],
|
2022-02-23 11:49:34 +01:00
|
|
|
ret: CPlace<'tcx>,
|
2022-04-16 09:27:54 -04:00
|
|
|
destination: Option<BasicBlock>,
|
2022-05-15 12:32:19 +02:00
|
|
|
source_info: mir::SourceInfo,
|
2024-01-31 20:39:59 +00:00
|
|
|
) -> Result<(), Instance<'tcx>> {
|
2024-01-31 14:29:12 +00:00
|
|
|
assert_eq!(generic_args, instance.args);
|
2022-02-23 11:49:34 +01:00
|
|
|
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
|
|
|
|
2022-07-26 18:53:46 +02:00
|
|
|
match intrinsic {
|
2023-02-09 12:38:16 +01:00
|
|
|
sym::abort => {
|
|
|
|
fx.bcx.ins().trap(TrapCode::User(0));
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2023-02-09 12:38:16 +01:00
|
|
|
}
|
2022-07-26 18:53:46 +02:00
|
|
|
sym::likely | sym::unlikely => {
|
|
|
|
intrinsic_args!(fx, args => (a); intrinsic);
|
2018-10-05 19:55:06 +02:00
|
|
|
|
|
|
|
ret.write_cvalue(fx, a);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::breakpoint => {
|
|
|
|
intrinsic_args!(fx, args => (); intrinsic);
|
|
|
|
|
2019-02-11 18:49:59 +01:00
|
|
|
fx.bcx.ins().debugtrap();
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
2023-03-15 14:41:48 +00:00
|
|
|
sym::copy => {
|
2022-07-26 18:53:46 +02:00
|
|
|
intrinsic_args!(fx, args => (src, dst, count); intrinsic);
|
|
|
|
let src = src.load_scalar(fx);
|
|
|
|
let dst = dst.load_scalar(fx);
|
|
|
|
let count = count.load_scalar(fx);
|
|
|
|
|
2023-07-11 22:35:29 +01:00
|
|
|
let elem_ty = generic_args.type_at(0);
|
2018-10-03 18:21:52 +02:00
|
|
|
let elem_size: u64 = fx.layout_of(elem_ty).size.bytes();
|
|
|
|
assert_eq!(args.len(), 3);
|
2022-07-26 18:53:46 +02:00
|
|
|
let byte_amount =
|
|
|
|
if elem_size != 1 { fx.bcx.ins().imul_imm(count, elem_size as i64) } else { count };
|
2018-10-03 18:21:52 +02:00
|
|
|
|
2023-03-15 14:41:48 +00:00
|
|
|
// FIXME emit_small_memmove
|
|
|
|
fx.bcx.call_memmove(fx.target_config, dst, src, byte_amount);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::volatile_copy_memory | sym::volatile_copy_nonoverlapping_memory => {
|
|
|
|
// NOTE: the volatile variants have src and dst swapped
|
|
|
|
intrinsic_args!(fx, args => (dst, src, count); intrinsic);
|
|
|
|
let dst = dst.load_scalar(fx);
|
|
|
|
let src = src.load_scalar(fx);
|
|
|
|
let count = count.load_scalar(fx);
|
|
|
|
|
2023-07-11 22:35:29 +01:00
|
|
|
let elem_ty = generic_args.type_at(0);
|
2020-05-01 17:28:45 +02:00
|
|
|
let elem_size: u64 = fx.layout_of(elem_ty).size.bytes();
|
|
|
|
assert_eq!(args.len(), 3);
|
2022-07-26 18:53:46 +02:00
|
|
|
let byte_amount =
|
|
|
|
if elem_size != 1 { fx.bcx.ins().imul_imm(count, elem_size as i64) } else { count };
|
2020-05-01 17:28:45 +02:00
|
|
|
|
|
|
|
// FIXME make the copy actually volatile when using emit_small_mem{cpy,move}
|
2021-04-30 14:49:58 +02:00
|
|
|
if intrinsic == sym::volatile_copy_nonoverlapping_memory {
|
2020-01-04 12:33:39 +01:00
|
|
|
// FIXME emit_small_memcpy
|
2021-12-20 18:56:35 +01:00
|
|
|
fx.bcx.call_memcpy(fx.target_config, dst, src, byte_amount);
|
2018-10-03 18:21:52 +02:00
|
|
|
} else {
|
2020-01-04 12:33:39 +01:00
|
|
|
// FIXME emit_small_memmove
|
2021-12-20 18:56:35 +01:00
|
|
|
fx.bcx.call_memmove(fx.target_config, dst, src, byte_amount);
|
2018-10-03 18:21:52 +02:00
|
|
|
}
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::size_of_val => {
|
|
|
|
intrinsic_args!(fx, args => (ptr); intrinsic);
|
|
|
|
|
2023-07-11 22:35:29 +01:00
|
|
|
let layout = fx.layout_of(generic_args.type_at(0));
|
2022-07-25 16:07:57 +02:00
|
|
|
// Note: Can't use is_unsized here as truly unsized types need to take the fixed size
|
|
|
|
// branch
|
2023-12-19 12:46:39 +00:00
|
|
|
let meta = if let Abi::ScalarPair(_, _) = ptr.layout().abi {
|
|
|
|
Some(ptr.load_scalar_pair(fx).1)
|
2018-12-29 15:33:34 +01:00
|
|
|
} else {
|
2023-12-19 12:46:39 +00:00
|
|
|
None
|
2018-10-03 18:21:52 +02:00
|
|
|
};
|
2023-12-19 12:46:39 +00:00
|
|
|
let (size, _align) = crate::unsize::size_and_align_of(fx, layout, meta);
|
2019-06-11 16:25:07 +02:00
|
|
|
ret.write_cvalue(fx, CValue::by_val(size, usize_layout));
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::min_align_of_val => {
|
|
|
|
intrinsic_args!(fx, args => (ptr); intrinsic);
|
|
|
|
|
2023-07-11 22:35:29 +01:00
|
|
|
let layout = fx.layout_of(generic_args.type_at(0));
|
2022-07-25 16:07:57 +02:00
|
|
|
// Note: Can't use is_unsized here as truly unsized types need to take the fixed size
|
|
|
|
// branch
|
2023-12-19 12:46:39 +00:00
|
|
|
let meta = if let Abi::ScalarPair(_, _) = ptr.layout().abi {
|
|
|
|
Some(ptr.load_scalar_pair(fx).1)
|
2018-12-29 15:33:34 +01:00
|
|
|
} else {
|
2023-12-19 12:46:39 +00:00
|
|
|
None
|
2018-10-03 18:21:52 +02:00
|
|
|
};
|
2023-12-19 12:46:39 +00:00
|
|
|
let (_size, align) = crate::unsize::size_and_align_of(fx, layout, meta);
|
2019-06-11 16:25:07 +02:00
|
|
|
ret.write_cvalue(fx, CValue::by_val(align, usize_layout));
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sym::vtable_size => {
|
|
|
|
intrinsic_args!(fx, args => (vtable); intrinsic);
|
|
|
|
let vtable = vtable.load_scalar(fx);
|
2019-06-23 16:33:34 +02:00
|
|
|
|
2022-07-20 13:36:58 +00:00
|
|
|
let size = crate::vtable::size_of_obj(fx, vtable);
|
|
|
|
ret.write_cvalue(fx, CValue::by_val(size, usize_layout));
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sym::vtable_align => {
|
|
|
|
intrinsic_args!(fx, args => (vtable); intrinsic);
|
|
|
|
let vtable = vtable.load_scalar(fx);
|
2022-07-20 13:36:58 +00:00
|
|
|
|
|
|
|
let align = crate::vtable::min_align_of_obj(fx, vtable);
|
|
|
|
ret.write_cvalue(fx, CValue::by_val(align, usize_layout));
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
2023-06-03 02:38:22 -07:00
|
|
|
sym::exact_div => {
|
2022-07-26 18:53:46 +02:00
|
|
|
intrinsic_args!(fx, args => (x, y); intrinsic);
|
2022-07-20 13:36:58 +00:00
|
|
|
|
2023-06-03 02:38:22 -07:00
|
|
|
// FIXME trap on inexact
|
|
|
|
let res = crate::num::codegen_int_binop(fx, BinOp::Div, x, y);
|
2018-10-03 18:21:52 +02:00
|
|
|
ret.write_cvalue(fx, res);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::saturating_add | sym::saturating_sub => {
|
|
|
|
intrinsic_args!(fx, args => (lhs, rhs); intrinsic);
|
|
|
|
|
2019-08-20 10:40:08 +02:00
|
|
|
assert_eq!(lhs.layout().ty, rhs.layout().ty);
|
2019-03-04 18:57:09 +01:00
|
|
|
let bin_op = match intrinsic {
|
2021-04-30 14:49:58 +02:00
|
|
|
sym::saturating_add => BinOp::Add,
|
|
|
|
sym::saturating_sub => BinOp::Sub,
|
|
|
|
_ => unreachable!(),
|
2019-03-04 18:57:09 +01:00
|
|
|
};
|
2019-08-08 15:54:13 +02:00
|
|
|
|
2022-10-23 16:22:55 +02:00
|
|
|
let res = crate::num::codegen_saturating_int_binop(fx, bin_op, lhs, rhs);
|
2019-03-04 18:57:09 +01:00
|
|
|
ret.write_cvalue(fx, res);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::rotate_left => {
|
|
|
|
intrinsic_args!(fx, args => (x, y); intrinsic);
|
|
|
|
let y = y.load_scalar(fx);
|
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
let layout = x.layout();
|
|
|
|
let x = x.load_scalar(fx);
|
2018-11-16 19:50:02 +01:00
|
|
|
let res = fx.bcx.ins().rotl(x, y);
|
2019-06-11 16:25:07 +02:00
|
|
|
ret.write_cvalue(fx, CValue::by_val(res, layout));
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::rotate_right => {
|
|
|
|
intrinsic_args!(fx, args => (x, y); intrinsic);
|
|
|
|
let y = y.load_scalar(fx);
|
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
let layout = x.layout();
|
|
|
|
let x = x.load_scalar(fx);
|
2018-11-16 19:50:02 +01:00
|
|
|
let res = fx.bcx.ins().rotr(x, y);
|
2019-06-11 16:25:07 +02:00
|
|
|
ret.write_cvalue(fx, CValue::by_val(res, layout));
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
2019-02-16 13:49:42 +01:00
|
|
|
|
|
|
|
// The only difference between offset and arith_offset is regarding UB. Because Cranelift
|
|
|
|
// doesn't have UB both are codegen'ed the same way
|
2023-04-25 12:10:55 -07:00
|
|
|
sym::arith_offset => {
|
2022-07-26 18:53:46 +02:00
|
|
|
intrinsic_args!(fx, args => (base, offset); intrinsic);
|
|
|
|
let offset = offset.load_scalar(fx);
|
|
|
|
|
2024-05-09 22:45:14 -04:00
|
|
|
let pointee_ty = base.layout().ty.builtin_deref(true).unwrap();
|
2019-02-11 18:49:59 +01:00
|
|
|
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
|
2020-11-27 20:48:53 +01:00
|
|
|
let ptr_diff = if pointee_size != 1 {
|
|
|
|
fx.bcx.ins().imul_imm(offset, pointee_size as i64)
|
|
|
|
} else {
|
|
|
|
offset
|
|
|
|
};
|
2019-02-11 18:49:59 +01:00
|
|
|
let base_val = base.load_scalar(fx);
|
|
|
|
let res = fx.bcx.ins().iadd(base_val, ptr_diff);
|
2019-07-28 11:24:33 +02:00
|
|
|
ret.write_cvalue(fx, CValue::by_val(res, base.layout()));
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
2022-05-11 17:52:00 +04:00
|
|
|
sym::ptr_mask => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, mask); intrinsic);
|
2022-08-07 22:32:26 +04:00
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
let mask = mask.load_scalar(fx);
|
2022-05-11 21:43:13 +04:00
|
|
|
fx.bcx.ins().band(ptr, mask);
|
2022-05-11 17:52:00 +04:00
|
|
|
}
|
|
|
|
|
2022-07-26 18:53:46 +02:00
|
|
|
sym::write_bytes | sym::volatile_set_memory => {
|
|
|
|
intrinsic_args!(fx, args => (dst, val, count); intrinsic);
|
|
|
|
let val = val.load_scalar(fx);
|
|
|
|
let count = count.load_scalar(fx);
|
|
|
|
|
2024-05-09 22:45:14 -04:00
|
|
|
let pointee_ty = dst.layout().ty.builtin_deref(true).unwrap();
|
2019-02-16 13:49:42 +01:00
|
|
|
let pointee_size = fx.layout_of(pointee_ty).size.bytes();
|
2020-11-27 20:48:53 +01:00
|
|
|
let count = if pointee_size != 1 {
|
|
|
|
fx.bcx.ins().imul_imm(count, pointee_size as i64)
|
|
|
|
} else {
|
|
|
|
count
|
|
|
|
};
|
2019-02-16 13:49:42 +01:00
|
|
|
let dst_ptr = dst.load_scalar(fx);
|
2020-05-01 17:28:45 +02:00
|
|
|
// FIXME make the memset actually volatile when switching to emit_small_memset
|
|
|
|
// FIXME use emit_small_memset
|
2021-12-20 18:56:35 +01:00
|
|
|
fx.bcx.call_memset(fx.target_config, dst_ptr, val, count);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::ctlz | sym::ctlz_nonzero => {
|
|
|
|
intrinsic_args!(fx, args => (arg); intrinsic);
|
2022-02-23 11:49:34 +01:00
|
|
|
let val = arg.load_scalar(fx);
|
2022-07-26 18:53:46 +02:00
|
|
|
|
2019-08-13 11:46:59 +02:00
|
|
|
// FIXME trap on `ctlz_nonzero` with zero arg.
|
2022-02-23 11:49:34 +01:00
|
|
|
let res = fx.bcx.ins().clz(val);
|
2024-04-19 18:45:25 +00:00
|
|
|
let res = clif_intcast(fx, res, types::I32, false);
|
|
|
|
let res = CValue::by_val(res, ret.layout());
|
2018-10-03 18:21:52 +02:00
|
|
|
ret.write_cvalue(fx, res);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::cttz | sym::cttz_nonzero => {
|
|
|
|
intrinsic_args!(fx, args => (arg); intrinsic);
|
2022-02-23 11:49:34 +01:00
|
|
|
let val = arg.load_scalar(fx);
|
2022-07-26 18:53:46 +02:00
|
|
|
|
2019-08-13 11:46:59 +02:00
|
|
|
// FIXME trap on `cttz_nonzero` with zero arg.
|
2022-02-23 11:49:34 +01:00
|
|
|
let res = fx.bcx.ins().ctz(val);
|
2024-04-19 18:45:25 +00:00
|
|
|
let res = clif_intcast(fx, res, types::I32, false);
|
|
|
|
let res = CValue::by_val(res, ret.layout());
|
2018-10-03 18:21:52 +02:00
|
|
|
ret.write_cvalue(fx, res);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::ctpop => {
|
|
|
|
intrinsic_args!(fx, args => (arg); intrinsic);
|
2022-02-23 11:49:34 +01:00
|
|
|
let val = arg.load_scalar(fx);
|
2022-07-26 18:53:46 +02:00
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
let res = fx.bcx.ins().popcnt(val);
|
2024-04-19 18:45:25 +00:00
|
|
|
let res = clif_intcast(fx, res, types::I32, false);
|
|
|
|
let res = CValue::by_val(res, ret.layout());
|
2018-10-03 18:21:52 +02:00
|
|
|
ret.write_cvalue(fx, res);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::bitreverse => {
|
|
|
|
intrinsic_args!(fx, args => (arg); intrinsic);
|
2022-02-23 11:49:34 +01:00
|
|
|
let val = arg.load_scalar(fx);
|
2022-07-26 18:53:46 +02:00
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
let res = fx.bcx.ins().bitrev(val);
|
|
|
|
let res = CValue::by_val(res, arg.layout());
|
2018-10-03 18:21:52 +02:00
|
|
|
ret.write_cvalue(fx, res);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::bswap => {
|
|
|
|
intrinsic_args!(fx, args => (arg); intrinsic);
|
2022-02-23 11:49:34 +01:00
|
|
|
let val = arg.load_scalar(fx);
|
2022-07-26 18:53:46 +02:00
|
|
|
|
2022-12-14 19:30:46 +01:00
|
|
|
let res = if fx.bcx.func.dfg.value_type(val) == types::I8 {
|
|
|
|
val
|
|
|
|
} else {
|
|
|
|
fx.bcx.ins().bswap(val)
|
|
|
|
};
|
|
|
|
let res = CValue::by_val(res, arg.layout());
|
2018-11-17 18:52:47 +01:00
|
|
|
ret.write_cvalue(fx, res);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
2022-12-12 15:47:32 +01:00
|
|
|
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_mem_uninitialized_valid => {
|
2022-07-26 18:53:46 +02:00
|
|
|
intrinsic_args!(fx, args => (); intrinsic);
|
|
|
|
|
2023-07-11 22:35:29 +01:00
|
|
|
let ty = generic_args.type_at(0);
|
2020-03-12 21:04:00 +01:00
|
|
|
|
2023-02-26 21:50:19 +00:00
|
|
|
let requirement = ValidityRequirement::from_intrinsic(intrinsic);
|
2020-03-12 21:04:00 +01:00
|
|
|
|
2023-02-26 21:50:19 +00:00
|
|
|
if let Some(requirement) = requirement {
|
|
|
|
let do_panic = !fx
|
2023-02-14 00:59:40 +00:00
|
|
|
.tcx
|
2023-02-26 21:50:19 +00:00
|
|
|
.check_validity_requirement((requirement, fx.param_env().and(ty)))
|
|
|
|
.expect("expect to have layout during codegen");
|
|
|
|
|
|
|
|
if do_panic {
|
|
|
|
let layout = fx.layout_of(ty);
|
2023-03-15 14:41:48 +00:00
|
|
|
let msg_str = with_no_visible_paths!({
|
|
|
|
with_no_trimmed_paths!({
|
|
|
|
if layout.abi.is_uninhabited() {
|
|
|
|
// Use this error even for the other intrinsics as it is more precise.
|
|
|
|
format!("attempted to instantiate uninhabited type `{}`", ty)
|
|
|
|
} else if intrinsic == sym::assert_zero_valid {
|
2023-02-26 21:50:19 +00:00
|
|
|
format!(
|
|
|
|
"attempted to zero-initialize type `{}`, which is invalid",
|
2023-03-15 14:41:48 +00:00
|
|
|
ty
|
2023-02-26 21:50:19 +00:00
|
|
|
)
|
|
|
|
} else {
|
|
|
|
format!(
|
|
|
|
"attempted to leave type `{}` uninitialized, which is invalid",
|
2023-03-15 14:41:48 +00:00
|
|
|
ty
|
2023-02-26 21:50:19 +00:00
|
|
|
)
|
2023-03-15 14:41:48 +00:00
|
|
|
}
|
|
|
|
})
|
2023-02-26 21:50:19 +00:00
|
|
|
});
|
2023-12-19 12:46:39 +00:00
|
|
|
crate::base::codegen_panic_nounwind(fx, &msg_str, Some(source_info.span));
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2023-02-26 21:50:19 +00:00
|
|
|
}
|
2019-01-06 15:27:20 +01:00
|
|
|
}
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sym::volatile_load | sym::unaligned_volatile_load => {
|
|
|
|
intrinsic_args!(fx, args => (ptr); intrinsic);
|
2018-10-06 10:24:09 +02:00
|
|
|
|
2019-06-23 16:33:34 +02:00
|
|
|
// Cranelift treats loads as volatile by default
|
2020-07-23 12:37:27 +02:00
|
|
|
// FIXME correctly handle unaligned_volatile_load
|
2024-05-09 22:45:14 -04:00
|
|
|
let inner_layout = fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap());
|
2019-12-20 16:02:47 +01:00
|
|
|
let val = CValue::by_ref(Pointer::new(ptr.load_scalar(fx)), inner_layout);
|
2019-06-23 16:33:34 +02:00
|
|
|
ret.write_cvalue(fx, val);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
2023-07-22 13:32:34 +00:00
|
|
|
sym::volatile_store | sym::unaligned_volatile_store | sym::nontemporal_store => {
|
2022-07-26 18:53:46 +02:00
|
|
|
intrinsic_args!(fx, args => (ptr, val); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2019-06-23 16:33:34 +02:00
|
|
|
// Cranelift treats stores as volatile by default
|
2020-07-23 12:37:27 +02:00
|
|
|
// FIXME correctly handle unaligned_volatile_store
|
2023-07-22 13:32:34 +00:00
|
|
|
// FIXME actually do nontemporal stores if requested
|
2019-12-20 16:02:47 +01:00
|
|
|
let dest = CPlace::for_ptr(Pointer::new(ptr), val.layout());
|
2019-06-23 16:33:34 +02:00
|
|
|
dest.write_cvalue(fx, val);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sym::pref_align_of
|
|
|
|
| sym::needs_drop
|
|
|
|
| sym::type_id
|
|
|
|
| sym::type_name
|
|
|
|
| sym::variant_count => {
|
|
|
|
intrinsic_args!(fx, args => (); intrinsic);
|
2019-06-23 16:33:34 +02:00
|
|
|
|
2024-03-14 09:10:28 +00:00
|
|
|
let const_val = fx
|
|
|
|
.tcx
|
|
|
|
.const_eval_instance(ParamEnv::reveal_all(), instance, source_info.span)
|
|
|
|
.unwrap();
|
2022-07-26 18:53:46 +02:00
|
|
|
let val = crate::constant::codegen_const_value(fx, const_val, ret.layout().ty);
|
2019-09-21 11:30:29 +02:00
|
|
|
ret.write_cvalue(fx, val);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
2019-09-21 11:30:29 +02:00
|
|
|
|
2022-07-26 18:53:46 +02:00
|
|
|
sym::ptr_offset_from | sym::ptr_offset_from_unsigned => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, base); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
let base = base.load_scalar(fx);
|
2023-07-11 22:35:29 +01:00
|
|
|
let ty = generic_args.type_at(0);
|
2019-11-09 11:14:18 +01:00
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
let pointee_size: u64 = fx.layout_of(ty).size.bytes();
|
2022-04-09 01:27:47 -07:00
|
|
|
let diff_bytes = fx.bcx.ins().isub(ptr, base);
|
2019-11-09 11:14:18 +01:00
|
|
|
// FIXME this can be an exact division.
|
2022-05-15 12:32:19 +02:00
|
|
|
let val = if intrinsic == sym::ptr_offset_from_unsigned {
|
|
|
|
let usize_layout = fx.layout_of(fx.tcx.types.usize);
|
2022-04-09 14:14:35 -07:00
|
|
|
// Because diff_bytes ULE isize::MAX, this would be fine as signed,
|
2022-04-09 01:27:47 -07:00
|
|
|
// but unsigned is slightly easier to codegen, so might as well.
|
2022-05-15 12:32:19 +02:00
|
|
|
CValue::by_val(fx.bcx.ins().udiv_imm(diff_bytes, pointee_size as i64), usize_layout)
|
2022-04-09 01:27:47 -07:00
|
|
|
} else {
|
2022-05-15 12:32:19 +02:00
|
|
|
let isize_layout = fx.layout_of(fx.tcx.types.isize);
|
|
|
|
CValue::by_val(fx.bcx.ins().sdiv_imm(diff_bytes, pointee_size as i64), isize_layout)
|
2022-04-09 01:27:47 -07:00
|
|
|
};
|
2019-11-09 11:14:18 +01:00
|
|
|
ret.write_cvalue(fx, val);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sym::caller_location => {
|
|
|
|
intrinsic_args!(fx, args => (); intrinsic);
|
2020-06-27 11:29:39 +02:00
|
|
|
|
2022-05-15 12:32:19 +02:00
|
|
|
let caller_location = fx.get_caller_location(source_info);
|
2019-11-09 11:14:18 +01:00
|
|
|
ret.write_cvalue(fx, caller_location);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_fence") => {
|
|
|
|
intrinsic_args!(fx, args => (); intrinsic);
|
2019-11-09 11:14:18 +01:00
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
fx.bcx.ins().fence();
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_singlethreadfence") => {
|
|
|
|
intrinsic_args!(fx, args => (); intrinsic);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
// FIXME use a compiler fence once Cranelift supports it
|
|
|
|
fx.bcx.ins().fence();
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_load") => {
|
|
|
|
intrinsic_args!(fx, args => (ptr); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2023-07-11 22:35:29 +01:00
|
|
|
let ty = generic_args.type_at(0);
|
2022-02-23 11:49:34 +01:00
|
|
|
match ty.kind() {
|
2022-03-20 16:55:21 +01:00
|
|
|
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
|
|
|
|
// FIXME implement 128bit atomics
|
|
|
|
if fx.tcx.is_compiler_builtins(LOCAL_CRATE) {
|
|
|
|
// special case for compiler-builtins to avoid having to patch it
|
|
|
|
crate::trap::trap_unimplemented(fx, "128bit atomics not yet supported");
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-03-20 16:55:21 +01:00
|
|
|
} else {
|
2022-07-26 18:53:46 +02:00
|
|
|
fx.tcx
|
2023-12-18 22:21:37 +11:00
|
|
|
.dcx()
|
2022-07-26 18:53:46 +02:00
|
|
|
.span_fatal(source_info.span, "128bit atomics not yet supported");
|
2022-03-20 16:55:21 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-23 11:49:34 +01:00
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
let clif_ty = fx.clif_type(ty).unwrap();
|
2020-01-18 12:43:31 +01:00
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
let val = fx.bcx.ins().atomic_load(clif_ty, MemFlags::trusted(), ptr);
|
2020-01-18 12:43:31 +01:00
|
|
|
|
2022-02-23 11:49:34 +01:00
|
|
|
let val = CValue::by_val(val, fx.layout_of(ty));
|
2021-03-05 19:12:59 +01:00
|
|
|
ret.write_cvalue(fx, val);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_store") => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, val); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2023-07-11 22:35:29 +01:00
|
|
|
let ty = generic_args.type_at(0);
|
2022-02-23 11:49:34 +01:00
|
|
|
match ty.kind() {
|
2022-03-20 16:55:21 +01:00
|
|
|
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
|
|
|
|
// FIXME implement 128bit atomics
|
|
|
|
if fx.tcx.is_compiler_builtins(LOCAL_CRATE) {
|
|
|
|
// special case for compiler-builtins to avoid having to patch it
|
|
|
|
crate::trap::trap_unimplemented(fx, "128bit atomics not yet supported");
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-03-20 16:55:21 +01:00
|
|
|
} else {
|
2022-07-26 18:53:46 +02:00
|
|
|
fx.tcx
|
2023-12-18 22:21:37 +11:00
|
|
|
.dcx()
|
2022-07-26 18:53:46 +02:00
|
|
|
.span_fatal(source_info.span, "128bit atomics not yet supported");
|
2022-03-20 16:55:21 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-23 11:49:34 +01:00
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
2020-07-03 16:52:37 +02:00
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let val = val.load_scalar(fx);
|
2020-01-18 12:43:31 +01:00
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
fx.bcx.ins().atomic_store(MemFlags::trusted(), val, ptr);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_xchg") => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, new); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let layout = new.layout();
|
2022-02-23 11:49:34 +01:00
|
|
|
match layout.ty.kind() {
|
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 19:12:59 +01:00
|
|
|
let ty = fx.clif_type(layout.ty).unwrap();
|
2020-07-03 16:52:37 +02:00
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let new = new.load_scalar(fx);
|
2018-10-06 10:24:09 +02:00
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Xchg, ptr, new);
|
2020-01-18 12:43:31 +01:00
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let old = CValue::by_val(old, layout);
|
|
|
|
ret.write_cvalue(fx, old);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_cxchg") => {
|
|
|
|
// both atomic_cxchg_* and atomic_cxchgweak_*
|
|
|
|
intrinsic_args!(fx, args => (ptr, test_old, new); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let layout = new.layout();
|
2022-02-23 11:49:34 +01:00
|
|
|
match layout.ty.kind() {
|
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
2020-07-03 16:52:37 +02:00
|
|
|
|
|
|
|
let test_old = test_old.load_scalar(fx);
|
|
|
|
let new = new.load_scalar(fx);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let old = fx.bcx.ins().atomic_cas(MemFlags::trusted(), ptr, test_old, new);
|
2020-06-20 13:23:31 +02:00
|
|
|
let is_eq = fx.bcx.ins().icmp(IntCC::Equal, old, test_old);
|
2018-10-06 10:24:09 +02:00
|
|
|
|
2022-12-14 19:30:46 +01:00
|
|
|
let ret_val = CValue::by_val_pair(old, is_eq, ret.layout());
|
2021-03-05 19:12:59 +01:00
|
|
|
ret.write_cvalue(fx, ret_val)
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_xadd") => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, amount); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
2018-10-06 10:24:09 +02:00
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let layout = amount.layout();
|
2022-02-23 11:49:34 +01:00
|
|
|
match layout.ty.kind() {
|
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 19:12:59 +01:00
|
|
|
let ty = fx.clif_type(layout.ty).unwrap();
|
|
|
|
|
2020-07-03 16:52:37 +02:00
|
|
|
let amount = amount.load_scalar(fx);
|
2021-03-05 19:12:59 +01:00
|
|
|
|
2022-07-26 18:53:46 +02:00
|
|
|
let old =
|
|
|
|
fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Add, ptr, amount);
|
2021-03-05 19:12:59 +01:00
|
|
|
|
|
|
|
let old = CValue::by_val(old, layout);
|
|
|
|
ret.write_cvalue(fx, old);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_xsub") => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, amount); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let layout = amount.layout();
|
2022-02-23 11:49:34 +01:00
|
|
|
match layout.ty.kind() {
|
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 19:12:59 +01:00
|
|
|
let ty = fx.clif_type(layout.ty).unwrap();
|
|
|
|
|
2020-07-03 16:52:37 +02:00
|
|
|
let amount = amount.load_scalar(fx);
|
2021-03-05 19:12:59 +01:00
|
|
|
|
2022-07-26 18:53:46 +02:00
|
|
|
let old =
|
|
|
|
fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Sub, ptr, amount);
|
2021-03-05 19:12:59 +01:00
|
|
|
|
|
|
|
let old = CValue::by_val(old, layout);
|
|
|
|
ret.write_cvalue(fx, old);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_and") => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, src); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let layout = src.layout();
|
2022-02-23 11:49:34 +01:00
|
|
|
match layout.ty.kind() {
|
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 19:12:59 +01:00
|
|
|
let ty = fx.clif_type(layout.ty).unwrap();
|
|
|
|
|
2020-07-03 16:52:37 +02:00
|
|
|
let src = src.load_scalar(fx);
|
2021-03-05 19:12:59 +01:00
|
|
|
|
|
|
|
let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::And, ptr, src);
|
|
|
|
|
|
|
|
let old = CValue::by_val(old, layout);
|
|
|
|
ret.write_cvalue(fx, old);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_or") => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, src); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let layout = src.layout();
|
2022-02-23 11:49:34 +01:00
|
|
|
match layout.ty.kind() {
|
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 19:12:59 +01:00
|
|
|
let ty = fx.clif_type(layout.ty).unwrap();
|
2020-07-03 16:52:37 +02:00
|
|
|
|
|
|
|
let src = src.load_scalar(fx);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Or, ptr, src);
|
2020-01-18 12:43:31 +01:00
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let old = CValue::by_val(old, layout);
|
|
|
|
ret.write_cvalue(fx, old);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_xor") => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, src); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let layout = src.layout();
|
2022-02-23 11:49:34 +01:00
|
|
|
match layout.ty.kind() {
|
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 19:12:59 +01:00
|
|
|
let ty = fx.clif_type(layout.ty).unwrap();
|
|
|
|
|
2020-07-03 16:52:37 +02:00
|
|
|
let src = src.load_scalar(fx);
|
2021-03-05 19:12:59 +01:00
|
|
|
|
|
|
|
let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Xor, ptr, src);
|
|
|
|
|
|
|
|
let old = CValue::by_val(old, layout);
|
|
|
|
ret.write_cvalue(fx, old);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_nand") => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, src); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let layout = src.layout();
|
2022-02-23 11:49:34 +01:00
|
|
|
match layout.ty.kind() {
|
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 19:12:59 +01:00
|
|
|
let ty = fx.clif_type(layout.ty).unwrap();
|
|
|
|
|
2020-07-03 16:52:37 +02:00
|
|
|
let src = src.load_scalar(fx);
|
2021-03-05 19:12:59 +01:00
|
|
|
|
|
|
|
let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Nand, ptr, src);
|
|
|
|
|
|
|
|
let old = CValue::by_val(old, layout);
|
|
|
|
ret.write_cvalue(fx, old);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_max") => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, src); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let layout = src.layout();
|
2022-02-23 11:49:34 +01:00
|
|
|
match layout.ty.kind() {
|
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 19:12:59 +01:00
|
|
|
let ty = fx.clif_type(layout.ty).unwrap();
|
2018-10-06 10:24:09 +02:00
|
|
|
|
2020-07-03 16:52:37 +02:00
|
|
|
let src = src.load_scalar(fx);
|
2021-03-05 19:12:59 +01:00
|
|
|
|
|
|
|
let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Smax, ptr, src);
|
|
|
|
|
|
|
|
let old = CValue::by_val(old, layout);
|
|
|
|
ret.write_cvalue(fx, old);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_umax") => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, src); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let layout = src.layout();
|
2022-02-23 11:49:34 +01:00
|
|
|
match layout.ty.kind() {
|
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 19:12:59 +01:00
|
|
|
let ty = fx.clif_type(layout.ty).unwrap();
|
|
|
|
|
2020-07-03 16:52:37 +02:00
|
|
|
let src = src.load_scalar(fx);
|
2021-03-05 19:12:59 +01:00
|
|
|
|
|
|
|
let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Umax, ptr, src);
|
|
|
|
|
|
|
|
let old = CValue::by_val(old, layout);
|
|
|
|
ret.write_cvalue(fx, old);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_min") => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, src); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let layout = src.layout();
|
2022-02-23 11:49:34 +01:00
|
|
|
match layout.ty.kind() {
|
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 19:12:59 +01:00
|
|
|
let ty = fx.clif_type(layout.ty).unwrap();
|
|
|
|
|
2020-07-03 16:52:37 +02:00
|
|
|
let src = src.load_scalar(fx);
|
2021-03-05 19:12:59 +01:00
|
|
|
|
|
|
|
let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Smin, ptr, src);
|
|
|
|
|
|
|
|
let old = CValue::by_val(old, layout);
|
|
|
|
ret.write_cvalue(fx, old);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
_ if intrinsic.as_str().starts_with("atomic_umin") => {
|
|
|
|
intrinsic_args!(fx, args => (ptr, src); intrinsic);
|
|
|
|
let ptr = ptr.load_scalar(fx);
|
|
|
|
|
2021-03-05 19:12:59 +01:00
|
|
|
let layout = src.layout();
|
2022-02-23 11:49:34 +01:00
|
|
|
match layout.ty.kind() {
|
|
|
|
ty::Uint(_) | ty::Int(_) | ty::RawPtr(..) => {}
|
|
|
|
_ => {
|
2022-05-15 12:32:19 +02:00
|
|
|
report_atomic_type_validation_error(fx, intrinsic, source_info.span, layout.ty);
|
2024-01-31 14:29:12 +00:00
|
|
|
return Ok(());
|
2022-02-23 11:49:34 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 19:12:59 +01:00
|
|
|
let ty = fx.clif_type(layout.ty).unwrap();
|
|
|
|
|
2020-07-03 16:52:37 +02:00
|
|
|
let src = src.load_scalar(fx);
|
2021-03-05 19:12:59 +01:00
|
|
|
|
|
|
|
let old = fx.bcx.ins().atomic_rmw(ty, MemFlags::trusted(), AtomicRmwOp::Umin, ptr, src);
|
|
|
|
|
|
|
|
let old = CValue::by_val(old, layout);
|
|
|
|
ret.write_cvalue(fx, old);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sym::minnumf32 => {
|
|
|
|
intrinsic_args!(fx, args => (a, b); intrinsic);
|
|
|
|
let a = a.load_scalar(fx);
|
|
|
|
let b = b.load_scalar(fx);
|
2019-07-27 17:48:24 +02:00
|
|
|
|
2022-04-22 21:11:38 +02:00
|
|
|
let val = crate::num::codegen_float_min(fx, a, b);
|
2020-08-22 16:47:31 +02:00
|
|
|
let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f32));
|
2019-07-27 17:48:24 +02:00
|
|
|
ret.write_cvalue(fx, val);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::minnumf64 => {
|
|
|
|
intrinsic_args!(fx, args => (a, b); intrinsic);
|
|
|
|
let a = a.load_scalar(fx);
|
|
|
|
let b = b.load_scalar(fx);
|
|
|
|
|
2022-04-22 21:11:38 +02:00
|
|
|
let val = crate::num::codegen_float_min(fx, a, b);
|
2020-08-22 16:47:31 +02:00
|
|
|
let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f64));
|
2019-07-27 17:48:24 +02:00
|
|
|
ret.write_cvalue(fx, val);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::maxnumf32 => {
|
|
|
|
intrinsic_args!(fx, args => (a, b); intrinsic);
|
|
|
|
let a = a.load_scalar(fx);
|
|
|
|
let b = b.load_scalar(fx);
|
|
|
|
|
2022-04-22 21:11:38 +02:00
|
|
|
let val = crate::num::codegen_float_max(fx, a, b);
|
2020-08-22 16:47:31 +02:00
|
|
|
let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f32));
|
2019-07-27 17:48:24 +02:00
|
|
|
ret.write_cvalue(fx, val);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::maxnumf64 => {
|
|
|
|
intrinsic_args!(fx, args => (a, b); intrinsic);
|
|
|
|
let a = a.load_scalar(fx);
|
|
|
|
let b = b.load_scalar(fx);
|
|
|
|
|
2022-04-22 21:11:38 +02:00
|
|
|
let val = crate::num::codegen_float_max(fx, a, b);
|
2020-08-22 16:47:31 +02:00
|
|
|
let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f64));
|
2019-07-27 17:48:24 +02:00
|
|
|
ret.write_cvalue(fx, val);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
2024-02-25 18:51:22 +01:00
|
|
|
sym::catch_unwind => {
|
2022-07-26 18:53:46 +02:00
|
|
|
intrinsic_args!(fx, args => (f, data, catch_fn); intrinsic);
|
|
|
|
let f = f.load_scalar(fx);
|
|
|
|
let data = data.load_scalar(fx);
|
|
|
|
let _catch_fn = catch_fn.load_scalar(fx);
|
2019-07-27 17:48:24 +02:00
|
|
|
|
2019-07-31 14:04:00 +02:00
|
|
|
// FIXME once unwinding is supported, change this to actually catch panics
|
|
|
|
let f_sig = fx.bcx.func.import_signature(Signature {
|
2021-12-20 18:56:35 +01:00
|
|
|
call_conv: fx.target_config.default_call_conv,
|
2022-10-23 16:22:55 +02:00
|
|
|
params: vec![AbiParam::new(pointer_ty(fx.tcx))],
|
2019-07-31 14:04:00 +02:00
|
|
|
returns: vec![],
|
|
|
|
});
|
|
|
|
|
|
|
|
fx.bcx.ins().call_indirect(f_sig, f, &[data]);
|
|
|
|
|
2023-04-29 12:00:43 +00:00
|
|
|
let layout = fx.layout_of(fx.tcx.types.i32);
|
|
|
|
let ret_val = CValue::by_val(fx.bcx.ins().iconst(types::I32, 0), layout);
|
2019-07-31 14:04:00 +02:00
|
|
|
ret.write_cvalue(fx, ret_val);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
2020-05-01 17:35:20 +02:00
|
|
|
|
2024-02-06 14:32:00 -05:00
|
|
|
sym::fadd_fast
|
|
|
|
| sym::fsub_fast
|
|
|
|
| sym::fmul_fast
|
|
|
|
| sym::fdiv_fast
|
|
|
|
| sym::frem_fast
|
|
|
|
| sym::fadd_algebraic
|
|
|
|
| sym::fsub_algebraic
|
|
|
|
| sym::fmul_algebraic
|
|
|
|
| sym::fdiv_algebraic
|
|
|
|
| sym::frem_algebraic => {
|
2022-07-26 18:53:46 +02:00
|
|
|
intrinsic_args!(fx, args => (x, y); intrinsic);
|
|
|
|
|
|
|
|
let res = crate::num::codegen_float_binop(
|
|
|
|
fx,
|
|
|
|
match intrinsic {
|
2024-02-06 14:32:00 -05:00
|
|
|
sym::fadd_fast | sym::fadd_algebraic => BinOp::Add,
|
|
|
|
sym::fsub_fast | sym::fsub_algebraic => BinOp::Sub,
|
|
|
|
sym::fmul_fast | sym::fmul_algebraic => BinOp::Mul,
|
|
|
|
sym::fdiv_fast | sym::fdiv_algebraic => BinOp::Div,
|
|
|
|
sym::frem_fast | sym::frem_algebraic => BinOp::Rem,
|
2022-07-26 18:53:46 +02:00
|
|
|
_ => unreachable!(),
|
|
|
|
},
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
);
|
2020-05-01 17:35:20 +02:00
|
|
|
ret.write_cvalue(fx, res);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
sym::float_to_int_unchecked => {
|
|
|
|
intrinsic_args!(fx, args => (f); intrinsic);
|
|
|
|
let f = f.load_scalar(fx);
|
|
|
|
|
2020-05-10 18:17:58 +02:00
|
|
|
let res = crate::cast::clif_int_or_float_cast(
|
|
|
|
fx,
|
|
|
|
f,
|
|
|
|
false,
|
|
|
|
fx.clif_type(ret.layout().ty).unwrap(),
|
|
|
|
type_sign(ret.layout().ty),
|
|
|
|
);
|
|
|
|
ret.write_cvalue(fx, CValue::by_val(res, ret.layout()));
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sym::raw_eq => {
|
|
|
|
intrinsic_args!(fx, args => (lhs_ref, rhs_ref); intrinsic);
|
|
|
|
let lhs_ref = lhs_ref.load_scalar(fx);
|
|
|
|
let rhs_ref = rhs_ref.load_scalar(fx);
|
2021-05-30 18:04:07 -07:00
|
|
|
|
2023-07-11 22:35:29 +01:00
|
|
|
let size = fx.layout_of(generic_args.type_at(0)).layout.size();
|
2021-08-06 16:26:56 +02:00
|
|
|
// FIXME add and use emit_small_memcmp
|
2022-07-26 18:53:46 +02:00
|
|
|
let is_eq_value = if size == Size::ZERO {
|
|
|
|
// No bytes means they're trivially equal
|
|
|
|
fx.bcx.ins().iconst(types::I8, 1)
|
|
|
|
} else if let Some(clty) = size.bits().try_into().ok().and_then(Type::int) {
|
|
|
|
// Can't use `trusted` for these loads; they could be unaligned.
|
|
|
|
let mut flags = MemFlags::new();
|
|
|
|
flags.set_notrap();
|
|
|
|
let lhs_val = fx.bcx.ins().load(clty, flags, lhs_ref, 0);
|
|
|
|
let rhs_val = fx.bcx.ins().load(clty, flags, rhs_ref, 0);
|
2022-12-14 19:30:46 +01:00
|
|
|
fx.bcx.ins().icmp(IntCC::Equal, lhs_val, rhs_val)
|
2022-07-26 18:53:46 +02:00
|
|
|
} else {
|
|
|
|
// Just call `memcmp` (like slices do in core) when the
|
|
|
|
// size is too large or it's not a power-of-two.
|
|
|
|
let signed_bytes = i64::try_from(size.bytes()).unwrap();
|
|
|
|
let bytes_val = fx.bcx.ins().iconst(fx.pointer_type, signed_bytes);
|
|
|
|
let params = vec![AbiParam::new(fx.pointer_type); 3];
|
|
|
|
let returns = vec![AbiParam::new(types::I32)];
|
|
|
|
let args = &[lhs_ref, rhs_ref, bytes_val];
|
|
|
|
let cmp = fx.lib_call("memcmp", params, returns, args)[0];
|
2022-12-14 19:30:46 +01:00
|
|
|
fx.bcx.ins().icmp_imm(IntCC::Equal, cmp, 0)
|
2022-07-26 18:53:46 +02:00
|
|
|
};
|
2021-05-30 18:04:07 -07:00
|
|
|
ret.write_cvalue(fx, CValue::by_val(is_eq_value, ret.layout()));
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
2023-08-02 12:45:52 -07:00
|
|
|
sym::compare_bytes => {
|
|
|
|
intrinsic_args!(fx, args => (lhs_ptr, rhs_ptr, bytes_val); intrinsic);
|
|
|
|
let lhs_ptr = lhs_ptr.load_scalar(fx);
|
|
|
|
let rhs_ptr = rhs_ptr.load_scalar(fx);
|
|
|
|
let bytes_val = bytes_val.load_scalar(fx);
|
|
|
|
|
|
|
|
let params = vec![AbiParam::new(fx.pointer_type); 3];
|
|
|
|
let returns = vec![AbiParam::new(types::I32)];
|
|
|
|
let args = &[lhs_ptr, rhs_ptr, bytes_val];
|
2023-08-04 06:22:50 +00:00
|
|
|
// Here we assume that the `memcmp` provided by the target is a NOP for size 0.
|
2023-08-02 12:45:52 -07:00
|
|
|
let cmp = fx.lib_call("memcmp", params, returns, args)[0];
|
|
|
|
ret.write_cvalue(fx, CValue::by_val(cmp, ret.layout()));
|
|
|
|
}
|
|
|
|
|
2022-07-26 18:53:46 +02:00
|
|
|
sym::black_box => {
|
|
|
|
intrinsic_args!(fx, args => (a); intrinsic);
|
2022-02-23 11:49:34 +01:00
|
|
|
|
2021-08-10 11:50:33 +01:00
|
|
|
// FIXME implement black_box semantics
|
|
|
|
ret.write_cvalue(fx, a);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
2022-07-25 16:07:57 +02:00
|
|
|
|
|
|
|
// FIXME implement variadics in cranelift
|
2022-07-26 18:53:46 +02:00
|
|
|
sym::va_copy | sym::va_arg | sym::va_end => {
|
2023-12-18 22:21:37 +11:00
|
|
|
fx.tcx.dcx().span_fatal(
|
2022-07-25 16:07:57 +02:00
|
|
|
source_info.span,
|
|
|
|
"Defining variadic functions is not yet supported by Cranelift",
|
|
|
|
);
|
2022-07-26 18:53:46 +02:00
|
|
|
}
|
|
|
|
|
2024-01-31 20:39:59 +00:00
|
|
|
// Unimplemented intrinsics must have a fallback body. The fallback body is obtained
|
|
|
|
// by converting the `InstanceDef::Intrinsic` to an `InstanceDef::Item`.
|
2024-02-19 17:35:12 +00:00
|
|
|
_ => {
|
|
|
|
let intrinsic = fx.tcx.intrinsic(instance.def_id()).unwrap();
|
|
|
|
if intrinsic.must_be_overridden {
|
|
|
|
span_bug!(
|
|
|
|
source_info.span,
|
|
|
|
"intrinsic {} must be overridden by codegen_cranelift, but isn't",
|
|
|
|
intrinsic.name,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Err(Instance::new(instance.def_id(), instance.args));
|
|
|
|
}
|
2018-10-03 18:21:52 +02:00
|
|
|
}
|
|
|
|
|
2022-04-16 09:27:54 -04:00
|
|
|
let ret_block = fx.get_block(destination.unwrap());
|
2022-03-20 16:55:21 +01:00
|
|
|
fx.bcx.ins().jump(ret_block, &[]);
|
2024-01-31 14:29:12 +00:00
|
|
|
Ok(())
|
2018-10-03 18:21:52 +02:00
|
|
|
}
|