How can pass be used to optimize a project?

Hi, I have written a pass and get a file. My pass optimization relies on some of my own target files.
This is how I use them when there is only one source file.

For example:

The dependent object file: units.o and helper.o

Target file: simple.c

I’m using the following command.

/usr/local/bin/clang -emit-llvm -c -o obj/simple.bc simple.c
/usr/local/bin/llvm-link obj/simple.bc ./units.o ./helper.o > obj/simple-link.bc
/usr/local/bin/opt -load …/ -O3 < obj/simple-link.bc > obj/simple-opt.bc
/usr/local/bin/clang -o obj/simple obj/simple-opt.bc -g -O3

Now, I need to optimize a large project with my pass and object file( units.o and helper.o),such as “md5sum” project.It needs to be compiled and installed using the following command:



make install

I need use LLVM to compile and optimize it. How can I apply my pass to the entire program?
What should I do? Please tell me an easy way.

Please help me!
Thank you!


one solution is to create wrappers and use them as CC and CXX (as in
./configure CC=path/to/wrapper CXX=/path/to/wrapper) in the project
you are building.

For example, you can create a Python script which receives the
command-line arguments passed originally to the C compiler and decides
what to do based on them:

1. if a "-c" is present, it's a compilation job, therefore add
"-emit-llvm" to the argument list.
2. else, this is a link job, therefore call llvm-link, then opt, then
generate the binary.

There are a few more cases to cover depending on the project. For
instance, if static libraries are built, you may need to create a
wrapper for 'ar' as well.