Benjamin Smedberg
2007-Dec-04 00:50 UTC
[LLVMdev] Memory allocation (or deallocation) model?
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I've been reading the headers and http://llvm.org/releases/2.1/docs/ProgrammersManual.html and I'm still confused about a pretty fundamental point... who is expected to clean up various objects when we're finished with them, and when? Let's say I've created a module, retrieved a bunch of types, created a function, a basic block, and instructions and inserted them all together. I've linked it all to an execution engine, and gotten a function pointer to actually call using getPointerToFunctionOrStub: * Does the function pointer stay good as long as the execution engine is alive? * Once the function is JITted, will all those types/instructions/functions still be allocated in memory? ** If so, is there a way to explicitly free them? * Can I "delete executionEngine" to free up all the memory? - --BDS - -- Benjamin Smedberg Platform Guru Mozilla Corporation benjamin at smedbergs.us http://benjamin.smedbergs.us/ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFHVKRfSSwGp5sTYNkRAg5KAKCkaYvIqD9ERW8d6HXVNUoSY3jcUwCfcLYX TSO793MS0OzgxSEOKURY1/M=pjhx -----END PGP SIGNATURE-----
On Mon, 3 Dec 2007, Benjamin Smedberg wrote:> I've been reading the headers and > http://llvm.org/releases/2.1/docs/ProgrammersManual.html and I'm still > confused about a pretty fundamental point... who is expected to clean up > various objects when we're finished with them, and when?Ok, different objects have different life times. The important ones are: (most) Constants and Types are uniqued and live "forever", where forever means "until llvm_shutdown() is called". The exceptions to this case are tied to a specific module, and are thus deleted when the module is. Other IR objects (like instructions) have very simple ownership. An instruction is owned by its basic block, a bb is owned by the function, a function is owned by thet module. If you're JIT'ing from a module, the JIT object (an instance of ExecutionEngine) owns the module.> Let's say I've created a module, retrieved a bunch of types, created a > function, a basic block, and instructions and inserted them all together. > I've linked it all to an execution engine, and gotten a function pointer to > actually call using getPointerToFunctionOrStub: > > * Does the function pointer stay good as long as the execution engine is alive?Yes, or until you explicitly free it with EE->freeMachineCodeForFunction(F). Note that you can free the IR for the function body after you JIT the function by using F->deleteBody().> * Once the function is JITted, will all those types/instructions/functions > still be allocated in memory?Yes, unless you free them.> ** If so, is there a way to explicitly free them?Yep.> * Can I "delete executionEngine" to free up all the memory?Yep, delete it, then call llvm_shutdown(). -Chris -- http://nondot.org/sabre/ http://llvm.org/
Jonathan Brandmeyer
2007-Dec-04 02:59 UTC
[LLVMdev] Memory allocation (or deallocation) model?
On Mon, 2007-12-03 at 18:56 -0800, Chris Lattner wrote:> Other IR objects (like instructions) have very simple ownership. An > instruction is owned by its basic block, a bb is owned by the function, a > function is owned by thet module.If an instruction is initially allocated with its Instruction *insertAtEnd parameter defaulted to null, and then later appended to a BasicBlock, will the BasicBlock take ownership of the Instruction? Thanks, -Jonathan