[英]LLVM: Retrieving the value of constant function parameters from the C++ API
我正在使用LLVM API编写一些代码。 我正在使用llvm :: CallGraph对象遍历由父函数调用的所有子函数:
CallGraph cg( *mod );
for( auto i = cg.begin(); i != cg.end(); ++i )
{
const Function *parent = i->first;
if( !parent )
continue;
for( auto j = i->second->begin(); j != i->second->end(); ++j )
{
Function *child = j->second->getFunction();
if( !child )
continue;
for( auto iarg = child->arg_begin(); iarg != child->arg_end(); ++iarg )
{
// Print values here!
}
}
o.flush();
我感兴趣的IR中的实际函数调用如下所示:
call void @_ZN3abc3FooC1Ejjj(%"struct.abc::Foo"* %5, i32 4, i32 2, i32 0)
而我想做的就是检索最后三个常量整数值:4、2、0。如果我也可以检索%5,则可以得到加分,但这并不重要。 我已经花了大约两个小时盯着http://llvm.org/docs/doxygen/,但是我根本无法弄清楚应该如何得出这三个值。
在第二个循环中,当遍历CallGraphNode
,您将返回std::pair<WeakVH, CallGraphNode*>
实例。 WeakVH
代表调用指令,而CallGraphNode*
代表被调用函数。 您所拥有的代码的问题在于,您正在查看被调用的函数并遍历其定义中的形式参数,而不是查看调用站点。 您想要的是这样的东西(nb我还没有测试过,只是去除了签名):
CallGraph cg( *mod );
for( auto i = cg.begin(); i != cg.end(); ++i )
{
for( auto j = i->second->begin(); j != i->second->end(); ++j )
{
CallSite CS(*j->first);
for (auto arg = CS.arg_begin(); arg != CS.arg_end(); ++arg) {
// Print values here!
}
}
o.flush();
从那里可以找到代表参数的Value*
指针,检查它们是否为ConstantInt
,等等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.