Rodney M. Bates
2014-Dec-02 18:55 UTC
[LLVMdev] Questions about deallocation responsibilities
I am, from a front end, calling functions like LLVMModuleCreateWithName, found in Core.h, ultimately calling LLVMWriteBitcodeToFile, found in BitWriter.h. Do I correctly presume, from the existence of LLVMDisposeModule, that I am responsible for calling it when I'm done? Will I need to do deeper disposing myself? I presume at least I will need to free strings I allocated myself, such as the module name I passed in. What about, for example, llvm::DIBuilder::DICreateCompileUnit? I haven't been able so far to find a companion dispose for this object. -- Rodney Bates rodney.m.bates at acm.org
Reid Kleckner
2014-Dec-02 19:17 UTC
[LLVMdev] Questions about deallocation responsibilities
LLVM has some standard ownership conventions: - A LLVMContext owns constants and types, and must outlive all other IR data structures using it - A Module owns all functions, globals, aliases, metadata, and other stuff in it - A Function owns all basic blocks in it - A BasicBlock owns all of its instructions Disposing a module should throw away all the other IR it contains, but you also need to throw away the context if you want to really throw away all of LLVM's state. LLVM typically copies symbol names into it's own internal data structures, so any strings you allocate for symbol names are owned by the frontend. I'm not familiar with DIBuilder, but I'm pretty sure the metadata it creates is owned by the module or context depending on the type. On Tue, Dec 2, 2014 at 10:55 AM, Rodney M. Bates <rodney_bates at lcwb.coop> wrote:> I am, from a front end, calling functions like LLVMModuleCreateWithName, > found > in Core.h, ultimately calling LLVMWriteBitcodeToFile, found in BitWriter.h. > > Do I correctly presume, from the existence of LLVMDisposeModule, that > I am responsible for calling it when I'm done? Will I need to do deeper > disposing myself? I presume at least I will need to free strings I > allocated > myself, such as the module name I passed in. > > What about, for example, llvm::DIBuilder::DICreateCompileUnit? I haven't > been able so far to find a companion dispose for this object. > > > -- > Rodney Bates > rodney.m.bates at acm.org > _______________________________________________ > 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/20141202/e4d28970/attachment.html>
David Blaikie
2014-Dec-02 19:18 UTC
[LLVMdev] Questions about deallocation responsibilities
On Tue, Dec 2, 2014 at 10:55 AM, Rodney M. Bates <rodney_bates at lcwb.coop> wrote:> I am, from a front end, calling functions like LLVMModuleCreateWithName, > found > in Core.h, ultimately calling LLVMWriteBitcodeToFile, found in BitWriter.h. > > Do I correctly presume, from the existence of LLVMDisposeModule, that > I am responsible for calling it when I'm done? Will I need to do deeper > disposing myself? I presume at least I will need to free strings I > allocated > myself, such as the module name I passed in. > > What about, for example, llvm::DIBuilder::DICreateCompileUnit? I haven't > been able so far to find a companion dispose for this object.Metadata is owned by the LLVMContext on construction. (except temporary metadata, which must be destroyed manually (there's a corresponding destroy function in llvm::MDNode) usually after RAUWing it with something else).> > > > -- > Rodney Bates > rodney.m.bates at acm.org > _______________________________________________ > 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/20141202/81510acc/attachment.html>
Rodney M. Bates
2014-Dec-03 15:43 UTC
[LLVMdev] Questions about deallocation responsibilities
Thanks. These posts help a lot. On 12/02/2014 01:18 PM, David Blaikie wrote:> > > On Tue, Dec 2, 2014 at 10:55 AM, Rodney M. Bates <rodney_bates at lcwb.coop <mailto:rodney_bates at lcwb.coop>> wrote: > > I am, from a front end, calling functions like LLVMModuleCreateWithName, found > in Core.h, ultimately calling LLVMWriteBitcodeToFile, found in BitWriter.h. > > Do I correctly presume, from the existence of LLVMDisposeModule, that > I am responsible for calling it when I'm done? Will I need to do deeper > disposing myself? I presume at least I will need to free strings I allocated > myself, such as the module name I passed in. > > What about, for example, llvm::DIBuilder::__DICreateCompileUnit? I haven't > been able so far to find a companion dispose for this object. > > > Metadata is owned by the LLVMContext on construction. (except temporary metadata, which must be destroyed manually (there's a corresponding destroy function in llvm::MDNode) usually after RAUWing it with something else). > > > > > -- > Rodney Bates > rodney.m.bates at acm.org <mailto:rodney.m.bates at acm.org> > _________________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/__mailman/listinfo/llvmdev <http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev> > >-- Rodney Bates rodney.m.bates at acm.org