[LLVMdev] Registering a custom opt pass as a default one

Alexander Potapenko
Mon, 18 Apr 2011 13:46:51 -0000

Hi all,

we're working on compile-time instrumentation for ThreadSanitizer (a
data race detector, see http://code.google.com/p/data-race-test and
http://code.google.com/p/data-race-test/wiki/CompileTimeInstrumentation),
which is implemented as an opt plugin that is ran for each client
C/C++ module we compile.

To build a binary consisting of several modules the following steps
are performed:

1. each filename.cc module is translated into LLVM internal
representation (filename.ll file) using llvm-gcc
2. the instrumentation pass is ran on each filename.ll file using opt
to produce filename-instr.ll
3. filename-instr.ll is translated into assembly file filename.S
4. filename.S is compiled into filename.o using llvm-gcc
5. all .o files are linked together with the runtime library (actually
ThreadSanitizer) into the
resulting binary

In order to compile a large program using GNU make, we had to write
wrappers for gcc and g++ that parse the command-line args and perform
either steps 1-4 or step 5, and put those wrappers into $PATH.
On the other hand, if our opt pass was a default one, we could just do:
  $ llvm-gcc filename.cc <-opt_pass_name> <additional opt args> -o
filename.o
instead of steps 1-4.

The question is: does llvm-gcc (or Clang, or whatever) allow to
register a custom optimization pass as a default one (by means of env
vars, configuration files or anything besides rebuilding the
compiler)?

Thanks in advance,
Alexander Potapenko