[clang] [SPIR-V] Add hlsl_private address space for HLSL/SPIR-V (PR #122103)

Nathan Gauër via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 15 05:03:52 PST 2025


================
@@ -5362,6 +5362,23 @@ LangAS CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D) {
     if (OpenMPRuntime->hasAllocateAttributeForGlobalVar(D, AS))
       return AS;
   }
+
+  if (LangOpts.HLSL) {
+    if (D == nullptr)
+      return LangAS::hlsl_private;
+
+    // Except resources (Uniform, UniformConstant) & instanglble (handles)
+    if (D->getType()->isHLSLResourceType() ||
+        D->getType()->isHLSLIntangibleType())
+      return D->getType().getAddressSpace();
+
+    if (D->getStorageClass() != SC_Static)
+      return D->getType().getAddressSpace();
+
+    LangAS AS = D->getType().getAddressSpace();
+    return AS == LangAS::Default ? LangAS::hlsl_private : AS;
+  }
+
----------------
Keenuts wrote:

I recall having tried this method first, but for some reasons moved it to Codegen, but I don't recall the full context.

I just tried moving it in sema again, and seems there is a slight issue with `this-reference-template.hlsl` since the VarDecl type is from a template, something goes wrong (but works if the AS fixup is done in codegen).

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


More information about the cfe-commits mailing list