LLVM通行证可靠地使用InlineFuncon
我有一个输入比特代码文件无法修改。说我正在查看特定功能foo
。我想插入 all foo()
make> make:bar() - > baz()
和fez()
等等。也就是说,我希望结果输出在foo()
中没有呼叫指令。我如何编写 可靠 的LLVM通过?
我查看了描述的解决方案在这里。我编写了一个模块台词,该模块在模块中首先收集所有callInst
s,然后在它们上调用inlineFunction()
。
/* callInstVector contains all CallInsts in foo() */
for (CallInst *ci : callInstVector) {
CallBase *cb = dyn_cast<CallBase>(ci);
if (cb->getParent() && cb->getFunction()){
InlineFunctionInfo ifi;
auto res = llvm::InlineFunction(*cb, ifi);
outs() << res.isSuccess() << "\n";
}
}
假设所有所谓的函数在模块中都有一个定义,则这种模式似乎可以工作。
- 是否保证这种方法可以有效地内联
foo()
中的所有功能调用? inlineFunction()
的结果的成功/失败取决于什么?- 这是解决这个问题还是有其他选择的正确方法?
I have an input bitcode file cannot be modified. Say I am looking at a particular function foo
. I want to inline all the calls that foo()
makes: bar() -> baz()
and fez()
and several more. That is, I want the resulting output to have no call instructions in foo()
. How do I write an LLVM pass that reliably does this function inlining?
I looked at the solution described here. I wrote a ModulePass which first collects all CallInst
s in the module and then calls InlineFunction()
on them.
/* callInstVector contains all CallInsts in foo() */
for (CallInst *ci : callInstVector) {
CallBase *cb = dyn_cast<CallBase>(ci);
if (cb->getParent() && cb->getFunction()){
InlineFunctionInfo ifi;
auto res = llvm::InlineFunction(*cb, ifi);
outs() << res.isSuccess() << "\n";
}
}
This pattern seems to work, assuming all the called functions have a definition in the module.
- Is it guaranteed that such an approach could effectively inline all function calls in
foo()
? - What does the success/failure of
InlineFunction()
's result depend upon? - Is this the correct way to go about this or are any alternatives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种替代性,更可靠的方法是将
ewaysInline
属性添加到该功能,然后依靠LLVM Inliner来处理为您处理内部的复杂性。An alternative and more reliable way would be to add the
alwaysinline
attribute to the function, and then rely on the LLVM Inliner to handle the complexities of inlining for you.