[llvm-branch-commits] [clang] [HLSL] Introduce address space `hlsl_constant(2)` for constant buffer declarations (PR #123411)
Helena Kotas via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Jan 21 11:52:07 PST 2025
================
@@ -455,14 +456,22 @@ void createHostLayoutStructForBuffer(Sema &S, HLSLBufferDecl *BufDecl) {
LS->setImplicit(true);
LS->startDefinition();
- for (const Decl *D : BufDecl->decls()) {
- const VarDecl *VD = dyn_cast<VarDecl>(D);
+ for (Decl *D : BufDecl->decls()) {
+ VarDecl *VD = dyn_cast<VarDecl>(D);
if (!VD || VD->getStorageClass() == SC_Static)
continue;
const Type *Ty = VD->getType()->getUnqualifiedDesugaredType();
if (FieldDecl *FD = createFieldForHostLayoutStruct(
- S, Ty, VD->getIdentifier(), LS, BufDecl))
+ S, Ty, VD->getIdentifier(), LS, BufDecl)) {
+ // add the field decl to the layout struct
LS->addDecl(FD);
+ // update address space of the original decl to hlsl_constant
+ // and disable initialization
+ QualType NewTy =
+ AST.getAddrSpaceQualType(VD->getType(), LangAS::hlsl_constant);
+ VD->setType(NewTy);
+ VD->setInit(nullptr);
----------------
hekota wrote:
If we need to preserve the initializers in the AST even though they are not used, we could mark the generated global variable as `externally_initialized`. The global gets removed in the final DXIL after all.
https://github.com/llvm/llvm-project/pull/123411
More information about the llvm-branch-commits
mailing list