Skip to content

Commit ad18186

Browse files
committed
Update the minimum external LLVM to 18
1 parent c52c23b commit ad18186

Some content is hidden

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

57 files changed

+84
-396
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]
@@ -1317,15 +1317,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
13171317
}
13181318

13191319
fn apply_attrs_to_cleanup_callsite(&mut self, llret: &'ll Value) {
1320-
if llvm_util::get_version() < (17, 0, 2) {
1321-
// Work around https://github.com/llvm/llvm-project/issues/66984.
1322-
let noinline = llvm::AttributeKind::NoInline.create_attr(self.llcx);
1323-
attributes::apply_to_callsite(llret, llvm::AttributePlace::Function, &[noinline]);
1324-
} else {
1325-
// Cleanup is always the cold path.
1326-
let cold_inline = llvm::AttributeKind::Cold.create_attr(self.llcx);
1327-
attributes::apply_to_callsite(llret, llvm::AttributePlace::Function, &[cold_inline]);
1328-
}
1320+
// Cleanup is always the cold path.
1321+
let cold_inline = llvm::AttributeKind::Cold.create_attr(self.llcx);
1322+
attributes::apply_to_callsite(llret, llvm::AttributePlace::Function, &[cold_inline]);
13291323
}
13301324
}
13311325

@@ -1767,8 +1761,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
17671761
) {
17681762
debug!("mcdc_parameters() with args ({:?}, {:?}, {:?})", fn_name, hash, bitmap_bytes);
17691763

1770-
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");
1771-
17721764
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCParametersIntrinsic(self.cx().llmod) };
17731765
let llty = self.cx.type_func(
17741766
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32()],
@@ -1802,7 +1794,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
18021794
"mcdc_tvbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
18031795
fn_name, hash, bitmap_bytes, bitmap_index, mcdc_temp
18041796
);
1805-
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");
18061797

18071798
let llfn =
18081799
unsafe { llvm::LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(self.cx().llmod) };
@@ -1844,7 +1835,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
18441835
"mcdc_condbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
18451836
fn_name, hash, cond_loc, mcdc_temp, bool_value
18461837
);
1847-
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");
18481838
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(self.cx().llmod) };
18491839
let llty = self.cx.type_func(
18501840
&[

compiler/rustc_codegen_llvm/src/context.rs

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

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

134126
if llvm_version < (19, 0, 0) {
135127
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

-34
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@
3535
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
3636
#include "llvm/Transforms/Utils/AddDiscriminators.h"
3737
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
38-
#if LLVM_VERSION_GE(18, 0)
3938
#include "llvm/TargetParser/Host.h"
40-
#endif
4139
#include "llvm/Support/TimeProfiler.h"
4240
#include "llvm/Transforms/Instrumentation.h"
4341
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
@@ -241,11 +239,7 @@ enum class LLVMRustCodeGenOptLevel {
241239
Aggressive,
242240
};
243241

244-
#if LLVM_VERSION_GE(18, 0)
245242
using CodeGenOptLevelEnum = llvm::CodeGenOptLevel;
246-
#else
247-
using CodeGenOptLevelEnum = llvm::CodeGenOpt::Level;
248-
#endif
249243

250244
static CodeGenOptLevelEnum fromRust(LLVMRustCodeGenOptLevel Level) {
251245
switch (Level) {
@@ -371,29 +365,23 @@ extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM,
371365
}
372366

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

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

399387
extern "C" const char *LLVMRustGetHostCPUName(size_t *len) {
@@ -570,17 +558,9 @@ enum class LLVMRustFileType {
570558
static CodeGenFileType fromRust(LLVMRustFileType Type) {
571559
switch (Type) {
572560
case LLVMRustFileType::AssemblyFile:
573-
#if LLVM_VERSION_GE(18, 0)
574561
return CodeGenFileType::AssemblyFile;
575-
#else
576-
return CGFT_AssemblyFile;
577-
#endif
578562
case LLVMRustFileType::ObjectFile:
579-
#if LLVM_VERSION_GE(18, 0)
580563
return CodeGenFileType::ObjectFile;
581-
#else
582-
return CGFT_ObjectFile;
583-
#endif
584564
default:
585565
report_fatal_error("Bad FileType.");
586566
}
@@ -866,11 +846,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(
866846
// cargo run tests in multhreading mode by default
867847
// so use atomics for coverage counters
868848
Options.Atomic = true;
869-
#if LLVM_VERSION_GE(18, 0)
870849
MPM.addPass(InstrProfilingLoweringPass(Options, false));
871-
#else
872-
MPM.addPass(InstrProfiling(Options, false));
873-
#endif
874850
});
875851
}
876852

@@ -1211,19 +1187,13 @@ struct LLVMRustThinLTOData {
12111187

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

12291199
LLVMRustThinLTOData() : Index(/* HaveGVs = */ false) {}
@@ -1275,11 +1245,7 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules, int num_modules,
12751245

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

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

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

compiler/rustc_llvm/llvm-wrapper/SymbolWrapper.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,9 @@ extern "C" bool LLVMRustIsECObject(char *BufPtr, size_t BufLen) {
150150
return cast<llvm::object::COFFObjectFile>(&*Obj)->getMachine() !=
151151
COFF::IMAGE_FILE_MACHINE_ARM64;
152152

153-
#if LLVM_VERSION_GE(18, 0)
154153
if (Obj->isCOFFImportFile())
155154
return cast<llvm::object::COFFImportFile>(&*Obj)->getMachine() !=
156155
COFF::IMAGE_FILE_MACHINE_ARM64;
157-
#endif
158156

159157
if (Obj->isIR()) {
160158
Expected<std::string> TripleStr =

0 commit comments

Comments
 (0)