<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">On Nov 12, 2013, at 4:59 PM, Chandler Carruth <<a href="mailto:chandlerc@google.com">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 class="h5"><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; position: static; z-index: auto;"><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>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><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><div><br></div><div>-Chris</div><br></body></html>