Clang for source level loop transformation

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Clang for source level loop transformation

Zheng Wang
Hello,

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.

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.

If anyone can point out whether there is an example that I can refer to, it will be fantastic.

Thanks!

Cheers,
Zheng


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Clang for source level loop transformation

Douglas Gregor

On Apr 6, 2011, at 7:05 AM, Zheng Wang wrote:

> Hello,
>
> 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.

I don't know of any related examples.

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev