[llvm-dev] Experimenting with opt -Os/-Oz

Florian Hahn via llvm-dev llvm-dev at lists.llvm.org
Wed Mar 17 07:04:07 PDT 2021



> On Mar 17, 2021, at 13:55, Fernando Magno Quintao Pereira via llvm-dev <llvm-dev at lists.llvm.org> wrote:
> 
> Dear LLVMers,
> 
>     I would like to fiddle a bit with two standard optimization
> levels (Os/Oz) used by opt. So, could someone tell me where, in the
> implementation of LLVM, is the order of the passes within those levels
> defined? Ideally, I would like to recompile LLVM and change the
> default levels in my experiments.


I think a good place to start would be PassBuilder.cpp. Some passes are only added for certain optimization levels (e.g. see https://github.com/llvm/llvm-project/blob/main/llvm/lib/Passes/PassBuilder.cpp#L703) or take optimization level dependent options. You can also get the executed passes by using the `-debug-pass-manager` option (e.g. see https://github.com/llvm/llvm-project/blob/main/llvm/test/Other/new-pm-defaults.ll#L19)

Another thing to note is that some passes check for the `optsize`/`minsize` attributes on functions as well, so the result could be different even if the executed passes are the same. Frontends have to add those attributes.

Cheers,
Florian



More information about the llvm-dev mailing list