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

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 9 05:43:42 PDT 2025


yxsamliu wrote:

> @lalaniket8 @arsenm I don't have a strong opinion, but shouldn't this transformation be done during lowering to the target? Current version of the patch brings odd behavior for LLVM IR to SPIR-V lowering for OpenCL kernels. SPIR-V don't allow one EntryPoint to refer another EntryPoint, so during such lowering the translator moves kernel's body to impl function (just like this patch does). Together they result in quite odd behavior: [KhronosGroup/SPIRV-LLVM-Translator#3115](https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/3115)

My understanding is that for most targets kernel and non-kernel functions have different calling conventions which affects how struct-type arguments are passed. Allowing kernel functions callable in IR could cause issues in mid-end, that is why for any kernel a non-kernel `__clang_ocl_kern_imp*` function is created and used where the kernel function is called. This is necessary to have the proper IR.

For LLVM/SPIRV translator, this change should be transparent. `__clang_ocl_kern_imp*` should behave like a common non-kernel function called by a kernel function.

@arsenm

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


More information about the cfe-commits mailing list