aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorHelena Kotas <hekotas@microsoft.com>2025-02-25 16:57:07 -0800
committerGitHub <noreply@github.com>2025-02-25 16:57:07 -0800
commit2db8386867c5083980ff00bf2eae8937457ab9da (patch)
tree23b8dfc7c31256f48eeedd167b748a1d746e8c04 /clang/lib/CodeGen/CodeGenModule.cpp
parentcd4c30bb224e432d8cd37f375c138cbaada14f6c (diff)
downloadllvm-2db8386867c5083980ff00bf2eae8937457ab9da.zip
llvm-2db8386867c5083980ff00bf2eae8937457ab9da.tar.gz
llvm-2db8386867c5083980ff00bf2eae8937457ab9da.tar.bz2
[HLSL] Implement default constant buffer $Globals (2nd attempt) (#128589)
All variable declarations in the global scope that are not resources, static or empty are implicitly added to implicit constant buffer `$Globals`. They are created in `hlsl_constant` address space and collected in an implicit `HLSLBufferDecl` node that is added to the AST at the end of the translation unit. Codegen is the same as for explicit constant buffers. Fixes #123801 This is a second attempt to implement this feature. The first attempt had to be reverted because of memory leaks. The problem was adding a `SmallVector` member on `HLSLBufferDecl` node to represent a list of default buffer declarations. When this vector needed to grow, it allocated memory that was never released, because all memory used by AST nodes must be allocated by `ASTContext` allocator and is released all at once. Destructors on AST nodes are never called. It this change the list of default buffer declarations is collected in a `SmallVector` instance on `SemaHLSL`. The `HLSLBufDecl` representing `$Globals` is created at the end of the translation unit when the number of declarations is known, and the list is copied into an array allocated by the `ASTContext` allocator.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 7924c32..1b7d0ac 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5513,6 +5513,11 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
if (getLangOpts().OpenCL && ASTTy->isSamplerT())
return;
+ // HLSL default buffer constants will be emitted during HLSLBufferDecl codegen
+ if (getLangOpts().HLSL &&
+ D->getType().getAddressSpace() == LangAS::hlsl_constant)
+ return;
+
// If this is OpenMP device, check if it is legal to emit this global
// normally.
if (LangOpts.OpenMPIsTargetDevice && OpenMPRuntime &&