diff options
author | Helena Kotas <hekotas@microsoft.com> | 2025-08-18 18:20:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-08-18 18:20:46 -0700 |
commit | eb3d88423d412ef41ef343b96c274ab4699f3729 (patch) | |
tree | 347f7a27fc4859013d01c3f7d4692ffdc8fe2082 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 0c512f78971eb0e34541ee5ab51a89a52cd32f67 (diff) | |
download | llvm-eb3d88423d412ef41ef343b96c274ab4699f3729.zip llvm-eb3d88423d412ef41ef343b96c274ab4699f3729.tar.gz llvm-eb3d88423d412ef41ef343b96c274ab4699f3729.tar.bz2 |
[HLSL] Global resource arrays element access (#152454)
Adds support for accessing individual resources from fixed-size global resource arrays.
Design proposal:
https://github.com/llvm/wg-hlsl/blob/main/proposals/0028-resource-arrays.md
Enables indexing into globally scoped, fixed-size resource arrays to retrieve individual resources. The initialization logic is primarily handled during codegen. When a global resource array is indexed, the
codegen translates the `ArraySubscriptExpr` AST node into a constructor call for the corresponding resource record type and binding.
To support this behavior, Sema needs to ensure that:
- The constructor for the specific resource type is instantiated.
- An implicit binding attribute is added to resource arrays that lack explicit bindings (#152452).
Closes #145424
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 4146876..677d8bc 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -5796,11 +5796,16 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, (D->getType()->isCUDADeviceBuiltinSurfaceType() || D->getType()->isCUDADeviceBuiltinTextureType()); if (getLangOpts().CUDA && - (IsCUDASharedVar || IsCUDAShadowVar || IsCUDADeviceShadowVar)) + (IsCUDASharedVar || IsCUDAShadowVar || IsCUDADeviceShadowVar)) { Init = llvm::UndefValue::get(getTypes().ConvertTypeForMem(ASTTy)); - else if (D->hasAttr<LoaderUninitializedAttr>()) + } else if (getLangOpts().HLSL && + (D->getType()->isHLSLResourceRecord() || + D->getType()->isHLSLResourceRecordArray())) { + Init = llvm::PoisonValue::get(getTypes().ConvertType(ASTTy)); + NeedsGlobalCtor = D->getType()->isHLSLResourceRecord(); + } else if (D->hasAttr<LoaderUninitializedAttr>()) { Init = llvm::UndefValue::get(getTypes().ConvertTypeForMem(ASTTy)); - else if (!InitExpr) { + } else if (!InitExpr) { // This is a tentative definition; tentative definitions are // implicitly initialized with { 0 }. // @@ -5821,11 +5826,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, if (D->getType()->isReferenceType()) T = D->getType(); - if (getLangOpts().HLSL && - D->getType().getTypePtr()->isHLSLResourceRecord()) { - Init = llvm::PoisonValue::get(getTypes().ConvertType(ASTTy)); - NeedsGlobalCtor = true; - } else if (getLangOpts().CPlusPlus) { + if (getLangOpts().CPlusPlus) { Init = EmitNullConstant(T); if (!IsDefinitionAvailableExternally) NeedsGlobalCtor = true; |