<div dir="ltr">Hello,<div><br></div><div>the need here is to have a single LLVMContext used for multiple compilations.</div><div><br></div><div>You make a good point about that by the way. If there are outstanding users cleaning the context under their seats might still pose a risk to them, and in that case deleting + newing a new LLVMContextImpl might actually not be very different.</div>
<div><br></div><div>Marcello</div><div><div class="gmail_extra"><br><div class="gmail_quote">2014-06-24 17:14 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">
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>
<div><div><br>
On Tue, Jun 24, 2014 at 7:18 AM, Marcello Maggioni <<a href="mailto:hayarms@gmail.com" target="_blank">hayarms@gmail.com</a>> wrote:<br>
> Hello,<br>
><br>
> I'm trying to develop a way to reliably clean the LLVMContext in order 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 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 LLVMContextImpl<br>
> is actually exposed as a public pointer in the LLVMContext interface,making<br>
> it publicly available to objects that use it directly (this seems to happen<br>
> quite a lot in the codebase).<br>
><br>
> In LLVMContext the LLVMContextImpl is contained in a pImpl pointer that is<br>
> const (the pointer itself can't be changed) and I guess this is some 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 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 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 and<br>
> see what people think would be the best approach would be.<br>
><br>
> Thanks,<br>
> Marcello<br>
><br>
</div></div>> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">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>
</blockquote></div><br></div></div></div>