<div dir="ltr">Hi Hal,<div><br></div><div>Thanks for the reminder! You are right that I need to free the allocated memory when an exception is thrown. Where should the frees be inserted if an exception is thrown? I am not familiar with the exception handling mechanism in LLVM.<br>
<br></div><div>Bill<br> </div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Nov 13, 2013 at 3:59 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Bill,<br>
<br>
Just in case this is relevant for you: If you're working with C++ code, or otherwise have any functions that might throw exceptions, you might also need to catch those exceptions in order to free the allocated memory. This will involve looking for calls to functions that mayThrow(), changing their calls to invokes, and freeing the memory before resuming the unwinding.<br>

<br>
 -Hal<br>
<div class="HOEnZb"><div class="h5"><br>
----- Original Message -----<br>
><br>
><br>
> Thanks! I will try that and see whether it works.<br>
><br>
><br>
><br>
><br>
> On Wed, Nov 13, 2013 at 5:01 AM, Henrique Santos <<br>
> <a href="mailto:henrique.nazare.santos@gmail.com">henrique.nazare.santos@gmail.com</a> > wrote:<br>
><br>
><br>
><br>
><br>
><br>
><br>
> It seems that placing the calls to free at the predecessors of<br>
> dominance frontier is inadequate. It is possible that there are exit<br>
> blocks that are dominated by BB12 (calls to malloc). I guess we can<br>
> also insert calls to free at these exit blocks too.<br>
> That crossed my mind a few minutes later. : )<br>
><br>
><br>
> If you're interested, PRE.cpp existed last at r25315. It calculates<br>
> the "availability frontier" which is probably what you're looking<br>
> for.<br>
><br>
> I suggest, however, that you try coming up with another solution<br>
> instead. You might consider using -mergereturn.<br>
><br>
><br>
><br>
><br>
><br>
> H.<br>
><br>
><br>
><br>
><br>
><br>
> On Wed, Nov 13, 2013 at 2:13 AM, Bin Tzeng < <a href="mailto:bintzeng@gmail.com">bintzeng@gmail.com</a> ><br>
> wrote:<br>
><br>
><br>
><br>
><br>
> Hi Henrique,<br>
> Thanks for the quick reply!<br>
><br>
><br>
><br>
><br>
> On Tue, Nov 12, 2013 at 9:13 PM, Henrique Santos <<br>
> <a href="mailto:henrique.nazare.santos@gmail.com">henrique.nazare.santos@gmail.com</a> > wrote:<br>
><br>
><br>
><br>
><br>
><br>
><br>
> PRE normally uses a latest placement algorithm to do something of the<br>
> sort.<br>
> I don't know about GVN/PRE, but older version of PRE might have it.<br>
> Just placing the calls to free at the predecessors (dominated by<br>
> BB12) of the dominance frontier of BB12 seems to work, however. Is<br>
> there anything wrong with this?<br>
><br>
> It seems that placing the calls to free at the predecessors of<br>
> dominance frontier is inadequate. It is possible that there are exit<br>
> blocks that are dominated by BB12 (calls to malloc). I guess we can<br>
> also insert calls to free at these exit blocks too.<br>
><br>
><br>
><br>
><br>
> H.<br>
><br>
><br>
><br>
><br>
><br>
><br>
> On Tue, Nov 12, 2013 at 11:30 PM, Bin Tzeng < <a href="mailto:bintzeng@gmail.com">bintzeng@gmail.com</a> ><br>
> wrote:<br>
><br>
><br>
><br>
><br>
><br>
> Hi all,<br>
><br>
><br>
> I have been writing a pass to heapify some alloca's (it is<br>
> pessimistization, not optimization). For example, in the following<br>
> control flow graph, there is a call to malloc inserted in block<br>
> BB12. In order to avoid memory leak, free's are needed. The free<br>
> cannot be inserted in BB23 because BB23 is not dominated by BB12.<br>
> There are two ways to go I can think of here. One way is to insert a<br>
> new basic block, say BB24, to connect both BB21 and BB22 and a free<br>
> can be inserted into the new block BB24. The new block BB24 has to<br>
> post-dominate BB12 and all the users of malloc have to happen before<br>
> BB24. Another way to go is to insert a free in both BB21 and BB22.<br>
> That is, a free is inserted in all the paths from BB12 to all exits<br>
> after all users of malloc to avoid memory leak. I wonder whether<br>
> there is any pass that does similar analysis in order to avoid<br>
> duplication of efforts.<br>
><br>
><br>
> BB10 (entry)<br>
> / \<br>
> BB11 BB12 (malloc)<br>
> / / \<br>
> BB13 / BB15<br>
> \ / / \<br>
> \ / BB18 BB19<br>
> \ / \ /<br>
> BB20 BB21 BB22<br>
> \ | /<br>
> \ | /<br>
> \ | /<br>
> \ | /<br>
> BB23 (exit)<br>
><br>
><br>
> Any advice is appreciated. Thanks in advance!<br>
> Bill<br>
><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>
><br>
><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>
</div></div><span class="HOEnZb"><font color="#888888">--<br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory<br>
</font></span></blockquote></div><br></div>