[LLVMdev] Advantages of LLVM Optimization

Jonas Wagner
Fri, 08 Aug 2014 10:12:41 -0000

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
<http://llvm.org/docs/doxygen/html/PassManagerBuilder_8cpp_source.html#l00140>.
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
<http://tomlee.co/2014/04/03/a-more-detailed-tour-of-the-rust-compiler/>.
There is a frontend for the Go language <https://github.com/go-llvm/llgo>
as well, are certainly others.

Hope this helps,
Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20140808/a85aff9c/attachment.html>