LLVM、CLang 和 LLC 优化过程
我正在实现 LLVM 的新后端,从 CBackend 目标开始。 最终目标是使用“llc”生成输入 C 代码的源转换。 然而,我想做一些优化,但在这种情况下它们似乎没有得到很好的支持。 LLVM 目标代码的级别非常低,我必须检查它才能重新发现实际发生的情况。这在 AST 级别上会简单得多。 然而,AST 级别似乎是 Clang 内部构造,并且没有简单的方法可以插入它。
我是否必须自己检查 LLVM 目标代码并对更高级别的流程进行逆向工程? (每个后端都必须这样做吗?这看起来很浪费!)
I'm implementing a new back-end to LLVM, starting with the CBackend target.
The end goal is to use "llc" to generate source transforms of input C code.
However, there are a number of optimizations I'd like to make, which don't seem to be very well supported within this context.
The LLVM object code is very low level, and I have to inspect it to re-discover what's actually going on. This would be a lot simpler to do at the AST level.
However, it appears that the AST level is a Clang-internal construct, and there's no easy way to plug into this.
Do I have to inspect the LLVM object code and reverse-engineer the higher-level flow myself? (Does each back-end have to do this? That seems wasteful!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,你无法对一切进行逆向工程。所以,你只有两种可能性:
但实际上,您不应该在 LLVM IR 级别上进行任何源到源的转换,对于给定的目标来说,这是一个错误的工具。您肯定可以插入 AST 级别。例如,clang 源包含一个重写器,可以将 ObjC 代码转换为纯 C 代码。
In general, you cannot reverse-engineer everything. So, you have only two possibilities:
But really, you shouldn't do any source-to-source transform on LLVM IR level, it's a wrong tool for a given target. You can surely plug to AST level. E.g. clang sources contains a rewriter which turns ObjC code into plain C.