diff options
author | Helena Kotas <hekotas@microsoft.com> | 2025-01-24 16:48:35 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-24 16:48:35 -0800 |
commit | d92bac8a3ebb19106f6bca6b7613a27c52cb48ab (patch) | |
tree | 7b71bbc9369d73fe19c2ee0d0066c37f3d503376 /clang/lib/CodeGen/CGHLSLRuntime.cpp | |
parent | 1b4bd4e1a5120c8bb4daa44787a3bc4559b6b3b4 (diff) | |
download | llvm-d92bac8a3ebb19106f6bca6b7613a27c52cb48ab.zip llvm-d92bac8a3ebb19106f6bca6b7613a27c52cb48ab.tar.gz llvm-d92bac8a3ebb19106f6bca6b7613a27c52cb48ab.tar.bz2 |
[HLSL] Introduce address space `hlsl_constant(2)` for constant buffer declarations (#123411)
Introduces a new address space `hlsl_constant(2)` for constant buffer
declarations.
This address space is applied to declarations inside `cbuffer` block.
Later on, it will also be applied to `ConstantBuffer<T>` syntax and the
default `$Globals` constant buffer.
Clang codegen translates constant buffer declarations to global
variables and loads from `hlsl_constant(2)` address space. More work
coming soon will include addition of metadata that will map these
globals to individual constant buffers and enable their transformation
to appropriate constant buffer load intrinsics later on in an LLVM pass.
Fixes #123406
Diffstat (limited to 'clang/lib/CodeGen/CGHLSLRuntime.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGHLSLRuntime.cpp | 17 |
1 files changed, 1 insertions, 16 deletions
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 345e218..2ce54cc 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -100,22 +100,6 @@ GlobalVariable *replaceBuffer(CGHLSLRuntime::Buffer &Buf) { llvm::formatv("{0}{1}", Buf.Name, Buf.IsCBuffer ? ".cb." : ".tb."), GlobalValue::NotThreadLocal); - IRBuilder<> B(CBGV->getContext()); - Value *ZeroIdx = B.getInt32(0); - // Replace Const use with CB use. - for (auto &[GV, Offset] : Buf.Constants) { - Value *GEP = - B.CreateGEP(Buf.LayoutStruct, CBGV, {ZeroIdx, B.getInt32(Offset)}); - - assert(Buf.LayoutStruct->getElementType(Offset) == GV->getValueType() && - "constant type mismatch"); - - // Replace. - GV->replaceAllUsesWith(GEP); - // Erase GV. - GV->removeDeadConstantUsers(); - GV->eraseFromParent(); - } return CBGV; } @@ -144,6 +128,7 @@ void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) { } auto *GV = cast<GlobalVariable>(CGM.GetAddrOfGlobalVar(D)); + GV->setExternallyInitialized(true); // Add debug info for constVal. if (CGDebugInfo *DI = CGM.getModuleDebugInfo()) if (CGM.getCodeGenOpts().getDebugInfo() >= |