<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Jun 13, 2017 at 9:43 PM, Sean Fertile via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">As a follow up to <a href="https://reviews.llvm.org/D20217" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D20217</a> I would like to use<br>
lto/thinlto to refine when a symbol is marked as local/preemptable.<br>
I'm not very familiar with lto though so would appreciate some<br>
guidance about how best to go about this.<br></blockquote><div><br></div><div>Hi Sean,</div><div><br></div><div>The first thing that I would do is to try to get this working for regular LTO. There is a flag in the lto::SymbolResolution class named FinalDefinitionInLinkageUnit, which was intended to control whether the backend must make symbol references preemptible. Right now we copy a number of other fields from SymbolResolution onto the symbol definition, which is done by LTO::addRegularLTO in this loop:</div><div><a href="https://github.com/llvm-project/llvm-project-20170507/blob/4240587b0d490325dae8aa64d620ce599fa20840/llvm/lib/LTO/LTO.cpp#L555">https://github.com/llvm-project/llvm-project-20170507/blob/4240587b0d490325dae8aa64d620ce599fa20840/llvm/lib/LTO/LTO.cpp#L555</a></div><div>I imagine that this is where you would add code that translates FinalDefinitionInLinkageUnit into dso_local/dso_preemptible.</div><div><br></div><div>The next step would be to get it working for ThinLTO. This would involve the same basic mechanism: the FinalDefinitionInLinkageUnit flag would control whether to set dso_local/dso_preemptible on global values. The difference would be that the flag would need to be passed via the module summary index, as this is how information needs to be passed to the ThinLTO backends. The way that I imagine that this would work is that we would introduce a new flag in GlobalValueSummary::GVFlags into which you would copy the value of FinalDefinitionInLinkageUnit during LTO::addThinLTO. We already copy the Prevailing flag elsewhere using the GUID:</div><div><a href="https://github.com/llvm-project/llvm-project-20170507/blob/4240587b0d490325dae8aa64d620ce599fa20840/llvm/lib/LTO/LTO.cpp#L578">https://github.com/llvm-project/llvm-project-20170507/blob/4240587b0d490325dae8aa64d620ce599fa20840/llvm/lib/LTO/LTO.cpp#L578</a><br></div><div>but for this flag I imagine that you would want to copy it directly into the global's summary (see ModuleSummaryIndex::getValueInfo for how to look up a global value summary using a GUID).</div><div><br></div><div>The default value of this flag should mean "preemptible" -- Apple's linker uses a legacy API which will not set this flag, so that avoids breaking their linker.</div><div><br></div><div>Then in the thinBackend function you would translate the flag into dso_local/dso_preemptible. Probably the best place to do that is in FunctionImportGlobalProcessing::processGlobalForThinLTO here:</div><div><a href="https://github.com/llvm-project/llvm-project-20170507/blob/4240587b0d490325dae8aa64d620ce599fa20840/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp#L215">https://github.com/llvm-project/llvm-project-20170507/blob/4240587b0d490325dae8aa64d620ce599fa20840/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp#L215</a><br></div><div>See shouldPromoteLocalToGlobal for how to find the summary for the GlobalVariable at that point -- some of that code probably needs to be factored out.</div><div><br></div><div>There would also need to be bitcode reader/writer support for the new flag:</div><div><a href="https://github.com/llvm-project/llvm-project-20170507/blob/4240587b0d490325dae8aa64d620ce599fa20840/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L865">https://github.com/llvm-project/llvm-project-20170507/blob/4240587b0d490325dae8aa64d620ce599fa20840/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L865</a><br></div><div><a href="https://github.com/llvm-project/llvm-project-20170507/blob/4240587b0d490325dae8aa64d620ce599fa20840/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp#L879">https://github.com/llvm-project/llvm-project-20170507/blob/4240587b0d490325dae8aa64d620ce599fa20840/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp#L879</a><br></div><div>There is one subtlety however, which is that the summary index might not contain entries for functions without definitions. For now I would punt on this and mark declarations that are not present in the summary index as preemptible.</div><div><br></div><div>Peter</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
Regards<br>
Sean Fertile<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">-- <div>Peter</div></div></div>
</div></div>