Justin Bogner 3de88fe40f
[DirectX] Implement the DXILCBufferAccess pass (#134571)
This introduces a pass that walks accesses to globals in cbuffers and
replaces them with accesses via the cbuffer handle itself. The logic to
interpret the cbuffer metadata is kept in `lib/Frontend/HLSL` so that it
can be reused by other consumers of that metadata.

Fixes #124630.
2025-04-15 22:33:27 -07:00

26 lines
948 B
LLVM

; RUN: opt -S -dxil-cbuffer-access -mtriple=dxil--shadermodel6.3-library %s | FileCheck %s
%__cblayout_CB = type <{ float }>
@CB.cb = local_unnamed_addr global target("dx.CBuffer", target("dx.Layout", %__cblayout_CB, 4, 0)) poison
; CHECK: @CB.cb =
; CHECK-NOT: external {{.*}} addrspace(2) global
@x = external local_unnamed_addr addrspace(2) global float, align 4
; CHECK: define void @f
define void @f(ptr %dst) {
entry:
; CHECK: [[CB:%.*]] = load target("dx.CBuffer", {{.*}})), ptr @CB.cb
; CHECK: [[LOAD:%.*]] = call { float, float, float, float } @llvm.dx.resource.load.cbufferrow.4.{{.*}}(target("dx.CBuffer", {{.*}})) [[CB]], i32 0)
; CHECK: [[X:%.*]] = extractvalue { float, float, float, float } [[LOAD]], 0
; CHECK: store float [[X]], ptr %dst
%x = load float, ptr addrspace(2) @x, align 4
store float %x, ptr %dst, align 4
ret void
}
; CHECK-NOT: !hlsl.cbs =
!hlsl.cbs = !{!0}
!0 = !{ptr @CB.cb, ptr addrspace(2) @x}