diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1069,16 +1069,16 @@ DwoOS->keep(); } -static PassBuilder::OptimizationLevel mapToLevel(const CodeGenOptions &Opts) { +static OptimizationLevel mapToLevel(const CodeGenOptions &Opts) { switch (Opts.OptimizationLevel) { default: llvm_unreachable("Invalid optimization level!"); case 0: - return PassBuilder::OptimizationLevel::O0; + return OptimizationLevel::O0; case 1: - return PassBuilder::OptimizationLevel::O1; + return OptimizationLevel::O1; case 2: switch (Opts.OptimizeSize) { @@ -1086,17 +1086,17 @@ llvm_unreachable("Invalid optimization level for size!"); case 0: - return PassBuilder::OptimizationLevel::O2; + return OptimizationLevel::O2; case 1: - return PassBuilder::OptimizationLevel::Os; + return OptimizationLevel::Os; case 2: - return PassBuilder::OptimizationLevel::Oz; + return OptimizationLevel::Oz; } case 3: - return PassBuilder::OptimizationLevel::O3; + return OptimizationLevel::O3; } } @@ -1104,7 +1104,7 @@ const CodeGenOptions &CodeGenOpts, const LangOptions &LangOpts, PassBuilder &PB) { PB.registerOptimizerLastEPCallback([&](ModulePassManager &MPM, - PassBuilder::OptimizationLevel Level) { + OptimizationLevel Level) { if (CodeGenOpts.hasSanitizeCoverage()) { auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts); MPM.addPass(ModuleSanitizerCoveragePass( @@ -1122,7 +1122,7 @@ FunctionPassManager FPM; FPM.addPass( MemorySanitizerPass({TrackOrigins, Recover, CompileKernel})); - if (Level != PassBuilder::OptimizationLevel::O0) { + if (Level != OptimizationLevel::O0) { // MemorySanitizer inserts complex instrumentation that mostly // follows the logic of the original code, but operates on // "shadow" values. It can benefit from re-running some @@ -1325,26 +1325,26 @@ if (!CodeGenOpts.DisableLLVMPasses) { // Map our optimization levels into one of the distinct levels used to // configure the pipeline. - PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts); + OptimizationLevel Level = mapToLevel(CodeGenOpts); bool IsThinLTO = CodeGenOpts.PrepareForThinLTO; bool IsLTO = CodeGenOpts.PrepareForLTO; if (LangOpts.ObjCAutoRefCount) { PB.registerPipelineStartEPCallback( - [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { - if (Level != PassBuilder::OptimizationLevel::O0) + [](ModulePassManager &MPM, OptimizationLevel Level) { + if (Level != OptimizationLevel::O0) MPM.addPass( createModuleToFunctionPassAdaptor(ObjCARCExpandPass())); }); PB.registerPipelineEarlySimplificationEPCallback( - [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { - if (Level != PassBuilder::OptimizationLevel::O0) + [](ModulePassManager &MPM, OptimizationLevel Level) { + if (Level != OptimizationLevel::O0) MPM.addPass(ObjCARCAPElimPass()); }); PB.registerScalarOptimizerLateEPCallback( - [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { - if (Level != PassBuilder::OptimizationLevel::O0) + [](FunctionPassManager &FPM, OptimizationLevel Level) { + if (Level != OptimizationLevel::O0) FPM.addPass(ObjCARCOptPass()); }); } @@ -1357,7 +1357,7 @@ // vtables so that codegen doesn't complain. if (IsThinLTOPostLink) PB.registerPipelineStartEPCallback( - [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr, /*ImportSummary=*/nullptr, /*DropTypeTests=*/true)); @@ -1368,12 +1368,12 @@ CodeGenOpts.InstrumentFunctionsAfterInlining || CodeGenOpts.InstrumentForProfiling) { PB.registerPipelineStartEPCallback( - [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(createModuleToFunctionPassAdaptor( EntryExitInstrumenterPass(/*PostInlining=*/false))); }); PB.registerOptimizerLastEPCallback( - [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(createModuleToFunctionPassAdaptor( EntryExitInstrumenterPass(/*PostInlining=*/true))); }); @@ -1383,7 +1383,7 @@ // of the pipeline. if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) PB.registerScalarOptimizerLateEPCallback( - [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { + [](FunctionPassManager &FPM, OptimizationLevel Level) { FPM.addPass(BoundsCheckingPass()); }); @@ -1394,15 +1394,13 @@ if (Optional Options = getGCOVOptions(CodeGenOpts, LangOpts)) PB.registerPipelineStartEPCallback( - [Options](ModulePassManager &MPM, - PassBuilder::OptimizationLevel Level) { + [Options](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(GCOVProfilerPass(*Options)); }); if (Optional Options = getInstrProfOptions(CodeGenOpts, LangOpts)) PB.registerPipelineStartEPCallback( - [Options](ModulePassManager &MPM, - PassBuilder::OptimizationLevel Level) { + [Options](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(InstrProfiling(*Options, false)); }); diff --git a/llvm/examples/Bye/Bye.cpp b/llvm/examples/Bye/Bye.cpp --- a/llvm/examples/Bye/Bye.cpp +++ b/llvm/examples/Bye/Bye.cpp @@ -55,8 +55,7 @@ return {LLVM_PLUGIN_API_VERSION, "Bye", LLVM_VERSION_STRING, [](PassBuilder &PB) { PB.registerVectorizerStartEPCallback( - [](llvm::FunctionPassManager &PM, - llvm::PassBuilder::OptimizationLevel Level) { + [](llvm::FunctionPassManager &PM, OptimizationLevel Level) { PM.addPass(Bye()); }); PB.registerPipelineParsingCallback( diff --git a/llvm/include/llvm/Passes/OptimizationLevel.h b/llvm/include/llvm/Passes/OptimizationLevel.h new file mode 100644 --- /dev/null +++ b/llvm/include/llvm/Passes/OptimizationLevel.h @@ -0,0 +1,127 @@ +//===-------- LLVM-provided High-Level Optimization levels -*- C++ -*------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// \file +/// +/// This header enumerates the LLVM-provided high-level optimization levels. +/// Each level has a specific goal and rationale. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_PASSES_OPTIMIZATIONLEVEL_H +#define LLVM_PASSES_OPTIMIZATIONLEVEL_H + +#include + +namespace llvm { + +class OptimizationLevel final { + unsigned SpeedLevel = 2; + unsigned SizeLevel = 0; + OptimizationLevel(unsigned SpeedLevel, unsigned SizeLevel) + : SpeedLevel(SpeedLevel), SizeLevel(SizeLevel) { + // Check that only valid combinations are passed. + assert(SpeedLevel <= 3 && + "Optimization level for speed should be 0, 1, 2, or 3"); + assert(SizeLevel <= 2 && + "Optimization level for size should be 0, 1, or 2"); + assert((SizeLevel == 0 || SpeedLevel == 2) && + "Optimize for size should be encoded with speedup level == 2"); + } + +public: + OptimizationLevel() = default; + /// Disable as many optimizations as possible. This doesn't completely + /// disable the optimizer in all cases, for example always_inline functions + /// can be required to be inlined for correctness. + static const OptimizationLevel O0; + + /// Optimize quickly without destroying debuggability. + /// + /// This level is tuned to produce a result from the optimizer as quickly + /// as possible and to avoid destroying debuggability. This tends to result + /// in a very good development mode where the compiled code will be + /// immediately executed as part of testing. As a consequence, where + /// possible, we would like to produce efficient-to-execute code, but not + /// if it significantly slows down compilation or would prevent even basic + /// debugging of the resulting binary. + /// + /// As an example, complex loop transformations such as versioning, + /// vectorization, or fusion don't make sense here due to the degree to + /// which the executed code differs from the source code, and the compile + /// time cost. + static const OptimizationLevel O1; + /// Optimize for fast execution as much as possible without triggering + /// significant incremental compile time or code size growth. + /// + /// The key idea is that optimizations at this level should "pay for + /// themselves". So if an optimization increases compile time by 5% or + /// increases code size by 5% for a particular benchmark, that benchmark + /// should also be one which sees a 5% runtime improvement. If the compile + /// time or code size penalties happen on average across a diverse range of + /// LLVM users' benchmarks, then the improvements should as well. + /// + /// And no matter what, the compile time needs to not grow superlinearly + /// with the size of input to LLVM so that users can control the runtime of + /// the optimizer in this mode. + /// + /// This is expected to be a good default optimization level for the vast + /// majority of users. + static const OptimizationLevel O2; + /// Optimize for fast execution as much as possible. + /// + /// This mode is significantly more aggressive in trading off compile time + /// and code size to get execution time improvements. The core idea is that + /// this mode should include any optimization that helps execution time on + /// balance across a diverse collection of benchmarks, even if it increases + /// code size or compile time for some benchmarks without corresponding + /// improvements to execution time. + /// + /// Despite being willing to trade more compile time off to get improved + /// execution time, this mode still tries to avoid superlinear growth in + /// order to make even significantly slower compile times at least scale + /// reasonably. This does not preclude very substantial constant factor + /// costs though. + static const OptimizationLevel O3; + /// Similar to \c O2 but tries to optimize for small code size instead of + /// fast execution without triggering significant incremental execution + /// time slowdowns. + /// + /// The logic here is exactly the same as \c O2, but with code size and + /// execution time metrics swapped. + /// + /// A consequence of the different core goal is that this should in general + /// produce substantially smaller executables that still run in + /// a reasonable amount of time. + static const OptimizationLevel Os; + /// A very specialized mode that will optimize for code size at any and all + /// costs. + /// + /// This is useful primarily when there are absolute size limitations and + /// any effort taken to reduce the size is worth it regardless of the + /// execution time impact. You should expect this level to produce rather + /// slow, but very small, code. + static const OptimizationLevel Oz; + + bool isOptimizingForSpeed() const { return SizeLevel == 0 && SpeedLevel > 0; } + + bool isOptimizingForSize() const { return SizeLevel > 0; } + + bool operator==(const OptimizationLevel &Other) const { + return SizeLevel == Other.SizeLevel && SpeedLevel == Other.SpeedLevel; + } + bool operator!=(const OptimizationLevel &Other) const { + return SizeLevel != Other.SizeLevel || SpeedLevel != Other.SpeedLevel; + } + + unsigned getSpeedupLevel() const { return SpeedLevel; } + + unsigned getSizeLevel() const { return SizeLevel; } +}; +} // namespace llvm + +#endif diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h --- a/llvm/include/llvm/Passes/PassBuilder.h +++ b/llvm/include/llvm/Passes/PassBuilder.h @@ -18,6 +18,7 @@ #include "llvm/ADT/Optional.h" #include "llvm/Analysis/CGSCCPassManager.h" #include "llvm/IR/PassManager.h" +#include "llvm/Passes/OptimizationLevel.h" #include "llvm/Support/Error.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/IPO/Inliner.h" @@ -150,116 +151,6 @@ std::vector InnerPipeline; }; - /// LLVM-provided high-level optimization levels. - /// - /// This enumerates the LLVM-provided high-level optimization levels. Each - /// level has a specific goal and rationale. - class OptimizationLevel final { - unsigned SpeedLevel = 2; - unsigned SizeLevel = 0; - OptimizationLevel(unsigned SpeedLevel, unsigned SizeLevel) - : SpeedLevel(SpeedLevel), SizeLevel(SizeLevel) { - // Check that only valid combinations are passed. - assert(SpeedLevel <= 3 && - "Optimization level for speed should be 0, 1, 2, or 3"); - assert(SizeLevel <= 2 && - "Optimization level for size should be 0, 1, or 2"); - assert((SizeLevel == 0 || SpeedLevel == 2) && - "Optimize for size should be encoded with speedup level == 2"); - } - - public: - OptimizationLevel() = default; - /// Disable as many optimizations as possible. This doesn't completely - /// disable the optimizer in all cases, for example always_inline functions - /// can be required to be inlined for correctness. - static const OptimizationLevel O0; - - /// Optimize quickly without destroying debuggability. - /// - /// This level is tuned to produce a result from the optimizer as quickly - /// as possible and to avoid destroying debuggability. This tends to result - /// in a very good development mode where the compiled code will be - /// immediately executed as part of testing. As a consequence, where - /// possible, we would like to produce efficient-to-execute code, but not - /// if it significantly slows down compilation or would prevent even basic - /// debugging of the resulting binary. - /// - /// As an example, complex loop transformations such as versioning, - /// vectorization, or fusion don't make sense here due to the degree to - /// which the executed code differs from the source code, and the compile - /// time cost. - static const OptimizationLevel O1; - /// Optimize for fast execution as much as possible without triggering - /// significant incremental compile time or code size growth. - /// - /// The key idea is that optimizations at this level should "pay for - /// themselves". So if an optimization increases compile time by 5% or - /// increases code size by 5% for a particular benchmark, that benchmark - /// should also be one which sees a 5% runtime improvement. If the compile - /// time or code size penalties happen on average across a diverse range of - /// LLVM users' benchmarks, then the improvements should as well. - /// - /// And no matter what, the compile time needs to not grow superlinearly - /// with the size of input to LLVM so that users can control the runtime of - /// the optimizer in this mode. - /// - /// This is expected to be a good default optimization level for the vast - /// majority of users. - static const OptimizationLevel O2; - /// Optimize for fast execution as much as possible. - /// - /// This mode is significantly more aggressive in trading off compile time - /// and code size to get execution time improvements. The core idea is that - /// this mode should include any optimization that helps execution time on - /// balance across a diverse collection of benchmarks, even if it increases - /// code size or compile time for some benchmarks without corresponding - /// improvements to execution time. - /// - /// Despite being willing to trade more compile time off to get improved - /// execution time, this mode still tries to avoid superlinear growth in - /// order to make even significantly slower compile times at least scale - /// reasonably. This does not preclude very substantial constant factor - /// costs though. - static const OptimizationLevel O3; - /// Similar to \c O2 but tries to optimize for small code size instead of - /// fast execution without triggering significant incremental execution - /// time slowdowns. - /// - /// The logic here is exactly the same as \c O2, but with code size and - /// execution time metrics swapped. - /// - /// A consequence of the different core goal is that this should in general - /// produce substantially smaller executables that still run in - /// a reasonable amount of time. - static const OptimizationLevel Os; - /// A very specialized mode that will optimize for code size at any and all - /// costs. - /// - /// This is useful primarily when there are absolute size limitations and - /// any effort taken to reduce the size is worth it regardless of the - /// execution time impact. You should expect this level to produce rather - /// slow, but very small, code. - static const OptimizationLevel Oz; - - bool isOptimizingForSpeed() const { - return SizeLevel == 0 && SpeedLevel > 0; - } - - bool isOptimizingForSize() const { return SizeLevel > 0; } - - bool operator==(const OptimizationLevel &Other) const { - return SizeLevel == Other.SizeLevel && SpeedLevel == Other.SpeedLevel; - } - bool operator!=(const OptimizationLevel &Other) const { - return SizeLevel != Other.SizeLevel || SpeedLevel != Other.SpeedLevel; - } - - unsigned getSpeedupLevel() const { return SpeedLevel; } - - unsigned getSizeLevel() const { return SizeLevel; } - }; - explicit PassBuilder(TargetMachine *TM = nullptr, PipelineTuningOptions PTO = PipelineTuningOptions(), Optional PGOOpt = None, diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -269,22 +269,22 @@ if (!Conf.DisableVerify) MPM.addPass(VerifierPass()); - PassBuilder::OptimizationLevel OL; + OptimizationLevel OL; switch (OptLevel) { default: llvm_unreachable("Invalid optimization level"); case 0: - OL = PassBuilder::OptimizationLevel::O0; + OL = OptimizationLevel::O0; break; case 1: - OL = PassBuilder::OptimizationLevel::O1; + OL = OptimizationLevel::O1; break; case 2: - OL = PassBuilder::OptimizationLevel::O2; + OL = OptimizationLevel::O2; break; case 3: - OL = PassBuilder::OptimizationLevel::O3; + OL = OptimizationLevel::O3; break; } diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -303,22 +303,22 @@ ModulePassManager MPM; - PassBuilder::OptimizationLevel OL; + OptimizationLevel OL; switch (OptLevel) { default: llvm_unreachable("Invalid optimization level"); case 0: - OL = PassBuilder::OptimizationLevel::O0; + OL = OptimizationLevel::O0; break; case 1: - OL = PassBuilder::OptimizationLevel::O1; + OL = OptimizationLevel::O1; break; case 2: - OL = PassBuilder::OptimizationLevel::O2; + OL = OptimizationLevel::O2; break; case 3: - OL = PassBuilder::OptimizationLevel::O3; + OL = OptimizationLevel::O3; break; } diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -319,22 +319,22 @@ extern cl::opt PreInlineThreshold; } // namespace llvm -const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O0 = { +const OptimizationLevel OptimizationLevel::O0 = { /*SpeedLevel*/ 0, /*SizeLevel*/ 0}; -const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O1 = { +const OptimizationLevel OptimizationLevel::O1 = { /*SpeedLevel*/ 1, /*SizeLevel*/ 0}; -const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O2 = { +const OptimizationLevel OptimizationLevel::O2 = { /*SpeedLevel*/ 2, /*SizeLevel*/ 0}; -const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O3 = { +const OptimizationLevel OptimizationLevel::O3 = { /*SpeedLevel*/ 3, /*SizeLevel*/ 0}; -const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::Os = { +const OptimizationLevel OptimizationLevel::Os = { /*SpeedLevel*/ 2, /*SizeLevel*/ 1}; -const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::Oz = { +const OptimizationLevel OptimizationLevel::Oz = { /*SpeedLevel*/ 2, /*SizeLevel*/ 2}; @@ -475,8 +475,8 @@ } } -void PassBuilder::invokePeepholeEPCallbacks( - FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { +void PassBuilder::invokePeepholeEPCallbacks(FunctionPassManager &FPM, + OptimizationLevel Level) { for (auto &C : PeepholeEPCallbacks) C(FPM, Level); } @@ -874,9 +874,8 @@ } void PassBuilder::addPGOInstrPasses(ModulePassManager &MPM, - PassBuilder::OptimizationLevel Level, - bool RunProfileGen, bool IsCS, - std::string ProfileFile, + OptimizationLevel Level, bool RunProfileGen, + bool IsCS, std::string ProfileFile, std::string ProfileRemappingFile) { assert(Level != OptimizationLevel::O0 && "Not expecting O0 here!"); if (!IsCS && !DisablePreInliner) { @@ -963,8 +962,7 @@ MPM.addPass(InstrProfiling(Options, IsCS)); } -static InlineParams -getInlineParamsFromOptLevel(PassBuilder::OptimizationLevel Level) { +static InlineParams getInlineParamsFromOptLevel(OptimizationLevel Level) { return getInlineParams(Level.getSpeedupLevel(), Level.getSizeLevel()); } diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -690,19 +690,18 @@ }); PB.registerPipelineStartEPCallback( - [this](ModulePassManager &PM, PassBuilder::OptimizationLevel Level) { + [this](ModulePassManager &PM, OptimizationLevel Level) { FunctionPassManager FPM; FPM.addPass(AMDGPUPropagateAttributesEarlyPass(*this)); FPM.addPass(AMDGPUUseNativeCallsPass()); - if (EnableLibCallSimplify && - Level != PassBuilder::OptimizationLevel::O0) + if (EnableLibCallSimplify && Level != OptimizationLevel::O0) FPM.addPass(AMDGPUSimplifyLibCallsPass(*this)); PM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); }); PB.registerPipelineEarlySimplificationEPCallback( - [this](ModulePassManager &PM, PassBuilder::OptimizationLevel Level) { - if (Level == PassBuilder::OptimizationLevel::O0) + [this](ModulePassManager &PM, OptimizationLevel Level) { + if (Level == OptimizationLevel::O0) return; PM.addPass(AMDGPUUnifyMetadataPass()); @@ -720,8 +719,8 @@ }); PB.registerCGSCCOptimizerLateEPCallback( - [this](CGSCCPassManager &PM, PassBuilder::OptimizationLevel Level) { - if (Level == PassBuilder::OptimizationLevel::O0) + [this](CGSCCPassManager &PM, OptimizationLevel Level) { + if (Level == OptimizationLevel::O0) return; FunctionPassManager FPM; @@ -734,7 +733,7 @@ // anything, and before other cleanup optimizations. FPM.addPass(AMDGPULowerKernelAttributesPass()); - if (Level != PassBuilder::OptimizationLevel::O0) { + if (Level != OptimizationLevel::O0) { // Promote alloca to vector before SROA and loop unroll. If we // manage to eliminate allocas before unroll we may choose to unroll // less. diff --git a/llvm/lib/Target/BPF/BPFTargetMachine.cpp b/llvm/lib/Target/BPF/BPFTargetMachine.cpp --- a/llvm/lib/Target/BPF/BPFTargetMachine.cpp +++ b/llvm/lib/Target/BPF/BPFTargetMachine.cpp @@ -124,18 +124,18 @@ void BPFTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) { PB.registerPipelineStartEPCallback( - [=](ModulePassManager &MPM, PassBuilder::OptimizationLevel) { + [=](ModulePassManager &MPM, OptimizationLevel) { FunctionPassManager FPM; FPM.addPass(BPFAbstractMemberAccessPass(this)); FPM.addPass(BPFPreserveDITypePass()); MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); }); PB.registerPeepholeEPCallback([=](FunctionPassManager &FPM, - PassBuilder::OptimizationLevel Level) { + OptimizationLevel Level) { FPM.addPass(SimplifyCFGPass(SimplifyCFGOptions().hoistCommonInsts(true))); }); PB.registerPipelineEarlySimplificationEPCallback( - [=](ModulePassManager &MPM, PassBuilder::OptimizationLevel) { + [=](ModulePassManager &MPM, OptimizationLevel) { MPM.addPass(BPFAdjustOptPass()); }); } diff --git a/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp b/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp --- a/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp +++ b/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp @@ -280,11 +280,11 @@ void HexagonTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) { PB.registerLateLoopOptimizationsEPCallback( - [=](LoopPassManager &LPM, PassBuilder::OptimizationLevel Level) { + [=](LoopPassManager &LPM, OptimizationLevel Level) { LPM.addPass(HexagonLoopIdiomRecognitionPass()); }); PB.registerLoopOptimizerEndEPCallback( - [=](LoopPassManager &LPM, PassBuilder::OptimizationLevel Level) { + [=](LoopPassManager &LPM, OptimizationLevel Level) { LPM.addPass(HexagonVectorLoopCarriedReusePass()); }); } diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp --- a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp @@ -225,7 +225,7 @@ }); PB.registerPipelineStartEPCallback( - [this](ModulePassManager &PM, PassBuilder::OptimizationLevel Level) { + [this](ModulePassManager &PM, OptimizationLevel Level) { FunctionPassManager FPM; FPM.addPass(NVVMReflectPass(Subtarget.getSmVersion())); // FIXME: NVVMIntrRangePass is causing numerical discrepancies, diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp --- a/llvm/tools/opt/NewPMDriver.cpp +++ b/llvm/tools/opt/NewPMDriver.cpp @@ -173,58 +173,58 @@ static void registerEPCallbacks(PassBuilder &PB) { if (tryParsePipelineText(PB, PeepholeEPPipeline)) PB.registerPeepholeEPCallback( - [&PB](FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { + [&PB](FunctionPassManager &PM, OptimizationLevel Level) { ExitOnError Err("Unable to parse PeepholeEP pipeline: "); Err(PB.parsePassPipeline(PM, PeepholeEPPipeline)); }); if (tryParsePipelineText(PB, LateLoopOptimizationsEPPipeline)) PB.registerLateLoopOptimizationsEPCallback( - [&PB](LoopPassManager &PM, PassBuilder::OptimizationLevel Level) { + [&PB](LoopPassManager &PM, OptimizationLevel Level) { ExitOnError Err("Unable to parse LateLoopOptimizationsEP pipeline: "); Err(PB.parsePassPipeline(PM, LateLoopOptimizationsEPPipeline)); }); if (tryParsePipelineText(PB, LoopOptimizerEndEPPipeline)) PB.registerLoopOptimizerEndEPCallback( - [&PB](LoopPassManager &PM, PassBuilder::OptimizationLevel Level) { + [&PB](LoopPassManager &PM, OptimizationLevel Level) { ExitOnError Err("Unable to parse LoopOptimizerEndEP pipeline: "); Err(PB.parsePassPipeline(PM, LoopOptimizerEndEPPipeline)); }); if (tryParsePipelineText(PB, ScalarOptimizerLateEPPipeline)) PB.registerScalarOptimizerLateEPCallback( - [&PB](FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { + [&PB](FunctionPassManager &PM, OptimizationLevel Level) { ExitOnError Err("Unable to parse ScalarOptimizerLateEP pipeline: "); Err(PB.parsePassPipeline(PM, ScalarOptimizerLateEPPipeline)); }); if (tryParsePipelineText(PB, CGSCCOptimizerLateEPPipeline)) PB.registerCGSCCOptimizerLateEPCallback( - [&PB](CGSCCPassManager &PM, PassBuilder::OptimizationLevel Level) { + [&PB](CGSCCPassManager &PM, OptimizationLevel Level) { ExitOnError Err("Unable to parse CGSCCOptimizerLateEP pipeline: "); Err(PB.parsePassPipeline(PM, CGSCCOptimizerLateEPPipeline)); }); if (tryParsePipelineText(PB, VectorizerStartEPPipeline)) PB.registerVectorizerStartEPCallback( - [&PB](FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) { + [&PB](FunctionPassManager &PM, OptimizationLevel Level) { ExitOnError Err("Unable to parse VectorizerStartEP pipeline: "); Err(PB.parsePassPipeline(PM, VectorizerStartEPPipeline)); }); if (tryParsePipelineText(PB, PipelineStartEPPipeline)) PB.registerPipelineStartEPCallback( - [&PB](ModulePassManager &PM, PassBuilder::OptimizationLevel) { + [&PB](ModulePassManager &PM, OptimizationLevel) { ExitOnError Err("Unable to parse PipelineStartEP pipeline: "); Err(PB.parsePassPipeline(PM, PipelineStartEPPipeline)); }); if (tryParsePipelineText( PB, PipelineEarlySimplificationEPPipeline)) PB.registerPipelineEarlySimplificationEPCallback( - [&PB](ModulePassManager &PM, PassBuilder::OptimizationLevel) { + [&PB](ModulePassManager &PM, OptimizationLevel) { ExitOnError Err("Unable to parse EarlySimplification pipeline: "); Err(PB.parsePassPipeline(PM, PipelineEarlySimplificationEPPipeline)); }); if (tryParsePipelineText(PB, OptimizerLastEPPipeline)) PB.registerOptimizerLastEPCallback( - [&PB](ModulePassManager &PM, PassBuilder::OptimizationLevel) { + [&PB](ModulePassManager &PM, OptimizationLevel) { ExitOnError Err("Unable to parse OptimizerLastEP pipeline: "); Err(PB.parsePassPipeline(PM, OptimizerLastEPPipeline)); }); diff --git a/polly/include/polly/Canonicalization.h b/polly/include/polly/Canonicalization.h --- a/polly/include/polly/Canonicalization.h +++ b/polly/include/polly/Canonicalization.h @@ -30,7 +30,7 @@ llvm::FunctionPassManager buildCanonicalicationPassesForNPM(llvm::ModulePassManager &MPM, - llvm::PassBuilder::OptimizationLevel Level); + llvm::OptimizationLevel Level); } // namespace polly diff --git a/polly/lib/Support/RegisterPasses.cpp b/polly/lib/Support/RegisterPasses.cpp --- a/polly/lib/Support/RegisterPasses.cpp +++ b/polly/lib/Support/RegisterPasses.cpp @@ -474,7 +474,7 @@ /// the analysis passes are added, skipping Polly itself. /// The IR may still be modified. static void buildCommonPollyPipeline(FunctionPassManager &PM, - PassBuilder::OptimizationLevel Level, + OptimizationLevel Level, bool EnableForOpt) { PassBuilder PB; ScopPassManager SPM; @@ -574,7 +574,7 @@ } static void buildEarlyPollyPipeline(ModulePassManager &MPM, - PassBuilder::OptimizationLevel Level) { + OptimizationLevel Level) { bool EnableForOpt = shouldEnablePollyForOptimization() && Level.isOptimizingForSpeed(); if (!shouldEnablePollyForDiagnostic() && !EnableForOpt) @@ -603,7 +603,7 @@ } static void buildLatePollyPipeline(FunctionPassManager &PM, - PassBuilder::OptimizationLevel Level) { + OptimizationLevel Level) { bool EnableForOpt = shouldEnablePollyForOptimization() && Level.isOptimizingForSpeed(); if (!shouldEnablePollyForDiagnostic() && !EnableForOpt) diff --git a/polly/lib/Transform/Canonicalization.cpp b/polly/lib/Transform/Canonicalization.cpp --- a/polly/lib/Transform/Canonicalization.cpp +++ b/polly/lib/Transform/Canonicalization.cpp @@ -64,7 +64,7 @@ /// Adapted from llvm::PassBuilder::buildInlinerPipeline static ModuleInlinerWrapperPass -buildInlinePasses(llvm::PassBuilder::OptimizationLevel Level) { +buildInlinePasses(llvm::OptimizationLevel Level) { InlineParams IP = getInlineParams(200); ModuleInlinerWrapperPass MIWP(IP); @@ -92,8 +92,9 @@ return MIWP; } -FunctionPassManager polly::buildCanonicalicationPassesForNPM( - llvm::ModulePassManager &MPM, llvm::PassBuilder::OptimizationLevel Level) { +FunctionPassManager +polly::buildCanonicalicationPassesForNPM(llvm::ModulePassManager &MPM, + llvm::OptimizationLevel Level) { FunctionPassManager FPM; bool UseMemSSA = true; @@ -107,7 +108,7 @@ FPM.addPass(ReassociatePass()); { LoopPassManager LPM; - LPM.addPass(LoopRotatePass(Level != PassBuilder::OptimizationLevel::Oz)); + LPM.addPass(LoopRotatePass(Level != OptimizationLevel::Oz)); FPM.addPass(createFunctionToLoopPassAdaptor( std::move(LPM), /*UseMemorySSA=*/false, /*UseBlockFrequencyInfo=*/false));