<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">The code is live, because a ForcePassLinking global object is created, and its constructor calls all these functions.  I don't think even LTO can eliminate global objects?</div><div class=""><br class=""></div><div class="">This construction was originally added a long time ago, in <a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=19307" class="">r19307</a>, with an explanatory comment: "This header file is required for building with Microsoft's VC++, as it has no way of linking all registered passes into executables other than by explicit use".  A similar header for analysis passes was added by Chris in <a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=23921" class="">r23921</a>, and later merged into LinkAllPasses.h by Reid in <a href="http://llvm.org/viewvc/llvm-project?view=revision&revision=29787" class="">r29787</a>.</div><div class=""><br class=""></div><div class="">The goal is evidently to prevent LTO from optimizing away passes.  Apparently the passes are constructed in such a way that their data or functions are not always referenced, but they can still be used?  Some passes have comment similar to:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class="">// Create methods available outside of this file, to use them</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class="">// "include/llvm/LinkAllPasses.h". Otherwise the pass would be deleted by</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class="">// the link time optimization.</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class="">namespace<span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> llvm {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">  FunctionPass *createMachineRegionInfoPass() {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">    <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">new</span> MachineRegionInfoPass();</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">  }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">}</div></div><div class=""><br class=""></div><div class=""><div class="">I think the passes may try to avoid having any global constructors, and therefore there may be a risk of LTO optimizing them away...</div></div><div class=""><br class=""></div><div class="">-Dimitry</div><br class=""><div><blockquote type="cite" class=""><div class="">On 12 Jan 2016, at 17:50, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Jan 12, 2016 at 8:41 AM, Mehdi Amini <span dir="ltr" class=""><<a href="mailto:mehdi.amini@apple.com" target="_blank" class="">mehdi.amini@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">You need to be careful that an LTO build won’t inline and eliminate this.</div></blockquote><div class=""><br class=""></div><div class="">fair - but these calls, if they'd executed, would've been totally bogus, right? (they would've crashed/null dereferenced, etc)<br class=""><br class="">So somehow this code is live without it actually executing.<br class=""><br class="">To come back to the underlying issue: What is it we're trying to solve here? What entities are we trying to preserve & why are more traditional/normal ways of preserving them insufficient? (sorry if this is too much of a derailment/the rest  of you have enough context here, feel free to go on without me ;))</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><br class=""></div><div class="">— </div><span class="HOEnZb"><font color="#888888" class=""><div class="">Mehdi</div></font></span><div class=""><div class="h5"><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 12, 2016, at 8:02 AM, David Blaikie via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class="">Do you need to call anything? Could you just take the address of the function and return it, stuff it in a global, or otherwise escape it?</div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Jan 12, 2016 at 12:02 AM, Dimitry Andric via llvm-commits <span dir="ltr" class=""><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">dim added a subscriber: grosser.<br class="">
<br class="">
================<br class="">
Comment at: include/llvm/LinkAllPasses.h:191<br class="">
@@ -190,3 +196,3 @@<br class="">
<span class="">       llvm::RGPassManager RGM;<br class="">
-      ((llvm::RegionPass*)nullptr)->runOnRegion((llvm::Region*)nullptr, RGM);<br class="">
</span>       llvm::AliasSetTracker X(*(llvm::AliasAnalysis*)nullptr);<br class="">
----------------<br class="">
@grosser, you originally added this part in rL117263 ("Reference RegionPass to stop it being eliminated"), do you have any suggestions? If the goal is to to unsure RegionPass.cpp is linked in, I think we can call `RegionPass::createPrinterPass()` instead.<br class="">
<div class=""><div class=""><br class="">
<br class="">
<a href="http://reviews.llvm.org/D15996" rel="noreferrer" target="_blank" class="">http://reviews.llvm.org/D15996</a><br class="">
<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
llvm-commits mailing list<br class="">
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class="">
</div></div></blockquote></div><br class=""></div>
_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@lists.llvm.org" target="_blank" class="">llvm-commits@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br class=""></div></blockquote></div><br class=""></div></div></div></div></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></body></html>