<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 12, 2013 at 6:02 PM, Chris Lattner <span dir="ltr"><<a href="mailto:clattner@apple.com" target="_blank" class="cremed">clattner@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Nov 12, 2013, at 4:59 PM, Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank" class="cremed">chandlerc@google.com</a>> wrote:<br>
<div><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra">
<div class="gmail_quote"><div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div style="font-size:12px;font-family:Helvetica">Other options are:</div><div style="font-size:12px;font-family:Helvetica">
1> Using a different LLVMContext for the destination module, but it didn’t work out since Linker was not designed to work with different LLVMContexts for source vs destination.</div><div style="font-size:12px;font-family:Helvetica">




2> removeUnusedMDNodes checks if a MDNode is used in a different way  (i.e use_empty() && !hasValueHandler()), but it does not remove MDNodes that form cycles.</div></blockquote></div><br></div>3) Make the MDNode be owned by the module that uses it?</div>


</div></blockquote><div> </div></div></div><div>MDNode is shared among modules so multiple modules can use it, if we specify an owner for a MDNode, that will prevent sharing.</div></div></div></div></blockquote><div><br>

</div><div>From your stats (40% stuck in the old module) it doesn't sound like this is buying us anything...</div><div> </div></div></div></div></blockquote><br></div></div><div>If the old module is deleted, then these MDNodes can be reclaimed.</div>
<div><br></div><div>I think this proposal amounts to a “garbage collector” that clears out now-dead IR objects that are uniqued in the LLVM Context.  While MDNodes are your focus, the same thing would apply equally well to ConstantInt and other things that may become unreachable.</div>
</blockquote><div><br></div><div>I think the big difference is that there appears to be very little (relatively speaking) overlap between modules for MDNodes. This is different from types and many other things I suspect.</div>
<div><br></div><div>My question was: if we're not seeing a higher degree of sharing between modules by using context-uniqued MDNodes, why not have them be owned by the module rather than the context?</div><div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><br></div><div>Details matter on this (for it to be efficient), but I think that it would be very useful for LLVMContext to have a method that goes through and releases IR objects that aren’t used.  This could be used by the LTO driver, and if it actually reduces memory by 40%, that would be huge.</div>
</blockquote></div><br></div><div class="gmail_extra">My only worry is doing a relatively expensive walk over all types and constants when most are actually shared and don't get deleted. It sounds like the metadata nodes are weird in that they are mostly disjoint between modules.</div>
</div>