Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 53 additions & 26 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {

let name = format!("llvm.{}{oop_str}.with.overflow", if signed { 's' } else { 'u' });

let res = self.call_intrinsic(name, &[self.type_ix(width)], &[lhs, rhs]);
let res = self.call_intrinsic(name, &[self.type_ix(width)], None, &[lhs, rhs]);
(self.extract_value(res, 0), self.extract_value(res, 1))
}

Expand Down Expand Up @@ -962,11 +962,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}

fn fptoui_sat(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
self.call_intrinsic("llvm.fptoui.sat", &[dest_ty, self.val_ty(val)], &[val])
self.call_intrinsic("llvm.fptoui.sat", &[dest_ty, self.val_ty(val)], None, &[val])
}

fn fptosi_sat(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
self.call_intrinsic("llvm.fptosi.sat", &[dest_ty, self.val_ty(val)], &[val])
self.call_intrinsic("llvm.fptosi.sat", &[dest_ty, self.val_ty(val)], None, &[val])
}

fn fptoui(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
Expand All @@ -993,6 +993,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
return self.call_intrinsic(
"llvm.wasm.trunc.unsigned",
&[dest_ty, src_ty],
None,
&[val],
);
}
Expand All @@ -1012,6 +1013,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
return self.call_intrinsic(
"llvm.wasm.trunc.signed",
&[dest_ty, src_ty],
None,
&[val],
);
}
Expand Down Expand Up @@ -1078,7 +1080,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
let size = ty.primitive_size(self.tcx);
let name = if ty.is_signed() { "llvm.scmp" } else { "llvm.ucmp" };

self.call_intrinsic(name, &[self.type_i8(), self.type_ix(size.bits())], &[lhs, rhs])
self.call_intrinsic(name, &[self.type_i8(), self.type_ix(size.bits())], None, &[lhs, rhs])
}

/* Miscellaneous instructions */
Expand Down Expand Up @@ -1481,8 +1483,12 @@ impl<'ll> StaticBuilderMethods for Builder<'_, 'll, '_> {
// Forward to the `get_static` method of `CodegenCx`
let global = self.cx().get_static(def_id);
if self.cx().tcx.is_thread_local_static(def_id) {
let pointer =
self.call_intrinsic("llvm.threadlocal.address", &[self.val_ty(global)], &[global]);
let pointer = self.call_intrinsic(
"llvm.threadlocal.address",
&[self.val_ty(global)],
None,
&[global],
);
// Cast to default address space if globals are in a different addrspace
self.pointercast(pointer, self.type_ptr())
} else {
Expand Down Expand Up @@ -1520,11 +1526,11 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
}

pub(crate) fn minnum(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
self.call_intrinsic("llvm.minnum", &[self.val_ty(lhs)], &[lhs, rhs])
self.call_intrinsic("llvm.minnum", &[self.val_ty(lhs)], None, &[lhs, rhs])
}

pub(crate) fn maxnum(&mut self, lhs: &'ll Value, rhs: &'ll Value) -> &'ll Value {
self.call_intrinsic("llvm.maxnum", &[self.val_ty(lhs)], &[lhs, rhs])
self.call_intrinsic("llvm.maxnum", &[self.val_ty(lhs)], None, &[lhs, rhs])
}

pub(crate) fn insert_element(
Expand All @@ -1546,19 +1552,23 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
}

pub(crate) fn vector_reduce_fadd(&mut self, acc: &'ll Value, src: &'ll Value) -> &'ll Value {
self.call_intrinsic("llvm.vector.reduce.fadd", &[self.val_ty(src)], &[acc, src])
self.call_intrinsic("llvm.vector.reduce.fadd", &[self.val_ty(src)], None, &[acc, src])
}
pub(crate) fn vector_reduce_fmul(&mut self, acc: &'ll Value, src: &'ll Value) -> &'ll Value {
self.call_intrinsic("llvm.vector.reduce.fmul", &[self.val_ty(src)], &[acc, src])
self.call_intrinsic("llvm.vector.reduce.fmul", &[self.val_ty(src)], None, &[acc, src])
}
pub(crate) fn vector_reduce_fadd_reassoc(
&mut self,
acc: &'ll Value,
src: &'ll Value,
) -> &'ll Value {
unsafe {
let instr =
self.call_intrinsic("llvm.vector.reduce.fadd", &[self.val_ty(src)], &[acc, src]);
let instr = self.call_intrinsic(
"llvm.vector.reduce.fadd",
&[self.val_ty(src)],
None,
&[acc, src],
);
llvm::LLVMRustSetAllowReassoc(instr);
instr
}
Expand All @@ -1569,44 +1579,50 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
src: &'ll Value,
) -> &'ll Value {
unsafe {
let instr =
self.call_intrinsic("llvm.vector.reduce.fmul", &[self.val_ty(src)], &[acc, src]);
let instr = self.call_intrinsic(
"llvm.vector.reduce.fmul",
&[self.val_ty(src)],
None,
&[acc, src],
);
llvm::LLVMRustSetAllowReassoc(instr);
instr
}
}
pub(crate) fn vector_reduce_add(&mut self, src: &'ll Value) -> &'ll Value {
self.call_intrinsic("llvm.vector.reduce.add", &[self.val_ty(src)], &[src])
self.call_intrinsic("llvm.vector.reduce.add", &[self.val_ty(src)], None, &[src])
}
pub(crate) fn vector_reduce_mul(&mut self, src: &'ll Value) -> &'ll Value {
self.call_intrinsic("llvm.vector.reduce.mul", &[self.val_ty(src)], &[src])
self.call_intrinsic("llvm.vector.reduce.mul", &[self.val_ty(src)], None, &[src])
}
pub(crate) fn vector_reduce_and(&mut self, src: &'ll Value) -> &'ll Value {
self.call_intrinsic("llvm.vector.reduce.and", &[self.val_ty(src)], &[src])
self.call_intrinsic("llvm.vector.reduce.and", &[self.val_ty(src)], None, &[src])
}
pub(crate) fn vector_reduce_or(&mut self, src: &'ll Value) -> &'ll Value {
self.call_intrinsic("llvm.vector.reduce.or", &[self.val_ty(src)], &[src])
self.call_intrinsic("llvm.vector.reduce.or", &[self.val_ty(src)], None, &[src])
}
pub(crate) fn vector_reduce_xor(&mut self, src: &'ll Value) -> &'ll Value {
self.call_intrinsic("llvm.vector.reduce.xor", &[self.val_ty(src)], &[src])
self.call_intrinsic("llvm.vector.reduce.xor", &[self.val_ty(src)], None, &[src])
}
pub(crate) fn vector_reduce_fmin(&mut self, src: &'ll Value) -> &'ll Value {
self.call_intrinsic("llvm.vector.reduce.fmin", &[self.val_ty(src)], &[src])
self.call_intrinsic("llvm.vector.reduce.fmin", &[self.val_ty(src)], None, &[src])
}
pub(crate) fn vector_reduce_fmax(&mut self, src: &'ll Value) -> &'ll Value {
self.call_intrinsic("llvm.vector.reduce.fmax", &[self.val_ty(src)], &[src])
self.call_intrinsic("llvm.vector.reduce.fmax", &[self.val_ty(src)], None, &[src])
}
pub(crate) fn vector_reduce_min(&mut self, src: &'ll Value, is_signed: bool) -> &'ll Value {
self.call_intrinsic(
if is_signed { "llvm.vector.reduce.smin" } else { "llvm.vector.reduce.umin" },
&[self.val_ty(src)],
None,
&[src],
)
}
pub(crate) fn vector_reduce_max(&mut self, src: &'ll Value, is_signed: bool) -> &'ll Value {
self.call_intrinsic(
if is_signed { "llvm.vector.reduce.smax" } else { "llvm.vector.reduce.umax" },
&[self.val_ty(src)],
None,
&[src],
)
}
Expand Down Expand Up @@ -1678,10 +1694,11 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
&mut self,
base_name: impl Into<Cow<'static, str>>,
type_params: &[&'ll Type],
attrs: Option<&CodegenFnAttrs>,
args: &[&'ll Value],
) -> &'ll Value {
let (ty, f) = self.cx.get_intrinsic(base_name.into(), type_params);
self.call(ty, None, None, f, args, None, None)
self.call(ty, attrs, None, f, args, None, None)
}

fn call_lifetime_intrinsic(&mut self, intrinsic: &'static str, ptr: &'ll Value, size: Size) {
Expand All @@ -1695,9 +1712,14 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
}

if crate::llvm_util::get_version() >= (22, 0, 0) {
self.call_intrinsic(intrinsic, &[self.val_ty(ptr)], &[ptr]);
self.call_intrinsic(intrinsic, &[self.val_ty(ptr)], None, &[ptr]);
} else {
self.call_intrinsic(intrinsic, &[self.val_ty(ptr)], &[self.cx.const_u64(size), ptr]);
self.call_intrinsic(
intrinsic,
&[self.val_ty(ptr)],
None,
&[self.cx.const_u64(size), ptr],
);
}
}
}
Expand Down Expand Up @@ -1828,7 +1850,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
// llvm.type.test intrinsic. The LowerTypeTests link-time optimization pass replaces
// calls to this intrinsic with code to test type membership.
let typeid = self.get_metadata_value(typeid_metadata);
let cond = self.call_intrinsic("llvm.type.test", &[], &[llfn, typeid]);
let cond = self.call_intrinsic("llvm.type.test", &[], None, &[llfn, typeid]);
let bb_pass = self.append_sibling_block("type_test.pass");
let bb_fail = self.append_sibling_block("type_test.fail");
self.cond_br(cond, bb_pass, bb_fail);
Expand Down Expand Up @@ -1896,6 +1918,11 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
num_counters: &'ll Value,
index: &'ll Value,
) {
self.call_intrinsic("llvm.instrprof.increment", &[], &[fn_name, hash, num_counters, index]);
self.call_intrinsic(
"llvm.instrprof.increment",
&[],
None,
&[fn_name, hash, num_counters, index],
);
}
}
Loading
Loading