Skip to content

Commit

Permalink
Auto merge of #87798 - durin42:llvm-14, r=nikic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Aug 8, 2021
2 parents 835dce5 + 482f190 commit 2d10c2a
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,20 +331,24 @@ enum class LLVMRustPassBuilderOptLevel {
Oz,
};

static PassBuilder::OptimizationLevel fromRust(LLVMRustPassBuilderOptLevel Level) {
#if LLVM_VERSION_LT(14,0)
using OptimizationLevel = PassBuilder::OptimizationLevel;
#endif

static OptimizationLevel fromRust(LLVMRustPassBuilderOptLevel Level) {
switch (Level) {
case LLVMRustPassBuilderOptLevel::O0:
return PassBuilder::OptimizationLevel::O0;
return OptimizationLevel::O0;
case LLVMRustPassBuilderOptLevel::O1:
return PassBuilder::OptimizationLevel::O1;
return OptimizationLevel::O1;
case LLVMRustPassBuilderOptLevel::O2:
return PassBuilder::OptimizationLevel::O2;
return OptimizationLevel::O2;
case LLVMRustPassBuilderOptLevel::O3:
return PassBuilder::OptimizationLevel::O3;
return OptimizationLevel::O3;
case LLVMRustPassBuilderOptLevel::Os:
return PassBuilder::OptimizationLevel::Os;
return OptimizationLevel::Os;
case LLVMRustPassBuilderOptLevel::Oz:
return PassBuilder::OptimizationLevel::Oz;
return OptimizationLevel::Oz;
default:
report_fatal_error("Bad PassBuilderOptLevel.");
}
Expand Down Expand Up @@ -754,7 +758,7 @@ LLVMRustOptimizeWithNewPassManager(
const char *ExtraPasses, size_t ExtraPassesLen) {
Module *TheModule = unwrap(ModuleRef);
TargetMachine *TM = unwrap(TMRef);
PassBuilder::OptimizationLevel OptLevel = fromRust(OptLevelRust);
OptimizationLevel OptLevel = fromRust(OptLevelRust);


PipelineTuningOptions PTO;
Expand Down Expand Up @@ -827,35 +831,35 @@ LLVMRustOptimizeWithNewPassManager(

// We manually collect pipeline callbacks so we can apply them at O0, where the
// PassBuilder does not create a pipeline.
std::vector<std::function<void(ModulePassManager &, PassBuilder::OptimizationLevel)>>
std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>>
PipelineStartEPCallbacks;
#if LLVM_VERSION_GE(11, 0)
std::vector<std::function<void(ModulePassManager &, PassBuilder::OptimizationLevel)>>
std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>>
OptimizerLastEPCallbacks;
#else
std::vector<std::function<void(FunctionPassManager &, PassBuilder::OptimizationLevel)>>
std::vector<std::function<void(FunctionPassManager &, OptimizationLevel)>>
OptimizerLastEPCallbacks;
#endif

if (VerifyIR) {
PipelineStartEPCallbacks.push_back(
[VerifyIR](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
[VerifyIR](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(VerifierPass());
}
);
}

if (InstrumentGCOV) {
PipelineStartEPCallbacks.push_back(
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
[](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(GCOVProfilerPass(GCOVOptions::getDefault()));
}
);
}

if (InstrumentCoverage) {
PipelineStartEPCallbacks.push_back(
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
[](ModulePassManager &MPM, OptimizationLevel Level) {
InstrProfOptions Options;
MPM.addPass(InstrProfiling(Options, false));
}
Expand All @@ -870,19 +874,19 @@ LLVMRustOptimizeWithNewPassManager(
/*CompileKernel=*/false);
#if LLVM_VERSION_GE(11, 0)
OptimizerLastEPCallbacks.push_back(
[Options](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(MemorySanitizerPass(Options));
MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass(Options)));
}
);
#else
PipelineStartEPCallbacks.push_back(
[Options](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(MemorySanitizerPass(Options));
}
);
OptimizerLastEPCallbacks.push_back(
[Options](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
[Options](FunctionPassManager &FPM, OptimizationLevel Level) {
FPM.addPass(MemorySanitizerPass(Options));
}
);
Expand All @@ -892,19 +896,19 @@ LLVMRustOptimizeWithNewPassManager(
if (SanitizerOptions->SanitizeThread) {
#if LLVM_VERSION_GE(11, 0)
OptimizerLastEPCallbacks.push_back(
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
[](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(ThreadSanitizerPass());
MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
}
);
#else
PipelineStartEPCallbacks.push_back(
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
[](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(ThreadSanitizerPass());
}
);
OptimizerLastEPCallbacks.push_back(
[](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
[](FunctionPassManager &FPM, OptimizationLevel Level) {
FPM.addPass(ThreadSanitizerPass());
}
);
Expand All @@ -914,7 +918,7 @@ LLVMRustOptimizeWithNewPassManager(
if (SanitizerOptions->SanitizeAddress) {
#if LLVM_VERSION_GE(11, 0)
OptimizerLastEPCallbacks.push_back(
[SanitizerOptions](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
MPM.addPass(ModuleAddressSanitizerPass(
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover));
Expand All @@ -925,19 +929,19 @@ LLVMRustOptimizeWithNewPassManager(
);
#else
PipelineStartEPCallbacks.push_back(
[&](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
[&](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
}
);
OptimizerLastEPCallbacks.push_back(
[SanitizerOptions](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
[SanitizerOptions](FunctionPassManager &FPM, OptimizationLevel Level) {
FPM.addPass(AddressSanitizerPass(
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover,
/*UseAfterScope=*/true));
}
);
PipelineStartEPCallbacks.push_back(
[SanitizerOptions](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(ModuleAddressSanitizerPass(
/*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover));
}
Expand All @@ -947,14 +951,14 @@ LLVMRustOptimizeWithNewPassManager(
if (SanitizerOptions->SanitizeHWAddress) {
#if LLVM_VERSION_GE(11, 0)
OptimizerLastEPCallbacks.push_back(
[SanitizerOptions](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(HWAddressSanitizerPass(
/*CompileKernel=*/false, SanitizerOptions->SanitizeHWAddressRecover));
}
);
#else
PipelineStartEPCallbacks.push_back(
[SanitizerOptions](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
MPM.addPass(HWAddressSanitizerPass(
/*CompileKernel=*/false, SanitizerOptions->SanitizeHWAddressRecover));
}
Expand All @@ -970,7 +974,7 @@ LLVMRustOptimizeWithNewPassManager(
#endif
bool NeedThinLTOBufferPasses = UseThinLTOBuffers;
if (!NoPrepopulatePasses) {
if (OptLevel == PassBuilder::OptimizationLevel::O0) {
if (OptLevel == OptimizationLevel::O0) {
#if LLVM_VERSION_GE(12, 0)
for (const auto &C : PipelineStartEPCallbacks)
PB.registerPipelineStartEPCallback(C);
Expand Down

0 comments on commit 2d10c2a

Please sign in to comment.