Jon Watte
Jon Watte

Reputation: 7228

LLVM, CLang and LLC optimization pass

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!)

Upvotes: 4

Views: 1972

Answers (1)

Anton Korobeynikov
Anton Korobeynikov

Reputation: 9324

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.

Upvotes: 6

Related Questions