I am struggling a little bit with finding how to free memory allocated by LLVM functions. For example, when I call the function Function::Create() to create an LLVM function, how can I free the memory allocated to it? Same actually applies to many LLVM functions like IRBuilder::CreateAlloca(), IRBuilder::CreateStore(), etc. Any idea?
I am struggling a little bit with finding how to free memory allocated by
Share
First of all, when deleting any kind of
Value, make sure it doesn’t have anyUsers anymore. Deleting used values will, obviously, lead to errors (in the form of an assertion). This can easily be tested by callinggetNumUses(), or better (read: faster)hasNUses(0).When you’re sure your value isn’t used anymore, different kind of values sometimes need different ways to delete them. For your two cases:
Functions can simply be deleted by callingoperator delete. This makes sure the function is removed correctly from theModule.Instructions should be deleted by callingeraseFromParent(). Or, equivalently, by first callingremoveFromParent()and then deleting it manually.