Remove unnecessary int_type_width_signed
function
This commit is contained in:
parent
ca13e9169f
commit
18d7b9a12f
1 changed files with 76 additions and 92 deletions
|
@ -352,8 +352,17 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
||||||
| sym::saturating_add
|
| sym::saturating_add
|
||||||
| sym::saturating_sub => {
|
| sym::saturating_sub => {
|
||||||
let ty = arg_tys[0];
|
let ty = arg_tys[0];
|
||||||
match int_type_width_signed(ty, self) {
|
if !ty.is_integral() {
|
||||||
Some((width, signed)) => match name {
|
tcx.dcx().emit_err(InvalidMonomorphization::BasicIntegerType {
|
||||||
|
span,
|
||||||
|
name,
|
||||||
|
ty,
|
||||||
|
});
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let (size, signed) = ty.int_size_and_signed(self.tcx);
|
||||||
|
let width = size.bits();
|
||||||
|
match name {
|
||||||
sym::ctlz | sym::cttz => {
|
sym::ctlz | sym::cttz => {
|
||||||
let y = self.const_bool(false);
|
let y = self.const_bool(false);
|
||||||
let ret = self.call_intrinsic(&format!("llvm.{name}.i{width}"), &[
|
let ret = self.call_intrinsic(&format!("llvm.{name}.i{width}"), &[
|
||||||
|
@ -376,9 +385,9 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
||||||
self.intcast(ret, llret_ty, false)
|
self.intcast(ret, llret_ty, false)
|
||||||
}
|
}
|
||||||
sym::ctpop => {
|
sym::ctpop => {
|
||||||
let ret = self.call_intrinsic(&format!("llvm.ctpop.i{width}"), &[args
|
let ret = self.call_intrinsic(&format!("llvm.ctpop.i{width}"), &[
|
||||||
[0]
|
args[0].immediate()
|
||||||
.immediate()]);
|
]);
|
||||||
self.intcast(ret, llret_ty, false)
|
self.intcast(ret, llret_ty, false)
|
||||||
}
|
}
|
||||||
sym::bswap => {
|
sym::bswap => {
|
||||||
|
@ -421,15 +430,6 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
||||||
self.call_intrinsic(llvm_name, &[lhs, rhs])
|
self.call_intrinsic(llvm_name, &[lhs, rhs])
|
||||||
}
|
}
|
||||||
_ => bug!(),
|
_ => bug!(),
|
||||||
},
|
|
||||||
None => {
|
|
||||||
tcx.dcx().emit_err(InvalidMonomorphization::BasicIntegerType {
|
|
||||||
span,
|
|
||||||
name,
|
|
||||||
ty,
|
|
||||||
});
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2531,19 +2531,3 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
|
||||||
|
|
||||||
span_bug!(span, "unknown SIMD intrinsic");
|
span_bug!(span, "unknown SIMD intrinsic");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the width of an int Ty, and if it's signed or not
|
|
||||||
// Returns None if the type is not an integer
|
|
||||||
// FIXME: there’s multiple of this functions, investigate using some of the already existing
|
|
||||||
// stuffs.
|
|
||||||
fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, bool)> {
|
|
||||||
match ty.kind() {
|
|
||||||
ty::Int(t) => {
|
|
||||||
Some((t.bit_width().unwrap_or(u64::from(cx.tcx.sess.target.pointer_width)), true))
|
|
||||||
}
|
|
||||||
ty::Uint(t) => {
|
|
||||||
Some((t.bit_width().unwrap_or(u64::from(cx.tcx.sess.target.pointer_width)), false))
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue