Advantages of LLVM Optimization

Hi,

I am planning to use LLVM in my compiler dev project. I would like to know what power LLVM code optimization phase provides to my code ?

I had a look at http://llvm.org/docs/Passes.html which describes the optimization passes.
From a newbie standpoint can you please explain the power of LLVM optimization?

Thank you,
Prakash

Adding to my previous question.
Can you also kindly tell me the list of languages which purely use LLVM as its backend instead of its own ?

I would like to know the languages which does not have its own backend optimizer and code generator and bets it on LLVM only.

Thanks for your help.

Thank you,
Prakash

Hi,

I had a look at http://llvm.org/docs/Passes.html which describes the optimization passes.
From a newbie standpoint can you please explain the power of LLVM optimization?

There are different levels of answers to your question. I will give it a try, but it’s certainly no substitute for reading the docs. LLVM is a complex system…

  • What effect do compiler optimizations have?

In general, they make your program faster. To get a feeling for that, I recommend you take your favorite C/C++ program, compile it with the ‘-O0’, ‘-O1’, ‘-O2’ and ‘-O3’ flags, and run each of the versions.

  • What do compiler optimizations do?

Many optimizations in LLVM are classical, and found in similar form in other compilers. Examples are:

  • Instcombine: knows about many arithmetic simplifications, e.g., n*1 => n

  • DCE: Dead code elimination removes values that are computed, but never needed

  • SimplifyCFG: Removes unreachable code, and converts things such as if (a) x; if (a) y; => if (a) { x; y; }

Other instrumentations are more specific to the way the LLVM intermediate representation works. For example, SROA tries to put values in registers instead of having them in memory, thereby reducing the number of memory accesses.

  • What does LLVM actually do to optimize programs?

I recommend you to have a look at the PassManagerBuilder. It select the optimization passes that LLVM actually uses, and determines their order. This will give you a good feeling for the inner workings of LLVM.

Can you also kindly tell me the list of languages which purely use LLVM as its backend instead of its own ?

Personally, I’ve used LLVM with C/C++. The rust compiler also translates to LLVM. There is a frontend for the Go language as well, are certainly others.

Hope this helps,
Jonas