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

Helena Kotas via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 14 13:30:25 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;
+  }
+
----------------
hekota wrote:

Have you considered applying the `hlsl_private` address space in the Sema (SemaHLSL::ActOnVariableDeclarator handler) onto the VarDecl QualType?

FYI, I am currently looking into adding `hlsl_constant` address space to be used for constant buffer declarations and this is probably the place where I'll add it.

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


More information about the cfe-commits mailing list