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

Aniket Lal via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 4 02:13:59 PST 2024


================
@@ -1085,8 +1085,10 @@ llvm::Value *CodeGenFunction::EmitBlockLiteral(const CGBlockInfo &blockInfo) {
       blockAddr.getPointer(), ConvertType(blockInfo.getBlockExpr()->getType()));
 
   if (IsOpenCL) {
-    CGM.getOpenCLRuntime().recordBlockInfo(blockInfo.BlockExpression, InvokeFn,
-                                           result, blockInfo.StructureType);
+    CGM.getOpenCLRuntime().recordBlockInfo(
+        blockInfo.BlockExpression, InvokeFn, result, blockInfo.StructureType,
+        CurGD && CurGD.isDeclOpenCLKernel() &&
+            (CurGD.getKernelReferenceKind() == KernelReferenceKind::Kernel));
----------------
lalaniket8 wrote:

> a kernel to kernel function call is replaced by a kernel to stub to kernel call 

Calls to kernel (from device and kernel functions) is not supported during backend IselLowering : https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp#L1127
So, we can't have a stub calling a kernel go into the backend.
In-lining the callee kernel body into the stub function might not be helpful in cases where callee kernel is just a function declaration.

> kernel is emitted first and then directly cloning the kernel body into the stub

> emit kernels by emitting the stub and then directly cloning the function body into the kernel

Some doubts on these points: Wouldn't this also result in having two copies of the kernel body ? Would this avoid the problems we see during double emission ?

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


More information about the cfe-commits mailing list