[clang] [Clang][OpenCL][AMDGPU] Allow a kernel to call another kernel (PR #115821)

John McCall via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 2 00:04:35 PST 2024


================
@@ -71,14 +71,19 @@ class GlobalDecl {
   GlobalDecl(const FunctionDecl *D, unsigned MVIndex = 0)
       : MultiVersionIndex(MVIndex) {
     if (!D->hasAttr<CUDAGlobalAttr>()) {
+      if (D->hasAttr<OpenCLKernelAttr>()) {
+        Value.setPointerAndInt(D, unsigned(KernelReferenceKind::Kernel));
+        return;
+      }
----------------
rjmccall wrote:

It looks like there's new commonality between OpenCL and CUDA kernels, and this feels like a generalizable feature.  Please add a method to `FunctionDecl` (and, looking at the rest of the patch, also `FunctionTemplateDecl`?) named something like `isReferenceableKernel()` that checks for either of these two attributes.  Most of the diffs in this patch should end up just changing various bits of existing code that check specifically for `CUDAGlobalAttr` to call that method instead.

For this change specifically, you'll want to make sure that `getDefaultKernelReference` does the right thing for OpenCL kernels.

https://github.com/llvm/llvm-project/pull/115821


More information about the cfe-commits mailing list