[LLVMdev] opt, llcc, ll++, -O1, -O2, -O3

Chris Lattner sabre at nondot.org
Sat May 1 06:44:03 PDT 2004

On Sat, 1 May 2004, [koi8-r] "Valery A.Khamenya[koi8-r] "  wrote:

> there are two issues concerning invoking optimizations:
> 1.
> this document:
>   http://llvm.cs.uiuc.edu/docs/GettingStarted.html
> is very nice, it would be good though to add in a section
>   An Example Using the LLVM Tool Chain
> examples on optimization step.

That's an interesting idea.  LLVM currently enables the maximal
optimizations by default, you can only disable options.  For example, you
can use -Wl,-disable-inlining to disable the link-time inliner, or
-Wl,-disable-opt to disable all link-time optimizations.  Unfortunately we
don't have a centralized place that lists all of the optimizations that
can be disabled (this should be added to the command guide), but you can
see them by using 'gccas --help' or 'gccld --help'.  To disable a gccas
option, use -Wa,-disable-foo, for gccld, use -Wl,-disable-foo on the
llvmgcc command line.

Additionally, you can use opt to run individual optimizations, of which
there are a lot. :)

I added the following patch to the GSG.  If you have a better suggestion,
please let me know:

> 2.
> If i am not wrong there is no tool, which integrates all
> steps:
> llvmgcc->opt->llc into something like llcc
> (and llvmg++->opt->llc into something like ll++),
> where options -O1, -O2, -O3 are available. For example,
> `llcc -O3 ackerman.c' should make similar (but better!)
> things as `gcc -O3 ackerman.c' does.

You should be able to do this with the gccld -native or -native-cbe

For example:
$ llvmgcc ackerman.c -o ackerman -Wl,-native-cbe

... compiles to a native 'ackerman' executable, using the C backend. These
are link-time options, so you can compile any way you normally would, for
example by using 'llvmgcc -c x.c -o x.o', as long as the flag gets passed
in when the program is linked.

If you use the -native option, it uses LLC, though it doesn't turn on
Alkis's nice register allocator.  If you want to enable the linearscan
allocator with the -native option, you currently have to hack
llvm/tools/gccld/GenerateCode.cpp:GenerateAssembly to pass in the
'-regalloc=linearscan' option.  When this allocator is completely stable,
we will enable it by default.

> Anyway, it would be good to have a starting point for those who'd like
> to try "fully LLVM-optimized" C/C++ code. Indeed, the tool "opt" has
> quite big set of options...

Yup, it looks like opt has 75 optimizer passes available in it right now.
:)  If you start playing with them, make sure to avoid the "experimental
optimizations", which are not likely to work well:

LLVM really needs an optimizer guide that lists the various
optimizations, the high-level overview of what they do, the algorithms
used, useful-to-know-about interactions between passes (e.g. a pass that
leaves around a lot of unpropagates constants), and when they are likely
to be useful (most of this information is available in the comments at
the top of the file for the optimization).  This has been on my TODO list
for about 2.5 years now, but I have a *very* long TODO list.  :)

Here are some examples of the header comments:



More information about the llvm-dev mailing list