3

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.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
Paschalis
  • 11,929
  • 9
  • 52
  • 82
  • The only option that I found that it is not being ignore is `-fstrict-aliasing`, which is not listed in the 2 links I attached in the Q. – Paschalis Jun 06 '14 at 18:27

2 Answers2

6

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.

Anton Korobeynikov
  • 9,074
  • 25
  • 28
  • A have a couple of questions: Where I can find the clang optimisation flags? What should I use? clang's flags or LLVM's passes? Are the clang's flags implemented by using the LLVM's passes? – Paschalis Jun 08 '14 at 15:05
  • Just to note: you can in fact use something like `clang -cc1 -backend-option -instcombine` to set LLVM passes from clang, though using `opt` may well be a better option. – Max Jan 04 '16 at 00:05
2

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:

  1. The list of the LLVM-opt could be found Here!

  2. 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.

  1. OPTing a whole project

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.

Amir
  • 1,348
  • 3
  • 21
  • 44