OpenCl Built-in function declaration

Hi,

i'm trying to use Clang to generate the AST of an OpenCL kernel, to then
parse it and get some statistics about it (e.g. the number of floating
additions).

I'm using Clang the following way: clang -cc1 -ast-dump -x cl "Kernel file"

"Kernel ast"

The point in here is that clang doesn't recognize OpenCl built-in functions,
functions such as "get_local_id()" give implicit declaration error. My
question is if there is any file where all these functions are defined.

I've searched along the mailing list and the most similar solution to my
problem i've found is in:
http://lists.cs.uiuc.edu/pipermail/cfe-dev/2011-October/017800.html

The ocldef.h file done by Speziale Ettore contains several definitions for
built-in functions
generated by TableGen as described in the post.
This file doesn't include all the functions in the OpenCl specification
Section 6, just some done by hand with TableGen, so i don't know if the only
solution is to complete this file or there is some
header file with all the declarations.

Thanks in advice.

Hi,

The ocldef.h file done by Speziale Ettore contains several definitions for
built-in functions
generated by TableGen as described in the post.
This file doesn't include all the functions in the OpenCl specification
Section 6, just some done by hand with TableGen, so i don't know if the only
solution is to complete this file or there is some
header file with all the declarations.

You should use libclc:

http://libclc.llvm.org/

Bye,
speziale.ettore@gmail.com

You can also look at libclc, which is a project aimed to become a
standard library implementation for OpenCL C. libclc is nowhere
near finished but it covers many commonly used functions, and you
are welcome to contribute more.

http://libclc.llvm.org/

The compile-test.sh script in the root directory shows you how to
compile a source file using libclc for the ptx32 target. Since you
are only collecting statistics it shouldn't matter much which target
you use, so ptx32 should be fine.

Thanks,

Hi,

i just tried libclc and it contains several definitions that could be useful for my goal,
although it doesn’t contain the whole OpenCL spec. Maybe i will have to add
some functions but it works for me now.

Thanks.

2012/3/6 Peter Collingbourne <peter@pcc.me.uk>