[Mlir-commits] [mlir] a8f6b57 - [PassBuilder] Support O0 in default pipelines
Nikita Popov
llvmlistbot at llvm.org
Fri Mar 17 02:00:18 PDT 2023
Author: Nikita Popov
Date: 2023-03-17T10:00:05+01:00
New Revision: a8f6b5763e89cfeec94d3fcf0f6b70f96b293f7d
URL: https://github.com/llvm/llvm-project/commit/a8f6b5763e89cfeec94d3fcf0f6b70f96b293f7d
DIFF: https://github.com/llvm/llvm-project/commit/a8f6b5763e89cfeec94d3fcf0f6b70f96b293f7d.diff
LOG: [PassBuilder] Support O0 in default pipelines
The default and pre-link pipeline builders currently require you to
call a separate method for optimization level O0, even though they
have perfectly well-defined O0 optimization pipelines.
Accept O0 optimization level and call buildO0DefaultPipeline()
internally, so all consumers don't need to repeat this.
Differential Revision: https://reviews.llvm.org/D146200
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
flang/lib/Frontend/FrontendActions.cpp
llvm/include/llvm/Passes/PassBuilder.h
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassBuilderPipelines.cpp
mlir/lib/ExecutionEngine/OptUtils.cpp
openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 95da681eb3bc8..17d0d8d653ac6 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -973,9 +973,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
MPM.addPass(InstrProfiling(*Options, false));
});
- if (CodeGenOpts.OptimizationLevel == 0) {
- MPM = PB.buildO0DefaultPipeline(Level, IsLTO || IsThinLTO);
- } else if (IsThinLTO) {
+ if (IsThinLTO) {
MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level);
} else if (IsLTO) {
MPM = PB.buildLTOPreLinkDefaultPipeline(Level);
diff --git a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
index de47cbf4b1ce3..bd3490e802e44 100644
--- a/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
+++ b/clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp
@@ -103,11 +103,7 @@ static void RunOptimizationPasses(raw_ostream &OS, Module &M,
PB.registerLoopAnalyses(LAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
- ModulePassManager MPM;
- if (OL == OptimizationLevel::O0)
- MPM = PB.buildO0DefaultPipeline(OL);
- else
- MPM = PB.buildPerModuleDefaultPipeline(OL);
+ ModulePassManager MPM = PB.buildPerModuleDefaultPipeline(OL);
MPM.addPass(PrintModulePass(OS));
MPM.run(M, MAM);
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 15c2b8b05688c..64cabd87e6a41 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -726,10 +726,7 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
// Create the pass manager.
llvm::ModulePassManager mpm;
- if (opts.OptimizationLevel == 0)
- mpm = pb.buildO0DefaultPipeline(level, opts.PrepareForFullLTO ||
- opts.PrepareForThinLTO);
- else if (opts.PrepareForFullLTO)
+ if (opts.PrepareForFullLTO)
mpm = pb.buildLTOPreLinkDefaultPipeline(level);
else if (opts.PrepareForThinLTO)
mpm = pb.buildThinLTOPreLinkDefaultPipeline(level);
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index 9d9f256f1ceda..40413aad1281c 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -259,11 +259,6 @@ class PassBuilder {
/// optimization and code generation. It is particularly tuned to fit well
/// when IR coming into the LTO phase was first run through \c
/// addPreLinkLTODefaultPipeline, and the two coordinate closely.
- ///
- /// Note that \p Level cannot be `O0` here. The pipelines produced are
- /// only intended for use when attempting to optimize code. If frontends
- /// require some transformations for semantic reasons, they should explicitly
- /// build them.
ModulePassManager
buildThinLTODefaultPipeline(OptimizationLevel Level,
const ModuleSummaryIndex *ImportSummary);
@@ -275,11 +270,6 @@ class PassBuilder {
/// run. It works to minimize the IR which needs to be analyzed without
/// making irreversible decisions which could be made better during the LTO
/// run.
- ///
- /// Note that \p Level cannot be `O0` here. The pipelines produced are
- /// only intended for use when attempting to optimize code. If frontends
- /// require some transformations for semantic reasons, they should explicitly
- /// build them.
ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level);
/// Build an LTO default optimization pipeline to a pass manager.
@@ -288,11 +278,6 @@ class PassBuilder {
/// optimization and code generation. It is particularly tuned to fit well
/// when IR coming into the LTO phase was first run through \c
/// addPreLinkLTODefaultPipeline, and the two coordinate closely.
- ///
- /// Note that \p Level cannot be `O0` here. The pipelines produced are
- /// only intended for use when attempting to optimize code. If frontends
- /// require some transformations for semantic reasons, they should explicitly
- /// build them.
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level,
ModuleSummaryIndex *ExportSummary);
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 38e79eb7fac39..61b882ee2d33d 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -1270,12 +1270,6 @@ Error PassBuilder::parseModulePass(ModulePassManager &MPM,
.Case("O3", OptimizationLevel::O3)
.Case("Os", OptimizationLevel::Os)
.Case("Oz", OptimizationLevel::Oz);
- if (L == OptimizationLevel::O0 && Matches[1] != "thinlto" &&
- Matches[1] != "lto") {
- MPM.addPass(buildO0DefaultPipeline(L, Matches[1] == "thinlto-pre-link" ||
- Matches[1] == "lto-pre-link"));
- return Error::success();
- }
// This is consistent with old pass manager invoked via opt, but
// inconsistent with clang. Clang doesn't enable loop vectorization
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index c006488f91db5..1d386139d9e6c 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -1398,8 +1398,8 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
ModulePassManager
PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
bool LTOPreLink) {
- assert(Level != OptimizationLevel::O0 &&
- "Must request optimizations for the default pipeline!");
+ if (Level == OptimizationLevel::O0)
+ return buildO0DefaultPipeline(Level, LTOPreLink);
ModulePassManager MPM;
@@ -1440,8 +1440,8 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
ModulePassManager
PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
- assert(Level != OptimizationLevel::O0 &&
- "Must request optimizations for the default pipeline!");
+ if (Level == OptimizationLevel::O0)
+ return buildO0DefaultPipeline(Level, /*LTOPreLink*/true);
ModulePassManager MPM;
@@ -1552,8 +1552,6 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
ModulePassManager
PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
- assert(Level != OptimizationLevel::O0 &&
- "Must request optimizations for the default pipeline!");
// FIXME: We should use a customized pre-link pipeline!
return buildPerModuleDefaultPipeline(Level,
/* LTOPreLink */ true);
diff --git a/mlir/lib/ExecutionEngine/OptUtils.cpp b/mlir/lib/ExecutionEngine/OptUtils.cpp
index 69216c57c2868..b024a625fbf53 100644
--- a/mlir/lib/ExecutionEngine/OptUtils.cpp
+++ b/mlir/lib/ExecutionEngine/OptUtils.cpp
@@ -84,11 +84,7 @@ mlir::makeOptimizingTransformer(unsigned optLevel, unsigned sizeLevel,
pb.crossRegisterProxies(lam, fam, cgam, mam);
ModulePassManager mpm;
- if (*ol == OptimizationLevel::O0)
- mpm.addPass(pb.buildO0DefaultPipeline(*ol));
- else
- mpm.addPass(pb.buildPerModuleDefaultPipeline(*ol));
-
+ mpm.addPass(pb.buildPerModuleDefaultPipeline(*ol));
mpm.run(*m, mam);
return Error::success();
};
diff --git a/openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.cpp b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.cpp
index 3983f7044dcf7..bdccefc616712 100644
--- a/openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.cpp
+++ b/openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.cpp
@@ -214,11 +214,7 @@ void JITEngine::opt(TargetMachine *TM, TargetLibraryInfoImpl *TLII, Module &M,
PB.registerLoopAnalyses(LAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
- if (OptLevel)
- MPM.addPass(PB.buildPerModuleDefaultPipeline(getOptLevel(OptLevel)));
- else
- MPM.addPass(PB.buildO0DefaultPipeline(getOptLevel(OptLevel)));
-
+ MPM.addPass(PB.buildPerModuleDefaultPipeline(getOptLevel(OptLevel)));
MPM.run(M, MAM);
}
More information about the Mlir-commits
mailing list