How to make clang stop after specific llvm pass?


I want to dump the whole module before specific LLVM pass (namely, loop-vectorize), so that I can then pass the dumped module to opt -loop-vectorize and debug the pass.

Apparently, clang -O2 test.c -mllvm -stop-before=loop-vectorize does not work; the error I get is that the pass is not registered.

I tried to use -print-before-all and manually extract the IR before the pass, but the output does not contain metadata, which makes the pass behave differently.

I also tried -mllvm -disable-llvm-passes to get pristine IR and -mllvm -debug-pass=arguments to figure out what passes are executed before loop-vectorize (so that I can pass them to opt and get the desired input to loop-vectorize), but it does not show which LLVM passes are being run, i.e. it only shows passes added by the backend.

So, how can I tell clang to dump the module before a specific pass? Sorry for dummy question, but google didn’t help this time.

If you also add “-print-module-scope” along with “-print-before-all” you’ll get more stuff printed, including metadata.

Thank you, it worked. Is this how people usually prepare tests for LLVM passes?

For opt passes I usually use a combination of that, llvm-reduce and/or bugpoint and utils/ (to simplify the opt pipeline).

1 Like