Skip to content

Commit 4559140

Browse files
committed
Auto merge of #90175 - cuviper:min-llvm-12, r=nagisa
Update the minimum external LLVM to 12 With this change, we'll have stable support for LLVM 12 and 13. For reference, the previous increase to LLVM 10 was #83387, and this replaces the pending increase to LLVM 11 in #90062. r? `@nagisa` `@nikic`
2 parents 91b9319 + 8b1504c commit 4559140

File tree

64 files changed

+63
-328
lines changed

Some content is hidden

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

64 files changed

+63
-328
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
- name: mingw-check
4444
os: ubuntu-latest-xl
4545
env: {}
46-
- name: x86_64-gnu-llvm-10
46+
- name: x86_64-gnu-llvm-12
4747
os: ubuntu-latest-xl
4848
env: {}
4949
- name: x86_64-gnu-tools
@@ -274,7 +274,7 @@ jobs:
274274
- name: x86_64-gnu-distcheck
275275
os: ubuntu-latest-xl
276276
env: {}
277-
- name: x86_64-gnu-llvm-10
277+
- name: x86_64-gnu-llvm-12
278278
env:
279279
RUST_BACKTRACE: 1
280280
os: ubuntu-latest-xl

compiler/rustc_codegen_llvm/src/llvm_util.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ unsafe fn configure_llvm(sess: &Session) {
9595
// Ref:
9696
// - https://github.com/rust-lang/rust/issues/85351
9797
// - https://reviews.llvm.org/D103167
98-
let llvm_version = llvm_util::get_version();
99-
if llvm_version >= (11, 0, 0) && llvm_version < (13, 0, 0) {
98+
if llvm_util::get_version() < (13, 0, 0) {
10099
add("-enable-machine-outliner=never", false);
101100
}
102101

compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,7 @@ extern "C" void LLVMRustCoverageWriteMapSectionNameToString(LLVMModuleRef M,
9898

9999
extern "C" void LLVMRustCoverageWriteFuncSectionNameToString(LLVMModuleRef M,
100100
RustStringRef Str) {
101-
#if LLVM_VERSION_GE(11, 0)
102101
WriteSectionNameToString(M, IPSK_covfun, Str);
103-
// else do nothing; the `Version` check will abort codegen on the Rust side
104-
#endif
105102
}
106103

107104
extern "C" void LLVMRustCoverageWriteMappingVarNameToString(RustStringRef Str) {
@@ -111,9 +108,5 @@ extern "C" void LLVMRustCoverageWriteMappingVarNameToString(RustStringRef Str) {
111108
}
112109

113110
extern "C" uint32_t LLVMRustCoverageMappingVersion() {
114-
#if LLVM_VERSION_GE(11, 0)
115111
return coverage::CovMapVersion::Version4;
116-
#else
117-
return coverage::CovMapVersion::Version3;
118-
#endif
119112
}

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+2-167
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
5454

5555
DEFINE_STDCXX_CONVERSION_FUNCTIONS(Pass, LLVMPassRef)
5656
DEFINE_STDCXX_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
57-
#if LLVM_VERSION_LT(11, 0)
58-
DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBuilder,
59-
LLVMPassManagerBuilderRef)
60-
#endif
6157

6258
extern "C" void LLVMInitializePasses() {
6359
PassRegistry &Registry = *PassRegistry::getPassRegistry();
@@ -685,7 +681,6 @@ void LLVMSelfProfileInitializeCallbacks(
685681
PassInstrumentationCallbacks& PIC, void* LlvmSelfProfiler,
686682
LLVMRustSelfProfileBeforePassCallback BeforePassCallback,
687683
LLVMRustSelfProfileAfterPassCallback AfterPassCallback) {
688-
#if LLVM_VERSION_GE(12, 0)
689684
PIC.registerBeforeNonSkippedPassCallback([LlvmSelfProfiler, BeforePassCallback](
690685
StringRef Pass, llvm::Any Ir) {
691686
std::string PassName = Pass.str();
@@ -703,25 +698,6 @@ void LLVMSelfProfileInitializeCallbacks(
703698
[LlvmSelfProfiler, AfterPassCallback](StringRef Pass, const PreservedAnalyses &Preserved) {
704699
AfterPassCallback(LlvmSelfProfiler);
705700
});
706-
#else
707-
PIC.registerBeforePassCallback([LlvmSelfProfiler, BeforePassCallback](
708-
StringRef Pass, llvm::Any Ir) {
709-
std::string PassName = Pass.str();
710-
std::string IrName = LLVMRustwrappedIrGetName(Ir);
711-
BeforePassCallback(LlvmSelfProfiler, PassName.c_str(), IrName.c_str());
712-
return true;
713-
});
714-
715-
PIC.registerAfterPassCallback(
716-
[LlvmSelfProfiler, AfterPassCallback](StringRef Pass, llvm::Any Ir) {
717-
AfterPassCallback(LlvmSelfProfiler);
718-
});
719-
720-
PIC.registerAfterPassInvalidatedCallback(
721-
[LlvmSelfProfiler, AfterPassCallback](StringRef Pass) {
722-
AfterPassCallback(LlvmSelfProfiler);
723-
});
724-
#endif
725701

726702
PIC.registerBeforeAnalysisCallback([LlvmSelfProfiler, BeforePassCallback](
727703
StringRef Pass, llvm::Any Ir) {
@@ -782,22 +758,13 @@ LLVMRustOptimizeWithNewPassManager(
782758
PTO.LoopInterleaving = UnrollLoops;
783759
PTO.LoopVectorization = LoopVectorize;
784760
PTO.SLPVectorization = SLPVectorize;
785-
#if LLVM_VERSION_GE(12, 0)
786761
PTO.MergeFunctions = MergeFunctions;
787-
#else
788-
// MergeFunctions is not supported by NewPM in older LLVM versions.
789-
(void) MergeFunctions;
790-
#endif
791762

792763
// FIXME: We may want to expose this as an option.
793764
bool DebugPassManager = false;
794765

795766
PassInstrumentationCallbacks PIC;
796-
#if LLVM_VERSION_GE(12, 0)
797767
StandardInstrumentations SI(DebugPassManager);
798-
#else
799-
StandardInstrumentations SI;
800-
#endif
801768
SI.registerCallbacks(PIC);
802769

803770
if (LlvmSelfProfiler){
@@ -821,18 +788,14 @@ LLVMRustOptimizeWithNewPassManager(
821788
PGOOptions::NoCSAction, DebugInfoForProfiling);
822789
}
823790

824-
#if LLVM_VERSION_GE(12, 0) && !LLVM_VERSION_GE(13,0)
825-
PassBuilder PB(DebugPassManager, TM, PTO, PGOOpt, &PIC);
826-
#else
827-
PassBuilder PB(TM, PTO, PGOOpt, &PIC);
828-
#endif
829-
830791
#if LLVM_VERSION_GE(13, 0)
792+
PassBuilder PB(TM, PTO, PGOOpt, &PIC);
831793
LoopAnalysisManager LAM;
832794
FunctionAnalysisManager FAM;
833795
CGSCCAnalysisManager CGAM;
834796
ModuleAnalysisManager MAM;
835797
#else
798+
PassBuilder PB(DebugPassManager, TM, PTO, PGOOpt, &PIC);
836799
LoopAnalysisManager LAM(DebugPassManager);
837800
FunctionAnalysisManager FAM(DebugPassManager);
838801
CGSCCAnalysisManager CGAM(DebugPassManager);
@@ -857,13 +820,8 @@ LLVMRustOptimizeWithNewPassManager(
857820
// PassBuilder does not create a pipeline.
858821
std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>>
859822
PipelineStartEPCallbacks;
860-
#if LLVM_VERSION_GE(11, 0)
861823
std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>>
862824
OptimizerLastEPCallbacks;
863-
#else
864-
std::vector<std::function<void(FunctionPassManager &, OptimizationLevel)>>
865-
OptimizerLastEPCallbacks;
866-
#endif
867825

868826
if (VerifyIR) {
869827
PipelineStartEPCallbacks.push_back(
@@ -896,7 +854,6 @@ LLVMRustOptimizeWithNewPassManager(
896854
SanitizerOptions->SanitizeMemoryTrackOrigins,
897855
SanitizerOptions->SanitizeMemoryRecover,
898856
/*CompileKernel=*/false);
899-
#if LLVM_VERSION_GE(11, 0)
900857
OptimizerLastEPCallbacks.push_back(
901858
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
902859
#if LLVM_VERSION_GE(14, 0)
@@ -907,22 +864,9 @@ LLVMRustOptimizeWithNewPassManager(
907864
MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass(Options)));
908865
}
909866
);
910-
#else
911-
PipelineStartEPCallbacks.push_back(
912-
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
913-
MPM.addPass(MemorySanitizerPass(Options));
914-
}
915-
);
916-
OptimizerLastEPCallbacks.push_back(
917-
[Options](FunctionPassManager &FPM, OptimizationLevel Level) {
918-
FPM.addPass(MemorySanitizerPass(Options));
919-
}
920-
);
921-
#endif
922867
}
923868

924869
if (SanitizerOptions->SanitizeThread) {
925-
#if LLVM_VERSION_GE(11, 0)
926870
OptimizerLastEPCallbacks.push_back(
927871
[](ModulePassManager &MPM, OptimizationLevel Level) {
928872
#if LLVM_VERSION_GE(14, 0)
@@ -933,22 +877,9 @@ LLVMRustOptimizeWithNewPassManager(
933877
MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
934878
}
935879
);
936-
#else
937-
PipelineStartEPCallbacks.push_back(
938-
[](ModulePassManager &MPM, OptimizationLevel Level) {
939-
MPM.addPass(ThreadSanitizerPass());
940-
}
941-
);
942-
OptimizerLastEPCallbacks.push_back(
943-
[](FunctionPassManager &FPM, OptimizationLevel Level) {
944-
FPM.addPass(ThreadSanitizerPass());
945-
}
946-
);
947-
#endif
948880
}
949881

950882
if (SanitizerOptions->SanitizeAddress) {
951-
#if LLVM_VERSION_GE(11, 0)
952883
OptimizerLastEPCallbacks.push_back(
953884
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
954885
MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
@@ -967,29 +898,8 @@ LLVMRustOptimizeWithNewPassManager(
967898
#endif
968899
}
969900
);
970-
#else
971-
PipelineStartEPCallbacks.push_back(
972-
[&](ModulePassManager &MPM, OptimizationLevel Level) {
973-
MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
974-
}
975-
);
976-
OptimizerLastEPCallbacks.push_back(
977-
[SanitizerOptions](FunctionPassManager &FPM, OptimizationLevel Level) {
978-
FPM.addPass(AddressSanitizerPass(
979-
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover,
980-
/*UseAfterScope=*/true));
981-
}
982-
);
983-
PipelineStartEPCallbacks.push_back(
984-
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
985-
MPM.addPass(ModuleAddressSanitizerPass(
986-
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover));
987-
}
988-
);
989-
#endif
990901
}
991902
if (SanitizerOptions->SanitizeHWAddress) {
992-
#if LLVM_VERSION_GE(11, 0)
993903
OptimizerLastEPCallbacks.push_back(
994904
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
995905
#if LLVM_VERSION_GE(14, 0)
@@ -1003,14 +913,6 @@ LLVMRustOptimizeWithNewPassManager(
1003913
#endif
1004914
}
1005915
);
1006-
#else
1007-
PipelineStartEPCallbacks.push_back(
1008-
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
1009-
MPM.addPass(HWAddressSanitizerPass(
1010-
/*CompileKernel=*/false, SanitizerOptions->SanitizeHWAddressRecover));
1011-
}
1012-
);
1013-
#endif
1014916
}
1015917
}
1016918

@@ -1025,48 +927,16 @@ LLVMRustOptimizeWithNewPassManager(
1025927
// At the same time, the LTO pipelines do support O0 and using them is required.
1026928
bool IsLTO = OptStage == LLVMRustOptStage::ThinLTO || OptStage == LLVMRustOptStage::FatLTO;
1027929
if (OptLevel == OptimizationLevel::O0 && !IsLTO) {
1028-
#if LLVM_VERSION_GE(12, 0)
1029930
for (const auto &C : PipelineStartEPCallbacks)
1030931
PB.registerPipelineStartEPCallback(C);
1031932
for (const auto &C : OptimizerLastEPCallbacks)
1032933
PB.registerOptimizerLastEPCallback(C);
1033934

1034935
// Pass false as we manually schedule ThinLTOBufferPasses below.
1035936
MPM = PB.buildO0DefaultPipeline(OptLevel, /* PreLinkLTO */ false);
1036-
#else
1037-
for (const auto &C : PipelineStartEPCallbacks)
1038-
C(MPM, OptLevel);
1039-
1040-
# if LLVM_VERSION_GE(11, 0)
1041-
for (const auto &C : OptimizerLastEPCallbacks)
1042-
C(MPM, OptLevel);
1043-
# else
1044-
if (!OptimizerLastEPCallbacks.empty()) {
1045-
FunctionPassManager FPM(DebugPassManager);
1046-
for (const auto &C : OptimizerLastEPCallbacks)
1047-
C(FPM, OptLevel);
1048-
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1049-
}
1050-
# endif
1051-
1052-
MPM.addPass(AlwaysInlinerPass(EmitLifetimeMarkers));
1053-
1054-
if (PGOOpt) {
1055-
PB.addPGOInstrPassesForO0(
1056-
MPM, DebugPassManager, PGOOpt->Action == PGOOptions::IRInstr,
1057-
/*IsCS=*/false, PGOOpt->ProfileFile, PGOOpt->ProfileRemappingFile);
1058-
}
1059-
#endif
1060937
} else {
1061-
#if LLVM_VERSION_GE(12, 0)
1062938
for (const auto &C : PipelineStartEPCallbacks)
1063939
PB.registerPipelineStartEPCallback(C);
1064-
#else
1065-
for (const auto &C : PipelineStartEPCallbacks)
1066-
PB.registerPipelineStartEPCallback([C, OptLevel](ModulePassManager &MPM) {
1067-
C(MPM, OptLevel);
1068-
});
1069-
#endif
1070940
if (OptStage != LLVMRustOptStage::PreLinkThinLTO) {
1071941
for (const auto &C : OptimizerLastEPCallbacks)
1072942
PB.registerOptimizerLastEPCallback(C);
@@ -1077,52 +947,27 @@ LLVMRustOptimizeWithNewPassManager(
1077947
MPM = PB.buildPerModuleDefaultPipeline(OptLevel, DebugPassManager);
1078948
break;
1079949
case LLVMRustOptStage::PreLinkThinLTO:
1080-
#if LLVM_VERSION_GE(12, 0)
1081950
MPM = PB.buildThinLTOPreLinkDefaultPipeline(OptLevel);
1082951
// The ThinLTOPreLink pipeline already includes ThinLTOBuffer passes. However, callback
1083952
// passes may still run afterwards. This means we need to run the buffer passes again.
1084953
// FIXME: In LLVM 13, the ThinLTOPreLink pipeline also runs OptimizerLastEPCallbacks
1085954
// before the RequiredLTOPreLinkPasses, in which case we can remove these hacks.
1086955
if (OptimizerLastEPCallbacks.empty())
1087956
NeedThinLTOBufferPasses = false;
1088-
#else
1089-
MPM = PB.buildThinLTOPreLinkDefaultPipeline(OptLevel, DebugPassManager);
1090-
#endif
1091-
#if LLVM_VERSION_GE(11, 0)
1092957
for (const auto &C : OptimizerLastEPCallbacks)
1093958
C(MPM, OptLevel);
1094-
#else
1095-
if (!OptimizerLastEPCallbacks.empty()) {
1096-
FunctionPassManager FPM(DebugPassManager);
1097-
for (const auto &C : OptimizerLastEPCallbacks)
1098-
C(FPM, OptLevel);
1099-
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
1100-
}
1101-
#endif
1102959
break;
1103960
case LLVMRustOptStage::PreLinkFatLTO:
1104-
#if LLVM_VERSION_GE(12, 0)
1105961
MPM = PB.buildLTOPreLinkDefaultPipeline(OptLevel);
1106962
NeedThinLTOBufferPasses = false;
1107-
#else
1108-
MPM = PB.buildLTOPreLinkDefaultPipeline(OptLevel, DebugPassManager);
1109-
#endif
1110963
break;
1111964
case LLVMRustOptStage::ThinLTO:
1112965
// FIXME: Does it make sense to pass the ModuleSummaryIndex?
1113966
// It only seems to be needed for C++ specific optimizations.
1114-
#if LLVM_VERSION_GE(12, 0)
1115967
MPM = PB.buildThinLTODefaultPipeline(OptLevel, nullptr);
1116-
#else
1117-
MPM = PB.buildThinLTODefaultPipeline(OptLevel, DebugPassManager, nullptr);
1118-
#endif
1119968
break;
1120969
case LLVMRustOptStage::FatLTO:
1121-
#if LLVM_VERSION_GE(12, 0)
1122970
MPM = PB.buildLTODefaultPipeline(OptLevel, nullptr);
1123-
#else
1124-
MPM = PB.buildLTODefaultPipeline(OptLevel, DebugPassManager, nullptr);
1125-
#endif
1126971
break;
1127972
}
1128973
}
@@ -1552,7 +1397,6 @@ LLVMRustFreeThinLTOData(LLVMRustThinLTOData *Data) {
15521397
// `ProcessThinLTOModule` function. Here they're split up into separate steps
15531398
// so rustc can save off the intermediate bytecode between each step.
15541399

1555-
#if LLVM_VERSION_GE(11, 0)
15561400
static bool
15571401
clearDSOLocalOnDeclarations(Module &Mod, TargetMachine &TM) {
15581402
// When linking an ELF shared object, dso_local should be dropped. We
@@ -1563,20 +1407,15 @@ clearDSOLocalOnDeclarations(Module &Mod, TargetMachine &TM) {
15631407
Mod.getPIELevel() == PIELevel::Default;
15641408
return ClearDSOLocalOnDeclarations;
15651409
}
1566-
#endif
15671410

15681411
extern "C" bool
15691412
LLVMRustPrepareThinLTORename(const LLVMRustThinLTOData *Data, LLVMModuleRef M,
15701413
LLVMTargetMachineRef TM) {
15711414
Module &Mod = *unwrap(M);
15721415
TargetMachine &Target = *unwrap(TM);
15731416

1574-
#if LLVM_VERSION_GE(11, 0)
15751417
bool ClearDSOLocal = clearDSOLocalOnDeclarations(Mod, Target);
15761418
bool error = renameModuleForThinLTO(Mod, Data->Index, ClearDSOLocal);
1577-
#else
1578-
bool error = renameModuleForThinLTO(Mod, Data->Index);
1579-
#endif
15801419

15811420
if (error) {
15821421
LLVMRustSetLastError("renameModuleForThinLTO failed");
@@ -1645,12 +1484,8 @@ LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data, LLVMModuleRef M,
16451484

16461485
return MOrErr;
16471486
};
1648-
#if LLVM_VERSION_GE(11, 0)
16491487
bool ClearDSOLocal = clearDSOLocalOnDeclarations(Mod, Target);
16501488
FunctionImporter Importer(Data->Index, Loader, ClearDSOLocal);
1651-
#else
1652-
FunctionImporter Importer(Data->Index, Loader);
1653-
#endif
16541489
Expected<bool> Result = Importer.importFunctions(Mod, ImportList);
16551490
if (!Result) {
16561491
LLVMRustSetLastError(toString(Result.takeError()).c_str());

0 commit comments

Comments
 (0)