获取 LLVM 模块中的所有值

Getting all Values in LLVM Module

本文关键字:LLVM 模块 获取      更新时间:2023-10-16

我正在处理分析过程,我需要在模块中找到所有InlineAsm值。

我尝试使用Module::getValueSymbolTable()但它看起来只包含全局和函数符号。

我还尝试为模块中的每个函数调用Function::getValueSymbolTable(),但文档不清楚它包含哪些符号,并且似乎仍然缺少我正在寻找的InlineAsm值。

仅供参考,我目前的(非工作(方法是这样的:

llvm::Module M = ...;
auto &MS = M.getValueSymbolTable();
for (auto it = MS.begin(), end = MS.end(); it != end; ++it) {
if (isa<InlineAsm>(it->second)) {
// do something
}
}
for (auto &F : M) {
auto FS = F.getValueSymbolTable();
for (auto it = FS->begin(), end = FS->end(); it != end; ++it) {
if (isa<InlineAsm>(it->second)) {
// do something
}
}
}

如何获取 llvm 模块上的所有值?

我假设您需要收集所有内联指令(而不是模块级内联汇编器节点(。为此,您需要遍历模块的所有函数。在函数中,您需要遍历所有指令,检查所讨论的指令是否代表InlineAsm指令。像 http://llvm.org/docs/ProgrammersManual.html#iterating-over-the-instruction-in-a-function 这样的东西会有所帮助。