[LLVMdev] General strategy to optimize LLVM IR

Duncan Sands baldrick at free.fr
Wed Jul 17 04:13:45 PDT 2013


Hi St├ęphane,

On 16/07/13 17:16, St├ęphane Letz wrote:
> Hi,
>
> Our DSL emit sub-optimal LLVM IR that we optimize later on (LLVM IR ==> LLVM IR) before dynamically compiling it with the JIT. We would like to simply follow what clang/clang++ does when compiling with -O1/-O2/-O3 options. Our strategy up to now what to look at the opt.cpp code and take part of it in order to implement our optimization code.
>
> It appears to be rather difficult to follow evolution of the LLVM IR optimization strategies. With LLVM 3.3 our optimization code does not produce code as fast as the one produced with clang -03 anymore. Moreover the new vectorizations passes are still not working.
>
> It there a recommended way to add -O1/-O2/-O3 kind of optimizations on LLVM IR code? Any code to look at beside the opt.cpp tool?

the list of passes (and the flags that can be used to tweak it) is in
   lib/Transforms/IPO/PassManagerBuilder.cpp
You can use the PassManagerBuilder to create your own pass list.  However
this is not enough to get good optimization, some more things are needed:

   1) You must add DataLayout info to the module (using setDataLayout).  For
the vectorizer to do anything I think you are also obliged to add a target
triple (using setTargetTriple);
   2) In order to get vectorization you also have to add target specific
analysis passes using addAnalysisPasses (see TargetMachine).

Ciao, Duncan.



More information about the llvm-dev mailing list