<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Mar 25, 2015 at 4:25 PM, ajay gopalakrishnan <span dir="ltr"><<a href="mailto:ajgopala@gmail.com" target="_blank">ajgopala@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p>I've recently started using LLVM IR generation APIs for my project. 
The documentation and LLC tool are pretty helpful, but I haven't been 
able to find answer to the following - </p>



<p>All code that creates LLVM IR instructions using their APIs seems to 
"new" instructions instead of creating them as stack variables.</p>

<pre><code>auto x = new Alloca(...) vs. Alloca(...) x;
</code></pre>

<p>I am wondering what the ownership semantics are for the pointers that
 are created? Do I have to call delete on these instruction objects. All
 code that I've seen calls "delete engine;". </p>

<p>I am guessing that all this memory is owned by this Module object and
 when the module is destroyed, all the memory occupied by these 
instructions are also destroyed. </p></div></blockquote><div>That's correct. There are various operations on Instructions/Basic Blocks/etc that allow you to remove an Instruction/BB/etc from a BB/Function/Module, etc and take ownership so you can insert it back in somewhere else if you want to.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p>By looking at some of the code, it 
seems that all these instruction objects are created by using "placement
 new" ... Is this understanding correct?</p></div></blockquote><div>Overloaded operator new, to be more precise - this is just to play some memory tricks so we can allocate objects more efficiently (take a look at User::operator new, for a/the canonical example) - performing a single allocation for an object and its dynamic but constant-at-constructor-time sequence of operands (or whatever) after it.<br><br>- David </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p>It would be great if someone can explain the memory allocation schema used by these APIs.</p><p>Thanks!</p></div>
<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></blockquote></div><br></div></div>