<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 26, 2016 at 10:53 AM, Mehdi Amini <span dir="ltr"><<a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Feb 26, 2016, at 10:38 AM, Teresa Johnson <<a href="mailto:tejohnson@google.com">tejohnson@google.com</a>> wrote:<br>
><br>
> tejohnson added a comment.<br>
><br>
> In <a href="http://reviews.llvm.org/D17212#362864" rel="noreferrer" target="_blank">http://reviews.llvm.org/D17212#362864</a>, @joker.eph wrote:<br>
><br>
>> How could we integrate accesses to global variable as part of this?<br>
>> It turns out that to be able to benefit from the linker information on what symbol is exported during the import, this is a must.<br>
><br>
><br>
> Well without it you still can see which function symbols will be exported, just not the variables, so you are running with less info and I guess need to assume that all static variables will be exposed and promote them.<br>
<br>
</span>The scheme I am currently setting up is:<br>
<br>
1) The linker gives us the list of symbols that need to be "preserved" (can't internalize)<br>
2) Link the combined index<br>
3) Compute the import list for every module *by just looking at the profile*<br>
4) Do the promotion<br>
<br>
There is absolutely no assumption for the promotion (last step): you exactly know what will be imported by *every module*, and you can promote the optimal minimal amount of symbols.<br>
<br>
All of that is good and should work with your call-graph patch "as is".<br>
<br>
I'm looking to go two steps further during stage 3:<br>
<br>
1) I want to drive the importing heuristic cost to actually take into account the need for promotion.<br>
I'll start some test on the extreme case by *forbiding* any promotion, i.e. if a function references an internal function or global, then it can't be imported in any other module. On the long term it may be interesting to include this in the importing threshold.<br>
This can be implemented with a flag or an int in the summary "numberOfInternalGlobalsReferenced", but will not be enough for step 2 (below).<br>
<br></blockquote><div><br></div><div>Interesting. What is the motivation for this type of tuning? Does is try to preserve more variable analysis (e.g, aliasing) in backend compilation?</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2) I want to benefit from the linker information from stage 1 to internalize symbols.<br>
It means that the information about the fact that a function is referencing an internal global *can't be in the summary* because the front-end does not know that the global will be internalized.<br>
This can be implemented by not having a "call graph" but a "reference graph" (not sure on the terminology): i.e. edges would be there for any uses of a symbol to another one and not only calls.<br></blockquote><div><br></div><div>Reference graph is what GCC uses :)</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=""><br>
<br>
<br>
> To refine that behavior for variables, yes, we'd need additional info in the summary.<br>
><br>
> (For davidxl or anyone else who didn't see the IRC conversation, Mehdi is looking at doing pure summary-based importing decisions in the linker step, then giving this info to the ThinLTO backends to avoid promotion of local values that aren't exported. For a distributed build if we wanted to do it this way the importing decisions would all be made in the plugin step, then would need to be serialized out for the distributed backends to check.)<br>
><br>
> Two possibilities depending on the fidelity of the info you think you need:<br>
><br>
> 1. One possibility is to just put a flag in the function summary if it accesses *any* local variables, and adjust the importing threshold accordingly. Then in the ThinLTO backend for the exporting module you need to check which of your own functions are on the import list, and which local variables they access, and promote accordingly.<br>
><br>
> 2. If it will be really beneficial to note exactly which local variables are accessed by which function, we'll need to broaden the edges list to include accesses to variables (I assume you only care about local variables here). E.g. the per-module summary edge list for a function would need to include value ids for any local variables referenced by that function (not sure that the other parts of the triple, the static and profile counts, are needed for that). Then in the combined VST we need to include entries for GUIDs of things that don't have a function summary, but are referenced by these edges. When accessing a function summary edge list for a candidate function to import, you could then see the GUID of any local variables accessed. You wouldn't know them by name, but if for example you wanted a heuristic like "if >=N hot import candidate functions from module M access a local variable with GUID G, go ahead and import those and let G be promoted by the backend (which like in approach #1 needs to check which local variables are accessed by any functions on an import list)".<br>
><br>
> Obviously 1) is easier and cheaper space-wise. What are your thoughts?<br>
<br>
<br>
</span>So 1) is cheaper, but 2) a lot more powerful as explained above :)<br></blockquote><div><br></div><div>yes -- we may find other good uses of it.</div><div><br></div><div>David</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class="HOEnZb"><font color="#888888"><br>
<br>
--<br>
Mehdi<br>
<br>
</font></span></blockquote></div><br></div></div>