PassWrapper: adapt for new parameter in LLVM

llvm/llvm-project@390300d9f4 added a new
parameter to some callbacks, so we have to handle them.

@rustbot label: +llvm-main
This commit is contained in:
Augie Fackler 2024-11-04 10:53:12 -05:00 committed by Zalathar
parent ca87b535a0
commit e8d17440e2

View File

@ -784,8 +784,14 @@ extern "C" LLVMRustResult LLVMRustOptimize(
// the PassBuilder does not create a pipeline. // the PassBuilder does not create a pipeline.
std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>> std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>>
PipelineStartEPCallbacks; PipelineStartEPCallbacks;
#if LLVM_VERSION_GE(20, 0)
std::vector<std::function<void(ModulePassManager &, OptimizationLevel,
ThinOrFullLTOPhase)>>
OptimizerLastEPCallbacks;
#else
std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>> std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>>
OptimizerLastEPCallbacks; OptimizerLastEPCallbacks;
#endif
if (!IsLinkerPluginLTO && SanitizerOptions && SanitizerOptions->SanitizeCFI && if (!IsLinkerPluginLTO && SanitizerOptions && SanitizerOptions->SanitizeCFI &&
!NoPrepopulatePasses) { !NoPrepopulatePasses) {
@ -832,7 +838,12 @@ extern "C" LLVMRustResult LLVMRustOptimize(
SanitizerOptions->SanitizeDataFlowABIList + SanitizerOptions->SanitizeDataFlowABIList +
SanitizerOptions->SanitizeDataFlowABIListLen); SanitizerOptions->SanitizeDataFlowABIListLen);
OptimizerLastEPCallbacks.push_back( OptimizerLastEPCallbacks.push_back(
#if LLVM_VERSION_GE(20, 0)
[ABIListFiles](ModulePassManager &MPM, OptimizationLevel Level,
ThinOrFullLTOPhase phase) {
#else
[ABIListFiles](ModulePassManager &MPM, OptimizationLevel Level) { [ABIListFiles](ModulePassManager &MPM, OptimizationLevel Level) {
#endif
MPM.addPass(DataFlowSanitizerPass(ABIListFiles)); MPM.addPass(DataFlowSanitizerPass(ABIListFiles));
}); });
} }
@ -844,23 +855,39 @@ extern "C" LLVMRustResult LLVMRustOptimize(
/*CompileKernel=*/false, /*CompileKernel=*/false,
/*EagerChecks=*/true); /*EagerChecks=*/true);
OptimizerLastEPCallbacks.push_back( OptimizerLastEPCallbacks.push_back(
#if LLVM_VERSION_GE(20, 0)
[Options](ModulePassManager &MPM, OptimizationLevel Level,
ThinOrFullLTOPhase phase) {
#else
[Options](ModulePassManager &MPM, OptimizationLevel Level) { [Options](ModulePassManager &MPM, OptimizationLevel Level) {
#endif
MPM.addPass(MemorySanitizerPass(Options)); MPM.addPass(MemorySanitizerPass(Options));
}); });
} }
if (SanitizerOptions->SanitizeThread) { if (SanitizerOptions->SanitizeThread) {
OptimizerLastEPCallbacks.push_back([](ModulePassManager &MPM, OptimizerLastEPCallbacks.push_back(
OptimizationLevel Level) { #if LLVM_VERSION_GE(20, 0)
MPM.addPass(ModuleThreadSanitizerPass()); [](ModulePassManager &MPM, OptimizationLevel Level,
MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); ThinOrFullLTOPhase phase) {
}); #else
[](ModulePassManager &MPM, OptimizationLevel Level) {
#endif
MPM.addPass(ModuleThreadSanitizerPass());
MPM.addPass(
createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
});
} }
if (SanitizerOptions->SanitizeAddress || if (SanitizerOptions->SanitizeAddress ||
SanitizerOptions->SanitizeKernelAddress) { SanitizerOptions->SanitizeKernelAddress) {
OptimizerLastEPCallbacks.push_back( OptimizerLastEPCallbacks.push_back(
#if LLVM_VERSION_GE(20, 0)
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level,
ThinOrFullLTOPhase phase) {
#else
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) { [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
#endif
auto CompileKernel = SanitizerOptions->SanitizeKernelAddress; auto CompileKernel = SanitizerOptions->SanitizeKernelAddress;
AddressSanitizerOptions opts = AddressSanitizerOptions{ AddressSanitizerOptions opts = AddressSanitizerOptions{
CompileKernel, CompileKernel,
@ -874,7 +901,12 @@ extern "C" LLVMRustResult LLVMRustOptimize(
} }
if (SanitizerOptions->SanitizeHWAddress) { if (SanitizerOptions->SanitizeHWAddress) {
OptimizerLastEPCallbacks.push_back( OptimizerLastEPCallbacks.push_back(
#if LLVM_VERSION_GE(20, 0)
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level,
ThinOrFullLTOPhase phase) {
#else
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) { [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
#endif
HWAddressSanitizerOptions opts( HWAddressSanitizerOptions opts(
/*CompileKernel=*/false, /*CompileKernel=*/false,
SanitizerOptions->SanitizeHWAddressRecover, SanitizerOptions->SanitizeHWAddressRecover,
@ -935,7 +967,11 @@ extern "C" LLVMRustResult LLVMRustOptimize(
for (const auto &C : PipelineStartEPCallbacks) for (const auto &C : PipelineStartEPCallbacks)
C(MPM, OptLevel); C(MPM, OptLevel);
for (const auto &C : OptimizerLastEPCallbacks) for (const auto &C : OptimizerLastEPCallbacks)
#if LLVM_VERSION_GE(20, 0)
C(MPM, OptLevel, ThinOrFullLTOPhase::None);
#else
C(MPM, OptLevel); C(MPM, OptLevel);
#endif
} }
if (ExtraPassesLen) { if (ExtraPassesLen) {