Skip to content

Commit 8bedc43

Browse files
committed
rustc_codegen_llvm: adapt for LLVM 22 change to pass masked intrinsic alignment as an attribute
This was a bit more invasive than I had kind of hoped. An alternate approach would be to add an extra call_intrinsic_with_attrs() that would have the new-in-this-change signature for call_intrinsic, but this felt about equivalent and made it a little easier to audit the relevant callsites of call_intrinsic().
1 parent bd4a800 commit 8bedc43

File tree

7 files changed

+184
-70
lines changed

7 files changed

+184
-70
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
583583

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

586-
let res = self.call_intrinsic(name, &[self.type_ix(width)], &[lhs, rhs]);
586+
let res = self.call_intrinsic(name, &[self.type_ix(width)], None, &[lhs, rhs]);
587587
(self.extract_value(res, 0), self.extract_value(res, 1))
588588
}
589589

@@ -962,11 +962,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
962962
}
963963

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

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

972972
fn fptoui(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
@@ -993,6 +993,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
993993
return self.call_intrinsic(
994994
"llvm.wasm.trunc.unsigned",
995995
&[dest_ty, src_ty],
996+
None,
996997
&[val],
997998
);
998999
}
@@ -1012,6 +1013,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10121013
return self.call_intrinsic(
10131014
"llvm.wasm.trunc.signed",
10141015
&[dest_ty, src_ty],
1016+
None,
10151017
&[val],
10161018
);
10171019
}
@@ -1078,7 +1080,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
10781080
let size = ty.primitive_size(self.tcx);
10791081
let name = if ty.is_signed() { "llvm.scmp" } else { "llvm.ucmp" };
10801082

1081-
self.call_intrinsic(name, &[self.type_i8(), self.type_ix(size.bits())], &[lhs, rhs])
1083+
self.call_intrinsic(name, &[self.type_i8(), self.type_ix(size.bits())], None, &[lhs, rhs])
10821084
}
10831085

10841086
/* Miscellaneous instructions */
@@ -1481,8 +1483,12 @@ impl<'ll> StaticBuilderMethods for Builder<'_, 'll, '_> {
14811483
// Forward to the `get_static` method of `CodegenCx`
14821484
let global = self.cx().get_static(def_id);
14831485
if self.cx().tcx.is_thread_local_static(def_id) {
1484-
let pointer =
1485-
self.call_intrinsic("llvm.threadlocal.address", &[self.val_ty(global)], &[global]);
1486+
let pointer = self.call_intrinsic(
1487+
"llvm.threadlocal.address",
1488+
&[self.val_ty(global)],
1489+
None,
1490+
&[global],
1491+
);
14861492
// Cast to default address space if globals are in a different addrspace
14871493
self.pointercast(pointer, self.type_ptr())
14881494
} else {
@@ -1520,11 +1526,11 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15201526
}
15211527

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

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

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

15481554
pub(crate) fn vector_reduce_fadd(&mut self, acc: &'ll Value, src: &'ll Value) -> &'ll Value {
1549-
self.call_intrinsic("llvm.vector.reduce.fadd", &[self.val_ty(src)], &[acc, src])
1555+
self.call_intrinsic("llvm.vector.reduce.fadd", &[self.val_ty(src)], None, &[acc, src])
15501556
}
15511557
pub(crate) fn vector_reduce_fmul(&mut self, acc: &'ll Value, src: &'ll Value) -> &'ll Value {
1552-
self.call_intrinsic("llvm.vector.reduce.fmul", &[self.val_ty(src)], &[acc, src])
1558+
self.call_intrinsic("llvm.vector.reduce.fmul", &[self.val_ty(src)], None, &[acc, src])
15531559
}
15541560
pub(crate) fn vector_reduce_fadd_reassoc(
15551561
&mut self,
15561562
acc: &'ll Value,
15571563
src: &'ll Value,
15581564
) -> &'ll Value {
15591565
unsafe {
1560-
let instr =
1561-
self.call_intrinsic("llvm.vector.reduce.fadd", &[self.val_ty(src)], &[acc, src]);
1566+
let instr = self.call_intrinsic(
1567+
"llvm.vector.reduce.fadd",
1568+
&[self.val_ty(src)],
1569+
None,
1570+
&[acc, src],
1571+
);
15621572
llvm::LLVMRustSetAllowReassoc(instr);
15631573
instr
15641574
}
@@ -1569,44 +1579,50 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
15691579
src: &'ll Value,
15701580
) -> &'ll Value {
15711581
unsafe {
1572-
let instr =
1573-
self.call_intrinsic("llvm.vector.reduce.fmul", &[self.val_ty(src)], &[acc, src]);
1582+
let instr = self.call_intrinsic(
1583+
"llvm.vector.reduce.fmul",
1584+
&[self.val_ty(src)],
1585+
None,
1586+
&[acc, src],
1587+
);
15741588
llvm::LLVMRustSetAllowReassoc(instr);
15751589
instr
15761590
}
15771591
}
15781592
pub(crate) fn vector_reduce_add(&mut self, src: &'ll Value) -> &'ll Value {
1579-
self.call_intrinsic("llvm.vector.reduce.add", &[self.val_ty(src)], &[src])
1593+
self.call_intrinsic("llvm.vector.reduce.add", &[self.val_ty(src)], None, &[src])
15801594
}
15811595
pub(crate) fn vector_reduce_mul(&mut self, src: &'ll Value) -> &'ll Value {
1582-
self.call_intrinsic("llvm.vector.reduce.mul", &[self.val_ty(src)], &[src])
1596+
self.call_intrinsic("llvm.vector.reduce.mul", &[self.val_ty(src)], None, &[src])
15831597
}
15841598
pub(crate) fn vector_reduce_and(&mut self, src: &'ll Value) -> &'ll Value {
1585-
self.call_intrinsic("llvm.vector.reduce.and", &[self.val_ty(src)], &[src])
1599+
self.call_intrinsic("llvm.vector.reduce.and", &[self.val_ty(src)], None, &[src])
15861600
}
15871601
pub(crate) fn vector_reduce_or(&mut self, src: &'ll Value) -> &'ll Value {
1588-
self.call_intrinsic("llvm.vector.reduce.or", &[self.val_ty(src)], &[src])
1602+
self.call_intrinsic("llvm.vector.reduce.or", &[self.val_ty(src)], None, &[src])
15891603
}
15901604
pub(crate) fn vector_reduce_xor(&mut self, src: &'ll Value) -> &'ll Value {
1591-
self.call_intrinsic("llvm.vector.reduce.xor", &[self.val_ty(src)], &[src])
1605+
self.call_intrinsic("llvm.vector.reduce.xor", &[self.val_ty(src)], None, &[src])
15921606
}
15931607
pub(crate) fn vector_reduce_fmin(&mut self, src: &'ll Value) -> &'ll Value {
1594-
self.call_intrinsic("llvm.vector.reduce.fmin", &[self.val_ty(src)], &[src])
1608+
self.call_intrinsic("llvm.vector.reduce.fmin", &[self.val_ty(src)], None, &[src])
15951609
}
15961610
pub(crate) fn vector_reduce_fmax(&mut self, src: &'ll Value) -> &'ll Value {
1597-
self.call_intrinsic("llvm.vector.reduce.fmax", &[self.val_ty(src)], &[src])
1611+
self.call_intrinsic("llvm.vector.reduce.fmax", &[self.val_ty(src)], None, &[src])
15981612
}
15991613
pub(crate) fn vector_reduce_min(&mut self, src: &'ll Value, is_signed: bool) -> &'ll Value {
16001614
self.call_intrinsic(
16011615
if is_signed { "llvm.vector.reduce.smin" } else { "llvm.vector.reduce.umin" },
16021616
&[self.val_ty(src)],
1617+
None,
16031618
&[src],
16041619
)
16051620
}
16061621
pub(crate) fn vector_reduce_max(&mut self, src: &'ll Value, is_signed: bool) -> &'ll Value {
16071622
self.call_intrinsic(
16081623
if is_signed { "llvm.vector.reduce.smax" } else { "llvm.vector.reduce.umax" },
16091624
&[self.val_ty(src)],
1625+
None,
16101626
&[src],
16111627
)
16121628
}
@@ -1678,10 +1694,11 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
16781694
&mut self,
16791695
base_name: impl Into<Cow<'static, str>>,
16801696
type_params: &[&'ll Type],
1697+
attrs: Option<&CodegenFnAttrs>,
16811698
args: &[&'ll Value],
16821699
) -> &'ll Value {
16831700
let (ty, f) = self.cx.get_intrinsic(base_name.into(), type_params);
1684-
self.call(ty, None, None, f, args, None, None)
1701+
self.call(ty, attrs, None, f, args, None, None)
16851702
}
16861703

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

16971714
if crate::llvm_util::get_version() >= (22, 0, 0) {
1698-
self.call_intrinsic(intrinsic, &[self.val_ty(ptr)], &[ptr]);
1715+
self.call_intrinsic(intrinsic, &[self.val_ty(ptr)], None, &[ptr]);
16991716
} else {
1700-
self.call_intrinsic(intrinsic, &[self.val_ty(ptr)], &[self.cx.const_u64(size), ptr]);
1717+
self.call_intrinsic(
1718+
intrinsic,
1719+
&[self.val_ty(ptr)],
1720+
None,
1721+
&[self.cx.const_u64(size), ptr],
1722+
);
17011723
}
17021724
}
17031725
}
@@ -1828,7 +1850,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
18281850
// llvm.type.test intrinsic. The LowerTypeTests link-time optimization pass replaces
18291851
// calls to this intrinsic with code to test type membership.
18301852
let typeid = self.get_metadata_value(typeid_metadata);
1831-
let cond = self.call_intrinsic("llvm.type.test", &[], &[llfn, typeid]);
1853+
let cond = self.call_intrinsic("llvm.type.test", &[], None, &[llfn, typeid]);
18321854
let bb_pass = self.append_sibling_block("type_test.pass");
18331855
let bb_fail = self.append_sibling_block("type_test.fail");
18341856
self.cond_br(cond, bb_pass, bb_fail);
@@ -1896,6 +1918,11 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
18961918
num_counters: &'ll Value,
18971919
index: &'ll Value,
18981920
) {
1899-
self.call_intrinsic("llvm.instrprof.increment", &[], &[fn_name, hash, num_counters, index]);
1921+
self.call_intrinsic(
1922+
"llvm.instrprof.increment",
1923+
&[],
1924+
None,
1925+
&[fn_name, hash, num_counters, index],
1926+
);
19001927
}
19011928
}

0 commit comments

Comments
 (0)