Skip to content

Commit abd107d

Browse files
committed
Update the minimum external LLVM to 19
1 parent 4f0de4c commit abd107d

File tree

70 files changed

+187
-1872
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+187
-1872
lines changed

compiler/rustc_codegen_llvm/src/abi.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ use rustc_target::callconv::{
1717
use rustc_target::spec::SanitizerSet;
1818
use smallvec::SmallVec;
1919

20-
use crate::attributes::llfn_attrs_from_instance;
20+
use crate::attributes::{self, llfn_attrs_from_instance};
2121
use crate::builder::Builder;
2222
use crate::context::CodegenCx;
2323
use crate::llvm::{self, Attribute, AttributePlace};
2424
use crate::type_::Type;
2525
use crate::type_of::LayoutLlvmExt;
2626
use crate::value::Value;
27-
use crate::{attributes, llvm_util};
2827

2928
trait ArgAttributesExt {
3029
fn apply_attrs_to_llfn(&self, idx: AttributePlace, cx: &CodegenCx<'_, '_>, llfn: &Value);
@@ -437,7 +436,6 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
437436

438437
let apply_range_attr = |idx: AttributePlace, scalar: rustc_abi::Scalar| {
439438
if cx.sess().opts.optimize != config::OptLevel::No
440-
&& llvm_util::get_version() >= (19, 0, 0)
441439
&& matches!(scalar.primitive(), Primitive::Int(..))
442440
// If the value is a boolean, the range is 0..2 and that ultimately
443441
// become 0..0 when the type becomes i1, which would be rejected
@@ -571,19 +569,6 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
571569
}
572570
_ => {}
573571
}
574-
if bx.cx.sess().opts.optimize != config::OptLevel::No
575-
&& llvm_util::get_version() < (19, 0, 0)
576-
&& let BackendRepr::Scalar(scalar) = self.ret.layout.backend_repr
577-
&& matches!(scalar.primitive(), Primitive::Int(..))
578-
// If the value is a boolean, the range is 0..2 and that ultimately
579-
// become 0..0 when the type becomes i1, which would be rejected
580-
// by the LLVM verifier.
581-
&& !scalar.is_bool()
582-
// LLVM also rejects full range.
583-
&& !scalar.is_always_valid(bx)
584-
{
585-
bx.range_metadata(callsite, scalar.valid_range(bx));
586-
}
587572
for arg in self.args.iter() {
588573
match &arg.mode {
589574
PassMode::Ignore => {}

compiler/rustc_codegen_llvm/src/attributes.rs

+21-29
Original file line numberDiff line numberDiff line change
@@ -407,30 +407,28 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
407407
// Do not set sanitizer attributes for naked functions.
408408
to_add.extend(sanitize_attrs(cx, codegen_fn_attrs.no_sanitize));
409409

410-
if llvm_util::get_version() >= (19, 0, 0) {
411-
// For non-naked functions, set branch protection attributes on aarch64.
412-
if let Some(BranchProtection { bti, pac_ret }) =
413-
cx.sess().opts.unstable_opts.branch_protection
414-
{
415-
assert!(cx.sess().target.arch == "aarch64");
416-
if bti {
417-
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-target-enforcement"));
418-
}
419-
if let Some(PacRet { leaf, pc, key }) = pac_ret {
420-
if pc {
421-
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-protection-pauth-lr"));
422-
}
423-
to_add.push(llvm::CreateAttrStringValue(
424-
cx.llcx,
425-
"sign-return-address",
426-
if leaf { "all" } else { "non-leaf" },
427-
));
428-
to_add.push(llvm::CreateAttrStringValue(
429-
cx.llcx,
430-
"sign-return-address-key",
431-
if key == PAuthKey::A { "a_key" } else { "b_key" },
432-
));
410+
// For non-naked functions, set branch protection attributes on aarch64.
411+
if let Some(BranchProtection { bti, pac_ret }) =
412+
cx.sess().opts.unstable_opts.branch_protection
413+
{
414+
assert!(cx.sess().target.arch == "aarch64");
415+
if bti {
416+
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-target-enforcement"));
417+
}
418+
if let Some(PacRet { leaf, pc, key }) = pac_ret {
419+
if pc {
420+
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-protection-pauth-lr"));
433421
}
422+
to_add.push(llvm::CreateAttrStringValue(
423+
cx.llcx,
424+
"sign-return-address",
425+
if leaf { "all" } else { "non-leaf" },
426+
));
427+
to_add.push(llvm::CreateAttrStringValue(
428+
cx.llcx,
429+
"sign-return-address-key",
430+
if key == PAuthKey::A { "a_key" } else { "b_key" },
431+
));
434432
}
435433
}
436434
}
@@ -510,12 +508,6 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
510508
InstructionSetAttr::ArmA32 => "-thumb-mode".to_string(),
511509
InstructionSetAttr::ArmT32 => "+thumb-mode".to_string(),
512510
}))
513-
// HACK: LLVM versions 19+ do not have the FPMR feature and treat it as always enabled
514-
// It only exists as a feature in LLVM 18, cannot be passed down for any other version
515-
.chain(match &*cx.tcx.sess.target.arch {
516-
"aarch64" if llvm_util::get_version().0 == 18 => vec!["+fpmr".to_string()],
517-
_ => vec![],
518-
})
519511
.collect::<Vec<String>>();
520512

521513
if cx.tcx.sess.target.is_like_wasm {

compiler/rustc_codegen_llvm/src/builder.rs

+7-23
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use smallvec::SmallVec;
3030
use tracing::{debug, instrument};
3131

3232
use crate::abi::FnAbiLlvmExt;
33+
use crate::attributes;
3334
use crate::common::Funclet;
3435
use crate::context::{CodegenCx, FullCx, GenericCx, SCx};
3536
use crate::llvm::{
@@ -38,7 +39,6 @@ use crate::llvm::{
3839
use crate::type_::Type;
3940
use crate::type_of::LayoutLlvmExt;
4041
use crate::value::Value;
41-
use crate::{attributes, llvm_util};
4242

4343
#[must_use]
4444
pub(crate) struct GenericBuilder<'a, 'll, CX: Borrow<SCx<'ll>>> {
@@ -927,11 +927,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
927927
debug_assert_ne!(self.val_ty(val), dest_ty);
928928

929929
let trunc = self.trunc(val, dest_ty);
930-
if llvm_util::get_version() >= (19, 0, 0) {
931-
unsafe {
932-
if llvm::LLVMIsAInstruction(trunc).is_some() {
933-
llvm::LLVMSetNUW(trunc, True);
934-
}
930+
unsafe {
931+
if llvm::LLVMIsAInstruction(trunc).is_some() {
932+
llvm::LLVMSetNUW(trunc, True);
935933
}
936934
}
937935
trunc
@@ -941,11 +939,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
941939
debug_assert_ne!(self.val_ty(val), dest_ty);
942940

943941
let trunc = self.trunc(val, dest_ty);
944-
if llvm_util::get_version() >= (19, 0, 0) {
945-
unsafe {
946-
if llvm::LLVMIsAInstruction(trunc).is_some() {
947-
llvm::LLVMSetNSW(trunc, True);
948-
}
942+
unsafe {
943+
if llvm::LLVMIsAInstruction(trunc).is_some() {
944+
llvm::LLVMSetNSW(trunc, True);
949945
}
950946
}
951947
trunc
@@ -1899,10 +1895,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
18991895
hash: &'ll Value,
19001896
bitmap_bits: &'ll Value,
19011897
) {
1902-
assert!(
1903-
crate::llvm_util::get_version() >= (19, 0, 0),
1904-
"MCDC intrinsics require LLVM 19 or later"
1905-
);
19061898
self.call_intrinsic("llvm.instrprof.mcdc.parameters", &[fn_name, hash, bitmap_bits]);
19071899
}
19081900

@@ -1914,10 +1906,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
19141906
bitmap_index: &'ll Value,
19151907
mcdc_temp: &'ll Value,
19161908
) {
1917-
assert!(
1918-
crate::llvm_util::get_version() >= (19, 0, 0),
1919-
"MCDC intrinsics require LLVM 19 or later"
1920-
);
19211909
let args = &[fn_name, hash, bitmap_index, mcdc_temp];
19221910
self.call_intrinsic("llvm.instrprof.mcdc.tvbitmap.update", args);
19231911
}
@@ -1929,10 +1917,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
19291917

19301918
#[instrument(level = "debug", skip(self))]
19311919
pub(crate) fn mcdc_condbitmap_update(&mut self, cond_index: &'ll Value, mcdc_temp: &'ll Value) {
1932-
assert!(
1933-
crate::llvm_util::get_version() >= (19, 0, 0),
1934-
"MCDC intrinsics require LLVM 19 or later"
1935-
);
19361920
let align = self.tcx.data_layout.i32_align.abi;
19371921
let current_tv_index = self.load(self.cx.type_i32(), mcdc_temp, align);
19381922
let new_tv_index = self.add(current_tv_index, cond_index);

compiler/rustc_codegen_llvm/src/context.rs

+2-21
Original file line numberDiff line numberDiff line change
@@ -163,23 +163,6 @@ pub(crate) unsafe fn create_module<'ll>(
163163
let mut target_data_layout = sess.target.data_layout.to_string();
164164
let llvm_version = llvm_util::get_version();
165165

166-
if llvm_version < (19, 0, 0) {
167-
if sess.target.arch == "aarch64" || sess.target.arch.starts_with("arm64") {
168-
// LLVM 19 sets -Fn32 in its data layout string for 64-bit ARM
169-
// Earlier LLVMs leave this default, so remove it.
170-
// See https://github.com/llvm/llvm-project/pull/90702
171-
target_data_layout = target_data_layout.replace("-Fn32", "");
172-
}
173-
}
174-
175-
if llvm_version < (19, 0, 0) {
176-
if sess.target.arch == "loongarch64" {
177-
// LLVM 19 updates the LoongArch64 data layout.
178-
// See https://github.com/llvm/llvm-project/pull/93814
179-
target_data_layout = target_data_layout.replace("-n32:64", "-n64");
180-
}
181-
}
182-
183166
if llvm_version < (20, 0, 0) {
184167
if sess.target.arch == "aarch64" || sess.target.arch.starts_with("arm64") {
185168
// LLVM 20 defines three additional address spaces for alternate
@@ -1183,10 +1166,8 @@ impl<'ll> CodegenCx<'ll, '_> {
11831166

11841167
if self.sess().instrument_coverage() {
11851168
ifn!("llvm.instrprof.increment", fn(ptr, t_i64, t_i32, t_i32) -> void);
1186-
if crate::llvm_util::get_version() >= (19, 0, 0) {
1187-
ifn!("llvm.instrprof.mcdc.parameters", fn(ptr, t_i64, t_i32) -> void);
1188-
ifn!("llvm.instrprof.mcdc.tvbitmap.update", fn(ptr, t_i64, t_i32, ptr) -> void);
1189-
}
1169+
ifn!("llvm.instrprof.mcdc.parameters", fn(ptr, t_i64, t_i32) -> void);
1170+
ifn!("llvm.instrprof.mcdc.tvbitmap.update", fn(ptr, t_i64, t_i32, ptr) -> void);
11901171
}
11911172

11921173
ifn!("llvm.type.test", fn(ptr, t_metadata) -> i1);

compiler/rustc_codegen_llvm/src/llvm_util.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
256256
("aarch64", "pmuv3") => Some(LLVMFeature::new("perfmon")),
257257
("aarch64", "paca") => Some(LLVMFeature::new("pauth")),
258258
("aarch64", "pacg") => Some(LLVMFeature::new("pauth")),
259-
("aarch64", "pauth-lr") if get_version().0 < 19 => None,
260259
// Before LLVM 20 those two features were packaged together as b16b16
261260
("aarch64", "sve-b16b16") if get_version().0 < 20 => Some(LLVMFeature::new("b16b16")),
262261
("aarch64", "sme-b16b16") if get_version().0 < 20 => Some(LLVMFeature::new("b16b16")),
@@ -270,20 +269,9 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
270269
("aarch64", "fhm") => Some(LLVMFeature::new("fp16fml")),
271270
("aarch64", "fp16") => Some(LLVMFeature::new("fullfp16")),
272271
// Filter out features that are not supported by the current LLVM version
273-
("aarch64", "fpmr") if get_version().0 != 18 => None,
272+
("aarch64", "fpmr") => None, // only existed in 18
274273
("arm", "fp16") => Some(LLVMFeature::new("fullfp16")),
275-
// In LLVM 18, `unaligned-scalar-mem` was merged with `unaligned-vector-mem` into a single
276-
// feature called `fast-unaligned-access`. In LLVM 19, it was split back out.
277-
("riscv32" | "riscv64", "unaligned-scalar-mem" | "unaligned-vector-mem")
278-
if get_version().0 == 18 =>
279-
{
280-
Some(LLVMFeature::new("fast-unaligned-access"))
281-
}
282274
// Filter out features that are not supported by the current LLVM version
283-
("riscv32" | "riscv64", "zaamo") if get_version().0 < 19 => None,
284-
("riscv32" | "riscv64", "zabha") if get_version().0 < 19 => None,
285-
("riscv32" | "riscv64", "zalrsc") if get_version().0 < 19 => None,
286-
("riscv32" | "riscv64", "zama16b") if get_version().0 < 19 => None,
287275
("riscv32" | "riscv64", "zacas") if get_version().0 < 20 => None,
288276
// Enable the evex512 target feature if an avx512 target feature is enabled.
289277
("x86", s) if s.starts_with("avx512") => {
@@ -295,10 +283,9 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
295283
("sparc", "leoncasa") => Some(LLVMFeature::new("hasleoncasa")),
296284
// In LLVM 19, there is no `v8plus` feature and `v9` means "SPARC-V9 instruction available and SPARC-V8+ ABI used".
297285
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp#L27-L28
298-
// Before LLVM 19, there is no `v8plus` feature and `v9` means "SPARC-V9 instruction available".
286+
// Before LLVM 19, there was no `v8plus` feature and `v9` means "SPARC-V9 instruction available".
299287
// https://github.com/llvm/llvm-project/blob/llvmorg-18.1.0/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp#L26
300288
("sparc", "v8plus") if get_version().0 == 19 => Some(LLVMFeature::new("v9")),
301-
("sparc", "v8plus") if get_version().0 < 19 => None,
302289
("powerpc", "power8-crypto") => Some(LLVMFeature::new("crypto")),
303290
// These new `amx` variants and `movrs` were introduced in LLVM20
304291
("x86", "amx-avx512" | "amx-fp8" | "amx-movrs" | "amx-tf32" | "amx-transpose")

compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ struct LLVMRustMCDCBranchParameters {
4747
int16_t ConditionIDs[2];
4848
};
4949

50-
#if LLVM_VERSION_GE(19, 0)
5150
static coverage::mcdc::BranchParameters
5251
fromRust(LLVMRustMCDCBranchParameters Params) {
5352
return coverage::mcdc::BranchParameters(
@@ -59,7 +58,6 @@ fromRust(LLVMRustMCDCDecisionParameters Params) {
5958
return coverage::mcdc::DecisionParameters(Params.BitmapIdx,
6059
Params.NumConditions);
6160
}
62-
#endif
6361

6462
// Must match the layout of
6563
// `rustc_codegen_llvm::coverageinfo::ffi::CoverageSpan`.
@@ -203,7 +201,6 @@ extern "C" void LLVMRustCoverageWriteFunctionMappingsToBuffer(
203201
Region.Span.LineEnd, Region.Span.ColumnEnd));
204202
}
205203

206-
#if LLVM_VERSION_GE(19, 0)
207204
// MC/DC branch regions:
208205
for (const auto &Region : ArrayRef(MCDCBranchRegions, NumMCDCBranchRegions)) {
209206
MappingRegions.push_back(coverage::CounterMappingRegion::makeBranchRegion(
@@ -221,7 +218,6 @@ extern "C" void LLVMRustCoverageWriteFunctionMappingsToBuffer(
221218
Region.Span.LineStart, Region.Span.ColumnStart, Region.Span.LineEnd,
222219
Region.Span.ColumnEnd));
223220
}
224-
#endif
225221

226222
// Write the converted expressions and mappings to a byte buffer.
227223
auto CoverageMappingWriter = coverage::CoverageMappingWriter(

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+1-28
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@
4747
#include <vector>
4848

4949
// Conditional includes prevent clang-format from fully sorting the list,
50-
// so keep them separate.
51-
#if LLVM_VERSION_GE(19, 0)
52-
#include "llvm/Support/PGOOptions.h"
53-
#endif
50+
// so if any are needed, keep them separate down here.
5451

5552
using namespace llvm;
5653

@@ -432,31 +429,15 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
432429
}
433430
if (!strcmp("zlib", DebugInfoCompression) &&
434431
llvm::compression::zlib::isAvailable()) {
435-
#if LLVM_VERSION_GE(19, 0)
436432
Options.MCOptions.CompressDebugSections = DebugCompressionType::Zlib;
437-
#else
438-
Options.CompressDebugSections = DebugCompressionType::Zlib;
439-
#endif
440433
} else if (!strcmp("zstd", DebugInfoCompression) &&
441434
llvm::compression::zstd::isAvailable()) {
442-
#if LLVM_VERSION_GE(19, 0)
443435
Options.MCOptions.CompressDebugSections = DebugCompressionType::Zstd;
444-
#else
445-
Options.CompressDebugSections = DebugCompressionType::Zstd;
446-
#endif
447436
} else if (!strcmp("none", DebugInfoCompression)) {
448-
#if LLVM_VERSION_GE(19, 0)
449437
Options.MCOptions.CompressDebugSections = DebugCompressionType::None;
450-
#else
451-
Options.CompressDebugSections = DebugCompressionType::None;
452-
#endif
453438
}
454439

455-
#if LLVM_VERSION_GE(19, 0)
456440
Options.MCOptions.X86RelaxRelocations = RelaxELFRelocations;
457-
#else
458-
Options.RelaxELFRelocations = RelaxELFRelocations;
459-
#endif
460441
Options.UseInitArray = UseInitArray;
461442
Options.EmulatedTLS = UseEmulatedTls;
462443

@@ -755,31 +736,23 @@ extern "C" LLVMRustResult LLVMRustOptimize(
755736
assert(!PGOUsePath && !PGOSampleUsePath);
756737
PGOOpt = PGOOptions(PGOGenPath, "", "", "", FS, PGOOptions::IRInstr,
757738
PGOOptions::NoCSAction,
758-
#if LLVM_VERSION_GE(19, 0)
759739
PGOOptions::ColdFuncOpt::Default,
760-
#endif
761740
DebugInfoForProfiling);
762741
} else if (PGOUsePath) {
763742
assert(!PGOSampleUsePath);
764743
PGOOpt = PGOOptions(PGOUsePath, "", "", "", FS, PGOOptions::IRUse,
765744
PGOOptions::NoCSAction,
766-
#if LLVM_VERSION_GE(19, 0)
767745
PGOOptions::ColdFuncOpt::Default,
768-
#endif
769746
DebugInfoForProfiling);
770747
} else if (PGOSampleUsePath) {
771748
PGOOpt = PGOOptions(PGOSampleUsePath, "", "", "", FS, PGOOptions::SampleUse,
772749
PGOOptions::NoCSAction,
773-
#if LLVM_VERSION_GE(19, 0)
774750
PGOOptions::ColdFuncOpt::Default,
775-
#endif
776751
DebugInfoForProfiling);
777752
} else if (DebugInfoForProfiling) {
778753
PGOOpt = PGOOptions("", "", "", "", FS, PGOOptions::NoAction,
779754
PGOOptions::NoCSAction,
780-
#if LLVM_VERSION_GE(19, 0)
781755
PGOOptions::ColdFuncOpt::Default,
782-
#endif
783756
DebugInfoForProfiling);
784757
}
785758

0 commit comments

Comments
 (0)