LLVM Source-to-Source transformation

Hi,

I plan to use LLVM for some compiler transformation.

My requirement is that I require a source to source transformation. I need
to parse the given program and look for loops. Then I need to create
another source file where I can use this source information like the
iteration bounds and the loop body into the new file. I was looking at the
LoopExtract pass in LLVM passes. However, it enables to extract only loop
body. I need some more information like variables used and array dimension
in loop body and convert it to source level.
Can this be done using llvm? Can I get some pointers on this.

My problem can be analogous viewed as adding OpenMP pragmas for auto
parallelization.

Regarsd,
Kamal

There are two routes you can take here:

1. You can do this in clang as a source to source transformation. The good thing about this is that it makes it very trivial to do thing at the C level of for loops etc, and makes it really easy to rewrite the source. OTOH, clang doesn't have as much analysis infrastructure as the LLVM level, and it doesn't support C++ yet.

2. You can do this at the LLVM level, which gives you a lot of analysis and transformation tools. However, it doesn't give you a good way to pretty print back source code. You can get "working" C code, but it is hideously ugly, not something you want to look at.

-Chris