开发者

LLVM, CLang and LLC optimization pass

开发者 https://www.devze.com 2023-02-14 21:36 出处:网络
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.

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 go开发者_如何学运维ing 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!)


In general, you cannot reverse-engineer everything. So, you have only two possibilities:

  1. Do everything on clang AST level.
  2. Emit additional information (e.g. via metadata) which might help you to recover some aspects of the input source.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消