[all-commits] [llvm/llvm-project] 2db838: [HLSL] Implement default constant buffer $Globals ...

Helena Kotas via All-commits all-commits at lists.llvm.org
Tue Feb 25 16:57:28 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2db8386867c5083980ff00bf2eae8937457ab9da
      https://github.com/llvm/llvm-project/commit/2db8386867c5083980ff00bf2eae8937457ab9da
  Author: Helena Kotas <hekotas at microsoft.com>
  Date:   2025-02-25 (Tue, 25 Feb 2025)

  Changed paths:
    M clang/include/clang/AST/Decl.h
    M clang/include/clang/Sema/SemaHLSL.h
    M clang/lib/AST/Decl.cpp
    M clang/lib/CodeGen/CGHLSLRuntime.cpp
    M clang/lib/CodeGen/CodeGenModule.cpp
    M clang/lib/Sema/Sema.cpp
    M clang/lib/Sema/SemaHLSL.cpp
    A clang/test/AST/HLSL/default_cbuffer.hlsl
    M clang/test/CodeGenHLSL/basic_types.hlsl
    A clang/test/CodeGenHLSL/default_cbuffer.hlsl

  Log Message:
  -----------
  [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.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list