On Wed, Mar 25, 2015 at 4:25 PM, ajay gopalakrishnan <ajgopala at
gmail.com>
wrote:
> 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 -
>
> All code that creates LLVM IR instructions using their APIs seems to
"new"
> instructions instead of creating them as stack variables.
>
> auto x = new Alloca(...) vs. Alloca(...) x;
>
> 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;".
>
> 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.
>
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.
> By looking at some of the code, it seems that all these instruction
> objects are created by using "placement new" ... Is this
understanding
> correct?
>
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.
- David
> It would be great if someone can explain the memory allocation schema used
> by these APIs.
>
> Thanks!
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20150327/6d71aa10/attachment.html>