I created my own LLVM optimization pass in LLVM 3.7.0 . I want to use this pass within a cmake project. I need to run the pass as last, after all optimization passes of -O2 (or -O3) are executed by clang (or clang++).
Unfortunately, I did not find a mechanism to invoke the pass by passing the flag directly from the clang (if you point me out a way to do that, this would already be helpful).
Assuming there is no way to run the pass by giving a flag to clang, I need an extra optimization pass in my toolchain to be placed between the compilation and the linking phase. I need it throughout the whole cmake project.
The commands I would need to generate a binary from a two source files are:
clang -c -g -emit-llvm -O3 mySource0.c -o mySource0.bc
clang -c -g -emit-llvm -O3 mySource1.c -o mySource.bc
llvm-link mySource0.bc mySource1.bc -o main.bc
opt -load myAnalysis.so -myAnalysis main.bc -o main.analysis.bc
clang <libraryRelatedFlags> main.analysis.bc -o myExecutable
My pass is registered as:
static RegisterPass<myAnalysis> X("myAnalysis", "Implement my analysis", false, false);
as in: http://llvm.org/docs/WritingAnLLVMPass.html#basic-code-required