[PATCH] D81223: Size LTO (1/3): Standardizing the use of OptimizationLevel
Rodrigo Caetano Rocha via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 5 08:18:44 PDT 2020
rcorcs added a comment.
LLVM already has the class PassBuilder::OptimizationLevel that encapsulates the logic of both speed and size optimization levels. This class already checks which values for SpeedLevel and SizeLevel are valid.
However, other parts of the code define two separate variables to describe speed and size optimization levels with their semantic specified either in comments or code. Note that when SizeLevel!=0, OptLevel (or SpeedLevel) is usually expected to be 2, that is, their values are interdependent.
>From my understanding, ideally, LLVM would use the same OptimizationLevel encapsulation everywhere. If the same encapsulation is used everywhere we can avoid conversions and guarantee
that they always have the same semantics.
For example, the class PassManagerBuilder defines these two separate variables with their semantics in comments:
/// The Optimization Level - Specify the basic optimization level.
/// 0 = -O0, 1 = -O1, 2 = -O2, 3 = -O3
unsigned OptLevel;
/// SizeLevel - How much we're optimizing for size.
/// 0 = none, 1 = -Os, 2 = -Oz
unsigned SizeLevel;
On the other hand, the class ThinLTOCodeGenerator defines the semantics of OptLevel in code:
/// IR optimization level: from 0 to 3.
void setOptLevel(unsigned NewOptLevel) {
OptLevel = (NewOptLevel > 3) ? 3 : NewOptLevel;
}
This patch standardizes the use of OptimizationLevel across PassBuilder, PassManagerBuilder, LTO configuration, and LTO code generators. Even with this patch, further work is still needed to standardize the use of OptimizationLevel across LLVM.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D81223/new/
https://reviews.llvm.org/D81223
More information about the cfe-commits
mailing list