Skip to content

Commit 2d10c2a

Browse files
committed
Auto merge of rust-lang#87798 - durin42:llvm-14, r=nikic
PassWrapper: handle move of OptimizationLevel class out of PassBuilder This is the first build break of the LLVM 14 cycle, and was caused by https://reviews.llvm.org/D107025. Mercifully an easy fix.
2 parents 835dce5 + 482f190 commit 2d10c2a

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+31-27
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,24 @@ enum class LLVMRustPassBuilderOptLevel {
331331
Oz,
332332
};
333333

334-
static PassBuilder::OptimizationLevel fromRust(LLVMRustPassBuilderOptLevel Level) {
334+
#if LLVM_VERSION_LT(14,0)
335+
using OptimizationLevel = PassBuilder::OptimizationLevel;
336+
#endif
337+
338+
static OptimizationLevel fromRust(LLVMRustPassBuilderOptLevel Level) {
335339
switch (Level) {
336340
case LLVMRustPassBuilderOptLevel::O0:
337-
return PassBuilder::OptimizationLevel::O0;
341+
return OptimizationLevel::O0;
338342
case LLVMRustPassBuilderOptLevel::O1:
339-
return PassBuilder::OptimizationLevel::O1;
343+
return OptimizationLevel::O1;
340344
case LLVMRustPassBuilderOptLevel::O2:
341-
return PassBuilder::OptimizationLevel::O2;
345+
return OptimizationLevel::O2;
342346
case LLVMRustPassBuilderOptLevel::O3:
343-
return PassBuilder::OptimizationLevel::O3;
347+
return OptimizationLevel::O3;
344348
case LLVMRustPassBuilderOptLevel::Os:
345-
return PassBuilder::OptimizationLevel::Os;
349+
return OptimizationLevel::Os;
346350
case LLVMRustPassBuilderOptLevel::Oz:
347-
return PassBuilder::OptimizationLevel::Oz;
351+
return OptimizationLevel::Oz;
348352
default:
349353
report_fatal_error("Bad PassBuilderOptLevel.");
350354
}
@@ -754,7 +758,7 @@ LLVMRustOptimizeWithNewPassManager(
754758
const char *ExtraPasses, size_t ExtraPassesLen) {
755759
Module *TheModule = unwrap(ModuleRef);
756760
TargetMachine *TM = unwrap(TMRef);
757-
PassBuilder::OptimizationLevel OptLevel = fromRust(OptLevelRust);
761+
OptimizationLevel OptLevel = fromRust(OptLevelRust);
758762

759763

760764
PipelineTuningOptions PTO;
@@ -827,35 +831,35 @@ LLVMRustOptimizeWithNewPassManager(
827831

828832
// We manually collect pipeline callbacks so we can apply them at O0, where the
829833
// PassBuilder does not create a pipeline.
830-
std::vector<std::function<void(ModulePassManager &, PassBuilder::OptimizationLevel)>>
834+
std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>>
831835
PipelineStartEPCallbacks;
832836
#if LLVM_VERSION_GE(11, 0)
833-
std::vector<std::function<void(ModulePassManager &, PassBuilder::OptimizationLevel)>>
837+
std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>>
834838
OptimizerLastEPCallbacks;
835839
#else
836-
std::vector<std::function<void(FunctionPassManager &, PassBuilder::OptimizationLevel)>>
840+
std::vector<std::function<void(FunctionPassManager &, OptimizationLevel)>>
837841
OptimizerLastEPCallbacks;
838842
#endif
839843

840844
if (VerifyIR) {
841845
PipelineStartEPCallbacks.push_back(
842-
[VerifyIR](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
846+
[VerifyIR](ModulePassManager &MPM, OptimizationLevel Level) {
843847
MPM.addPass(VerifierPass());
844848
}
845849
);
846850
}
847851

848852
if (InstrumentGCOV) {
849853
PipelineStartEPCallbacks.push_back(
850-
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
854+
[](ModulePassManager &MPM, OptimizationLevel Level) {
851855
MPM.addPass(GCOVProfilerPass(GCOVOptions::getDefault()));
852856
}
853857
);
854858
}
855859

856860
if (InstrumentCoverage) {
857861
PipelineStartEPCallbacks.push_back(
858-
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
862+
[](ModulePassManager &MPM, OptimizationLevel Level) {
859863
InstrProfOptions Options;
860864
MPM.addPass(InstrProfiling(Options, false));
861865
}
@@ -870,19 +874,19 @@ LLVMRustOptimizeWithNewPassManager(
870874
/*CompileKernel=*/false);
871875
#if LLVM_VERSION_GE(11, 0)
872876
OptimizerLastEPCallbacks.push_back(
873-
[Options](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
877+
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
874878
MPM.addPass(MemorySanitizerPass(Options));
875879
MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass(Options)));
876880
}
877881
);
878882
#else
879883
PipelineStartEPCallbacks.push_back(
880-
[Options](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
884+
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
881885
MPM.addPass(MemorySanitizerPass(Options));
882886
}
883887
);
884888
OptimizerLastEPCallbacks.push_back(
885-
[Options](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
889+
[Options](FunctionPassManager &FPM, OptimizationLevel Level) {
886890
FPM.addPass(MemorySanitizerPass(Options));
887891
}
888892
);
@@ -892,19 +896,19 @@ LLVMRustOptimizeWithNewPassManager(
892896
if (SanitizerOptions->SanitizeThread) {
893897
#if LLVM_VERSION_GE(11, 0)
894898
OptimizerLastEPCallbacks.push_back(
895-
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
899+
[](ModulePassManager &MPM, OptimizationLevel Level) {
896900
MPM.addPass(ThreadSanitizerPass());
897901
MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
898902
}
899903
);
900904
#else
901905
PipelineStartEPCallbacks.push_back(
902-
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
906+
[](ModulePassManager &MPM, OptimizationLevel Level) {
903907
MPM.addPass(ThreadSanitizerPass());
904908
}
905909
);
906910
OptimizerLastEPCallbacks.push_back(
907-
[](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
911+
[](FunctionPassManager &FPM, OptimizationLevel Level) {
908912
FPM.addPass(ThreadSanitizerPass());
909913
}
910914
);
@@ -914,7 +918,7 @@ LLVMRustOptimizeWithNewPassManager(
914918
if (SanitizerOptions->SanitizeAddress) {
915919
#if LLVM_VERSION_GE(11, 0)
916920
OptimizerLastEPCallbacks.push_back(
917-
[SanitizerOptions](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
921+
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
918922
MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
919923
MPM.addPass(ModuleAddressSanitizerPass(
920924
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover));
@@ -925,19 +929,19 @@ LLVMRustOptimizeWithNewPassManager(
925929
);
926930
#else
927931
PipelineStartEPCallbacks.push_back(
928-
[&](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
932+
[&](ModulePassManager &MPM, OptimizationLevel Level) {
929933
MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
930934
}
931935
);
932936
OptimizerLastEPCallbacks.push_back(
933-
[SanitizerOptions](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
937+
[SanitizerOptions](FunctionPassManager &FPM, OptimizationLevel Level) {
934938
FPM.addPass(AddressSanitizerPass(
935939
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover,
936940
/*UseAfterScope=*/true));
937941
}
938942
);
939943
PipelineStartEPCallbacks.push_back(
940-
[SanitizerOptions](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
944+
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
941945
MPM.addPass(ModuleAddressSanitizerPass(
942946
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover));
943947
}
@@ -947,14 +951,14 @@ LLVMRustOptimizeWithNewPassManager(
947951
if (SanitizerOptions->SanitizeHWAddress) {
948952
#if LLVM_VERSION_GE(11, 0)
949953
OptimizerLastEPCallbacks.push_back(
950-
[SanitizerOptions](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
954+
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
951955
MPM.addPass(HWAddressSanitizerPass(
952956
/*CompileKernel=*/false, SanitizerOptions->SanitizeHWAddressRecover));
953957
}
954958
);
955959
#else
956960
PipelineStartEPCallbacks.push_back(
957-
[SanitizerOptions](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
961+
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
958962
MPM.addPass(HWAddressSanitizerPass(
959963
/*CompileKernel=*/false, SanitizerOptions->SanitizeHWAddressRecover));
960964
}
@@ -970,7 +974,7 @@ LLVMRustOptimizeWithNewPassManager(
970974
#endif
971975
bool NeedThinLTOBufferPasses = UseThinLTOBuffers;
972976
if (!NoPrepopulatePasses) {
973-
if (OptLevel == PassBuilder::OptimizationLevel::O0) {
977+
if (OptLevel == OptimizationLevel::O0) {
974978
#if LLVM_VERSION_GE(12, 0)
975979
for (const auto &C : PipelineStartEPCallbacks)
976980
PB.registerPipelineStartEPCallback(C);

0 commit comments

Comments
 (0)