如何取消分配llvm :: module [英] How to deallocate llvm::module
问题描述
我有一个基于Kaleidoscope教程的使用LLVM生成和运行代码的小型语言解析器.
I have a small language parser that uses LLVM to generate and run code, based on the Kaleidoscope tutorial.
我的约束是我必须重新创建模块,因为我需要多次处理同一个输入文件,并且在第一次编译后,LLVM会抱怨该模块已经包含函数,x等.看到的是在两者之间重新创建模块,这意味着我也必须重新创建ExecutionEngine
.
My constraint is that I have to recreate the module because I need to process the same input file multiple times, and after the first compilation, LLVM would complain about the module already containing functions, x, etc. The only way forward I see is to recreate the module in between, and this means that I have to recreate ExecutionEngine
as well.
但是,我想消除大量内存泄漏.如何正确解除llvm::Module
和llvm::ExecutionEngine
的分配?
However, there are a huge amount of memory leaks occurring which I want to get rid of. How do I properly deallocate the llvm::Module
and llvm::ExecutionEngine
?
如果我简单地删除两者,则它会在LLVM中某处出现段错误.我当前的实现是这样的:
If I simply delete both, it segfaults somewhere in LLVM. My current implementation goes like this:
TheExecutionEngine->removeModule(module);
delete module();
delete TheExecutionEngine;
但是,仍然有大约14000个泄漏报告,所以这似乎是错误的.
However, there are still about 14000 leaks reported, so this seems wrong.
我不需要在模块中复制任何现有功能.我只想要一个新鲜的,空的.
I do not need to duplicate any existing functions in a module. I just want a fresh, empty one.
推荐答案
如果我对您的理解正确,那么您希望在程序的生命周期内多次创建ExecutionEngine
和Module
实例,并对其进行正确清理.
If I understood you correctly, you want to create ExecutionEngine
and Module
instances multiple times during the lifetime of your program, and clean them up properly.
请勿单独删除模块,因为一旦addModule
,ExecutionEngine
就会拥有"它.这意味着它将负责删除和清理.
Do not delete the Module separately, since ExecutionEngine
"owns" it once you addModule
. This means it will take care of deleting and cleaning up.
在LLVM中,最好总是从示例中学习.我建议您看一下tools/lli/lli.cpp
的源代码,它可以完成所有需要的工作,包括清理工作.
In LLVM it's always best to learn from examples. I suggest you take a look at the source code of tools/lli/lli.cpp
, which does all of what you need, including cleanup.
这篇关于如何取消分配llvm :: module的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!