rcorcs created this revision.
rcorcs added a reviewer: hiraditya.
rcorcs added projects: LLVM, lld.
Herald added subscribers: cfe-commits, msifontes, jurahul, Kayjukh, frgossen,
grosul1, Joonsoo, stephenneuendorffer, liufengdb, lucyrfox, mgester,
arpith-jacob, nicolasvasilache, antiagainst, shauheen, jpienaar, rriddle,
mehdi_amini, dexonsmith, steven_wu, MaskRay, aheejin, arichardson, inglorion,
sbc100, mgorny, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: MaskRay.
Herald added projects: clang, MLIR.
This patch is the first in the sequence of three patches for supporting size
optimization with LTO. The planned patches are:
1: Standardizing the use of OptimizationLevel across pass builders, which
includes both SpeedupLevel and SizeLevel.
2: Enable the support for -Os and -Oz for LTO in lld.
3: Tune the LTO pipeline for size optimization.
Since we already have a class that describes both speed and size levels of
optimization, I believe it is a good idea to use across the code base when
defining optimization levels.
In the next patch, instead of adding a SizeLevel variable for the LTO
configuration, I'll be able to simply use this OptimizationLevel variable.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D81223
Files:
clang/lib/CodeGen/BackendUtil.cpp
lld/COFF/LTO.cpp
lld/ELF/LTO.cpp
lld/wasm/LTO.cpp
llvm/examples/Bye/Bye.cpp
llvm/include/llvm/IR/PassManager.h
llvm/include/llvm/LTO/Config.h
llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h
llvm/include/llvm/Passes/PassBuilder.h
llvm/include/llvm/Transforms/IPO/PassManagerBuilder.h
llvm/lib/IR/PassManager.cpp
llvm/lib/LTO/LTO.cpp
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/lib/LTO/ThinLTOCodeGenerator.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
llvm/tools/bugpoint/bugpoint.cpp
llvm/tools/llvm-lto/llvm-lto.cpp
llvm/tools/llvm-lto2/llvm-lto2.cpp
llvm/tools/lto/lto.cpp
llvm/tools/opt/CMakeLists.txt
llvm/tools/opt/NewPMDriver.cpp
llvm/tools/opt/opt.cpp
mlir/lib/ExecutionEngine/OptUtils.cpp
Index: mlir/lib/ExecutionEngine/OptUtils.cpp
===
--- mlir/lib/ExecutionEngine/OptUtils.cpp
+++ mlir/lib/ExecutionEngine/OptUtils.cpp
@@ -65,8 +65,7 @@
unsigned optLevel, unsigned sizeLevel,
llvm::TargetMachine *targetMachine) {
llvm::PassManagerBuilder builder;
- builder.OptLevel = optLevel;
- builder.SizeLevel = sizeLevel;
+ builder.OptLevel = {optLevel, sizeLevel};
builder.Inliner = llvm::createFunctionInliningPass(
optLevel, sizeLevel, /*DisableInlineHotCallSite=*/false);
builder.LoopVectorize = optLevel > 1 && sizeLevel < 2;
Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -393,8 +393,7 @@
FPM.add(createVerifierPass()); // Verify that input is correct
PassManagerBuilder Builder;
- Builder.OptLevel = OptLevel;
- Builder.SizeLevel = SizeLevel;
+ Builder.OptLevel = {OptLevel, SizeLevel};
if (DisableInline) {
// No inlining pass
@@ -450,7 +449,7 @@
PassManagerBuilder Builder;
Builder.VerifyInput = true;
if (DisableOptimizations)
-Builder.OptLevel = 0;
+Builder.OptLevel = OptimizationLevel::O0;
if (!DisableInline)
Builder.Inliner = createFunctionInliningPass();
Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -143,7 +143,7 @@
if (tryParsePipelineText(PB, PeepholeEPPipeline))
PB.registerPeepholeEPCallback(
[&PB, VerifyEachPass, DebugLogging](
-FunctionPassManager &PM, PassBuilder::OptimizationLevel Level) {
+FunctionPassManager &PM, OptimizationLevel Level) {
ExitOnError Err("Unable to parse PeepholeEP pipeline: ");
Err(PB.parsePassPipeline(PM, PeepholeEPPipeline, VerifyEachPass,
DebugLogging));
@@ -152,7 +152,7 @@
LateLoopOptimizationsEPPipeline))
PB.registerLateLoopOptimizationsEPCallback(
[&PB, VerifyEachPass, DebugLogging](
-LoopPassManager &PM, PassBuilder::OptimizationLevel Level) {
+LoopPassManager &PM, OptimizationLevel Level) {
ExitOnError Err("Unable to parse LateLoopOptimizationsEP pipeline: ");
Err(PB.parsePassPipeline(PM, LateLoopOptimizationsEPPipeline,
VerifyEachPass, DebugLogging));
@@ -160,7 +160,7 @@
if (tryParsePipelineText(PB, LoopOptimizerEndEPPipeline))
PB.registerLoopOptimizerEndEPCallback(
[&PB, VerifyEachPass, DebugLogging](
-LoopPassManager &PM, Pa