<div dir="ltr">Approved.<div><br></div><div>Peter</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 18, 2017 at 10:51 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">Hi Peter,<br>
<br>
I’d like to cherry-pick this into the 4.0 release. This is a follow-up to r291027, it achieve what was originally promised.<br>
<br>
It will only affect ThinLTO, as lazy-loading happens only there.<br>
<br>
Thanks,<br>
<br>
—<br>
<span class="HOEnZb"><font color="#888888">Mehdi<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> On Jan 18, 2017, at 10:36 AM, Mehdi Amini via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
><br>
> Author: mehdi_amini<br>
> Date: Wed Jan 18 12:36:21 2017<br>
> New Revision: 292420<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=292420&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=292420&view=rev</a><br>
> Log:<br>
> [ThinLTO] Add a recursive step in Metadata lazy-loading<br>
><br>
> Summary:<br>
> Without this, we're stressing the RAUW of unique nodes,<br>
> which is a costly operation. This is intended to limit<br>
> the number of RAUW, and is very effective on the total<br>
> link-time of opt with ThinLTO, before:<br>
><br>
> real 4m4.587s user 15m3.401s sys 0m23.616s<br>
><br>
> after:<br>
><br>
> real 3m25.261s user 12m22.132s sys 0m24.152s<br>
><br>
> Reviewers: tejohnson, pcc<br>
><br>
> Subscribers: llvm-commits<br>
><br>
> Differential Revision: <a href="https://reviews.llvm.org/D28751" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D28751</a><br>
><br>
> Modified:<br>
> llvm/trunk/lib/Bitcode/Reader/<wbr>MetadataLoader.cpp<br>
> llvm/trunk/test/ThinLTO/X86/<wbr>lazyload_metadata.ll<br>
><br>
> Modified: llvm/trunk/lib/Bitcode/Reader/<wbr>MetadataLoader.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/MetadataLoader.cpp?rev=292420&r1=292419&r2=292420&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/lib/<wbr>Bitcode/Reader/MetadataLoader.<wbr>cpp?rev=292420&r1=292419&r2=<wbr>292420&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/lib/Bitcode/Reader/<wbr>MetadataLoader.cpp (original)<br>
> +++ llvm/trunk/lib/Bitcode/Reader/<wbr>MetadataLoader.cpp Wed Jan 18 12:36:21 2017<br>
> @@ -768,13 +768,12 @@ void MetadataLoader::<wbr>MetadataLoaderImpl:<br>
> unsigned ID, PlaceholderQueue &Placeholders) {<br>
> assert(ID < (MDStringRef.size()) + GlobalMetadataBitPosIndex.<wbr>size());<br>
> assert(ID >= MDStringRef.size() && "Unexpected lazy-loading of MDString");<br>
> -#ifndef NDEBUG<br>
> // Lookup first if the metadata hasn't already been loaded.<br>
> if (auto *MD = MetadataList.lookup(ID)) {<br>
> auto *N = dyn_cast_or_null<MDNode>(MD);<br>
> - assert(N && N->isTemporary() && "Lazy loading an already loaded metadata");<br>
> + if (!N->isTemporary())<br>
> + return;<br>
> }<br>
> -#endif<br>
> SmallVector<uint64_t, 64> Record;<br>
> StringRef Blob;<br>
> IndexCursor.JumpToBit(<wbr>GlobalMetadataBitPosIndex[ID - MDStringRef.size()]);<br>
> @@ -827,8 +826,22 @@ Error MetadataLoader::<wbr>MetadataLoaderImpl<br>
> auto getMD = [&](unsigned ID) -> Metadata * {<br>
> if (ID < MDStringRef.size())<br>
> return lazyLoadOneMDString(ID);<br>
> - if (!IsDistinct)<br>
> + if (!IsDistinct) {<br>
> + if (auto *MD = MetadataList.lookup(ID))<br>
> + return MD;<br>
> + // If lazy-loading is enabled, we try recursively to load the operand<br>
> + // instead of creating a temporary.<br>
> + if (ID < (MDStringRef.size() + GlobalMetadataBitPosIndex.<wbr>size())) {<br>
> + // Create a temporary for the node that is referencing the operand we<br>
> + // will lazy-load. It is needed before recursing in case there are<br>
> + // uniquing cycles.<br>
> + MetadataList.<wbr>getMetadataFwdRef(<wbr>NextMetadataNo);<br>
> + lazyLoadOneMetadata(ID, Placeholders);<br>
> + return MetadataList.lookup(ID);<br>
> + }<br>
> + // Return a temporary.<br>
> return MetadataList.<wbr>getMetadataFwdRef(ID);<br>
> + }<br>
> if (auto *MD = MetadataList.<wbr>getMetadataIfResolved(ID))<br>
> return MD;<br>
> return &Placeholders.<wbr>getPlaceholderOp(ID);<br>
><br>
> Modified: llvm/trunk/test/ThinLTO/X86/<wbr>lazyload_metadata.ll<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/lazyload_metadata.ll?rev=292420&r1=292419&r2=292420&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/llvm/trunk/test/<wbr>ThinLTO/X86/lazyload_metadata.<wbr>ll?rev=292420&r1=292419&r2=<wbr>292420&view=diff</a><br>
> ==============================<wbr>==============================<wbr>==================<br>
> --- llvm/trunk/test/ThinLTO/X86/<wbr>lazyload_metadata.ll (original)<br>
> +++ llvm/trunk/test/ThinLTO/X86/<wbr>lazyload_metadata.ll Wed Jan 18 12:36:21 2017<br>
> @@ -17,7 +17,7 @@<br>
> ; RUN: -o /dev/null -disable-ondemand-mds-loading -stats \<br>
> ; RUN: 2>&1 | FileCheck %s -check-prefix=NOTLAZY<br>
> ; NOTLAZY: 58 bitcode-reader - Number of Metadata records loaded<br>
> -; NOTLAZY: 8 bitcode-reader - Number of MDStrings loaded<br>
> +; NOTLAZY: 6 bitcode-reader - Number of MDStrings loaded<br>
><br>
><br>
> target datalayout = "e-m:o-i64:64-f80:128-n8:16:<wbr>32:64-S128"<br>
> @@ -48,7 +48,7 @@ define void @globalfunc3(i32 %arg) {<br>
> !3 = !{!"3"}<br>
> !4 = !{!"4"}<br>
> !5 = !{!"5"}<br>
> -!6 = !{!"6"}<br>
> +!6 = !{!9}<br>
> !7 = !{!"7"}<br>
> !8 = !{!"8"}<br>
> -!9 = !{!"9"}<br>
> +!9 = !{!6}<br>
><br>
><br>
> ______________________________<wbr>_________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">-- <div>Peter</div></div></div>
</div>