<div dir="ltr">In general we should try to allow users to control compilation settings at compile time, however I don't think that settings that affect the linked program as a whole should fall into this category. Some examples of this are linker flags for performing whole-program size optimizations (e.g. --icf, --gc-sections, -O). Another example is the LTO opt level, which essentially controls the amount of cross-module optimization done by LTO. The backend operates on a per-function basis, so the work that it does is unrelated to cross-module optimization and therefore should not be controlled by the LTO opt level but rather (ideally) function-level attributes. You can imagine future extensions to the backend that could cause it to operate on a cross-module basis, such as interprocedural register allocation, but I think those should again be controlled by the LTO opt level.<div><br></div><div>Peter</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 7, 2018 at 4:27 PM, Rafael Avila de Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">It sounds reasonable. It is also nice to have lld and gold agree on<br>
this, but could expand a bit on why it is a bad idea to set it on the<br>
linker?<br>
<br>
Cheers,<br>
Rafael<br>
<div class="HOEnZb"><div class="h5"><br>
Peter Collingbourne <<a href="mailto:peter@pcc.me.uk">peter@pcc.me.uk</a>> writes:<br>
<br>
> We use CodeGenOpt::Default (i.e. 2).<br>
><br>
> Peter<br>
><br>
> On Wed, Feb 7, 2018 at 3:44 PM, Rafael Avila de Espindola <<br>
> <a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br>
><br>
>> What level is used without a IR attribute or Conf.CGOptLevel being set?<br>
>><br>
>> Cheers,<br>
>> Rafael<br>
>><br>
>> Peter Collingbourne via Phabricator via llvm-commits<br>
>> <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> writes:<br>
>><br>
>> > pcc created this revision.<br>
>> > pcc added reviewers: tejohnson, eugenis.<br>
>> > Herald added subscribers: inglorion, mehdi_amini.<br>
>> ><br>
>> > The LTO opt level should not affect the codegen opt level, and indeed<br>
>> > it does not affect it in lld. Ideally the codegen opt level should<br>
>> > be controlled by an IR-level attribute based on the compile-time opt<br>
>> > level, but that hasn't been implemented yet.<br>
>> ><br>
>> ><br>
>> > <a href="https://reviews.llvm.org/D43040" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D43040</a><br>
>> ><br>
>> > Files:<br>
>> >   llvm/tools/gold/gold-plugin.<wbr>cpp<br>
>> ><br>
>> ><br>
>> > Index: llvm/tools/gold/gold-plugin.<wbr>cpp<br>
>> > ==============================<wbr>==============================<wbr>=======<br>
>> > --- llvm/tools/gold/gold-plugin.<wbr>cpp<br>
>> > +++ llvm/tools/gold/gold-plugin.<wbr>cpp<br>
>> > @@ -727,20 +727,6 @@<br>
>> >    return FD;<br>
>> >  }<br>
>> ><br>
>> > -static CodeGenOpt::Level getCGOptLevel() {<br>
>> > -  switch (options::OptLevel) {<br>
>> > -  case 0:<br>
>> > -    return CodeGenOpt::None;<br>
>> > -  case 1:<br>
>> > -    return CodeGenOpt::Less;<br>
>> > -  case 2:<br>
>> > -    return CodeGenOpt::Default;<br>
>> > -  case 3:<br>
>> > -    return CodeGenOpt::Aggressive;<br>
>> > -  }<br>
>> > -  llvm_unreachable("Invalid optimization level");<br>
>> > -}<br>
>> > -<br>
>> >  /// Parse the thinlto_prefix_replace option into the \p OldPrefix and<br>
>> >  /// \p NewPrefix strings, if it was specified.<br>
>> >  static void getThinLTOOldAndNewPrefix(std:<wbr>:string &OldPrefix,<br>
>> > @@ -767,7 +753,6 @@<br>
>> ><br>
>> >    Conf.MAttrs = MAttrs;<br>
>> >    Conf.RelocModel = RelocationModel;<br>
>> > -  Conf.CGOptLevel = getCGOptLevel();<br>
>> >    Conf.DisableVerify = options::DisableVerify;<br>
>> >    Conf.OptLevel = options::OptLevel;<br>
>> >    if (options::Parallelism)<br>
>> ><br>
>> ><br>
>> > Index: llvm/tools/gold/gold-plugin.<wbr>cpp<br>
>> > ==============================<wbr>==============================<wbr>=======<br>
>> > --- llvm/tools/gold/gold-plugin.<wbr>cpp<br>
>> > +++ llvm/tools/gold/gold-plugin.<wbr>cpp<br>
>> > @@ -727,20 +727,6 @@<br>
>> >    return FD;<br>
>> >  }<br>
>> ><br>
>> > -static CodeGenOpt::Level getCGOptLevel() {<br>
>> > -  switch (options::OptLevel) {<br>
>> > -  case 0:<br>
>> > -    return CodeGenOpt::None;<br>
>> > -  case 1:<br>
>> > -    return CodeGenOpt::Less;<br>
>> > -  case 2:<br>
>> > -    return CodeGenOpt::Default;<br>
>> > -  case 3:<br>
>> > -    return CodeGenOpt::Aggressive;<br>
>> > -  }<br>
>> > -  llvm_unreachable("Invalid optimization level");<br>
>> > -}<br>
>> > -<br>
>> >  /// Parse the thinlto_prefix_replace option into the \p OldPrefix and<br>
>> >  /// \p NewPrefix strings, if it was specified.<br>
>> >  static void getThinLTOOldAndNewPrefix(std:<wbr>:string &OldPrefix,<br>
>> > @@ -767,7 +753,6 @@<br>
>> ><br>
>> >    Conf.MAttrs = MAttrs;<br>
>> >    Conf.RelocModel = RelocationModel;<br>
>> > -  Conf.CGOptLevel = getCGOptLevel();<br>
>> >    Conf.DisableVerify = options::DisableVerify;<br>
>> >    Conf.OptLevel = options::OptLevel;<br>
>> >    if (options::Parallelism)<br>
>> > ______________________________<wbr>_________________<br>
>> > llvm-commits mailing list<br>
>> > <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
>> > <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
>><br>
><br>
><br>
><br>
> --<br>
> --<br>
> Peter<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">-- <div>Peter</div></div></div>
</div>