I am trying to compile a program, using clang3.4, and the optimisation passes (or flags?!) I used, are ignored.
For example I am trying to compile and I pass the following options"
-O1 -instcombine
I get:
clang34: warning: argument unused during compilation: '-instcombine'
The list of all available optimisation passes of LLVM can be found here, and in this question. Am I missing something?
Thank you.
These are LLVM optimization passes, not clang's. You cannot invoke LLVM optimization passes directly. However, you can emit LLVM IR vie -emit-llvm option and use opt tool to invoke any LLVM optimization passes.
as @Anton has mentioned above, these Compiler passes are meant to be used with llvm-opt not the clang, clang only supports the standard optimization level -O[X]. However if you would like to use your compiler flags. i.e. "-instcombine", first you have to add the option -emit-llvm while using the clang.
Some comments and examples:
The list of the LLVM-opt could be found Here!
Here is a short example of using the LLVM-opt:
clang -S -emit-llvm foo.c -lm
opt ${<MY_DESIRED_COMPILER_FLAGS>} -S -o foo_OPTIMIZED.ll foo.ll
clang foo_OPTIMIZED.ll -lm
Now, if you take a diff of the both versions of LLVM-IR or .ll files, you can see the differences.
For that matter, you should put these commands in loop and apply the opt on each of every files you need
OR
Write a makefile that does this for you.
OR
Create your own pass consisting of your desired passes and include them as a .so file. More Info Here!
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With