Where to find the list of passes run by clang/opt with -O3

Hi,

I am trying to locate the passes run by clang/opt when it is passed the option -O3. Can someone point me where to look at? Eventually, I want to turn off just the LoopStrengthReduction pass in the -O3 set of default passes.

Thanks,

Best Regards,
Nitish

Are you looking for code or just a textual dump?
In the former case, look at the functions in
lib/Transforms/IPO/PassManagerBuilder.cpp
(in llvm) [or lib/Passes if you're using the new pass manager
infrastructure]. The pipelines should be almost identical, FWIW.
If you want that from clang, you can either add `-mllvm
-debug-pass=Arguments` to get the passes passed to `opt`, or `-mllvm
-opt-bisect-limit=-1` which will show all the passes (and the order on
which they're run on each function in your Module).

Hope this answers your question (if it doesn't, feel free to ask again :slight_smile:

Also, the easiest hack to turn off LSR is that of probably just
commenting out the line that adds the pass in PassManagerBuilder.cpp.
If you use `opt` + the new pass manager there's a flag for testing to
specify a custom pipeline, but that will be more work.

I had asked a similar question earlier this year regarding which passes are involved at a particular optimisation level (lists.llvm.org/pipermail/llvm-dev/2017-June/114543.html), and the most helpful suggestion I received was to invoke the compiler with the following options:

  -O3 -mllvm -debug-pass=Structure

So I ran the compiler with each of '-O0' .. '-O3' to get the answer I was looking for.

I don't know how to generally disable a particular pass from the command line with LLVM v4.0, but the pass you want to disable identifies itself as:

  Loop Strength Reduction

and can be disabled with the option (see 'lib/CodeGen/TargetPassConfig.cpp'):

  -mllvm -disable-lsr

I haven't yet started working with LLVM v5.0 and the new pass manager though so this may already be an obsolete suggestion.

All the best,

    MartinO

Hi Martin,

Thanks for the help. -mllvm -disable-lsr worked for me.

Thanks a lot!

Best Regards,
Nitish