> I would like to use clang to build a source level tool that generates OpenCL code.
> Basically, the idea is that given an annotation of a loop, the tool can convert the loop to an OpenCL kernel.
> For example, a C program with an pragma annotation will look like:
> #pragma opencl parallel for private(v1, v2)
> for (...)
> and the tool will read the source code in, parse the source and generate an OpenCL kernel as a C-like program.
You'd have to extend Clang to parse that pragma and attach that information to the loop.
> I am wondering whether the CLANG AST can keep information about the loop, such as the loop index, the loop boundary, and statements of the loop body?
> I don't know whether I need to go into the LLVM bitcode level to retrieve such information. However, I generally don't want to go to such a low level.
Clang's AST keeps lots of source information, from which you can extract information about the loop as it was written. However, all of the loop analysis (finding induction variables and such) is done at the LLVM IR level, so either you need to deal with LLVM IR or you need to re-implement some of that loop analysis on the Clang AST itself.
> If anyone can point out whether there is an example that I can refer to, it will be fantastic.