Converting a clang -cc1 invocation into an llc invocation

I've been compiling programs by invoking clang -cc1 like this:

clang -cc1 -triple thumbv7-eabi -O3 -target-cpu cortex-a8 t.c -S

I encounter an interesting problem that I want to investigate by looking
at the SelectionDAGs. However, clang -cc1 doesn't accept the
-view-legalize-dags option that llc accepts. What should I do?

I notice that (strings `which clang` | grep view-legalize-dags), so is
there a way of giving that argument to clang -cc1?

Alternatively, is there a way of converting the clang -cc1 invocation
into an llc invocation that will give exactly the same behaviour so that
I can do the following?

clang -cc1 -triple thumbv7-eabi -O3 -target-cpu cortex-a8 t.c
-emit-llvm-bc
llc t.bc ... -view-legalize-dags

You just answered your own question :). That will work quite nicely
actually.

Chip

You forgot to reply to the list. Also CC'ing LLVMdev.

clang -cc1 -triple thumbv7-eabi -O3 -target-cpu cortex-a8 t.c
-emit-llvm-bc
llc t.bc ... -view-legalize-dags

You just answered your own question :). That will work quite nicely
actually.

Maybe it would if I knew exactly what to put instead of "...". I can't use the same options as with clang -cc1 as they are not recognised. If I put nothing I won't even be targeting the same architecture.

Oh sorry, I didn't notice that '...'. (Silly me...)

You can use -mtriple to specify the target triple to llc, and -mcpu to
specify the CPU type:
llc t.bc -mtriple=thumbv7-eabi -mcpu=cortex-a8 -view-legalize-dags

Of course, specifying the triple shouldn't be necessary, since Clang
encodes that information into the BC file. If you disassembled the BC
file into human-readable IR, you'd see something like this at the top:

target triple thumbv7-eabi

so you should only have to specify the CPU type with -mcpu.

Hope that helps.

Chip

Hi Edmund,

Chip answered this, mostly, but there are some subtle details in how
llc is invoked that aren't always obvious. For example, depending on
the exact arguments to Clang you may need to pass -O0 to llc, or
-mcpu, or target attrs, or the relocation model, or -disable-fp-elim,
etc. Unfortunately there is currently no easy way to get the exact
invocation.

My plan is to eventually extend the Clang driver to support this
directly to solve this problem.

- Daniel