[clang] [llvm] [SPIRV][Offload] Implement `DynSharedMemory` for L0 (PR #231160)

Tom Honermann via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 24 17:11:56 PST 2026


================
@@ -0,0 +1,272 @@
+//===- SPIRVLowerDynamicLocalMemory.cpp - Lower dynamic local memory ------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Dynamic local memory, i.e. an unsized external Workgroup array such as
+// CUDA's `extern __shared__ T Buf[]`, has a size only known at launch. OpenCL
+// and Level Zero runtimes cannot specify the size of such an array and instead
+// they rely on `ptr addrspace(3)` kernel arguments to provide such memory.
+//
+// This pass appends a `ptr addrspace(3)` parameter to every kernel of a module
+// referencing dynamic local memory. Each kernel stores the parameter into an
+// internal Workgroup variable on entry, and every use of the dynamic local
+// memory is replaced with a load of that variable. All declarations of dynamic
+// local memory alias the same memory, as in CUDA.
----------------
tahonermann wrote:

I agree with @blazej-smorawski. We don't have a way to do the necessary transformation in the AST because the full offload kernel entry point isn't represented there. `SYCLKernelCallStmt` holds an outlined version of the entry point that is target independent (and maintains the same representation for host and device compilations). If the frontend were to handle this, it would have to be in code generation where it would be target dependent anyway (because CUDA and HIP have different requirements relative to OpenCL and Level Zero). This PR handles the transformations in a nicely self-contained way; no code elsewhere needs to be aware of it.

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


More information about the cfe-commits mailing list