Cleanest way to do llvm-driven compile with specified passes

Hi there,

I have a target platform for which I’m compiling code with llvm and my own backend. My current compilation route to create an executable is to just call something like:

$ clang -O3 -ccc-host-triple arcompact [-I…] file_to_compile.c another_file.c [-lm etc]

Importantly, clang here is running with the target version of gcc as the driver, so that gcc (call it gcc-arcompact) takes care of calling the correct assembler, linker, etc for the backend output.

Now what I want to do is select my own optimization passes specifically. As far as I can tell, the following seems to be the only way to do it:

$ clang -S -emit-llvm -ccc-host-triple arcompact [–I… -L… etc] file_to_compile.c another_file.c
$ opt [passes] file_to_compile.s | llc -march=arcompact -o file_to_compile.s
$ opt [passes] another_file.s | llc -march=arcompact -o another_file.s
$ gcc-arcompact [-L… etc] file_to_compile.s another_file.s [-lm etc]

Is there a cleaner way to do this - i.e. by telling clang what optimization passes to run (or to pass onto the backend to run), or by not having to run a unique opt command for each input file (of which there may be a few…)?

Thanks for any help,
Stephen

Now what I want to do is select my own optimization passes specifically. As
far as I can tell, the following seems to be the only way to do it:

From the command line without rebuilding? That's about it. That said

if you are willing to rebuild the compiler you can edit the list of
passes being run at various O levels and use that.

-eric