Arch D. Robison
Arch D. Robison

Reputation: 4049

How to make clang stop before a specified LLVM pass and dump the LLVM IR

How do I run clang and have it stop just before a pass, say loop-vectorize, and dump the IR to an .ll file that can be later fed to opt?

opt has a -stop-after= option, but Clang seems to be missing the equivalent option. Here is a failed attempt with Clang 3.7.0rc2:

$ ../build/bin/clang -O2 -mllvm -stop-after=loop-vectorize a.cpp
clang (LLVM option parsing): Unknown command line argument '-stop-after=loop-vectorize'.  Try: 'clang (LLVM option parsing) -help'
clang (LLVM option parsing): Did you mean '-print-after=loop-vectorize'?

I've also tried running clang -O0 -emit-llvm -S and then running opt -O2, but the results were different than running clang -O2 directly.

Upvotes: 3

Views: 2262

Answers (1)

jtv
jtv

Reputation: 118

I'm not aware of any way to stop after a specific pass when compiling with Clang, but instead I can offer a hopefully helpful alternative.

First, to address opt and Clang producing different IR files, it may be helpful to compare the pass lists for clang -O2 and opt -O2 manually. This can be done for both by passing -debug-pass=Arguments. When running Clang you will need -mllvm to pass the argument along.

Having done this myself it appears that a different set of passes are being run for each of them but I would suggest confirming for yourself.

To address your initial question, you might simply copy the list of passes run during -O2 only up through loop-vectorize and simply run opt manually passing it the reduced list.

Upvotes: 2

Related Questions