<div dir="ltr">An example is that a lot of data just accumulates between different compilations, like Constants for example or MDNodes.<div><br></div><div>In the long run the memory hogged starts to become a concern.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-06-24 18:51 GMT+01:00 David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="">On Tue, Jun 24, 2014 at 10:44 AM, Marcello Maggioni <<a href="mailto:hayarms@gmail.com">hayarms@gmail.com</a>> wrote:<br>
> Hello,<br>
><br>
</div><div class="">> the need here is to have a single LLVMContext used for multiple<br>
> compilations.<br>
<br>
</div>What I'm trying to understand is why is that a need - is that not<br>
equivalent to just building a new LLVMContext for each compilation? Is<br>
there a performance concern (with data to back it up?) about doing<br>
that?<br>
<br>
What is it that goes wrong if you just start the next compilation<br>
without clearing the context in any way? (what's the persistent state<br>
that interferes with the next run?)<br>
<span class="HOEnZb"><font color="#888888"><br>
- David<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
> You make a good point about that by the way. If there are outstanding users<br>
> cleaning the context under their seats might still pose a risk to them, and<br>
> in that case deleting + newing a new LLVMContextImpl might actually not be<br>
> very different.<br>
><br>
> Marcello<br>
><br>
> 2014-06-24 17:14 GMT+01:00 David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>>:<br>
><br>
>> What're the situation in which you need to clear it? If there are<br>
>> outstanding users of it (given that you mention clients possibly<br>
>> holding references to the pimpl, it sounds like you might have<br>
>> outstanding users) then wouldn't they be at risk of breaking if you<br>
>> mutate the LLVMContext underneath them?<br>
>><br>
>> & if you don't have outstanding users, is there any particular benefit<br>
>> to resetting the LLVMContext compared to just making a new one?<br>
>><br>
>> On Tue, Jun 24, 2014 at 7:18 AM, Marcello Maggioni <<a href="mailto:hayarms@gmail.com">hayarms@gmail.com</a>><br>
>> wrote:<br>
>> > Hello,<br>
>> ><br>
>> > I'm trying to develop a way to reliably clean the LLVMContext in order<br>
>> > to<br>
>> > make it possible to use it multiple times.<br>
>> ><br>
>> > LLVMContext itself is an almost empty object delegating almost all its<br>
>> > content to LLVMContextImpl.<br>
>> > This makes it very clean ideally, because clearing the LLVMContext would<br>
>> > be<br>
>> > as easy as deleting the LLVMContextImpl and creating a new one.<br>
>> ><br>
>> > The problem is that for some reason which I'm not aware of<br>
>> > LLVMContextImpl<br>
>> > is actually exposed as a public pointer in the LLVMContext<br>
>> > interface,making<br>
>> > it publicly available to objects that use it directly (this seems to<br>
>> > happen<br>
>> > quite a lot in the codebase).<br>
>> ><br>
>> > In LLVMContext the LLVMContextImpl is contained in a pImpl pointer that<br>
>> > is<br>
>> > const (the pointer itself can't be changed) and I guess this is some<br>
>> > kind of<br>
>> > protection against object replacing the LLVMContextImpl directly, which<br>
>> > stops us from just deleting it + getting a new one.<br>
>> > In addition to that, being pImpl public, there is no guarantee that<br>
>> > objects<br>
>> > don't rely on pImpl remaining always the same pointer.<br>
>> ><br>
>> > This makes it more difficult to clear LLVMContext.<br>
>> ><br>
>> > An approach I thought of could be adding a clear() method to LLVMContext<br>
>> > that:<br>
>> >  - Calls directly the destructor of LLVMContextImpl on the pImpl object<br>
>> >  - Uses a placement new to reinitialize the object.<br>
>> >  - Recreates the fixed metadata kinds like the LLVMContext constructor<br>
>> > does<br>
>> ><br>
>> > I'm attaching a patch that show this approach in this mail.<br>
>> ><br>
>> > I would like to know a general idea about what people think about this<br>
>> > and<br>
>> > see what people think would be the best approach would be.<br>
>> ><br>
>> > Thanks,<br>
>> > Marcello<br>
>> ><br>
>> > _______________________________________________<br>
>> > LLVM Developers mailing list<br>
>> > <a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
>> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br></div>