Experimenting with opt -Os/-Oz

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.

Kind regards,

Fernando

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

Dear Florian,

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)

Thank you! That was pretty much what I was looking for. Even the
comments in the header of PassBuilder are nice to learn more about
those default levels.

Regards,

Fernando