<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 16, 2017 at 3:32 PM, Sean Silva <span dir="ltr"><<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Mon, Jan 16, 2017 at 2:31 PM, Davide Italiano <span dir="ltr"><<a href="mailto:davide@freebsd.org" target="_blank">davide@freebsd.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On Mon, Jan 16, 2017 at 2:07 PM, Mehdi Amini <<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>> wrote:<br>
><br>
> On Jan 16, 2017, at 1:47 PM, Sean Silva <<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Mon, Jan 16, 2017 at 1:25 PM, Davide Italiano <<a href="mailto:davide@freebsd.org" target="_blank">davide@freebsd.org</a>> wrote:<br>
>><br>
>> On Mon, Jan 16, 2017 at 12:31 PM, Sean Silva via llvm-dev<br>
>> <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
>> > Do we have any open projects on LLD?<br>
>> ><br>
>> > I know we usually try to avoid any big "projects" and mainly add/fix<br>
>> > things<br>
>> > in response to user needs, but just wondering if somebody has any ideas.<br>
>> ><br>
>><br>
>> I'm not particularly active in lld anymore, but the last big item I'd<br>
>> like to see implemented is Pettis-Hansen layout.<br>
>> <a href="http://perso.ensta-paristech.fr/~bmonsuez/Cours/B6-4/Articles/papers15.pdf" rel="noreferrer" target="_blank">http://perso.ensta-paristech.f<wbr>r/~bmonsuez/Cours/B6-4/Article<wbr>s/papers15.pdf</a><br>
>> (mainly because it improves performances of the final executable).<br>
>> GCC/gold have an implementation of the algorithm that can be used as<br>
>> base. I'll expand if anybody is interested.<br>
>> Side note: I'd like to propose a couple of llvm projects as well, I'll<br>
>> sit down later today and write them.<br>
><br>
><br>
><br>
> I’m not sure, can you confirm that such layout optimization on ELF requires<br>
> -ffunction-sections?<br>
><br>
<br>
</span>For the non-LTO case, I think so.<br>
<span><br>
> Also, for clang on OSX the best layout we could get is to order functions in<br>
> the order in which they get executed at runtime.<br>
><br>
<br>
</span>That's what we already do for lld. We collect and order file (run a<br>
profiler) and pass that to the linker that lays out functions<br>
accordingly.<br>
This is to improve startup time for a class of startup-time-sensitive<br>
operations. The algorithm proposed by Pettis (allegedly) aims to<br>
reduce the TLB misses as it tries to lay out hot functions (or<br>
functions that are likely to  be called together near in the final<br>
binary).<br></blockquote><div><br></div></div></div><div>IIRC from when I looked at the paper a while ago, it is mostly just a "huffman tree construction" type algorithm (agglomerating based on highest probability) and assumes that if two functions are hot then they are likely to be needed together. This is not always the case.</div><div><br></div><div>E.g. consider a server that accepts RPC requests and based on those requests either does Foo or Bar which are largely disjoint. It's entirely possible for the top two functions of the profile to be one in Foo and one in Bar, but laying them out near each other doesn't make sense since there is never locality (for a given RPC, either Foo or Bar gets run). A static call graph analysis can provide the needed signals to handle this case better. </div><span class="HOEnZb"><font color="#888888"><div><br></div></font></span></div></div></div></blockquote><div><br></div><div>Hence you said "allegedly" :) I know we've talked about this before. Just wanted to put the backstory of the "allegedly" on the list.</div><div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="HOEnZb"><font color="#888888"><div></div><div>-- Sean Silva</div></font></span><div><div class="h5"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span><br>
><br>
> For FullLTO it is conceptually pretty easy to get profile data we need for<br>
> this, but I'm not sure about the ThinLTO case.<br>
><br>
> Teresa, Mehdi,<br>
><br>
> Are there any plans (or things already working!) for getting profile data<br>
> from ThinLTO in a format that the linker can use for code layout? I assume<br>
> that profile data is being used already to guide importing, so it may just<br>
> be a matter of siphoning that off.<br>
><br>
><br>
> I’m not sure what kind of “profile information” is needed, and what makes it<br>
> easier for MonolithicLTO compared to ThinLTO?<br>
><br>
> Or maybe that layout code should be inside LLVM; maybe part of the general<br>
> LTO interface? It looks like the current gcc plugin calls back into gcc for<br>
> the actual layout algorithm itself (function call<br>
> find_pettis_hansen_function_la<wbr>yout) rather than the reordering logic living<br>
> in the linker:<br>
> <a href="https://android.googlesource.com/toolchain/gcc/+/3f73d6ef90458b45bbbb33ef4c2b174d4662a22d/gcc-4.6/function_reordering_plugin/function_reordering_plugin.c" rel="noreferrer" target="_blank">https://android.googlesource.c<wbr>om/toolchain/gcc/+/3f73d6ef904<wbr>58b45bbbb33ef4c2b174d4662a22d/<wbr>gcc-4.6/function_reordering_<wbr>plugin/function_reordering_<wbr>plugin.c</a><br>
><br>
><br>
> I was thinking about this: could this be done by reorganizing the module<br>
> itself for LTO?<br>
><br>
> That wouldn’t help non-LTO and ThinLTO though.<br>
<br>
</span>This is a dimension that I think can be explored. The fact that it<br>
wouldn't help with other modes of operation is completely orthogonal,<br>
in particular until it's proven that this kind of optimization makes<br>
sense with ThinLTO (and if it doesn't, it can be an optimization ran<br>
only during full LTO).<br>
<div class="m_1399328833334621314HOEnZb"><div class="m_1399328833334621314h5"><br>
--<br>
Davide<br>
<br>
"There are no solved problems; there are only problems that are more<br>
or less solved" -- Henri Poincare<br>
</div></div></blockquote></div></div></div><br></div></div>
</blockquote></div><br></div></div>