<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Apr 10, 2018 at 11:52 PM, Mehdi AMINI <span dir="ltr"><<a href="mailto:joker.eph@gmail.com" target="_blank">joker.eph@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><br><div class="gmail_quote"><span class=""><div dir="ltr">Le mar. 10 avr. 2018 à 23:18, <<a href="mailto:katya.romanova@sony.com" target="_blank">katya.romanova@sony.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div lang="EN-US">
<div class="m_-2804418632046339604gmail-m_-2135444533988741634WordSection1">
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Hi Mehdi,<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Awesome! It’s a very clear design. The only question left is which pipeline to choose for unified compile-phase optimization pipeline.
<u></u><u></u></span></p>
<p class="m_-2804418632046339604gmail-m_-2135444533988741634MsoListParagraph"><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><span>-<span style="font-style:normal;font-variant-caps:normal;font-weight:normal;font-stretch:normal;font-size:7pt;line-height:normal;font-family:"Times New Roman"">
</span></span></span><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">ThinLTO compile-phase pipeline? It might very negatively affect compile-time and the memory footprint for FullLTO link-phase. That was the reason why
so many optimization were moved from the link-phase to the parallel compile-phase for FullLTO in the first place.</span></p></div></div></blockquote><div><br></div></span><div>Just to clarify: "optimizations" were not "moved from the link-phase to the parallel compile-phase for FullLTO", they have never been in the link phase for FullLTO. It has always been this way.</div><div><br></div><div>I think that the ThinLTO compile-phase pipeline will only affect FullLTO in the sense that we need to add more passes during the link phase, is this what you meant?</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div class="m_-2804418632046339604gmail-m_-2135444533988741634WordSection1"><p class="m_-2804418632046339604gmail-m_-2135444533988741634MsoListParagraph"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u><u></u></span></p>
<p class="m_-2804418632046339604gmail-m_-2135444533988741634MsoListParagraph"><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><span>-<span style="font-style:normal;font-variant-caps:normal;font-weight:normal;font-stretch:normal;font-size:7pt;line-height:normal;font-family:"Times New Roman"">
</span></span></span><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">FullLTO compile-phase pipeline? More optimization passes at compile-phase will obviously increase compile time for ThinLTO, though I suspect it will
be tolerable. It is not very clear how this choice will affect the overall runtime performance for ThinLTO. Assuming we keep well-tuned link-phase/backend optimization pipeline “as is” for ThinLTO and FullLTO, we will repeat some optimization passes for ThinLTO
at compile-phase and later at link-phase which potentially could improve the performance… or it could make it worse, because we might perform an optimization early at compile-time, potentially preventing more aggressive optimization at link-phase when we see
a larger scope. Any prediction on what would happen to the ThinLTO runtime performance at run-time?</span></p></div></div></blockquote><div><br></div></span><div>Note: repeating optimization is not supposed to improve performance, at least this isn't the goal of the pipeline. </div><div>The pipeline for ThinLTO has been modeled on O3, good or bad we felt there was no reason to really deviate and any improvement to one could (should!) reflect on the other.</div><div><br></div><div>The rational behind the ThinLTO pipeline is not only compile time: it split the O3 pipeline at the point where we stop the "function simplification" / inliner loop and before we get into unrolling/vectorization.</div></div></div></blockquote><div><br></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Right - see my reply on this from last night, at the very least the ThinLTO importing thresholds will need retuning if we will perform optimizations like unrolling/vectorization/etc that tend to increase code side. </span></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_quote"><div>I remember even trying to stop the compile-phase without inlining but the generated IR was too big: the inliner CGSCC visit actually reduces the size of the IR considerably in some cases.</div></div></div></blockquote><div><br></div><div>To add on, this affects not only the importing thresholds, but also the cost of doing the thin link (which will have a graph with many more nodes/edges).</div><div><br></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_quote"><span class=""><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div class="m_-2804418632046339604gmail-m_-2135444533988741634WordSection1"><p class="m_-2804418632046339604gmail-m_-2135444533988741634MsoListParagraph"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u><u></u></span></p>
<p class="m_-2804418632046339604gmail-m_-2135444533988741634MsoListParagraph"><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><span>-<span style="font-style:normal;font-variant-caps:normal;font-weight:normal;font-stretch:normal;font-size:7pt;line-height:normal;font-family:"Times New Roman"">
</span></span></span><u></u><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">New “unified” compile-phase pipeline?<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">I guess, there is not a definitive answer and we have to experiment, measure compile-time/run-time performance and potentially make some adjustments to the pipeline
and to the thresholds. We have a few proprietary tests in Sony that we could use for the performance measurements, but it will be nicer if there are some open source benchmarks that we could use. What did you use in Google/Apple for ThinLTO/FullLTO measurements?
Have you used some proprietary benchmarks also? It’s important to make sure we won’t have run-time/compile-time performance degradation, but it will be nicer if anyone can run previously used ThinLTO/FullLTO benchmarks oneself, while making changes to the
optimization pipeline and heuristics.</span></p></div></div></blockquote><div><br></div></span><div>We benchmarked multiple variants of the pipeline two years ago. There were some regressions when adoption the ThinLTO pipeline in FullLTO (and some improvements), but when investigated we didn't find any real regressions that couldn't be solved by fixing the optimizer. </div><div>I.e. these are cases where FullLTO gets it right "by luck" and not by principle, and fixing such cases helps the non-LTO O3 (for example this test case <a href="https://bugs.llvm.org/show_bug.cgi?id=27395" target="_blank">https://bugs.llvm.org/<wbr>show_bug.cgi?id=27395</a> )</div></div></div></blockquote><div><br></div><div>We have a number of internal benchmarks/applications used to evaluate ThinLTO changes. We don't use Full LTO (with very limited exceptions). </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_quote"><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div class="m_-2804418632046339604gmail-m_-2135444533988741634WordSection1"><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal">>> # No flag: use the compile-phase preference, perform ThinLTO on a.o and FullLTO on b.o/c.o, but allow ThinLTO import between the LTO group and the ThinLTO >> objects<u></u><u></u></p>
<p class="MsoNormal">>> $ clang a.o b.o c.o<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">If I understood you correctly, while doing ThinLTO on a.o, we could import from b.o and c.o (this is possible since the summaries are available), while we won’t
see a.o when doing FullLTO for b.o/c.o. (i.e., the previous non-permeable barrier between ThinLTO and FullLTO groups will become permeable in one direction).</span></p></div></div></blockquote><div><br></div></span><div>It could be permeable in both direction: b.o+c.o become "like a single ThinLTO object" after they get merged.</div></div></div></blockquote><div><br></div><div>Yes in fact right now (at least in the new LTO API, but certainly similar in the old one) the Full LTO partition gets fully merged/optimized/codegened before running any ThinLTO. If we wanted a mixed-mode LTO compilation, it would be better to do some of the Full LTO in parallel with the ThinLTO. The Thin Link will need to be split out and done before any Full LTO optimization/codegen. E.g., if we are importing from FullLTO into ThinLTO, then some symbols will need to be promoted in the Full LTO IR. And to import from ThinLTO into FullLTO, we will also need to have the Thin Link results. Either the ThinLink + ThinLTO optimizations like importing/promotion would need to be done before any Full LTO IR merging + backend, or as Mehdi suggests, do the Full LTO IR merging, then treat as a new ThinLTO IR object during the ThinLink and beyond. For distributed builds, we would need to serialize out the Full LTO IR. I'm not sure if it will be worth it from an optimization standpoint in that case.</div><div><br></div><div>Before we start modifying this significantly, BTW, it would be good to revisit the idea of migrating the old LTO library to the new LTO API. Is anyone thinking of investing in that? I know Mehdi started this a long time back, but I'm sure doesn't have the bandwidth.</div><div><br></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_quote"><span class=""><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div class="m_-2804418632046339604gmail-m_-2135444533988741634WordSection1"><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> However, do you think by doing this, we will achieve a better performance than doing ThinLTO backend
for all of the files (a.o, b.o, c.o)?</span></p></div></div></blockquote><div><br></div></span><div>Performance is always very much use-case dependent.</div><div>One may know that a group of files performs better when they get merged together with FullLTO while the rest of the app does not?</div></div></div></blockquote><div><br></div><div>That's what I am wondering. There are still some places where Full LTO outperforms ThinLTO due to optimizations not ported to ThinLTO (e.g. some global variable optimizations). But you'd need to figure out how to detect these opportunities ahead of time.</div><div><br></div><div>Katya - did you have a particular use case in mind?</div><div><br></div><div>Thanks,</div><div>Teresa</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_quote"><div><br></div><div>I don't know but this all needs to be carefully looked at from a user-interface point of view I think (will it be intuitive for the users? Will it fit in every (most) scenarios? etc.).</div><div><br></div><div>Cheers,</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-- </div><div>Mehdi</div></font></span><div><div class="h5"><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div lang="EN-US"><div class="m_-2804418632046339604gmail-m_-2135444533988741634WordSection1"><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> <u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Thank you!<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Katya.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> <wbr> <wbr> <wbr> <wbr> <wbr>
<u></u><u></u></span></p>
<p class="MsoNormal"><b><span style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif"> Mehdi AMINI <<a href="mailto:joker.eph@gmail.com" target="_blank">joker.eph@gmail.com</a>>
<br>
<b>Sent:</b> Tuesday, April 10, 2018 5:25 PM<br>
<b>To:</b> Romanova, Katya <<a href="mailto:katya.romanova@sony.com" target="_blank">katya.romanova@sony.com</a>><br>
<b>Cc:</b> David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>>; Teresa Johnson <<a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a>>; llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
<b>Subject:</b> Re: [llvm-dev] exploring possibilities for unifying ThinLTO and FullLTO frontend + initial optimization pipeline<u></u><u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">Hi,<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">It is non trivial to recompute summaries (which is why we have summaries in the bitcode in the first place by the way), because bitcode is expensive to load.<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">I think shipping two different variant of the bitcode, one with and one without summaries isn't providing much benefit while complicating the flow. We could achieve what you're looking for by revisiting the flow a little.<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I would try to consider if we can:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">1) always generate summaries.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">2) Use the same compile-phase optimization pipeline for ThinLTO and LTO.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">3) Decide at link time if you want to do FullLTO or ThinLTO.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">We haven't got this route 2 years ago because during the bringup we didn't want to affect FullLTO in any way, but it may make sense now to have `clang -flto=thin` and `clang -flto=full` be identical and change the linker plugins to operate
either in full-LTO mode or in ThinLTO mode but not differentiate based on the availability of the summaries.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">A possible behavior could be:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># The -flto flag in the compile phase does not change the produced bitcode but for a flag that record the preference in the bitcode (FullLTO vs ThinLTO)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">$ clang -c -flto=thin a.cpp<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">$ clang -c -flto=full b.cpp<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">$ clang -c -flto=full c.cpp<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># At link time the behavior depends on the -flto flag passed in.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># No flag: use the compile-phase preference, perform ThinLTO on a.o and FullLTO on b.o/c.o, but allow ThinLTO import between the LTO group and the ThinLTO objects<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">$ clang a.o b.o c.o<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># Forces full LTO, merges all the objects, no cross module importing will happen.<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">clang a.o b.o c.o -flto=full<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"># Forces ThinLTO for all objects, FullLTO won't happen, no objects will be merged.<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">clang a.o b.o c.o -flto=thin<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Cheers,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">-- <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">Mehdi<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<p class="MsoNormal">Le mar. 10 avr. 2018 à 15:51, via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> a écrit :<u></u><u></u></p>
</div>
<blockquote style="border-style:none none none solid;border-left-width:1pt;border-left-color:rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal">Hi David,<u></u><u></u></p>
<p class="MsoNormal">Thank you so much for your reply!<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">>> You're dealing with a situation where you are shipped BC files offline and then do one, or multiple builds with these BC files?<br>
<span style="font-family:Arial,sans-serif;color:black">Yes, that’s exactly the case.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:Arial,sans-serif;color:rgb(31,73,125)"> </span><u></u><u></u></p>
<p class="MsoNormal">>> If the scenario was more like a naive build: Multiple BC files generated on a single (multi-core/threaded) machine (but some Thin, some
<u></u><u></u></p>
<p class="MsoNormal">>> Full) & then fed to the linker, I would wonder if it'd be relatively cheap for the LTO step to support this by computing summaries for
<u></u><u></u></p>
<p class="MsoNormal">>> FullLTO files on the fly (without a separate tool/writing the summary to disk, etc).<u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:Arial,sans-serif;color:rgb(31,73,125)"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:Arial,sans-serif;color:black">I think so. My understanding that for FullLTO files, it’s possible to perform name anonymous globals pass and compute summaries
on the fly, which should allow to perform ThinLTO at link phase. </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:Arial,sans-serif;color:black"> </span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:Arial,sans-serif;color:black">Katya.</span><u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:Arial,sans-serif;color:rgb(31,73,125)"> </span><u></u><u></u></p>
<p class="MsoNormal"><b><span style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif"> David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>>
<br>
<b>Sent:</b> Tuesday, April 10, 2018 7:38 AM<br>
<b>To:</b> Romanova, Katya <<a href="mailto:katya.romanova@sony.com" target="_blank">katya.romanova@sony.com</a>>; Teresa Johnson <<a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a>><br>
<b>Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> Re: [llvm-dev] exploring possibilities for unifying ThinLTO and FullLTO frontend + initial optimization pipeline</span><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-bottom:12pt">Hi Katya,<br>
<br>
[+Teresa since this is about ThinLTO & she's the owner there]<br>
<br>
I'm not sure how other folks feel, but terminologically I'm not sure I think of these as different formats (for example you mention the idea of stripping the summaries from ThinLTO BC files to then feed them in as FullLTO files - I would imagine it'd be reasonable
to modify/fix/improve the linker integration to have it (perhaps optionally) /ignore/ the summaries, or use the summaries but in a non-siloed way (so that there's not that optimization boundary between ThinLTO and FullLTO))<br>
<br>
You're dealing with a situation where you are shipped BC files offline and then do one, or multiple builds with these BC files?<br>
<br>
If the scenario was more like a naive build: Multiple BC files generated on a single (multi-core/threaded) machine (but some Thin, some Full) & then fed to the linker, I would wonder if it'd be relatively cheap for the LTO step to support this by computing
summaries for FullLTO files on the fly (without a separate tool/writing the summary to disk, etc). Though I suppose that'd produce a pretty wildly different behavior in the link when just a single ThinLTO BC file was added to an otherwise FullLTO build.<br>
<br>
Anyway - just some (admittedly fairly uninformed) thoughts. I'm sure Teresa has more informed ideas about how this might all look.<u></u><u></u></p>
<div>
<div>
<p class="MsoNormal">On Mon, Apr 9, 2018 at 12:20 PM via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p>
</div>
<blockquote style="border-style:none none none solid;border-left-width:1pt;border-left-color:rgb(204,204,204);padding:0in 0in 0in 6pt;margin:5pt 0in 5pt 4.8pt">
<div>
<div>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">Hello,</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">I am exploring the possibility of unifying the BC file generation phase for ThinLTO and FullLTO. Our third party library providers prefer to give us only one version of the BC archives, rather than test and ship both Thin and Full
LTO BC archives. We want to find a way to allow our users to pick either Thin or Full LTO, while having only one “unified” version of the BC archive.</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">Note, I am not necessarily proposing to do this work in the upstream compiler. If there is no interest from other companies, we might have to keep this as a private patch for Sony.</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">One of the ideas (not my preference) is to mix and match files in the Thin and Full BC formats. I'm not sure how well the "mix and match" scenario works in general. I was wondering if Apple or Google are doing this for production?</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">I wrote a toy example, compiled one group of files with ThinLTO and the rest with FullLTO, linked them with gold. I saw that irrespective of whether the Thin or Full LTO option was used at the link step, files are optimized within
the Thin group and within the Full group separately, but they don't know about the files in the other group (which makes sense). Basically, the border between Thin and Full LTO bitcode files created an artificial "barrier" which prevented cross-border optimization.</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">Obviously, I am not too fond of this idea. Even if mixing and matching ThinLTO and FullLTO bitcode files will work “as is”, I suspect we will see a non-trivial runtime performance degradation because of the "ThinLTO"/"FullLTO" border.
Are you aware of any potential problems with this solution, other than performance?</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black"> </span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">Another, hopefully, better idea is to introduce a "unified" BC format, which could either be FullLTO, ThinLTO, or neither (e.g., something in between).</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">If the user chooses FullLTO at the link step, but some of the files are in the Thin BC format – the linker will call a special LTO API to convert these files to the Full LTO BC format (i.e., stripping the module summary section + potentially
do some additional optimizations from the FullLTO pass manager pipeline).</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">If the user chooses ThinLTO at the link step, but some of the files are in the Full BC format – the linker will call an LTO API to convert these files to the Thin LTO bitcode format (by regenerating the module summary section dynamically
for the Full LTO bitcode files). </span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">I think the most reasonable idea for the unification of the Thin and Full LTO compilation pipelines is to use Full LTO as the “unified” BC format. If the user requests FullLTO – no additional work is needed, the linker will perform
FullLTO as usual. If the user request ThinLTO, the linker will call an API to regenerate the module summary section for all the files in the FullLTO format and perform ThinLTO as usual.
</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">In reality I suspect things will be much more complicated. The pipelines for the Thin and Full LTO compilation phases are quite different. ThinLTO can afford to do much more optimization in the linking phase (since it has parallel
backends & smaller IR compared to FullLTO), while for FullLTO we are forced to move some optimizations from linking to the compilation phase.</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">So, if we pick FullLTO as our unified format, we would increase the build time for ThinLTO (we will be doing the FullLTO initial optimization pipeline in the compile phase, which is more than what ThinLTO is currently doing, but the
pipeline of the optimizations in the backend will stay the same). It’s not clear what will happen with the runtime performance: we might improve it (because we repeat some of the optimizations several times), or we might make it worse (because we might do
an optimization in the early compilation phase, potentially preventing more aggressive optimization later). What are your expectations? Will this approach work in general? If so, what do you think will happen with the runtime performance?</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">I also noticed that the pass manager pipeline is different for ThinLTO+Sample PGO (use profile case). This might create some additional complications for unification of Thin and FullLTO BC generation phase too, but it’s too small detail
to worry about right now. I’m more interested in choosing a right general direction for solving this problem now.</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">Please share your thoughts!</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">Thank you!</span><u></u><u></u></p>
<p class="MsoNormal" style="margin-bottom:8pt;line-height:105%">
<span style="color:black">Katya.</span><u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal"><span style="font-family:Arial,sans-serif"> </span><u></u><u></u></p>
</div>
</div>
<p class="MsoNormal">______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
</div>
<p class="MsoNormal">______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><u></u><u></u></p>
</blockquote>
</div>
</div>
</div>
</blockquote></div></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><span style="font-family:Times;font-size:medium"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td nowrap style="border-top-style:solid;border-top-color:rgb(213,15,37);border-top-width:2px">Teresa Johnson |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(51,105,232);border-top-width:2px"> Software Engineer |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(0,153,57);border-top-width:2px"> <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(238,178,17);border-top-width:2px"> 408-460-2413</td></tr></tbody></table></span></div>
</div></div>