Make ptr_guaranteed_cmp a rustc_intrinsic and favor its body over backends implementing it
This commit is contained in:
parent
e0d67aeb0b
commit
3e5c468662
4 changed files with 19 additions and 24 deletions
|
@ -757,13 +757,6 @@ fn codegen_regular_intrinsic_call<'tcx>(
|
||||||
ret.write_cvalue(fx, val);
|
ret.write_cvalue(fx, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
sym::ptr_guaranteed_cmp => {
|
|
||||||
intrinsic_args!(fx, args => (a, b); intrinsic);
|
|
||||||
|
|
||||||
let val = crate::num::codegen_ptr_binop(fx, BinOp::Eq, a, b).load_scalar(fx);
|
|
||||||
ret.write_cvalue(fx, CValue::by_val(val, fx.layout_of(fx.tcx.types.u8)));
|
|
||||||
}
|
|
||||||
|
|
||||||
sym::caller_location => {
|
sym::caller_location => {
|
||||||
intrinsic_args!(fx, args => (); intrinsic);
|
intrinsic_args!(fx, args => (); intrinsic);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use super::operand::{OperandRef, OperandValue};
|
use super::operand::{OperandRef, OperandValue};
|
||||||
use super::place::PlaceRef;
|
use super::place::PlaceRef;
|
||||||
use super::FunctionCx;
|
use super::FunctionCx;
|
||||||
use crate::common::IntPredicate;
|
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
use crate::errors::InvalidMonomorphization;
|
use crate::errors::InvalidMonomorphization;
|
||||||
use crate::meth;
|
use crate::meth;
|
||||||
|
@ -456,12 +455,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
sym::ptr_guaranteed_cmp => {
|
|
||||||
let a = args[0].immediate();
|
|
||||||
let b = args[1].immediate();
|
|
||||||
bx.icmp(IntPredicate::IntEQ, a, b)
|
|
||||||
}
|
|
||||||
|
|
||||||
sym::ptr_offset_from | sym::ptr_offset_from_unsigned => {
|
sym::ptr_offset_from | sym::ptr_offset_from_unsigned => {
|
||||||
let ty = fn_args.type_at(0);
|
let ty = fn_args.type_at(0);
|
||||||
let pointee_size = bx.layout_of(ty).size;
|
let pointee_size = bx.layout_of(ty).size;
|
||||||
|
|
|
@ -441,7 +441,7 @@ pub fn check_intrinsic_type(
|
||||||
|
|
||||||
sym::ptr_guaranteed_cmp => (
|
sym::ptr_guaranteed_cmp => (
|
||||||
1,
|
1,
|
||||||
0,
|
1,
|
||||||
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
|
vec![Ty::new_imm_ptr(tcx, param(0)), Ty::new_imm_ptr(tcx, param(0))],
|
||||||
tcx.types.u8,
|
tcx.types.u8,
|
||||||
),
|
),
|
||||||
|
|
|
@ -2434,20 +2434,29 @@ extern "rust-intrinsic" {
|
||||||
#[rustc_nounwind]
|
#[rustc_nounwind]
|
||||||
pub fn ptr_offset_from_unsigned<T>(ptr: *const T, base: *const T) -> usize;
|
pub fn ptr_offset_from_unsigned<T>(ptr: *const T, base: *const T) -> usize;
|
||||||
|
|
||||||
|
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
|
||||||
|
#[rustc_safe_intrinsic]
|
||||||
|
#[rustc_nounwind]
|
||||||
|
#[cfg(bootstrap)]
|
||||||
|
pub fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8;
|
||||||
|
}
|
||||||
|
|
||||||
/// See documentation of `<*const T>::guaranteed_eq` for details.
|
/// See documentation of `<*const T>::guaranteed_eq` for details.
|
||||||
/// Returns `2` if the result is unknown.
|
/// Returns `2` if the result is unknown.
|
||||||
/// Returns `1` if the pointers are guaranteed equal
|
/// Returns `1` if the pointers are guaranteed equal
|
||||||
/// Returns `0` if the pointers are guaranteed inequal
|
/// Returns `0` if the pointers are guaranteed inequal
|
||||||
///
|
|
||||||
/// Note that, unlike most intrinsics, this is safe to call;
|
|
||||||
/// it does not require an `unsafe` block.
|
|
||||||
/// Therefore, implementations must not require the user to uphold
|
|
||||||
/// any safety invariants.
|
|
||||||
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
|
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
|
||||||
#[rustc_safe_intrinsic]
|
#[unstable(feature = "core_intrinsics", issue = "none")]
|
||||||
|
#[rustc_intrinsic]
|
||||||
|
#[cfg(not(bootstrap))]
|
||||||
#[rustc_nounwind]
|
#[rustc_nounwind]
|
||||||
pub fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8;
|
#[rustc_do_not_const_check]
|
||||||
|
#[inline]
|
||||||
|
pub const fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8 {
|
||||||
|
(ptr == other) as u8
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "rust-intrinsic" {
|
||||||
/// Determines whether the raw bytes of the two values are equal.
|
/// Determines whether the raw bytes of the two values are equal.
|
||||||
///
|
///
|
||||||
/// This is particularly handy for arrays, since it allows things like just
|
/// This is particularly handy for arrays, since it allows things like just
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue