<div dir="ltr">How much much of the LTO time is actually spent in the optimization passes?<div><br></div><div>-- Sean Silva</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 18, 2015 at 4:27 PM, Peter Collingbourne <span dir="ltr"><<a href="mailto:peter@pcc.me.uk" target="_blank">peter@pcc.me.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi all,<br>
<br>
I wanted to start a thread to discuss ways to control the optimization<br>
level when using LTO. We have found that there are use cases for the LTO<br>
mechanism beyond whole-program optimization, in which full optimization<br>
is not always needed or desired. We started that discussion over in<br>
<a href="http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150316/266560.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150316/266560.html</a><br>
and I thought I'd summarize the problem and possible solutions here:<br>
<br>
Problem<br>
-------<br>
<br>
As currently implemented, the control flow integrity checks in Clang rely on<br>
a so-called bit set lowering pass to implement its checks efficiently. The<br>
current implementation of the bit set lowering pass requires whole-program<br>
visibility. The full details of why are described in the design document at:<br>
<a href="http://clang.llvm.org/docs/ControlFlowIntegrityDesign.html" target="_blank">http://clang.llvm.org/docs/ControlFlowIntegrityDesign.html</a><br>
<br>
We currently achieve whole-program visibility using LTO. The trouble with LTO<br>
is that it comes with a significant compile time cost -- on large programs<br>
such as Chrome, compiling with link-time optimization can be over 7x slower<br>
(over 3 hours has been measured) than compiling without.<br>
<br>
So I would like there to be a way for users to choose whether to apply<br>
optimizations, and how much optimization to apply.<br>
<br>
Achieving this requires a design for how users should specify the level of<br>
optimization to apply, as well as a design for changes to the clang driver<br>
and the various LTO plugins so that the plugin knows whether optimizations<br>
are required.<br>
<br>
Solutions<br>
---------<br>
<br>
1) Controlled at compile time<br>
<br>
Strawman proposal for command line syntax:<br>
<br>
-flto-level=X means optimize at level X. At link time, the LTO plugin will<br>
take the maximum of all -flto-level flags and optimize at that level.<br>
<br>
-flto-level is inferred from other flags if not specified:<br>
<br>
-flto implies -flto-level=2.<br>
If -flto not specified, -O >= 1 implies -flto-level=1.<br>
Otherwise, default to -flto-level=0.<br>
<br>
This is probably easier to implement in a supported way. We can pass the<br>
LTO level to the linker via module flags as shown in the patches attached to<br>
<a href="http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150316/266778.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150316/266778.html</a><br>
<br>
2) Controlled at link time<br>
<br>
-flto-level has the same semantics as in the previous sub-section, except it is<br>
instead passed at link time.<br>
<br>
This is to a certain extent possible to implement with libLTO by passing<br>
-mllvm flags to the linker, or with gold by passing -plugin-opt flags.<br>
<br>
According to Duncan, passing flags to libLTO this way is unsupported --<br>
if we did want to accept flags at link time, and we absolutely don't want<br>
to pass flags to the linker that way, I suppose we could do something like<br>
have the clang driver synthesize a module containing the module flags we want.<br>
<br>
Optimization Levels<br>
-------------------<br>
<br>
We need to decide what the various optimization levels mean. The thing that<br>
works best for the CFI use case is for -flto-level=2 to mean what -flto<br>
currently means, for -flto-level=1 to mean "run only the globaldce and<br>
simplifycfg passes", and for -flto-level=0 to mean "run no passes", but this<br>
may not be the correct thing to do in every situation where we only want a<br>
few passes to run at link time. We may want to make -flto-level a cc1-level<br>
flag until we've had more experience and found more use cases.<br>
<br>
Thanks,<br>
<span class="HOEnZb"><font color="#888888">--<br>
Peter<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</font></span></blockquote></div><br></div>