LLVM通行证可靠地使用InlineFuncon

发布于 2025-01-31 18:29:36 字数 1029 浏览 3 评论 0原文

我有一个输入比特代码文件无法修改。说我正在查看特定功能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 CallInsts 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暮年 2025-02-07 18:29:36

一种替代性,更可靠的方法是将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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文