Skip to content

Commit fe489e4

Browse files
authored
Unrolled build for rust-lang#130487
Rollup merge of rust-lang#130487 - cuviper:min-llvm-18, r=nikic Update the minimum external LLVM to 18 With this change, we'll have stable support for LLVM 18 and 19. For reference, the previous increase to LLVM 17 was rust-lang#122649. cc `@rust-lang/wg-llvm` r? nikic
2 parents f79a912 + 8bab397 commit fe489e4

Some content is hidden

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

58 files changed

+89
-403
lines changed

compiler/rustc_codegen_llvm/src/abi.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
465465
cx.type_array(cx.type_i8(), self.ret.layout.size.bytes()),
466466
);
467467
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Argument(i), &[sret]);
468-
if cx.sess().opts.optimize != config::OptLevel::No
469-
&& llvm_util::get_version() >= (18, 0, 0)
470-
{
468+
if cx.sess().opts.optimize != config::OptLevel::No {
471469
attributes::apply_to_llfn(
472470
llfn,
473471
llvm::AttributePlace::Argument(i),

compiler/rustc_codegen_llvm/src/builder.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ use smallvec::SmallVec;
2626
use tracing::{debug, instrument};
2727

2828
use crate::abi::FnAbiLlvmExt;
29+
use crate::attributes;
2930
use crate::common::Funclet;
3031
use crate::context::CodegenCx;
3132
use crate::llvm::{self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, True};
3233
use crate::type_::Type;
3334
use crate::type_of::LayoutLlvmExt;
3435
use crate::value::Value;
35-
use crate::{attributes, llvm_util};
3636

3737
// All Builders must have an llfn associated with them
3838
#[must_use]
@@ -1311,15 +1311,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13111311
}
13121312

13131313
fn apply_attrs_to_cleanup_callsite(&mut self, llret: &'ll Value) {
1314-
if llvm_util::get_version() < (17, 0, 2) {
1315-
// Work around https://github.com/llvm/llvm-project/issues/66984.
1316-
let noinline = llvm::AttributeKind::NoInline.create_attr(self.llcx);
1317-
attributes::apply_to_callsite(llret, llvm::AttributePlace::Function, &[noinline]);
1318-
} else {
1319-
// Cleanup is always the cold path.
1320-
let cold_inline = llvm::AttributeKind::Cold.create_attr(self.llcx);
1321-
attributes::apply_to_callsite(llret, llvm::AttributePlace::Function, &[cold_inline]);
1322-
}
1314+
// Cleanup is always the cold path.
1315+
let cold_inline = llvm::AttributeKind::Cold.create_attr(self.llcx);
1316+
attributes::apply_to_callsite(llret, llvm::AttributePlace::Function, &[cold_inline]);
13231317
}
13241318
}
13251319

@@ -1761,8 +1755,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
17611755
) {
17621756
debug!("mcdc_parameters() with args ({:?}, {:?}, {:?})", fn_name, hash, bitmap_bytes);
17631757

1764-
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");
1765-
17661758
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCParametersIntrinsic(self.cx().llmod) };
17671759
let llty = self.cx.type_func(
17681760
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32()],
@@ -1796,7 +1788,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
17961788
"mcdc_tvbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
17971789
fn_name, hash, bitmap_bytes, bitmap_index, mcdc_temp
17981790
);
1799-
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");
18001791

18011792
let llfn =
18021793
unsafe { llvm::LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(self.cx().llmod) };
@@ -1838,7 +1829,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
18381829
"mcdc_condbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
18391830
fn_name, hash, cond_loc, mcdc_temp, bool_value
18401831
);
1841-
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");
18421832
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(self.cx().llmod) };
18431833
let llty = self.cx.type_func(
18441834
&[

compiler/rustc_codegen_llvm/src/context.rs

-8
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,6 @@ pub(crate) unsafe fn create_module<'ll>(
120120

121121
let mut target_data_layout = sess.target.data_layout.to_string();
122122
let llvm_version = llvm_util::get_version();
123-
if llvm_version < (18, 0, 0) {
124-
if sess.target.arch == "x86" || sess.target.arch == "x86_64" {
125-
// LLVM 18 adjusts i128 to be 128-bit aligned on x86 variants.
126-
// Earlier LLVMs leave this as default alignment, so remove it.
127-
// See https://reviews.llvm.org/D86310
128-
target_data_layout = target_data_layout.replace("-i128:128", "");
129-
}
130-
}
131123

132124
if llvm_version < (19, 0, 0) {
133125
if sess.target.arch == "aarch64" || sess.target.arch.starts_with("arm64") {

compiler/rustc_codegen_llvm/src/llvm_util.rs

+2-23
Original file line numberDiff line numberDiff line change
@@ -258,28 +258,14 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
258258
("aarch64", "fhm") => Some(LLVMFeature::new("fp16fml")),
259259
("aarch64", "fp16") => Some(LLVMFeature::new("fullfp16")),
260260
// Filter out features that are not supported by the current LLVM version
261-
("aarch64", "faminmax") if get_version().0 < 18 => None,
262-
("aarch64", "fp8") if get_version().0 < 18 => None,
263-
("aarch64", "fp8dot2") if get_version().0 < 18 => None,
264-
("aarch64", "fp8dot4") if get_version().0 < 18 => None,
265-
("aarch64", "fp8fma") if get_version().0 < 18 => None,
266261
("aarch64", "fpmr") if get_version().0 != 18 => None,
267-
("aarch64", "lut") if get_version().0 < 18 => None,
268-
("aarch64", "sme-f8f16") if get_version().0 < 18 => None,
269-
("aarch64", "sme-f8f32") if get_version().0 < 18 => None,
270-
("aarch64", "sme-fa64") if get_version().0 < 18 => None,
271-
("aarch64", "sme-lutv2") if get_version().0 < 18 => None,
272-
("aarch64", "ssve-fp8dot2") if get_version().0 < 18 => None,
273-
("aarch64", "ssve-fp8dot4") if get_version().0 < 18 => None,
274-
("aarch64", "ssve-fp8fma") if get_version().0 < 18 => None,
275-
("aarch64", "v9.5a") if get_version().0 < 18 => None,
276262
// In LLVM 18, `unaligned-scalar-mem` was merged with `unaligned-vector-mem` into a single feature called
277263
// `fast-unaligned-access`. In LLVM 19, it was split back out.
278264
("riscv32" | "riscv64", "unaligned-scalar-mem") if get_version().0 == 18 => {
279265
Some(LLVMFeature::new("fast-unaligned-access"))
280266
}
281-
// For LLVM 18, enable the evex512 target feature if a avx512 target feature is enabled.
282-
("x86", s) if get_version().0 >= 18 && s.starts_with("avx512") => {
267+
// Enable the evex512 target feature if an avx512 target feature is enabled.
268+
("x86", s) if s.starts_with("avx512") => {
283269
Some(LLVMFeature::with_dependency(s, TargetFeatureFoldStrength::EnableOnly("evex512")))
284270
}
285271
(_, s) => Some(LLVMFeature::new(s)),
@@ -587,7 +573,6 @@ pub(crate) fn global_llvm_features(
587573
// -Ctarget-features
588574
if !only_base_features {
589575
let supported_features = sess.target.supported_target_features();
590-
let (llvm_major, _, _) = get_version();
591576
let mut featsmap = FxHashMap::default();
592577

593578
// insert implied features
@@ -664,12 +649,6 @@ pub(crate) fn global_llvm_features(
664649
return None;
665650
}
666651

667-
// if the target-feature is "backchain" and LLVM version is greater than 18
668-
// then we also need to add "+backchain" to the target-features attribute.
669-
// otherwise, we will only add the naked `backchain` attribute to the attribute-group.
670-
if feature == "backchain" && llvm_major < 18 {
671-
return None;
672-
}
673652
// ... otherwise though we run through `to_llvm_features` when
674653
// passing requests down to LLVM. This means that all in-language
675654
// features also work on the command line instead of having two

compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,10 @@ extern "C" LLVMRustResult LLVMRustWriteArchive(
196196
}
197197
}
198198

199-
#if LLVM_VERSION_LT(18, 0)
200-
auto Result = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false);
201-
#else
202199
auto SymtabMode = WriteSymbtab ? SymtabWritingMode::NormalSymtab
203200
: SymtabWritingMode::NoSymtab;
204201
auto Result =
205202
writeArchive(Dst, Members, SymtabMode, Kind, true, false, nullptr, isEC);
206-
#endif
207203
if (!Result)
208204
return LLVMRustResult::Success;
209205
LLVMRustSetLastError(toString(std::move(Result)).c_str());

compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp

+3-10
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,10 @@ fromRust(LLVMRustCounterMappingRegionKind Kind) {
5858
return coverage::CounterMappingRegion::GapRegion;
5959
case LLVMRustCounterMappingRegionKind::BranchRegion:
6060
return coverage::CounterMappingRegion::BranchRegion;
61-
#if LLVM_VERSION_GE(18, 0)
6261
case LLVMRustCounterMappingRegionKind::MCDCDecisionRegion:
6362
return coverage::CounterMappingRegion::MCDCDecisionRegion;
6463
case LLVMRustCounterMappingRegionKind::MCDCBranchRegion:
6564
return coverage::CounterMappingRegion::MCDCBranchRegion;
66-
#else
67-
case LLVMRustCounterMappingRegionKind::MCDCDecisionRegion:
68-
break;
69-
case LLVMRustCounterMappingRegionKind::MCDCBranchRegion:
70-
break;
71-
#endif
7265
}
7366
report_fatal_error("Bad LLVMRustCounterMappingRegionKind!");
7467
}
@@ -100,7 +93,7 @@ struct LLVMRustMCDCParameters {
10093
// https://github.com/rust-lang/llvm-project/blob/66a2881a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L253-L263
10194
// and representations in 19
10295
// https://github.com/llvm/llvm-project/blob/843cc474faefad1d639f4c44c1cf3ad7dbda76c8/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
103-
#if LLVM_VERSION_GE(18, 0) && LLVM_VERSION_LT(19, 0)
96+
#if LLVM_VERSION_LT(19, 0)
10497
static coverage::CounterMappingRegion::MCDCParameters
10598
fromRust(LLVMRustMCDCParameters Params) {
10699
auto parameter = coverage::CounterMappingRegion::MCDCParameters{};
@@ -126,7 +119,7 @@ fromRust(LLVMRustMCDCParameters Params) {
126119
}
127120
report_fatal_error("Bad LLVMRustMCDCParametersTag!");
128121
}
129-
#elif LLVM_VERSION_GE(19, 0)
122+
#else
130123
static coverage::mcdc::Parameters fromRust(LLVMRustMCDCParameters Params) {
131124
switch (Params.Tag) {
132125
case LLVMRustMCDCParametersTag::None:
@@ -221,7 +214,7 @@ extern "C" void LLVMRustCoverageWriteMappingToBuffer(
221214
RustMappingRegions, NumMappingRegions)) {
222215
MappingRegions.emplace_back(
223216
fromRust(Region.Count), fromRust(Region.FalseCount),
224-
#if LLVM_VERSION_GE(18, 0) && LLVM_VERSION_LT(19, 0)
217+
#if LLVM_VERSION_LT(19, 0)
225218
// LLVM 19 may move this argument to last.
226219
fromRust(Region.MCDCParameters),
227220
#endif

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+4-38
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,19 @@
2626
#include "llvm/Passes/StandardInstrumentations.h"
2727
#include "llvm/Support/CBindingWrapping.h"
2828
#include "llvm/Support/FileSystem.h"
29+
#include "llvm/Support/TimeProfiler.h"
2930
#include "llvm/Support/VirtualFileSystem.h"
3031
#include "llvm/Target/TargetMachine.h"
32+
#include "llvm/TargetParser/Host.h"
3133
#include "llvm/Transforms/IPO/AlwaysInliner.h"
3234
#include "llvm/Transforms/IPO/FunctionImport.h"
3335
#include "llvm/Transforms/IPO/Internalize.h"
3436
#include "llvm/Transforms/IPO/LowerTypeTests.h"
3537
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
36-
#include "llvm/Transforms/Utils/AddDiscriminators.h"
37-
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
38-
#if LLVM_VERSION_GE(18, 0)
39-
#include "llvm/TargetParser/Host.h"
40-
#endif
41-
#include "llvm/Support/TimeProfiler.h"
4238
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
4339
#include "llvm/Transforms/Instrumentation/DataFlowSanitizer.h"
40+
#include "llvm/Transforms/Utils/AddDiscriminators.h"
41+
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
4442
#if LLVM_VERSION_GE(19, 0)
4543
#include "llvm/Support/PGOOptions.h"
4644
#endif
@@ -240,11 +238,7 @@ enum class LLVMRustCodeGenOptLevel {
240238
Aggressive,
241239
};
242240

243-
#if LLVM_VERSION_GE(18, 0)
244241
using CodeGenOptLevelEnum = llvm::CodeGenOptLevel;
245-
#else
246-
using CodeGenOptLevelEnum = llvm::CodeGenOpt::Level;
247-
#endif
248242

249243
static CodeGenOptLevelEnum fromRust(LLVMRustCodeGenOptLevel Level) {
250244
switch (Level) {
@@ -370,29 +364,23 @@ extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM,
370364
}
371365

372366
extern "C" size_t LLVMRustGetTargetFeaturesCount(LLVMTargetMachineRef TM) {
373-
#if LLVM_VERSION_GE(18, 0)
374367
const TargetMachine *Target = unwrap(TM);
375368
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
376369
const ArrayRef<SubtargetFeatureKV> FeatTable =
377370
MCInfo->getAllProcessorFeatures();
378371
return FeatTable.size();
379-
#else
380-
return 0;
381-
#endif
382372
}
383373

384374
extern "C" void LLVMRustGetTargetFeature(LLVMTargetMachineRef TM, size_t Index,
385375
const char **Feature,
386376
const char **Desc) {
387-
#if LLVM_VERSION_GE(18, 0)
388377
const TargetMachine *Target = unwrap(TM);
389378
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
390379
const ArrayRef<SubtargetFeatureKV> FeatTable =
391380
MCInfo->getAllProcessorFeatures();
392381
const SubtargetFeatureKV Feat = FeatTable[Index];
393382
*Feature = Feat.Key;
394383
*Desc = Feat.Desc;
395-
#endif
396384
}
397385

398386
extern "C" const char *LLVMRustGetHostCPUName(size_t *len) {
@@ -569,17 +557,9 @@ enum class LLVMRustFileType {
569557
static CodeGenFileType fromRust(LLVMRustFileType Type) {
570558
switch (Type) {
571559
case LLVMRustFileType::AssemblyFile:
572-
#if LLVM_VERSION_GE(18, 0)
573560
return CodeGenFileType::AssemblyFile;
574-
#else
575-
return CGFT_AssemblyFile;
576-
#endif
577561
case LLVMRustFileType::ObjectFile:
578-
#if LLVM_VERSION_GE(18, 0)
579562
return CodeGenFileType::ObjectFile;
580-
#else
581-
return CGFT_ObjectFile;
582-
#endif
583563
default:
584564
report_fatal_error("Bad FileType.");
585565
}
@@ -865,11 +845,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(
865845
// cargo run tests in multhreading mode by default
866846
// so use atomics for coverage counters
867847
Options.Atomic = true;
868-
#if LLVM_VERSION_GE(18, 0)
869848
MPM.addPass(InstrProfilingLoweringPass(Options, false));
870-
#else
871-
MPM.addPass(InstrProfiling(Options, false));
872-
#endif
873849
});
874850
}
875851

@@ -1210,19 +1186,13 @@ struct LLVMRustThinLTOData {
12101186

12111187
// Not 100% sure what these are, but they impact what's internalized and
12121188
// what's inlined across modules, I believe.
1213-
#if LLVM_VERSION_GE(18, 0)
12141189
#if LLVM_VERSION_GE(20, 0)
12151190
FunctionImporter::ImportListsTy ImportLists;
12161191
#else
12171192
DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists;
12181193
#endif
12191194
DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists;
12201195
DenseMap<StringRef, GVSummaryMapTy> ModuleToDefinedGVSummaries;
1221-
#else
1222-
StringMap<FunctionImporter::ImportMapTy> ImportLists;
1223-
StringMap<FunctionImporter::ExportSetTy> ExportLists;
1224-
StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries;
1225-
#endif
12261196
StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;
12271197

12281198
LLVMRustThinLTOData() : Index(/* HaveGVs = */ false) {}
@@ -1274,11 +1244,7 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules, int num_modules,
12741244

12751245
Ret->ModuleMap[module->identifier] = mem_buffer;
12761246

1277-
#if LLVM_VERSION_GE(18, 0)
12781247
if (Error Err = readModuleSummaryIndex(mem_buffer, Ret->Index)) {
1279-
#else
1280-
if (Error Err = readModuleSummaryIndex(mem_buffer, Ret->Index, i)) {
1281-
#endif
12821248
LLVMRustSetLastError(toString(std::move(Err)).c_str());
12831249
return nullptr;
12841250
}

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+3-24
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,10 @@ static Attribute::AttrKind fromRust(LLVMRustAttribute Kind) {
310310
return Attribute::SafeStack;
311311
case FnRetThunkExtern:
312312
return Attribute::FnRetThunkExtern;
313-
#if LLVM_VERSION_GE(18, 0)
314313
case Writable:
315314
return Attribute::Writable;
316315
case DeadOnUnwind:
317316
return Attribute::DeadOnUnwind;
318-
#else
319-
case Writable:
320-
case DeadOnUnwind:
321-
report_fatal_error("Not supported on this LLVM version");
322-
#endif
323317
}
324318
report_fatal_error("bad AttributeKind");
325319
}
@@ -1061,11 +1055,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateStaticMemberType(
10611055
return wrap(Builder->createStaticMemberType(
10621056
unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen),
10631057
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), fromRust(Flags),
1064-
unwrap<llvm::ConstantInt>(val),
1065-
#if LLVM_VERSION_GE(18, 0)
1066-
llvm::dwarf::DW_TAG_member,
1067-
#endif
1068-
AlignInBits));
1058+
unwrap<llvm::ConstantInt>(val), llvm::dwarf::DW_TAG_member, AlignInBits));
10691059
}
10701060

10711061
extern "C" LLVMMetadataRef
@@ -1182,10 +1172,7 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateEnumerationType(
11821172
unwrapDI<DIDescriptor>(Scope), StringRef(Name, NameLen),
11831173
unwrapDI<DIFile>(File), LineNumber, SizeInBits, AlignInBits,
11841174
DINodeArray(unwrapDI<MDTuple>(Elements)), unwrapDI<DIType>(ClassTy),
1185-
#if LLVM_VERSION_GE(18, 0)
1186-
/* RunTimeLang */ 0,
1187-
#endif
1188-
"", IsScoped));
1175+
/* RunTimeLang */ 0, "", IsScoped));
11891176
}
11901177

11911178
extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateUnionType(
@@ -1552,27 +1539,19 @@ LLVMRustGetInstrProfIncrementIntrinsic(LLVMModuleRef M) {
15521539

15531540
extern "C" LLVMValueRef
15541541
LLVMRustGetInstrProfMCDCParametersIntrinsic(LLVMModuleRef M) {
1555-
#if LLVM_VERSION_GE(18, 0)
15561542
return wrap(llvm::Intrinsic::getDeclaration(
15571543
unwrap(M), llvm::Intrinsic::instrprof_mcdc_parameters));
1558-
#else
1559-
report_fatal_error("LLVM 18.0 is required for mcdc intrinsic functions");
1560-
#endif
15611544
}
15621545

15631546
extern "C" LLVMValueRef
15641547
LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(LLVMModuleRef M) {
1565-
#if LLVM_VERSION_GE(18, 0)
15661548
return wrap(llvm::Intrinsic::getDeclaration(
15671549
unwrap(M), llvm::Intrinsic::instrprof_mcdc_tvbitmap_update));
1568-
#else
1569-
report_fatal_error("LLVM 18.0 is required for mcdc intrinsic functions");
1570-
#endif
15711550
}
15721551

15731552
extern "C" LLVMValueRef
15741553
LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(LLVMModuleRef M) {
1575-
#if LLVM_VERSION_GE(18, 0) && LLVM_VERSION_LT(19, 0)
1554+
#if LLVM_VERSION_LT(19, 0)
15761555
return wrap(llvm::Intrinsic::getDeclaration(
15771556
unwrap(M), llvm::Intrinsic::instrprof_mcdc_condbitmap_update));
15781557
#else

0 commit comments

Comments
 (0)