Skip to content

Commit a8f6b57

Browse files
committed
[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
1 parent 951a980 commit a8f6b57

File tree

8 files changed

+9
-49
lines changed

8 files changed

+9
-49
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,9 +973,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
973973
MPM.addPass(InstrProfiling(*Options, false));
974974
});
975975

976-
if (CodeGenOpts.OptimizationLevel == 0) {
977-
MPM = PB.buildO0DefaultPipeline(Level, IsLTO || IsThinLTO);
978-
} else if (IsThinLTO) {
976+
if (IsThinLTO) {
979977
MPM = PB.buildThinLTOPreLinkDefaultPipeline(Level);
980978
} else if (IsLTO) {
981979
MPM = PB.buildLTOPreLinkDefaultPipeline(Level);

clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,7 @@ static void RunOptimizationPasses(raw_ostream &OS, Module &M,
103103
PB.registerLoopAnalyses(LAM);
104104
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
105105

106-
ModulePassManager MPM;
107-
if (OL == OptimizationLevel::O0)
108-
MPM = PB.buildO0DefaultPipeline(OL);
109-
else
110-
MPM = PB.buildPerModuleDefaultPipeline(OL);
106+
ModulePassManager MPM = PB.buildPerModuleDefaultPipeline(OL);
111107
MPM.addPass(PrintModulePass(OS));
112108

113109
MPM.run(M, MAM);

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,7 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
726726

727727
// Create the pass manager.
728728
llvm::ModulePassManager mpm;
729-
if (opts.OptimizationLevel == 0)
730-
mpm = pb.buildO0DefaultPipeline(level, opts.PrepareForFullLTO ||
731-
opts.PrepareForThinLTO);
732-
else if (opts.PrepareForFullLTO)
729+
if (opts.PrepareForFullLTO)
733730
mpm = pb.buildLTOPreLinkDefaultPipeline(level);
734731
else if (opts.PrepareForThinLTO)
735732
mpm = pb.buildThinLTOPreLinkDefaultPipeline(level);

llvm/include/llvm/Passes/PassBuilder.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,6 @@ class PassBuilder {
259259
/// optimization and code generation. It is particularly tuned to fit well
260260
/// when IR coming into the LTO phase was first run through \c
261261
/// addPreLinkLTODefaultPipeline, and the two coordinate closely.
262-
///
263-
/// Note that \p Level cannot be `O0` here. The pipelines produced are
264-
/// only intended for use when attempting to optimize code. If frontends
265-
/// require some transformations for semantic reasons, they should explicitly
266-
/// build them.
267262
ModulePassManager
268263
buildThinLTODefaultPipeline(OptimizationLevel Level,
269264
const ModuleSummaryIndex *ImportSummary);
@@ -275,11 +270,6 @@ class PassBuilder {
275270
/// run. It works to minimize the IR which needs to be analyzed without
276271
/// making irreversible decisions which could be made better during the LTO
277272
/// run.
278-
///
279-
/// Note that \p Level cannot be `O0` here. The pipelines produced are
280-
/// only intended for use when attempting to optimize code. If frontends
281-
/// require some transformations for semantic reasons, they should explicitly
282-
/// build them.
283273
ModulePassManager buildLTOPreLinkDefaultPipeline(OptimizationLevel Level);
284274

285275
/// Build an LTO default optimization pipeline to a pass manager.
@@ -288,11 +278,6 @@ class PassBuilder {
288278
/// optimization and code generation. It is particularly tuned to fit well
289279
/// when IR coming into the LTO phase was first run through \c
290280
/// addPreLinkLTODefaultPipeline, and the two coordinate closely.
291-
///
292-
/// Note that \p Level cannot be `O0` here. The pipelines produced are
293-
/// only intended for use when attempting to optimize code. If frontends
294-
/// require some transformations for semantic reasons, they should explicitly
295-
/// build them.
296281
ModulePassManager buildLTODefaultPipeline(OptimizationLevel Level,
297282
ModuleSummaryIndex *ExportSummary);
298283

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,12 +1270,6 @@ Error PassBuilder::parseModulePass(ModulePassManager &MPM,
12701270
.Case("O3", OptimizationLevel::O3)
12711271
.Case("Os", OptimizationLevel::Os)
12721272
.Case("Oz", OptimizationLevel::Oz);
1273-
if (L == OptimizationLevel::O0 && Matches[1] != "thinlto" &&
1274-
Matches[1] != "lto") {
1275-
MPM.addPass(buildO0DefaultPipeline(L, Matches[1] == "thinlto-pre-link" ||
1276-
Matches[1] == "lto-pre-link"));
1277-
return Error::success();
1278-
}
12791273

12801274
// This is consistent with old pass manager invoked via opt, but
12811275
// inconsistent with clang. Clang doesn't enable loop vectorization

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,8 +1398,8 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
13981398
ModulePassManager
13991399
PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
14001400
bool LTOPreLink) {
1401-
assert(Level != OptimizationLevel::O0 &&
1402-
"Must request optimizations for the default pipeline!");
1401+
if (Level == OptimizationLevel::O0)
1402+
return buildO0DefaultPipeline(Level, LTOPreLink);
14031403

14041404
ModulePassManager MPM;
14051405

@@ -1440,8 +1440,8 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
14401440

14411441
ModulePassManager
14421442
PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
1443-
assert(Level != OptimizationLevel::O0 &&
1444-
"Must request optimizations for the default pipeline!");
1443+
if (Level == OptimizationLevel::O0)
1444+
return buildO0DefaultPipeline(Level, /*LTOPreLink*/true);
14451445

14461446
ModulePassManager MPM;
14471447

@@ -1552,8 +1552,6 @@ ModulePassManager PassBuilder::buildThinLTODefaultPipeline(
15521552

15531553
ModulePassManager
15541554
PassBuilder::buildLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
1555-
assert(Level != OptimizationLevel::O0 &&
1556-
"Must request optimizations for the default pipeline!");
15571555
// FIXME: We should use a customized pre-link pipeline!
15581556
return buildPerModuleDefaultPipeline(Level,
15591557
/* LTOPreLink */ true);

mlir/lib/ExecutionEngine/OptUtils.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,7 @@ mlir::makeOptimizingTransformer(unsigned optLevel, unsigned sizeLevel,
8484
pb.crossRegisterProxies(lam, fam, cgam, mam);
8585

8686
ModulePassManager mpm;
87-
if (*ol == OptimizationLevel::O0)
88-
mpm.addPass(pb.buildO0DefaultPipeline(*ol));
89-
else
90-
mpm.addPass(pb.buildPerModuleDefaultPipeline(*ol));
91-
87+
mpm.addPass(pb.buildPerModuleDefaultPipeline(*ol));
9288
mpm.run(*m, mam);
9389
return Error::success();
9490
};

openmp/libomptarget/plugins-nextgen/common/PluginInterface/JIT.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,7 @@ void JITEngine::opt(TargetMachine *TM, TargetLibraryInfoImpl *TLII, Module &M,
214214
PB.registerLoopAnalyses(LAM);
215215
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
216216

217-
if (OptLevel)
218-
MPM.addPass(PB.buildPerModuleDefaultPipeline(getOptLevel(OptLevel)));
219-
else
220-
MPM.addPass(PB.buildO0DefaultPipeline(getOptLevel(OptLevel)));
221-
217+
MPM.addPass(PB.buildPerModuleDefaultPipeline(getOptLevel(OptLevel)));
222218
MPM.run(M, MAM);
223219
}
224220

0 commit comments

Comments
 (0)