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

John Criswell criswell at cs.uiuc.edu
Sat May 1 10:34:01 PDT 2004


Chris Lattner wrote:
> 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:
> http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040426/014073.html
> 
> 
>>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
> options:

Just to clarify, because I think it can be easily overlooked:

The gccas and gccld programs are not just assemblers/linkers; they are 
also optimizers too.  gccas runs optimizations after assembling the 
file, and gccld runs  interprocedural optimizations at link time.  This 
is why you don't need to use the opt program when using llvm-gcc and 
llvm-g++; gccld and gccas run the optimizations for you.

Contrast this to llvm-as and llvm-link: they do not do any optimization 
(that I am aware of).  They only assemble and link LLVM code.

-- John T.


> 
> 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:
> http://llvm.cs.uiuc.edu/docs/ReleaseNotes.html#experimental
> 
> 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:
> http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp?rev=1.5&content-type=text/x-cvsweb-markup
> http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp?rev=1.16&content-type=text/x-cvsweb-markup
> http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/Scalar/LICM.cpp?rev=1.59&content-type=text/x-cvsweb-markup
> http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/Scalar/Reassociate.cpp?rev=1.30&content-type=text/x-cvsweb-markup
> http://llvm.cs.uiuc.edu/cvsweb/cvsweb.cgi/llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp?rev=1.13&content-type=text/x-cvsweb-markup
> 
> -Chris
> 


-- 
*********************************************************************
* John T. Criswell                         Email: criswell at uiuc.edu *
* Research Programmer                                               *
* University of Illinois at Urbana-Champaign                        *
*                                                                   *
* "It's today!" said Piglet. "My favorite day," said Pooh.          *
*********************************************************************





More information about the llvm-dev mailing list