<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 6, 2016 at 4:41 PM, Peter Collingbourne 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-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi all,<div><br></div><div>I'd like to propose changes to how we do promotion of global values in ThinLTO. The goal here is to make it possible to pre-compile parts of the translation unit to native code at compile time. For example, if we know that:</div><div><br></div><div>1) A function is a leaf function, so it will never import any other functions, and</div><div>2) The function's instruction count falls above a threshold specified at compile time, so it will never be imported.</div><div>or</div><div>3) The compile-time threshold is zero, so there is no possibility of functions being imported (What's the utility of this? Consider a program transformation that requires whole-program information, such as CFI. During development, the import threshold may be set to zero in order to minimize the incremental link time while still providing the same CFI enforcement that would be used in production builds of the application.)</div><div><br></div><div>then the function's body will not be affected by link-time decisions, and we might as well produce its object code at compile time. This will also allow the object code to be shared between linkage units (this should hopefully help solve a major scalability problem for Chromium, as that project contains a large number of test binaries based on common libraries).</div><div><br></div><div>This can be done with a change to the intermediate object file format. We can represent object files as native code containing statically compiled functions and global data in the .text,. data, .rodata (etc.) sections, with an .llvmbc section (or, I suppose, "__LLVM, __bitcode" when targeting Mach-O) containing bitcode for functions to be compiled at link time.</div><div><br></div><div>In order to make this work, we need to make sure that references from link-time compiled functions to statically compiled functions work correctly in the case where the statically compiled function has internal linkage. We can do this by promoting every global value with internal linkage, using a hash of the external names (as I mentioned in [1]).</div></div></blockquote><div><br></div><div>What about translation units that have no external names? I hit this problem with DWARF Fission hashing recently, where two files had code equivalent to this:<br><br> struct foo { foo(); }<br> static foo f;<br><br>Thus no external symbols, and indeed exactly the same set of symbols for two instances of this file (& I have seen examples of this in Google's codebase - though I haven't searched extensively, and it may be that the linker never actually picks two of these together, but the DWP tool doesn't have the same kind of "skip this library if no symbols are needed from it" behavior as the linker).<br><br>Also, (I haven't read the whole thread, but I assume) you're considering doing this with debug info too? All type information could pretty easily be emitted up-front and just reduced to declarations (again, on non-LLDB platforms... :/) for the rest of the debug info. The extra declarations might make object files a bit bigger, though. (eg: if there were types that weren't used in any of the ahead-of-time compiled code, but were used in the ThinLTO'd code - the naive approach would still produce the type info up front and a declaration in ThinLTO which would make for bigger output than just putting the type in the ThinLTO'd code - but it would potentially improve parallelism by reducing the amount of type goo needing to be imported/exported/emitted during ThinLTO)</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 dir="ltr"><div><br></div><div>I imagine that for some linkers, it may not be possible to deal with this scheme. For example, I did some investigation last year and discovered that I could not use the gold plugin interface to load a native object file if we had already claimed it as an IR file. I wouldn't be surprised to learn that ld64 has similar problems.</div><div><br></div><div>In cases where we completely control the linker (e.g. lld), we can easily support this scheme, as the linker can directly do whatever it wants. But for linkers that cannot support this, I suggest that we promote consistently under ThinLTO rather than having different promotion schemes for different linkers, in order to reduce overall complexity.</div><div><div><br></div><div>Thanks for your feedback!</div><div><br></div><div>Thanks,</div><span class=""><font color="#888888">-- <br><div><div dir="ltr">-- <div>Peter</div><div><br></div><div>[1] <a href="http://lists.llvm.org/pipermail/llvm-dev/2016-April/098062.html" target="_blank">http://lists.llvm.org/pipermail/llvm-dev/2016-April/098062.html</a></div></div></div>
</font></span></div></div>
<br>_______________________________________________<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/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>