[cfe-dev] OpenCL support
Anton Lokhmotov
Anton.Lokhmotov at arm.com
Thu Jan 27 09:16:53 PST 2011
We have updated the patch and added couple of test cases. We trust it can
be accepted now?
Thanks,
Anton.
> -----Original Message-----
> From: Anton Lokhmotov [mailto:Anton.Lokhmotov at arm.com]
> Sent: 19 January 2011 16:02
> To: 'Chris Lattner'
> Cc: 'Peter Collingbourne'; cfe-dev at cs.uiuc.edu
> Subject: RE: [cfe-dev] OpenCL support
>
> Hi Chris and Peter,
>
> Many thanks for your comments. We agree with everything (a revised
> patch attached) but this:
>
> > Why define these as keywords in the language? OpenCL requires an
> > implicit prefix header to be included (which has all the conversion
> > functions and a bunch of other stuff). It seems cleaner to just put
> a
> > #define in this header that defines __kernel to expand to an
> attribute.
>
> Initially, we indeed implemented "kernel" and "__kernel" in this way:
>
> #define __kernel __attribute__((opencl_kernel_function))
> #define kernel __kernel
>
> The OpenCL specification, however, requires them to be keywords in the
> language (section 6.1.9). This means that the frontend must report if
> these are used in an invalid context.
>
>
> For example, if we define:
>
> #define fakekernel __attribute__((opencl_kernel_function))
>
> and the programmer uses it in a valid context:
>
> fakekernel void fk() {}
> void fakekernel fk2() {}
>
> the net result is the same as if the programmer writes:
>
> kernel void k() {}
> void kernel k2() {}
>
>
> Here are couple of invalid examples and the compiler's response in each
> case:
>
> 1) The kernel function qualifier is used between the function name and
> the function body.
>
> - macro implementation
> fakekernel_2.cl:2:22: error: expected ';' after top level declarator
> void fk() fakekernel {}
> ^
> - keyword implementation
> kernel_2.cl:1:10: error: expected function body after function
> declarator
> void k() kernel {}
> ^
> The keyword implementation results in a precise error message.
>
>
> 2) The kernel function qualifier is used instead of the function name.
>
> - macro implementation
> fakekernel_3.cl:2:17: error: expected identifier or '('
> void fakekernel() {}
> ^
> - keyword implementation
> kernel_3.cl:1:13: error: expected identifier or '('
> void kernel() {}
> ^
> The error messages are (confusingly) the same.
>
>
> 3) The kernel function qualifier is used as the name of a variable.
>
> - macro implementation
> int_fakekernel.cl:2:1: warning: declaration does not declare anything
> int fakekernel;
> ^~~
>
> - keyword implementation
> int_kernel.cl:1:1: warning: declaration does not declare anything
> int kernel;
> ^~~~~~~~~~
>
> Again, the error messages are the same. Syntax highlighting, however,
> differs. The keyword implementation behaves similar to most other C99
> keywords, e.g. "register":
>
> - register
> int_register.cl:1:1: warning: declaration does not declare anything
> int register;
> ^~~~~~~~~~~~
>
> [
> Slightly confusingly, for some other keywords in this context the error
> messages differ, e.g. "while", "for", "return":
>
> - while
> int_while.cl:1:5: error: expected identifier or '('
> int while = 0;
> ^
> ]
>
>
> In summary, we believe that qualifiers that are defined in the
> specification as keywords must be implemented as Clang keywords, even
> if an alternative implementation is possible. In that way, error
> messages can be improved and behaviour will be consistent with other
> keywords.
>
> Cheers,
> Anton.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 00001-kernel-extensions-pragmas.patch
Type: application/octet-stream
Size: 15729 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110127/2aafbc62/attachment.obj>
More information about the cfe-dev
mailing list