[LLVMdev] Build Attributes Proposal

Török Edwin edwintorok at gmail.com
Thu Nov 18 07:55:41 PST 2010


On Thu, 18 Nov 2010 07:55:00 +0100
Duncan Sands <baldrick at free.fr> wrote:

> Hi Sandeep,
> 
> > Another use for build attributes would be as a means to record the
> > build flags selected for each translation unit so that LTO could
> > know how to optimize/tune the result. This use seems more important
> > to solve than the ARM attributes under discussion here.
> 
> why not have your build system just pass the appropriate flags
> directly to the linker?  Also, suppose some files were compiled at
> -O1, others at -O3.  If you do LTO then these files will all be
> linked together and optimized, but at what -O level?  I think it
> would be wrong to have the linker make policy decisions like
> "optimize at the highest -O level seen" or "optimize at the lowest -O
> level seen".  Better to have the user explicitly say what they want.
> But in that case is there any need to record the -O level in some
> special way in the module in the first place?

For GCC's LTO I think the optimization is the one you specify at link
time, the optimization specified at compile time is used only for
preprocessing and native code output. Since LLVM only outputs bitcode
when doing LTO, then I think that leaves us with the optimizatin level
specifeid at link time.

However that breaks the traditional CFLAGS="-O2", CFLAGS="-O3". You
usually don't need those on the link line, so you may end up with no
optimizations at all. Which is bad, and defeats the purpose of doing
LTO in the first place.
Of course easiest is to just use $CFLAGS on linker line too, but you
never know how someone's build system looks like

The linker could:
 - always override optimization levels by those specified on the linker
   line, if any
 - otherwise fall back to -std-link-opts (you're doing LTO, right?
   means you probably want fast code or you wouldn't be doing LTO in
   the first place), and warn
 - warn if the source files have different optimization levels, or
   different than the one specified at link time.

This avoids an easy pitfall (no opt level specified on linker line =
-O0 = LTO gave me worse performance), and works seamlessly if opt level
is specified. It is also compatible with how GCC behaves.

Best regards,
--Edwin



More information about the llvm-dev mailing list