I have a small parser that uses LLVM to generate and run code based on the Kaleidoscope tutorial.
My limitation is that I need to recreate the module, because I need to process the same input file several times, and after the first compilation, LLVM will complain about a module that already contains x functions, etc. The only way forward I can see is to recreate the module between them, which means that I need to recreate the ExecutionEngine as well.
However, there are a huge number of memory leaks that I want to get rid of. How to free llvm::Module and llvm::ExecutionEngine ?
If I just delete both, it segfaults somewhere in LLVM. My current implementation is as follows:
TheExecutionEngine->removeModule(module); delete module(); delete TheExecutionEngine;
However, there are still about 14,000 leaks, so this seems wrong.
I do not need to duplicate any existing functions in the module. I just want a new one, empty.
source share