Anastasia added a comment.

In D60455#1468386 <>, @Fznamznon wrote:

> In D60455#1467018 <>, @Anastasia wrote:
> > Just to understand how this will work. I would imagine you can have a 
> > device function definition preceding its use. When the function is being 
> > parsed it's not known yet whether it will be called from the device or not, 
> > so it won't be possible to set the language mode correctly and hence 
> > provide the right diagnostics. So is the plan to launch a separate parsing 
> > phase then just to extract the call graph and annotate the device functions?
> I'm not an expert in clang terminology but I will try briefly explain our 
> current implementation approach. 
>  In SYCL all kernel functions should be template functions so these functions 
> have a deferred instantiation. If we found that we instantiated a sycl kernel 
> function - we add it to a special array with sycl device functions (you can 
> see the corresponding code here 
> <>
>  and here 
> <>,
>  actually `AddSyclKernel` adds declaration to the special array inside the 
> Sema).  After performing
>  pending instantiations we run a recursive AST visitor for each SYCL kernel 
> to mark all device functions and add them to a special array with SYCL device 
> functions (here 
> <>
>  we start traverse AST from `MarkDevice` function, code of `MarkDevice` is 
> here 
> <>).
>  To get a correct set of SYCL device functions in produced module we added a 
> check for all declarations inside the CodeGen on  `sycl_device` attribute 
> existence - so it will ignore declarations without `sycl_device` attribute if 
> we are compiling for SYCL device (code is here 
> <>).
>  But with this check it's possible situation when function was parsed and 
> ignored by the CodeGen before we added `sycl_device` attribute to it so we 
> added yet another parsing action inside the `clang::ParseAST` to generate 
> code for all SYCL device functions from the special array (code is here 
> <>).

Thanks for explanation! I would need to spend a bit more time to go through the 
pointers you have provided. Btw just to understand whether the use case with 
externally defined device side functions is covered too? I.e. can you have 
something like this:

  extern void foo();
  [clang::sycl_kernel]] void bar() {

When `foo` is defined in a separate module that doesn't call it on a device side

  void foo() {

would compiler still be able to detect that this is a device function?

  rG LLVM Github Monorepo


cfe-commits mailing list

Reply via email to