[clang] [llvm] [HLSL] Remove old resource annotations (PR #130338)

Helena Kotas via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 12 08:54:19 PDT 2025


https://github.com/hekota updated https://github.com/llvm/llvm-project/pull/130338

>From 99539251dcf58aab9a88973f9162156ae6f1aa77 Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Thu, 6 Mar 2025 18:22:07 -0800
Subject: [PATCH 1/3] [HLSL][NFC] Update resource metadata tests to not use
 obsolete metadata annotations

---
 clang/test/CodeGenHLSL/cbuffer.hlsl           |  78 +++++++++-
 .../DirectX/Metadata/cbuffer_metadata.ll      |  80 +++++++++++
 .../CodeGen/DirectX/Metadata/srv_metadata.ll  | 103 +++++++++++++
 .../CodeGen/DirectX/Metadata/uav_metadata.ll  | 135 ++++++++++++++++++
 llvm/test/CodeGen/DirectX/UAVMetadata.ll      |  77 ----------
 llvm/test/CodeGen/DirectX/cbuf.ll             |  37 -----
 .../CodeGen/DirectX/legacy_cb_layout_0.ll     |  14 --
 .../CodeGen/DirectX/legacy_cb_layout_1.ll     |  37 -----
 .../CodeGen/DirectX/legacy_cb_layout_2.ll     |  51 -------
 .../CodeGen/DirectX/legacy_cb_layout_3.ll     |  81 -----------
 10 files changed, 394 insertions(+), 299 deletions(-)
 create mode 100644 llvm/test/CodeGen/DirectX/Metadata/cbuffer_metadata.ll
 create mode 100644 llvm/test/CodeGen/DirectX/Metadata/srv_metadata.ll
 create mode 100644 llvm/test/CodeGen/DirectX/Metadata/uav_metadata.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/UAVMetadata.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/cbuf.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/legacy_cb_layout_0.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/legacy_cb_layout_1.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/legacy_cb_layout_2.ll
 delete mode 100644 llvm/test/CodeGen/DirectX/legacy_cb_layout_3.ll

diff --git a/clang/test/CodeGenHLSL/cbuffer.hlsl b/clang/test/CodeGenHLSL/cbuffer.hlsl
index 38093c6dfacd7..b5e435619438f 100644
--- a/clang/test/CodeGenHLSL/cbuffer.hlsl
+++ b/clang/test/CodeGenHLSL/cbuffer.hlsl
@@ -20,6 +20,14 @@
 // CHECK: %anon = type <{ float }>
 // CHECK: %anon.0 = type <{ <2 x i32> }>
 
+// CHECK: %__cblayout_CB_A = type <{ [2 x double], [3 x <3 x float>], float, [3 x double], half, [1 x <2 x double>], float, [2 x <3 x half>], <3 x half> }>
+// CHECK: %__cblayout_CB_B = type <{ [3 x <3 x double>], <3 x half> }>
+// CHECK: %__cblayout_CB_C = type <{ i32, target("dx.Layout", %F, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90), half, target("dx.Layout", %G, 258, 0, 48, 64, 256), double }>
+
+// CHECK: %F = type <{ double, <3 x float>, float, <3 x double>, half, <2 x double>, float, <3 x half>, <3 x half> }>
+// CHECK: %G = type <{ target("dx.Layout", %E, 36, 0, 8, 16, 20, 22, 24, 32), [1 x float], [2 x target("dx.Layout", %F, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90)], half }>
+// CHECK: %E = type <{ float, double, float, half, i16, i64, i32 }>
+
 cbuffer CBScalars : register(b1, space5) {
   float a1;
   double a2;
@@ -155,6 +163,64 @@ cbuffer CBMix {
     uint16_t f9;
 };  
 
+// CHECK: @CB_A.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB_A, 188, 0, 32, 76, 80, 120, 128, 144, 160, 182))
+
+cbuffer CB_A {
+  double B0[2];
+  float3 B1[3];
+  float B2;
+  double B3[3];
+  half B4;
+  double2 B5[1];
+  float B6;
+  half3 B7[2];
+  half3 B8;
+}
+
+// CHECK: @CB_B.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB_B, 94, 0, 88))
+cbuffer CB_B {
+  double3 B9[3];
+  half3 B10;
+}
+
+struct E {
+  float A0;
+  double A1;
+  float A2;
+  half A3;
+  int16_t A4;
+  int64_t A5;
+  int A6;
+};
+
+struct F {
+  double B0;
+  float3 B1;
+  float B2;
+  double3 B3;
+  half B4;
+  double2 B5;
+  float B6;
+  half3 B7;
+  half3 B8;
+};
+
+struct G {
+  E C0;
+  float C1[1];
+  F C2[2];
+  half C3;
+};
+
+// CHECK: @CB_C.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB_C, 400, 0, 16, 112, 128, 392))
+cbuffer CB_C {
+  int D0;
+  F D1;
+  half D2;
+  G D3;
+  double D4;
+}
+
 // CHECK: define internal void @_init_resource_CBScalars.cb()
 // CHECK-NEXT: entry:
 // CHECK-NEXT: %[[HANDLE1:.*]] = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CBScalars, 56, 0, 8, 16, 24, 32, 36, 40, 48))
@@ -171,7 +237,7 @@ RWBuffer<float> Buf;
 
 [numthreads(4,1,1)]
 void main() {
-  Buf[0] = a1 + b1.z + c1[2] + a.f1.y + f1;
+  Buf[0] = a1 + b1.z + c1[2] + a.f1.y + f1 + B1[0].x + B10.z + D1.B2;
 }
 
 // CHECK: define internal void @_GLOBAL__sub_I_cbuffer.hlsl()
@@ -179,7 +245,8 @@ void main() {
 // CHECK-NEXT: call void @_init_resource_CBScalars.cb()
 // CHECK-NEXT: call void @_init_resource_CBArrays.cb()
 
-// CHECK: !hlsl.cbs = !{![[CBSCALARS:[0-9]+]], ![[CBVECTORS:[0-9]+]], ![[CBARRAYS:[0-9]+]], ![[CBSTRUCTS:[0-9]+]], ![[CBMIX:[0-9]+]]}
+// CHECK: !hlsl.cbs = !{![[CBSCALARS:[0-9]+]], ![[CBVECTORS:[0-9]+]], ![[CBARRAYS:[0-9]+]], ![[CBSTRUCTS:[0-9]+]], ![[CBMIX:[0-9]+]],
+// CHECK-SAME: ![[CB_A:[0-9]+]], ![[CB_B:[0-9]+]], ![[CB_C:[0-9]+]]}
 
 // CHECK: ![[CBSCALARS]] = !{ptr @CBScalars.cb, ptr addrspace(2) @a1, ptr addrspace(2) @a2, ptr addrspace(2) @a3, ptr addrspace(2) @a4,
 // CHECK-SAME: ptr addrspace(2) @a5, ptr addrspace(2) @a6, ptr addrspace(2) @a7, ptr addrspace(2) @a8}
@@ -195,3 +262,10 @@ void main() {
 
 // CHECK: ![[CBMIX]] = !{ptr @CBMix.cb, ptr addrspace(2) @test, ptr addrspace(2) @f1, ptr addrspace(2) @f2, ptr addrspace(2) @f3,
 // CHECK-SAME: ptr addrspace(2) @f4, ptr addrspace(2) @f5, ptr addrspace(2) @f6, ptr addrspace(2) @f7, ptr addrspace(2) @f8, ptr addrspace(2) @f9}
+
+// CHECK: ![[CB_A]] = !{ptr @CB_A.cb, ptr addrspace(2) @B0, ptr addrspace(2) @B1, ptr addrspace(2) @B2, ptr addrspace(2) @B3, ptr addrspace(2) @B4,
+// CHECK-SAME: ptr addrspace(2) @B5, ptr addrspace(2) @B6, ptr addrspace(2) @B7, ptr addrspace(2) @B8}
+
+// CHECK: ![[CB_B]] = !{ptr @CB_B.cb, ptr addrspace(2) @B9, ptr addrspace(2) @B10}
+
+// CHECK: ![[CB_C]] = !{ptr @CB_C.cb, ptr addrspace(2) @D0, ptr addrspace(2) @D1, ptr addrspace(2) @D2, ptr addrspace(2) @D3, ptr addrspace(2) @D4}
diff --git a/llvm/test/CodeGen/DirectX/Metadata/cbuffer_metadata.ll b/llvm/test/CodeGen/DirectX/Metadata/cbuffer_metadata.ll
new file mode 100644
index 0000000000000..b3dda74bf8bbf
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/Metadata/cbuffer_metadata.ll
@@ -0,0 +1,80 @@
+; RUN: opt -S -dxil-translate-metadata < %s | FileCheck %s
+; RUN: opt -S --passes="dxil-pretty-printer" < %s 2>&1 | FileCheck %s --check-prefix=PRINT
+; RUN: llc %s --filetype=asm -o - < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,PRINT
+
+target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
+target triple = "dxil-pc-shadermodel6.6-compute"
+
+%__cblayout_CB1 = type <{ float, i32, double, <2 x i32> }>
+ at CB1.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB1, 24, 0, 4, 8, 16))
+
+%__cblayout_CB2 = type <{ float, double, float, half, i16, i64, i32 }>
+ at CB2.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB2, 36, 0, 8, 16, 20, 22, 24, 32))
+
+%__cblayout_CB3 = type <{ double, <3 x float>, float, <3 x double>, half, <2 x double>, float, <3 x half>, <3 x half> }>
+ at CB3.cb = external constant target("dx.CBuffer", target("dx.Layout", %__cblayout_CB3, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90))
+
+; PRINT:; Resource Bindings:
+; PRINT-NEXT:;
+; PRINT-NEXT:; Name                                 Type  Format         Dim      ID      HLSL Bind  Count
+; PRINT-NEXT:; ------------------------------ ---------- ------- ----------- ------- -------------- ------
+; PRINT-NEXT:;                                   cbuffer      NA          NA     CB0            cb0     1
+; PRINT-NEXT:;                                   cbuffer      NA          NA     CB1            cb1     1
+; PRINT-NEXT:;                                   cbuffer      NA          NA     CB2    cb5,space15     1
+
+define void @test() #0 {
+
+  ; cbuffer CB1 : register(b0) {
+  ;   float a;
+  ;   int b;
+  ;   double c;
+  ;   int2 d;
+  ; }
+  %CB1.cb_h = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB1, 24, 0, 4, 8, 16))
+            @llvm.dx.resource.handlefrombinding.tdx.CBuffer_tdx.Layout_s___cblayout_CB1s_24_0_4_8_16tt(
+                i32 0, i32 0, i32 1, i32 0, i1 false)
+  store target("dx.CBuffer", target("dx.Layout", %__cblayout_CB1, 24, 0, 4, 8, 16)) %CB1.cb_h, ptr @CB1.cb, align 4
+
+  ; cbuffer CB2 : register(b0) {
+  ;   float a;
+  ;   double b;
+  ;   float c;
+  ;   half d;
+  ;   uint16_t e;
+  ;   int64_t f;
+  ;   int g;
+  ;}
+
+  %CB2.cb_h = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB2, 36, 0, 8, 16, 20, 22, 24, 32))
+            @llvm.dx.resource.handlefrombinding.tdx.CBuffer_tdx.Layout_s___cblayout_CB2s_36_0_8_16_20_22_24_32tt(
+                i32 0, i32 1, i32 1, i32 0, i1 false)
+  store target("dx.CBuffer", target("dx.Layout", %__cblayout_CB2, 36, 0, 8, 16, 20, 22, 24, 32)) %CB2.cb_h, ptr @CB2.cb, align 4
+
+  ; cbuffer CB3 : register(b5) {
+  ;   double B0;
+  ;   float3 B1;
+  ;   float B2;
+  ;   double3 B3;
+  ;   half B4;
+  ;   double2 B5;
+  ;   float B6;
+  ;   half3 B7;
+  ;   half3 B8;
+  ; }
+  %CB3.cb_h = call target("dx.CBuffer", target("dx.Layout", %__cblayout_CB3, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90))
+            @llvm.dx.resource.handlefrombinding.tdx.CBuffer_tdx.Layout_s___cblayout_CB3s_96_0_16_28_32_56_64_80_84_90tt(
+                i32 15, i32 5, i32 1, i32 0, i1 false)
+  store target("dx.CBuffer", target("dx.Layout", %__cblayout_CB3, 96, 0, 16, 28, 32, 56, 64, 80, 84, 90)) %CB3.cb_h, ptr @CB3.cb, align 4
+
+  ret void
+}
+
+attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
+
+; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}
+
+; CHECK: [[ResList]] = !{null, null, [[CBList:[!][0-9]+]], null}
+; CHECK: [[CBList]] = !{![[CB1:[0-9]+]], ![[CB2:[0-9]+]], ![[CB3:[0-9]+]]}
+; CHECK: ![[CB1]] = !{i32 0, ptr @0, !"", i32 0, i32 0, i32 1, i32 24, null}
+; CHECK: ![[CB2]] = !{i32 1, ptr @1, !"", i32 0, i32 1, i32 1, i32 36, null}
+; CHECK: ![[CB3]] = !{i32 2, ptr @2, !"", i32 15, i32 5, i32 1, i32 96, null}
diff --git a/llvm/test/CodeGen/DirectX/Metadata/srv_metadata.ll b/llvm/test/CodeGen/DirectX/Metadata/srv_metadata.ll
new file mode 100644
index 0000000000000..e1344035e01a7
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/Metadata/srv_metadata.ll
@@ -0,0 +1,103 @@
+; RUN: opt -S -dxil-translate-metadata < %s | FileCheck %s
+; RUN: opt -S --passes="dxil-pretty-printer" < %s 2>&1 | FileCheck %s --check-prefix=PRINT
+; RUN: llc %s --filetype=asm -o - < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,PRINT
+
+target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
+target triple = "dxil-pc-shadermodel6.6-compute"
+
+%"class.hlsl::Buffer" = type { target("dx.TypedBuffer", <4 x half>, 0, 0, 0) }
+%"class.hlsl::Buffer.1" = type { target("dx.TypedBuffer", <2 x float>, 0, 0, 0) }
+%"class.hlsl::Buffer.2" = type { target("dx.TypedBuffer", double, 0, 0, 0) }
+%"class.hlsl::Buffer.3" = type { target("dx.TypedBuffer", i32, 0, 0, 1) }
+%"class.hlsl::ByteAddressBuffer" = type { target("dx.RawBuffer", i8, 0, 0) }
+%"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", i16, 0, 0) }
+%"class.hlsl::Buffer.4" = type { target("dx.TypedBuffer", i64, 0, 0, 0) }
+
+ at Zero = internal global %"class.hlsl::Buffer" poison, align 4
+ at One = internal global %"class.hlsl::Buffer.1" poison, align 4
+ at Two = internal global %"class.hlsl::Buffer.2" poison, align 4
+ at Three = internal global %"class.hlsl::Buffer.3" poison, align 4
+ at Four = internal global %"class.hlsl::ByteAddressBuffer" poison, align 4
+ at Five = internal global %"class.hlsl::StructuredBuffer" poison, align 4
+ at Six = internal global %"class.hlsl::Buffer.4" poison, align 4
+
+; PRINT:; Resource Bindings:
+; PRINT-NEXT:;
+; PRINT-NEXT:; Name                                 Type  Format         Dim      ID      HLSL Bind  Count
+; PRINT-NEXT:; ------------------------------ ---------- ------- ----------- ------- -------------- ------
+; PRINT-NEXT:;                                       SRV     f16         buf      T0             t0     1
+; PRINT-NEXT:;                                       SRV     f32         buf      T1             t1     1
+; PRINT-NEXT:;                                       SRV     f64         buf      T2             t2     1
+; PRINT-NEXT:;                                       SRV     i32         buf      T3             t3     1
+; PRINT-NEXT:;                                       SRV    byte         r/o      T4             t5     1
+; PRINT-NEXT:;                                       SRV  struct         r/o      T5             t6     1
+; PRINT-NEXT:;                                       SRV     u64         buf      T6     t10,space2     1
+
+define void @test() #0 {
+  ; RWBuffer<half4> Buf : register(u0)
+  %Zero_h = call target("dx.TypedBuffer", <4 x half>, 0, 0, 0)
+            @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_v4f16_0_0_0t(
+                  i32 0, i32 0, i32 1, i32 0, i1 false)
+  store target("dx.TypedBuffer", <4 x half>, 0, 0, 0) %Zero_h, ptr @Zero, align 4
+ 
+  ; RWBuffer<float4> Buf : register(u1)
+  %One_h = call target("dx.TypedBuffer", <2 x float>, 0, 0, 0)
+            @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_v2f32_0_0_0t(
+                  i32 0, i32 1, i32 1, i32 0, i1 false)
+  store target("dx.TypedBuffer", <2 x float>, 0, 0, 0) %One_h, ptr @One, align 4
+ 
+  ; RWBuffer<double> Two : register(u2);
+  %Two_h = call target("dx.TypedBuffer", double, 0, 0, 0)
+            @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f64_0_0_0t(
+                  i32 0, i32 2, i32 1, i32 0, i1 false)
+  store target("dx.TypedBuffer", double, 0, 0, 0) %Two_h, ptr @Two, align 4
+
+  ; RWBuffer<int4> Three : register(u3);
+  %Three_h = call target("dx.TypedBuffer", <4 x i32>, 0, 0, 1)
+            @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_i32_0_0_1t(
+                  i32 0, i32 3, i32 1, i32 0, i1 false)
+  store target("dx.TypedBuffer", <4 x i32>, 0, 0, 1) %Three_h, ptr @Three, align 4
+
+  ; ByteAddressBuffer Four : register(u4)
+  %Four_h = call target("dx.RawBuffer", i8, 0, 0)
+            @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i8_0_0t(
+                  i32 0, i32 5, i32 1, i32 0, i1 false)
+  store target("dx.RawBuffer", i8, 0, 0) %Four_h, ptr @Four, align 4
+
+; StructuredBuffer<int16_t> Five : register(u6);
+  %Five_h = call target("dx.RawBuffer", i16, 0, 0)
+            @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i16_0_0t(
+                  i32 0, i32 6, i32 1, i32 0, i1 false)
+  store target("dx.RawBuffer", i16, 0, 0) %Five_h, ptr @Five, align 4  
+  
+  ; RWBuffer<double> Two : register(u2);
+  %Six_h = call target("dx.TypedBuffer", i64, 0, 0, 0)
+            @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f64_0_0_0t(
+                  i32 2, i32 10, i32 1, i32 0, i1 false)
+  store target("dx.TypedBuffer", i64, 0, 0, 0) %Six_h, ptr @Six, align 4
+
+  ret void
+}
+
+attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
+
+; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}
+
+; CHECK: [[ResList]] = !{[[SRVList:[!][0-9]+]], null, null, null}
+; CHECK: [[SRVList]] = !{![[Zero:[0-9]+]], ![[One:[0-9]+]], ![[Two:[0-9]+]],
+; CHECK-SAME: ![[Three:[0-9]+]], ![[Four:[0-9]+]], ![[Five:[0-9]+]],
+; CHECK-SAME: ![[Six:[0-9]+]]}
+
+; CHECK: ![[Zero]] = !{i32 0, ptr @0, !"", i32 0, i32 0, i32 1, i32 10, i32 0, ![[Half:[0-9]+]]}
+; CHECK: ![[Half]] = !{i32 0, i32 8}
+; CHECK: ![[One]] = !{i32 1, ptr @1, !"", i32 0, i32 1, i32 1, i32 10, i32 0, ![[Float:[0-9]+]]}
+; CHECK: ![[Float]] = !{i32 0, i32 9}
+; CHECK: ![[Two]] = !{i32 2, ptr @2, !"", i32 0, i32 2, i32 1, i32 10, i32 0, ![[Double:[0-9]+]]}
+; CHECK: ![[Double]] = !{i32 0, i32 10}
+; CHECK: ![[Three]] = !{i32 3, ptr @3, !"", i32 0, i32 3, i32 1, i32 10, i32 0, ![[I32:[0-9]+]]}
+; CHECK: ![[I32]] = !{i32 0, i32 4}
+; CHECK: ![[Four]] = !{i32 4, ptr @4, !"", i32 0, i32 5, i32 1, i32 11, i32 0, null}
+; CHECK: ![[Five]] = !{i32 5, ptr @5, !"", i32 0, i32 6, i32 1, i32 12, i32 0, ![[FiveStride:[0-9]+]]}
+; CHECK: ![[FiveStride]] = !{i32 1, i32 2}
+; CHECK: ![[Six]] = !{i32 6, ptr @6, !"", i32 2, i32 10, i32 1, i32 10, i32 0, ![[U64:[0-9]+]]}
+; CHECK: ![[U64]] = !{i32 0, i32 7}
diff --git a/llvm/test/CodeGen/DirectX/Metadata/uav_metadata.ll b/llvm/test/CodeGen/DirectX/Metadata/uav_metadata.ll
new file mode 100644
index 0000000000000..2c98c5d4a1809
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/Metadata/uav_metadata.ll
@@ -0,0 +1,135 @@
+; RUN: opt -S -dxil-translate-metadata < %s | FileCheck %s
+; RUN: opt -S --passes="dxil-pretty-printer" < %s 2>&1 | FileCheck %s --check-prefix=PRINT
+; RUN: llc %s --filetype=asm -o - < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,PRINT
+
+target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
+target triple = "dxil-pc-shadermodel6.6-compute"
+
+%"class.hlsl::RWBuffer" = type { target("dx.TypedBuffer", <4 x half>, 1, 0, 0) }
+%"class.hlsl::RWBuffer.1" = type { target("dx.TypedBuffer", <2 x float>, 1, 0, 0) }
+%"class.hlsl::RWBuffer.2" = type { target("dx.TypedBuffer", double, 1, 0, 0) }
+%"class.hlsl::RWBuffer.3" = type { target("dx.TypedBuffer", i32, 1, 0, 1) }
+%"class.hlsl::RWByteAddressBuffer" = type { target("dx.RawBuffer", i8, 1, 0) }
+%"class.hlsl::RWStructuredBuffer" = type { target("dx.RawBuffer", i16, 1, 0) }
+%"class.hlsl::RasterizerOrderedBuffer" = type { target("dx.TypedBuffer", <4 x i32>, 1, 1, 1) }
+%"class.hlsl::RasterizerOrderedStructuredBuffer" = type { target("dx.RawBuffer", <4 x i32>, 1, 1) }
+%"class.hlsl::RasterizerOrderedByteAddressBuffer" = type { target("dx.RawBuffer", i8, 1, 1) }
+%"class.hlsl::RWBuffer.4" = type { target("dx.TypedBuffer", i64, 1, 0, 0) }
+
+ at Zero = internal global %"class.hlsl::RWBuffer" poison, align 4
+ at One = internal global %"class.hlsl::RWBuffer.1" poison, align 4
+ at Two = internal global %"class.hlsl::RWBuffer.2" poison, align 4
+ at Three = internal global %"class.hlsl::RWBuffer.3" poison, align 4
+ at Four = internal global %"class.hlsl::RWByteAddressBuffer" poison, align 4
+ at Five = internal global %"class.hlsl::RWStructuredBuffer" poison, align 4
+ at Six = internal global %"class.hlsl::RasterizerOrderedBuffer" poison, align 4
+ at Seven = internal global %"class.hlsl::RasterizerOrderedStructuredBuffer" poison, align 4
+ at Eight = internal global %"class.hlsl::RasterizerOrderedByteAddressBuffer" poison, align 4
+ at Nine = internal global %"class.hlsl::RWBuffer.4" poison, align 4
+
+; PRINT:; Resource Bindings:
+; PRINT-NEXT:;
+; PRINT-NEXT:; Name                                 Type  Format         Dim      ID      HLSL Bind  Count
+; PRINT-NEXT:; ------------------------------ ---------- ------- ----------- ------- -------------- ------
+; PRINT-NEXT:;                                       UAV     f16         buf      U0             u0     1
+; PRINT-NEXT:;                                       UAV     f32         buf      U1             u1     1
+; PRINT-NEXT:;                                       UAV     f64         buf      U2             u2     1
+; PRINT-NEXT:;                                       UAV     i32         buf      U3             u3     1
+; PRINT-NEXT:;                                       UAV    byte         r/w      U4             u5     1
+; PRINT-NEXT:;                                       UAV  struct         r/w      U5             u6     1
+; PRINT-NEXT:;                                       UAV     i32         buf      U6             u7     1
+; PRINT-NEXT:;                                       UAV  struct         r/w      U7             u8     1
+; PRINT-NEXT:;                                       UAV    byte         r/w      U8             u9     1
+; PRINT-NEXT:;                                       UAV     u64         buf      U9     u10,space2     1
+
+define void @test() #0 {
+  ; RWBuffer<half4> Zero : register(u0)
+  %Zero_h = call target("dx.TypedBuffer", <4 x half>, 1, 0, 0)
+            @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_v4f16_1_0_0t(
+                  i32 0, i32 0, i32 1, i32 0, i1 false)
+  store target("dx.TypedBuffer", <4 x half>, 1, 0, 0) %Zero_h, ptr @Zero, align 4
+ 
+  ; RWBuffer<float4> One : register(u1)
+  %One_h = call target("dx.TypedBuffer", <2 x float>, 1, 0, 0)
+            @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_v2f32_1_0_0t(
+                  i32 0, i32 1, i32 1, i32 0, i1 false)
+  store target("dx.TypedBuffer", <2 x float>, 1, 0, 0) %One_h, ptr @One, align 4
+ 
+  ; RWBuffer<double> Two : register(u2);
+  %Two_h = call target("dx.TypedBuffer", double, 1, 0, 0)
+            @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f64_1_0_0t(
+                  i32 0, i32 2, i32 1, i32 0, i1 false)
+  store target("dx.TypedBuffer", double, 1, 0, 0) %Two_h, ptr @Two, align 4
+
+  ; RWBuffer<int4> Three : register(u3);
+  %Three_h = call target("dx.TypedBuffer", <4 x i32>, 1, 0, 1)
+            @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_i32_1_0_1t(
+                  i32 0, i32 3, i32 1, i32 0, i1 false)
+  store target("dx.TypedBuffer", <4 x i32>, 1, 0, 1) %Three_h, ptr @Three, align 4
+
+  ; ByteAddressBuffer Four : register(u5)
+  %Four_h = call target("dx.RawBuffer", i8, 1, 0)
+            @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i8_1_0t(
+                  i32 0, i32 5, i32 1, i32 0, i1 false)
+  store target("dx.RawBuffer", i8, 1, 0) %Four_h, ptr @Four, align 4
+
+  ; RWStructuredBuffer<int16_t> Five : register(u6);
+  %Five_h = call target("dx.RawBuffer", i16, 1, 0)
+            @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i16_1_0t(
+                  i32 0, i32 6, i32 1, i32 0, i1 false)
+  store target("dx.RawBuffer", i16, 1, 0) %Five_h, ptr @Five, align 4
+  
+  ; RasterizerOrderedBuffer<int4> Six : register(u7);
+  %Six_h = call target("dx.TypedBuffer", <4 x i32>, 1, 1, 1)
+            @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_v4i32_1_1_1t(
+                  i32 0, i32 7, i32 1, i32 0, i1 false)
+  store target("dx.TypedBuffer", <4 x i32>, 1, 1, 1) %Six_h, ptr @Six, align 4
+
+  ; RasterizerOrderedStructuredBuffer<uint4> Seven : register(u3, space10);
+  %Seven_h = call target("dx.RawBuffer", <4 x i32>, 1, 1)
+            @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_v4i32_1_1t(
+                  i32 0, i32 8, i32 1, i32 0, i1 false)
+  store target("dx.RawBuffer", <4 x i32>, 1, 1) %Seven_h, ptr @Seven, align 4
+
+  ; RasterizerOrderedByteAddressBuffer Eight : register(u9); 
+  %Eight_h = call target("dx.RawBuffer", i8, 1, 1) 
+            @llvm.dx.resource.handlefrombinding.tdx.RawBuffer_i8_1_1t(
+                  i32 0, i32 9, i32 1, i32 0, i1 false)
+  store target("dx.RawBuffer", i8, 1, 1) %Eight_h, ptr @Eight, align 4
+
+  ; RWBuffer<double> Nine : register(u2);
+  %Nine_h = call target("dx.TypedBuffer", i64, 1, 0, 0)
+            @llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f64_1_0_0t(
+                  i32 2, i32 10, i32 1, i32 0, i1 false)
+  store target("dx.TypedBuffer", i64, 1, 0, 0) %Nine_h, ptr @Nine, align 4
+
+  ret void
+}
+
+attributes #0 = { noinline nounwind "hlsl.shader"="compute" }
+
+; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}
+
+; CHECK: [[ResList]] = !{null, [[UAVList:[!][0-9]+]], null, null}
+; CHECK: [[UAVList]] = !{![[Zero:[0-9]+]], ![[One:[0-9]+]], ![[Two:[0-9]+]],
+; CHECK-SAME: ![[Three:[0-9]+]], ![[Four:[0-9]+]], ![[Five:[0-9]+]],
+; CHECK-SAME: ![[Six:[0-9]+]], ![[Seven:[0-9]+]], ![[Eight:[0-9]+]],
+; CHECK-SAME: ![[Nine:[0-9]+]]}
+
+; CHECK: ![[Zero]] = !{i32 0, ptr @0, !"", i32 0, i32 0, i32 1, i32 10, i1 false, i1 false, i1 false, ![[Half:[0-9]+]]}
+; CHECK: ![[Half]] = !{i32 0, i32 8}
+; CHECK: ![[One]] = !{i32 1, ptr @1, !"", i32 0, i32 1, i32 1, i32 10, i1 false, i1 false, i1 false, ![[Float:[0-9]+]]}
+; CHECK: ![[Float]] = !{i32 0, i32 9}
+; CHECK: ![[Two]] = !{i32 2, ptr @2, !"", i32 0, i32 2, i32 1, i32 10, i1 false, i1 false, i1 false, ![[Double:[0-9]+]]}
+; CHECK: ![[Double]] = !{i32 0, i32 10}
+; CHECK: ![[Three]] = !{i32 3, ptr @3, !"", i32 0, i32 3, i32 1, i32 10, i1 false, i1 false, i1 false, ![[I32:[0-9]+]]}
+; CHECK: ![[I32]] = !{i32 0, i32 4}
+; CHECK: ![[Four]] = !{i32 4, ptr @4, !"", i32 0, i32 5, i32 1, i32 11, i1 false, i1 false, i1 false, null}
+; CHECK: ![[Five]] = !{i32 5, ptr @5, !"", i32 0, i32 6, i32 1, i32 12, i1 false, i1 false, i1 false, ![[FiveStride:[0-9]+]]}
+; CHECK: ![[FiveStride]] = !{i32 1, i32 2}
+; CHECK: ![[Six]] = !{i32 6, ptr @6, !"", i32 0, i32 7, i32 1, i32 10, i1 false, i1 false, i1 true, ![[I32]]}
+; CHECK: ![[Seven]] = !{i32 7, ptr @7, !"", i32 0, i32 8, i32 1, i32 12, i1 false, i1 false, i1 true, ![[SevenStride:[0-9]+]]}
+; CHECK: ![[SevenStride]] = !{i32 1, i32 16}
+; CHECK: ![[Eight]] = !{i32 8, ptr @8, !"", i32 0, i32 9, i32 1, i32 11, i1 false, i1 false, i1 true, null}
+; CHECK: ![[Nine]] = !{i32 9, ptr @9, !"", i32 2, i32 10, i32 1, i32 10, i1 false, i1 false, i1 false, ![[U64:[0-9]+]]}
+; CHECK: ![[U64]] = !{i32 0, i32 7}
diff --git a/llvm/test/CodeGen/DirectX/UAVMetadata.ll b/llvm/test/CodeGen/DirectX/UAVMetadata.ll
deleted file mode 100644
index 2c242ec08eda5..0000000000000
--- a/llvm/test/CodeGen/DirectX/UAVMetadata.ll
+++ /dev/null
@@ -1,77 +0,0 @@
-; RUN: opt -S -dxil-translate-metadata < %s | FileCheck %s
-; RUN: opt -S --passes="dxil-pretty-printer" < %s 2>&1 | FileCheck %s --check-prefix=PRINT
-; RUN: llc %s --filetype=asm -o - < %s 2>&1 | FileCheck %s --check-prefixes=CHECK,PRINT
-
-target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
-target triple = "dxil-pc-shadermodel6.0-library"
-
-%"class.hlsl::RWBuffer" = type { ptr }
-
-
-; PRINT:; Resource Bindings:
-; PRINT-NEXT:;
-; PRINT-NEXT:; Name                                 Type  Format         Dim      ID      HLSL Bind  Count
-; PRINT-NEXT:; ------------------------------ ---------- ------- ----------- ------- -------------- ------
-; PRINT-NEXT:;                                       UAV     f16         buf      U0             u0     1
-; PRINT-NEXT:;                                       UAV     f32         buf      U1             u1     1
-; PRINT-NEXT:;                                       UAV     f64         buf      U2             u2     1
-; PRINT-NEXT:;                                       UAV      i1         buf      U3             u3     2
-; PRINT-NEXT:;                                       UAV    byte         r/w      U4             u5     1
-; PRINT-NEXT:;                                       UAV  struct         r/w      U5             u6     1
-; PRINT-NEXT:;                                       UAV     i32         buf      U6             u7     1
-; PRINT-NEXT:;                                       UAV  struct         r/w      U7             u8     1
-; PRINT-NEXT:;                                       UAV    byte         r/w      U8             u9     1
-; PRINT-NEXT:;                                       UAV     u64         buf      U9     u10,space2     1
-
- at Zero = local_unnamed_addr global %"class.hlsl::RWBuffer" zeroinitializer, align 4
- at One = local_unnamed_addr global %"class.hlsl::RWBuffer" zeroinitializer, align 4
- at Two = local_unnamed_addr global %"class.hlsl::RWBuffer" zeroinitializer, align 4
- at Three = local_unnamed_addr global [2 x %"class.hlsl::RWBuffer"] zeroinitializer, align 4
- at Four = local_unnamed_addr global %"class.hlsl::RWBuffer" zeroinitializer, align 4
- at Five = local_unnamed_addr global %"class.hlsl::RWBuffer" zeroinitializer, align 4
- at Six = local_unnamed_addr global %"class.hlsl::RWBuffer" zeroinitializer, align 4
- at Seven = local_unnamed_addr global %"class.hlsl::RWBuffer" zeroinitializer, align 4
- at Eight = local_unnamed_addr global %"class.hlsl::RWBuffer" zeroinitializer, align 4
- at Nine = local_unnamed_addr global %"class.hlsl::RWBuffer" zeroinitializer, align 4
-
-
-!hlsl.uavs = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
-
-!0 = !{ptr @Zero, i32 10, i32 8, i1 false, i32 0, i32 0}
-!1 = !{ptr @One, i32 10, i32 9, i1 false, i32 1, i32 0}
-!2 = !{ptr @Two, i32 10, i32 10, i1 false, i32 2, i32 0}
-!3 = !{ptr @Three, i32 10, i32 1, i1 false, i32 3, i32 0}
-!4 = !{ptr @Four, i32 11, i32 2, i1 false, i32 5, i32 0}
-!5 = !{ptr @Five, i32 12, i32 3, i1 false, i32 6, i32 0}
-!6 = !{ptr @Six, i32 10, i32 4, i1 true, i32 7, i32 0}
-!7 = !{ptr @Seven, i32 12, i32 5, i1 true, i32 8, i32 0}
-!8 = !{ptr @Eight, i32 11, i32 6, i1 true, i32 9, i32 0}
-!9 = !{ptr @Nine, i32 10, i32 7, i1 false, i32 10, i32 2}
-
-; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}
-
-; CHECK: [[ResList]] = !{null, [[UAVList:[!][0-9]+]], null, null}
-; CHECK: [[UAVList]] = !{[[Zero:[!][0-9]+]], [[One:[!][0-9]+]],
-; CHECK-SAME: [[Two:[!][0-9]+]], [[Three:[!][0-9]+]], [[Four:[!][0-9]+]],
-; CHECK-SAME: [[Five:[!][0-9]+]], [[Six:[!][0-9]+]], [[Seven:[!][0-9]+]],
-; CHECK-SAME: [[Eight:[!][0-9]+]], [[Nine:[!][0-9]+]]}
-; CHECK: [[Zero]] = !{i32 0, ptr @Zero, !"", i32 0, i32 0, i32 1, i32 10, i1 false, i1 false, i1 false, [[Half:[!][0-9]+]]}
-; CHECK: [[Half]] = !{i32 0, i32 8}
-; CHECK: [[One]] = !{i32 1, ptr @One, !"", i32 0, i32 1, i32 1, i32 10, i1 false, i1 false, i1 false, [[Float:[!][0-9]+]]}
-; CHECK: [[Float]] = !{i32 0, i32 9}
-; CHECK: [[Two]] = !{i32 2, ptr @Two, !"", i32 0, i32 2, i32 1, i32 10, i1 false, i1 false, i1 false, [[Double:[!][0-9]+]]}
-; CHECK: [[Double]] = !{i32 0, i32 10}
-; CHECK: [[Three]] = !{i32 3, ptr @Three, !"", i32 0, i32 3, i32 2, i32 10, i1 false, i1 false, i1 false, [[Bool:[!][0-9]+]]}
-; CHECK: [[Bool]] = !{i32 0, i32 1}
-; CHECK: [[Four]] = !{i32 4, ptr @Four, !"", i32 0, i32 5, i32 1, i32 11, i1 false, i1 false, i1 false, [[I16:[!][0-9]+]]}
-; CHECK: [[I16]] = !{i32 0, i32 2}
-; CHECK: [[Five]] = !{i32 5, ptr @Five, !"", i32 0, i32 6, i32 1, i32 12, i1 false, i1 false, i1 false, [[U16:[!][0-9]+]]}
-; CHECK: [[U16]] = !{i32 0, i32 3}
-; CHECK: [[Six]] = !{i32 6, ptr @Six, !"", i32 0, i32 7, i32 1, i32 10, i1 false, i1 false, i1 true, [[I32:[!][0-9]+]]}
-; CHECK: [[I32]] = !{i32 0, i32 4}
-; CHECK: [[Seven]] = !{i32 7, ptr @Seven, !"", i32 0, i32 8, i32 1, i32 12, i1 false, i1 false, i1 true, [[U32:[!][0-9]+]]}
-; CHECK: [[U32]] = !{i32 0, i32 5}
-; CHECK: [[Eight]] = !{i32 8, ptr @Eight, !"", i32 0, i32 9, i32 1, i32 11, i1 false, i1 false, i1 true, [[I64:[!][0-9]+]]}
-; CHECK: [[I64]] = !{i32 0, i32 6}
-; CHECK: [[Nine]] = !{i32 9, ptr @Nine, !"", i32 2, i32 10, i32 1, i32 10, i1 false, i1 false, i1 false, [[U64:[!][0-9]+]]}
-; CHECK: [[U64]] = !{i32 0, i32 7}
diff --git a/llvm/test/CodeGen/DirectX/cbuf.ll b/llvm/test/CodeGen/DirectX/cbuf.ll
deleted file mode 100644
index 7589da5e15bd7..0000000000000
--- a/llvm/test/CodeGen/DirectX/cbuf.ll
+++ /dev/null
@@ -1,37 +0,0 @@
-; RUN: opt -S -dxil-translate-metadata < %s | FileCheck %s --check-prefix=DXILMD
-; RUN: opt -S --passes="dxil-pretty-printer" < %s 2>&1 | FileCheck %s --check-prefix=PRINT
-
-target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
-target triple = "dxil-unknown-shadermodel6.7-library"
-
-; Make sure the size is 24 = 16 + 8 (float,i32,double -> 16 and int2 -> 8)
-; DXILMD:!{i32 0, ptr @A.cb., !"", i32 1, i32 2, i32 1, i32 24}
-
-; Make sure match register(b2, space1) with ID 0.
-; PRINT:cbuffer      NA          NA     CB0     cb2,space1     1
-
- at A.cb. = external constant { float, i32, double, <2 x i32> }
-
-; Function Attrs: noinline nounwind optnone
-define noundef float @"?foo@@YAMXZ"() #0 {
-entry:
-  %0 = load float, ptr @A.cb., align 4
-  %conv = fpext float %0 to double
-  %1 = load double, ptr getelementptr inbounds ({ float, i32, double, <2 x i32> }, ptr @A.cb., i32 0, i32 2), align 8
-  %2 = load <2 x i32>, ptr getelementptr inbounds ({ float, i32, double, <2 x i32> }, ptr @A.cb., i32 0, i32 3), align 8
-  %3 = extractelement <2 x i32> %2, i32 1
-  %conv1 = sitofp i32 %3 to double
-  %4 = call double @llvm.fmuladd.f64(double %1, double %conv1, double %conv)
-  %conv2 = fptrunc double %4 to float
-  ret float %conv2
-}
-
-; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
-declare double @llvm.fmuladd.f64(double, double, double) #1
-
-attributes #0 = { noinline nounwind }
-attributes #1 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
-
-!hlsl.cbufs = !{!1}
-
-!1 = !{ptr @A.cb., !"A.cb.ty", i32 13, i1 false, i32 2, i32 1}
diff --git a/llvm/test/CodeGen/DirectX/legacy_cb_layout_0.ll b/llvm/test/CodeGen/DirectX/legacy_cb_layout_0.ll
deleted file mode 100644
index 1a618092c5fed..0000000000000
--- a/llvm/test/CodeGen/DirectX/legacy_cb_layout_0.ll
+++ /dev/null
@@ -1,14 +0,0 @@
-; RUN: opt -S -dxil-translate-metadata < %s | FileCheck %s --check-prefix=DXILMD
-
-target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
-target triple = "dxil-unknown-shadermodel6.7-library"
-
-; Make sure the size is 36 = 16 + 16 + 4 (float, double -> 16, float, half, i16, i64 -> 16 and int -> 4)
-; DXILMD:!{i32 0, ptr @A.cb., !"", i32 0, i32 2, i32 1, i32 36}
-
- at A.cb. = external local_unnamed_addr constant { float, double, float, half, i16, i64, i32 }
-
-
-!hlsl.cbufs = !{!1}
-
-!1 = !{ptr @A.cb., !"A.cb.ty", i32 13, i1 false, i32 2, i32 0}
diff --git a/llvm/test/CodeGen/DirectX/legacy_cb_layout_1.ll b/llvm/test/CodeGen/DirectX/legacy_cb_layout_1.ll
deleted file mode 100644
index 6886f2690209d..0000000000000
--- a/llvm/test/CodeGen/DirectX/legacy_cb_layout_1.ll
+++ /dev/null
@@ -1,37 +0,0 @@
-; RUN: opt -S -dxil-translate-metadata < %s | FileCheck %s --check-prefix=DXILMD
-
-target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
-target triple = "dxil-unknown-shadermodel6.7-library"
-
-;
-; cbuffer B
-; {
-;
-;   struct B
-;   {
-;
-;       double B0;                                    ; Offset:    0
-;       float3 B1;                                    ; Offset:   16
-;       float B2;                                     ; Offset:   28
-;       double3 B3;                                   ; Offset:   32
-;       half B4;                                      ; Offset:   56
-;       double2 B5;                                   ; Offset:   64
-;       float B6;                                     ; Offset:   80
-;       half3 B7;                                     ; Offset:   84
-;       half3 B8;                                     ; Offset:   90
-;   
-;   } B;                                              ; Offset:    0 Size:    96
-;
-; }
-;
-
-
-; Make sure the size is 96
-; DXILMD:!{i32 0, ptr @B.cb., !"", i32 0, i32 1, i32 1, i32 96}
-
- at B.cb. = external local_unnamed_addr constant { double, <3 x float>, float, <3 x double>, half, <2 x double>, float, <3 x half>, <3 x half> }
-
-
-!hlsl.cbufs = !{!0}
-
-!0 = !{ptr @B.cb., !"B.cb.ty", i32 13, i1 false, i32 1, i32 0}
diff --git a/llvm/test/CodeGen/DirectX/legacy_cb_layout_2.ll b/llvm/test/CodeGen/DirectX/legacy_cb_layout_2.ll
deleted file mode 100644
index 3b08b25542201..0000000000000
--- a/llvm/test/CodeGen/DirectX/legacy_cb_layout_2.ll
+++ /dev/null
@@ -1,51 +0,0 @@
-; RUN: opt -S -dxil-translate-metadata < %s | FileCheck %s --check-prefix=DXILMD
-
-target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
-target triple = "dxil-unknown-shadermodel6.7-library"
-
-; cbuffer B
-; {
-;
-;   struct B
-;   {
-;
-;       double B0[2];                                 ; Offset:    0
-;       float3 B1[3];                                 ; Offset:   32
-;       float B2;                                     ; Offset:   76
-;       double B3[3];                                 ; Offset:   80
-;       half B4;                                      ; Offset:  120
-;       double2 B5[1];                                ; Offset:  128
-;       float B6;                                     ; Offset:  144
-;       half3 B7[2];                                  ; Offset:  160
-;       half3 B8;                                     ; Offset:  182
-;   
-;   } B;                                              ; Offset:    0 Size:   188
-;
-; }
-;
-; cbuffer B
-; {
-;
-;   struct B.0
-;   {
-;
-;       double3 B9[3];                                ; Offset:    0
-;       half3 B10;                                    ; Offset:   88
-;   
-;   } B;                                              ; Offset:    0 Size:    94
-;
-; }
-
-
-; Make sure the size is 188.
-; DXILMD:!{i32 0, ptr @B.cb., !"", i32 0, i32 1, i32 1, i32 188}
-; Make sure the size is 94.
-; DXILMD:!{i32 1, ptr @B.cb..1, !"", i32 0, i32 2, i32 1, i32 94}
-
- at B.cb. = external local_unnamed_addr constant { [2 x double], [3 x <3 x float>], float, [3 x double], half, [1 x <2 x double>], float, [2 x <3 x half>], <3 x half> }
- at B.cb..1 = external local_unnamed_addr constant { [3 x <3 x double>], <3 x half> }
-
-!hlsl.cbufs = !{!0, !1}
-
-!0 = !{ptr @B.cb., !"B.cb.ty", i32 13, i1 false, i32 1, i32 0}
-!1 = !{ptr @B.cb..1, !"B.cb.ty", i32 13, i1 false, i32 2, i32 0}
diff --git a/llvm/test/CodeGen/DirectX/legacy_cb_layout_3.ll b/llvm/test/CodeGen/DirectX/legacy_cb_layout_3.ll
deleted file mode 100644
index f01afbdab9673..0000000000000
--- a/llvm/test/CodeGen/DirectX/legacy_cb_layout_3.ll
+++ /dev/null
@@ -1,81 +0,0 @@
-; RUN: opt -S -dxil-translate-metadata < %s | FileCheck %s --check-prefix=DXILMD
-
-target datalayout = "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-f32:32-f64:64-n8:16:32:64"
-target triple = "dxil-unknown-shadermodel6.7-library"
-
-; cbuffer D
-; {
-;
-;   struct D
-;   {
-;
-;       int D0;                                       ; Offset:    0
-;       struct struct.B
-;       {
-;
-;           double B0;                                ; Offset:   16
-;           float3 B1;                                ; Offset:   32
-;           float B2;                                 ; Offset:   44
-;           double3 B3;                               ; Offset:   48
-;           half B4;                                  ; Offset:   72
-;           double2 B5;                               ; Offset:   80
-;           float B6;                                 ; Offset:   96
-;           half3 B7;                                 ; Offset:  100
-;           half3 B8;                                 ; Offset:  106
-;       
-;       } D1;                                         ; Offset:   16
-;
-;       half D2;                                      ; Offset:  112
-;       struct struct.C
-;       {
-;
-;           struct struct.A
-;           {
-;
-;               float A0;                             ; Offset:  128
-;               double A1;                            ; Offset:  136
-;               float A2;                             ; Offset:  144
-;               half A3;                              ; Offset:  148
-;               int16_t A4;                           ; Offset:  150
-;               int64_t A5;                           ; Offset:  152
-;               int A6;                               ; Offset:  160
-;           
-;           } C0;                                     ; Offset:  128
-;
-;           float C1[1];                              ; Offset:  176
-;           struct struct.B
-;           {
-;
-;               double B0;                            ; Offset:  192
-;               float3 B1;                            ; Offset:  208
-;               float B2;                             ; Offset:  220
-;               double3 B3;                           ; Offset:  224
-;               half B4;                              ; Offset:  248
-;               double2 B5;                           ; Offset:  256
-;               float B6;                             ; Offset:  272
-;               half3 B7;                             ; Offset:  276
-;               half3 B8;                             ; Offset:  282
-;           
-;           } C2[2];;                                 ; Offset:  192
-;
-;           half C3;                                  ; Offset:  384
-;       
-;       } D3;                                         ; Offset:  128
-;
-;       double D4;                                    ; Offset:  392
-;   
-;   } D;                                              ; Offset:    0 Size:   400
-
-
-; Make sure the size is 400
-; DXILMD:!{i32 0, ptr @D.cb., !"", i32 0, i32 1, i32 1, i32 400}
-
-
-%struct.B = type <{ double, <3 x float>, float, <3 x double>, half, <2 x double>, float, <3 x half>, <3 x half> }>
-%struct.C = type <{ %struct.A, [1 x float], [2 x %struct.B], half }>
-%struct.A = type <{ float, double, float, half, i16, i64, i32 }>
-
- at D.cb. = external local_unnamed_addr constant { i32, %struct.B, half, %struct.C, double }
-
-!hlsl.cbufs = !{!0}
-!0 = !{ptr @D.cb., !"D.cb.ty", i32 13, i1 false, i32 1, i32 0}

>From 80765757f067527816c4c8b9d728169568b04b7a Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Fri, 7 Mar 2025 10:40:20 -0800
Subject: [PATCH 2/3] [DirectX] Remove DXILResourceMDAnalysis

Part 1/2 of #114126
---
 llvm/lib/Target/DirectX/CMakeLists.txt        |   2 -
 .../Target/DirectX/DXILDataScalarization.h    |   1 -
 .../Target/DirectX/DXILIntrinsicExpansion.h   |   1 -
 llvm/lib/Target/DirectX/DXILOpLowering.cpp    |   2 -
 llvm/lib/Target/DirectX/DXILPrepare.cpp       |   2 -
 llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp |  23 +-
 llvm/lib/Target/DirectX/DXILResource.cpp      | 346 ------------------
 llvm/lib/Target/DirectX/DXILResource.h        | 133 -------
 .../Target/DirectX/DXILResourceAnalysis.cpp   |  41 ---
 .../lib/Target/DirectX/DXILResourceAnalysis.h |  55 ---
 .../Target/DirectX/DXILTranslateMetadata.cpp  |  31 +-
 llvm/lib/Target/DirectX/DirectX.h             |   3 -
 .../Target/DirectX/DirectXPassRegistry.def    |   1 -
 .../Target/DirectX/DirectXTargetMachine.cpp   |   2 -
 llvm/test/CodeGen/DirectX/llc-pipeline.ll     |   1 -
 15 files changed, 7 insertions(+), 637 deletions(-)
 delete mode 100644 llvm/lib/Target/DirectX/DXILResource.cpp
 delete mode 100644 llvm/lib/Target/DirectX/DXILResource.h
 delete mode 100644 llvm/lib/Target/DirectX/DXILResourceAnalysis.cpp
 delete mode 100644 llvm/lib/Target/DirectX/DXILResourceAnalysis.h

diff --git a/llvm/lib/Target/DirectX/CMakeLists.txt b/llvm/lib/Target/DirectX/CMakeLists.txt
index 5a167535b0afa..6904a1c0f1e73 100644
--- a/llvm/lib/Target/DirectX/CMakeLists.txt
+++ b/llvm/lib/Target/DirectX/CMakeLists.txt
@@ -28,8 +28,6 @@ add_llvm_target(DirectXCodeGen
   DXILOpLowering.cpp
   DXILPrepare.cpp
   DXILPrettyPrinter.cpp
-  DXILResource.cpp
-  DXILResourceAnalysis.cpp
   DXILResourceAccess.cpp
   DXILShaderFlags.cpp
   DXILTranslateMetadata.cpp
diff --git a/llvm/lib/Target/DirectX/DXILDataScalarization.h b/llvm/lib/Target/DirectX/DXILDataScalarization.h
index 560e061db96d0..e8cd495729431 100644
--- a/llvm/lib/Target/DirectX/DXILDataScalarization.h
+++ b/llvm/lib/Target/DirectX/DXILDataScalarization.h
@@ -9,7 +9,6 @@
 #ifndef LLVM_TARGET_DIRECTX_DXILDATASCALARIZATION_H
 #define LLVM_TARGET_DIRECTX_DXILDATASCALARIZATION_H
 
-#include "DXILResource.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
 
diff --git a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.h b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.h
index c283386c6e3df..43fc4d7735e1f 100644
--- a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.h
+++ b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.h
@@ -8,7 +8,6 @@
 #ifndef LLVM_TARGET_DIRECTX_DXILINTRINSICEXPANSION_H
 #define LLVM_TARGET_DIRECTX_DXILINTRINSICEXPANSION_H
 
-#include "DXILResource.h"
 #include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
 
diff --git a/llvm/lib/Target/DirectX/DXILOpLowering.cpp b/llvm/lib/Target/DirectX/DXILOpLowering.cpp
index 92b6787b9571e..1b02206464661 100644
--- a/llvm/lib/Target/DirectX/DXILOpLowering.cpp
+++ b/llvm/lib/Target/DirectX/DXILOpLowering.cpp
@@ -10,7 +10,6 @@
 #include "DXILConstants.h"
 #include "DXILIntrinsicExpansion.h"
 #include "DXILOpBuilder.h"
-#include "DXILResourceAnalysis.h"
 #include "DXILShaderFlags.h"
 #include "DirectX.h"
 #include "llvm/ADT/SmallVector.h"
@@ -889,7 +888,6 @@ class DXILOpLoweringLegacy : public ModulePass {
     AU.addRequired<DXILResourceTypeWrapperPass>();
     AU.addRequired<DXILResourceBindingWrapperPass>();
     AU.addPreserved<DXILResourceBindingWrapperPass>();
-    AU.addPreserved<DXILResourceMDWrapper>();
     AU.addPreserved<DXILMetadataAnalysisWrapperPass>();
     AU.addPreserved<ShaderFlagsAnalysisWrapper>();
   }
diff --git a/llvm/lib/Target/DirectX/DXILPrepare.cpp b/llvm/lib/Target/DirectX/DXILPrepare.cpp
index 355c79ae0edc9..0014cc9e1f67c 100644
--- a/llvm/lib/Target/DirectX/DXILPrepare.cpp
+++ b/llvm/lib/Target/DirectX/DXILPrepare.cpp
@@ -11,7 +11,6 @@
 /// Language (DXIL).
 //===----------------------------------------------------------------------===//
 
-#include "DXILResourceAnalysis.h"
 #include "DXILShaderFlags.h"
 #include "DirectX.h"
 #include "DirectXIRPasses/PointerTypeAnalysis.h"
@@ -248,7 +247,6 @@ class DXILPrepareModule : public ModulePass {
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<DXILMetadataAnalysisWrapperPass>();
     AU.addPreserved<ShaderFlagsAnalysisWrapper>();
-    AU.addPreserved<DXILResourceMDWrapper>();
     AU.addPreserved<DXILMetadataAnalysisWrapperPass>();
     AU.addPreserved<DXILResourceBindingWrapperPass>();
   }
diff --git a/llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp b/llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp
index 7255a9be06d51..c1f2483044693 100644
--- a/llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp
+++ b/llvm/lib/Target/DirectX/DXILPrettyPrinter.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "DXILPrettyPrinter.h"
-#include "DXILResourceAnalysis.h"
 #include "DirectX.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Analysis/DXILResource.h"
@@ -222,8 +221,7 @@ struct FormatBindingSize
 } // namespace
 
 static void prettyPrintResources(raw_ostream &OS, const DXILBindingMap &DBM,
-                                 DXILResourceTypeMap &DRTM,
-                                 const dxil::Resources &MDResources) {
+                                 DXILResourceTypeMap &DRTM) {
   // Column widths are arbitrary but match the widths DXC uses.
   OS << ";\n; Resource Bindings:\n;\n";
   OS << formatv("; {0,-30} {1,10} {2,7} {3,11} {4,7} {5,14} {6,9}\n", "Name",
@@ -237,11 +235,6 @@ static void prettyPrintResources(raw_ostream &OS, const DXILBindingMap &DBM,
     const dxil::ResourceTypeInfo &RTI = DRTM[RBI.getHandleTy()];
 
     dxil::ResourceClass RC = RTI.getResourceClass();
-    assert((RC != dxil::ResourceClass::CBuffer || !MDResources.hasCBuffers()) &&
-           "Old and new cbuffer representations can't coexist");
-    assert((RC != dxil::ResourceClass::UAV || !MDResources.hasUAVs()) &&
-           "Old and new UAV representations can't coexist");
-
     StringRef Name(RBI.getName());
     StringRef Type(getRCName(RC));
     StringRef Format(getFormatName(RTI));
@@ -252,12 +245,6 @@ static void prettyPrintResources(raw_ostream &OS, const DXILBindingMap &DBM,
     OS << formatv("; {0,-30} {1,10} {2,7} {3,11} {4,7} {5,14} {6,9}\n", Name,
                   Type, Format, Dim, ID, Bind, Count);
   }
-
-  if (MDResources.hasCBuffers())
-    MDResources.printCBuffers(OS);
-  if (MDResources.hasUAVs())
-    MDResources.printUAVs(OS);
-
   OS << ";\n";
 }
 
@@ -265,8 +252,7 @@ PreservedAnalyses DXILPrettyPrinterPass::run(Module &M,
                                              ModuleAnalysisManager &MAM) {
   const DXILBindingMap &DBM = MAM.getResult<DXILResourceBindingAnalysis>(M);
   DXILResourceTypeMap &DRTM = MAM.getResult<DXILResourceTypeAnalysis>(M);
-  const dxil::Resources &MDResources = MAM.getResult<DXILResourceMDAnalysis>(M);
-  prettyPrintResources(OS, DBM, DRTM, MDResources);
+  prettyPrintResources(OS, DBM, DRTM);
   return PreservedAnalyses::all();
 }
 
@@ -293,7 +279,6 @@ class DXILPrettyPrinterLegacy : public llvm::ModulePass {
     AU.setPreservesAll();
     AU.addRequired<DXILResourceTypeWrapperPass>();
     AU.addRequired<DXILResourceBindingWrapperPass>();
-    AU.addRequired<DXILResourceMDWrapper>();
   }
 };
 } // namespace
@@ -303,7 +288,6 @@ INITIALIZE_PASS_BEGIN(DXILPrettyPrinterLegacy, "dxil-pretty-printer",
                       "DXIL Metadata Pretty Printer", true, true)
 INITIALIZE_PASS_DEPENDENCY(DXILResourceTypeWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(DXILResourceBindingWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(DXILResourceMDWrapper)
 INITIALIZE_PASS_END(DXILPrettyPrinterLegacy, "dxil-pretty-printer",
                     "DXIL Metadata Pretty Printer", true, true)
 
@@ -312,8 +296,7 @@ bool DXILPrettyPrinterLegacy::runOnModule(Module &M) {
       getAnalysis<DXILResourceBindingWrapperPass>().getBindingMap();
   DXILResourceTypeMap &DRTM =
       getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
-  dxil::Resources &Res = getAnalysis<DXILResourceMDWrapper>().getDXILResource();
-  prettyPrintResources(OS, DBM, DRTM, Res);
+  prettyPrintResources(OS, DBM, DRTM);
   return false;
 }
 
diff --git a/llvm/lib/Target/DirectX/DXILResource.cpp b/llvm/lib/Target/DirectX/DXILResource.cpp
deleted file mode 100644
index f027283b70521..0000000000000
--- a/llvm/lib/Target/DirectX/DXILResource.cpp
+++ /dev/null
@@ -1,346 +0,0 @@
-//===- DXILResource.cpp - DXIL Resource helper objects --------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file This file contains helper objects for working with DXIL Resources.
-///
-//===----------------------------------------------------------------------===//
-
-#include "DXILResource.h"
-#include "CBufferDataLayout.h"
-#include "llvm/ADT/StringSwitch.h"
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/Metadata.h"
-#include "llvm/IR/Module.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/Format.h"
-
-using namespace llvm;
-using namespace llvm::dxil;
-
-template <typename T> void ResourceTable<T>::collect(Module &M) {
-  NamedMDNode *Entry = M.getNamedMetadata(MDName);
-  if (!Entry || Entry->getNumOperands() == 0)
-    return;
-
-  uint32_t Counter = 0;
-  for (auto *Res : Entry->operands()) {
-    Data.push_back(T(Counter++, hlsl::FrontendResource(cast<MDNode>(Res))));
-  }
-}
-
-template <> void ResourceTable<ConstantBuffer>::collect(Module &M) {
-  NamedMDNode *Entry = M.getNamedMetadata(MDName);
-  if (!Entry || Entry->getNumOperands() == 0)
-    return;
-
-  uint32_t Counter = 0;
-  for (auto *Res : Entry->operands()) {
-    Data.push_back(
-        ConstantBuffer(Counter++, hlsl::FrontendResource(cast<MDNode>(Res))));
-  }
-  // FIXME: share CBufferDataLayout with CBuffer load lowering.
-  //   See https://github.com/llvm/llvm-project/issues/58381
-  CBufferDataLayout CBDL(M.getDataLayout(), /*IsLegacy*/ true);
-  for (auto &CB : Data)
-    CB.setSize(CBDL);
-}
-
-void Resources::collect(Module &M) {
-  UAVs.collect(M);
-  CBuffers.collect(M);
-}
-
-ResourceBase::ResourceBase(uint32_t I, hlsl::FrontendResource R)
-    : ID(I), GV(R.getGlobalVariable()), Name(""), Space(R.getSpace()),
-      LowerBound(R.getResourceIndex()), RangeSize(1) {
-  if (auto *ArrTy = dyn_cast<ArrayType>(GV->getValueType()))
-    RangeSize = ArrTy->getNumElements();
-}
-
-StringRef ResourceBase::getElementTypeName(ElementType ElTy) {
-  switch (ElTy) {
-  case ElementType::Invalid:
-    return "invalid";
-  case ElementType::I1:
-    return "i1";
-  case ElementType::I16:
-    return "i16";
-  case ElementType::U16:
-    return "u16";
-  case ElementType::I32:
-    return "i32";
-  case ElementType::U32:
-    return "u32";
-  case ElementType::I64:
-    return "i64";
-  case ElementType::U64:
-    return "u64";
-  case ElementType::F16:
-    return "f16";
-  case ElementType::F32:
-    return "f32";
-  case ElementType::F64:
-    return "f64";
-  case ElementType::SNormF16:
-    return "snorm_f16";
-  case ElementType::UNormF16:
-    return "unorm_f16";
-  case ElementType::SNormF32:
-    return "snorm_f32";
-  case ElementType::UNormF32:
-    return "unorm_f32";
-  case ElementType::SNormF64:
-    return "snorm_f64";
-  case ElementType::UNormF64:
-    return "unorm_f64";
-  case ElementType::PackedS8x32:
-    return "p32i8";
-  case ElementType::PackedU8x32:
-    return "p32u8";
-  }
-  llvm_unreachable("All ElementType enums are handled in switch");
-}
-
-void ResourceBase::printElementType(ResourceKind Kind, ElementType ElTy,
-                                    unsigned Alignment, raw_ostream &OS) {
-  switch (Kind) {
-  default:
-    // TODO: add vector size.
-    OS << right_justify(getElementTypeName(ElTy), Alignment);
-    break;
-  case ResourceKind::RawBuffer:
-    OS << right_justify("byte", Alignment);
-    break;
-  case ResourceKind::StructuredBuffer:
-    OS << right_justify("struct", Alignment);
-    break;
-  case ResourceKind::CBuffer:
-  case ResourceKind::Sampler:
-    OS << right_justify("NA", Alignment);
-    break;
-  case ResourceKind::Invalid:
-  case ResourceKind::NumEntries:
-    break;
-  }
-}
-
-StringRef ResourceBase::getKindName(ResourceKind Kind) {
-  switch (Kind) {
-  case ResourceKind::NumEntries:
-  case ResourceKind::Invalid:
-    return "invalid";
-  case ResourceKind::Texture1D:
-    return "1d";
-  case ResourceKind::Texture2D:
-    return "2d";
-  case ResourceKind::Texture2DMS:
-    return "2dMS";
-  case ResourceKind::Texture3D:
-    return "3d";
-  case ResourceKind::TextureCube:
-    return "cube";
-  case ResourceKind::Texture1DArray:
-    return "1darray";
-  case ResourceKind::Texture2DArray:
-    return "2darray";
-  case ResourceKind::Texture2DMSArray:
-    return "2darrayMS";
-  case ResourceKind::TextureCubeArray:
-    return "cubearray";
-  case ResourceKind::TypedBuffer:
-    return "buf";
-  case ResourceKind::RawBuffer:
-    return "rawbuf";
-  case ResourceKind::StructuredBuffer:
-    return "structbuf";
-  case ResourceKind::CBuffer:
-    return "cbuffer";
-  case ResourceKind::Sampler:
-    return "sampler";
-  case ResourceKind::TBuffer:
-    return "tbuffer";
-  case ResourceKind::RTAccelerationStructure:
-    return "ras";
-  case ResourceKind::FeedbackTexture2D:
-    return "fbtex2d";
-  case ResourceKind::FeedbackTexture2DArray:
-    return "fbtex2darray";
-  }
-  llvm_unreachable("All ResourceKind enums are handled in switch");
-}
-
-void ResourceBase::printKind(ResourceKind Kind, unsigned Alignment,
-                             raw_ostream &OS, bool SRV, bool HasCounter,
-                             uint32_t SampleCount) {
-  switch (Kind) {
-  default:
-    OS << right_justify(getKindName(Kind), Alignment);
-    break;
-
-  case ResourceKind::RawBuffer:
-  case ResourceKind::StructuredBuffer:
-    if (SRV)
-      OS << right_justify("r/o", Alignment);
-    else {
-      if (!HasCounter)
-        OS << right_justify("r/w", Alignment);
-      else
-        OS << right_justify("r/w+cnt", Alignment);
-    }
-    break;
-  case ResourceKind::TypedBuffer:
-    OS << right_justify("buf", Alignment);
-    break;
-  case ResourceKind::Texture2DMS:
-  case ResourceKind::Texture2DMSArray: {
-    std::string DimName = getKindName(Kind).str();
-    if (SampleCount)
-      DimName += std::to_string(SampleCount);
-    OS << right_justify(DimName, Alignment);
-  } break;
-  case ResourceKind::CBuffer:
-  case ResourceKind::Sampler:
-    OS << right_justify("NA", Alignment);
-    break;
-  case ResourceKind::Invalid:
-  case ResourceKind::NumEntries:
-    break;
-  }
-}
-
-void ResourceBase::print(raw_ostream &OS, StringRef IDPrefix,
-                         StringRef BindingPrefix) const {
-  std::string ResID = IDPrefix.str();
-  ResID += std::to_string(ID);
-  OS << right_justify(ResID, 8);
-
-  std::string Bind = BindingPrefix.str();
-  Bind += std::to_string(LowerBound);
-  if (Space)
-    Bind += ",space" + std::to_string(Space);
-
-  OS << right_justify(Bind, 15);
-  if (RangeSize != UINT_MAX)
-    OS << right_justify(std::to_string(RangeSize), 6) << "\n";
-  else
-    OS << right_justify("unbounded", 6) << "\n";
-}
-
-void UAVResource::print(raw_ostream &OS) const {
-  OS << "; " << left_justify(Name, 31);
-
-  OS << right_justify("UAV", 10);
-
-  printElementType(Shape, ExtProps.ElementType.value_or(ElementType::Invalid),
-                   8, OS);
-
-  // FIXME: support SampleCount.
-  // See https://github.com/llvm/llvm-project/issues/58175
-  printKind(Shape, 12, OS, /*SRV*/ false, HasCounter);
-  // Print the binding part.
-  ResourceBase::print(OS, "U", "u");
-}
-
-ConstantBuffer::ConstantBuffer(uint32_t I, hlsl::FrontendResource R)
-    : ResourceBase(I, R) {}
-
-void ConstantBuffer::setSize(CBufferDataLayout &DL) {
-  CBufferSizeInBytes = DL.getTypeAllocSizeInBytes(GV->getValueType());
-}
-
-void ConstantBuffer::print(raw_ostream &OS) const {
-  OS << "; " << left_justify(Name, 31);
-
-  OS << right_justify("cbuffer", 10);
-
-  printElementType(ResourceKind::CBuffer, ElementType::Invalid, 8, OS);
-
-  printKind(ResourceKind::CBuffer, 12, OS, /*SRV*/ false, /*HasCounter*/ false);
-  // Print the binding part.
-  ResourceBase::print(OS, "CB", "cb");
-}
-
-template <typename T> void ResourceTable<T>::print(raw_ostream &OS) const {
-  for (auto &Res : Data)
-    Res.print(OS);
-}
-
-MDNode *ResourceBase::ExtendedProperties::write(LLVMContext &Ctx) const {
-  IRBuilder<> B(Ctx);
-  SmallVector<Metadata *> Entries;
-  if (ElementType) {
-    Entries.emplace_back(
-        ConstantAsMetadata::get(B.getInt32(TypedBufferElementType)));
-    Entries.emplace_back(ConstantAsMetadata::get(
-        B.getInt32(static_cast<uint32_t>(*ElementType))));
-  }
-  if (Entries.empty())
-    return nullptr;
-  return MDNode::get(Ctx, Entries);
-}
-
-void ResourceBase::write(LLVMContext &Ctx,
-                         MutableArrayRef<Metadata *> Entries) const {
-  IRBuilder<> B(Ctx);
-  Entries[0] = ConstantAsMetadata::get(B.getInt32(ID));
-  Entries[1] = ConstantAsMetadata::get(GV);
-  Entries[2] = MDString::get(Ctx, Name);
-  Entries[3] = ConstantAsMetadata::get(B.getInt32(Space));
-  Entries[4] = ConstantAsMetadata::get(B.getInt32(LowerBound));
-  Entries[5] = ConstantAsMetadata::get(B.getInt32(RangeSize));
-}
-
-MDNode *UAVResource::write() const {
-  auto &Ctx = GV->getContext();
-  IRBuilder<> B(Ctx);
-  Metadata *Entries[11];
-  ResourceBase::write(Ctx, Entries);
-  Entries[6] =
-      ConstantAsMetadata::get(B.getInt32(static_cast<uint32_t>(Shape)));
-  Entries[7] = ConstantAsMetadata::get(B.getInt1(GloballyCoherent));
-  Entries[8] = ConstantAsMetadata::get(B.getInt1(HasCounter));
-  Entries[9] = ConstantAsMetadata::get(B.getInt1(IsROV));
-  Entries[10] = ExtProps.write(Ctx);
-  return MDNode::get(Ctx, Entries);
-}
-
-MDNode *ConstantBuffer::write() const {
-  auto &Ctx = GV->getContext();
-  IRBuilder<> B(Ctx);
-  Metadata *Entries[7];
-  ResourceBase::write(Ctx, Entries);
-
-  Entries[6] = ConstantAsMetadata::get(B.getInt32(CBufferSizeInBytes));
-  return MDNode::get(Ctx, Entries);
-}
-
-template <typename T> MDNode *ResourceTable<T>::write(Module &M) const {
-  if (Data.empty())
-    return nullptr;
-  SmallVector<Metadata *> MDs;
-  for (auto &Res : Data)
-    MDs.emplace_back(Res.write());
-
-  NamedMDNode *Entry = M.getNamedMetadata(MDName);
-  if (Entry)
-    Entry->eraseFromParent();
-
-  return MDNode::get(M.getContext(), MDs);
-}
-
-Metadata *Resources::writeUAVs(Module &M) const { return UAVs.write(M); }
-void Resources::printUAVs(raw_ostream &OS) const { UAVs.print(OS); }
-Metadata *Resources::writeCBuffers(Module &M) const {
-  return CBuffers.write(M);
-}
-void Resources::printCBuffers(raw_ostream &OS) const { CBuffers.print(OS); }
-
-void Resources::dump() const {
-  printCBuffers(dbgs());
-  printUAVs(dbgs());
-}
diff --git a/llvm/lib/Target/DirectX/DXILResource.h b/llvm/lib/Target/DirectX/DXILResource.h
deleted file mode 100644
index 812729bc4dc57..0000000000000
--- a/llvm/lib/Target/DirectX/DXILResource.h
+++ /dev/null
@@ -1,133 +0,0 @@
-//===- DXILResource.h - DXIL Resource helper objects ----------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file This file contains helper objects for working with DXIL Resources.
-///
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_TARGET_DIRECTX_DXILRESOURCE_H
-#define LLVM_TARGET_DIRECTX_DXILRESOURCE_H
-
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Frontend/HLSL/HLSLResource.h"
-#include "llvm/IR/Metadata.h"
-#include "llvm/Support/Compiler.h"
-#include "llvm/Support/DXILABI.h"
-#include <cstdint>
-
-namespace llvm {
-class Module;
-class GlobalVariable;
-
-namespace dxil {
-class CBufferDataLayout;
-
-class ResourceBase {
-protected:
-  uint32_t ID;
-  GlobalVariable *GV;
-  StringRef Name;
-  uint32_t Space;
-  uint32_t LowerBound;
-  uint32_t RangeSize;
-  ResourceBase(uint32_t I, hlsl::FrontendResource R);
-
-  void write(LLVMContext &Ctx, MutableArrayRef<Metadata *> Entries) const;
-
-  void print(raw_ostream &O, StringRef IDPrefix, StringRef BindingPrefix) const;
-  static StringRef getKindName(dxil::ResourceKind Kind);
-  static void printKind(dxil::ResourceKind Kind, unsigned Alignment,
-                        raw_ostream &OS, bool SRV = false,
-                        bool HasCounter = false, uint32_t SampleCount = 0);
-
-  static StringRef getElementTypeName(dxil::ElementType CompType);
-  static void printElementType(dxil::ResourceKind Kind,
-                               dxil::ElementType CompType, unsigned Alignment,
-                               raw_ostream &OS);
-
-public:
-  struct ExtendedProperties {
-    std::optional<dxil::ElementType> ElementType;
-
-    // The value ordering of this enumeration is part of the DXIL ABI. Elements
-    // can only be added to the end, and not removed.
-    enum Tags : uint32_t {
-      TypedBufferElementType = 0,
-      StructuredBufferElementStride,
-      SamplerFeedbackKind,
-      Atomic64Use
-    };
-
-    MDNode *write(LLVMContext &Ctx) const;
-  };
-};
-
-class UAVResource : public ResourceBase {
-  dxil::ResourceKind Shape;
-  bool GloballyCoherent;
-  bool HasCounter;
-  bool IsROV;
-  ResourceBase::ExtendedProperties ExtProps;
-
-  void parseSourceType(StringRef S);
-
-public:
-  UAVResource(uint32_t I, hlsl::FrontendResource R)
-      : ResourceBase(I, R), Shape(R.getResourceKind()), GloballyCoherent(false),
-        HasCounter(false), IsROV(R.getIsROV()), ExtProps{R.getElementType()} {}
-
-  MDNode *write() const;
-  void print(raw_ostream &O) const;
-};
-
-class ConstantBuffer : public ResourceBase {
-  uint32_t CBufferSizeInBytes = 0; // Cbuffer used size in bytes.
-public:
-  ConstantBuffer(uint32_t I, hlsl::FrontendResource R);
-  void setSize(CBufferDataLayout &DL);
-  MDNode *write() const;
-  void print(raw_ostream &O) const;
-};
-
-template <typename T> class ResourceTable {
-  StringRef MDName;
-
-  llvm::SmallVector<T> Data;
-
-public:
-  ResourceTable(StringRef Name) : MDName(Name) {}
-  void collect(Module &M);
-  bool empty() const { return Data.empty(); }
-  MDNode *write(Module &M) const;
-  void print(raw_ostream &O) const;
-};
-
-// FIXME: Fully computing the resource structures requires analyzing the IR
-// because some flags are set based on what operations are performed on the
-// resource. This partial patch handles some of the leg work, but not all of it.
-// See issue https://github.com/llvm/llvm-project/issues/57936.
-class Resources {
-  ResourceTable<UAVResource> UAVs = {"hlsl.uavs"};
-  ResourceTable<ConstantBuffer> CBuffers = {"hlsl.cbufs"};
-
-public:
-  void collect(Module &M);
-  bool hasUAVs() const { return !UAVs.empty(); }
-  Metadata *writeUAVs(Module &M) const;
-  void printUAVs(raw_ostream &OS) const;
-  bool hasCBuffers() const { return !CBuffers.empty(); }
-  Metadata *writeCBuffers(Module &M) const;
-  void printCBuffers(raw_ostream &OS) const;
-  LLVM_DUMP_METHOD void dump() const;
-};
-
-} // namespace dxil
-} // namespace llvm
-
-#endif // LLVM_TARGET_DIRECTX_DXILRESOURCE_H
diff --git a/llvm/lib/Target/DirectX/DXILResourceAnalysis.cpp b/llvm/lib/Target/DirectX/DXILResourceAnalysis.cpp
deleted file mode 100644
index d423220bb902e..0000000000000
--- a/llvm/lib/Target/DirectX/DXILResourceAnalysis.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-//===- DXILResourceAnalysis.cpp - DXIL Resource analysis-------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file This file contains Analysis for information about DXIL resources.
-///
-//===----------------------------------------------------------------------===//
-
-#include "DXILResourceAnalysis.h"
-#include "DirectX.h"
-#include "llvm/IR/PassManager.h"
-
-using namespace llvm;
-
-#define DEBUG_TYPE "dxil-resource-analysis"
-
-dxil::Resources DXILResourceMDAnalysis::run(Module &M,
-                                            ModuleAnalysisManager &AM) {
-  dxil::Resources R;
-  R.collect(M);
-  return R;
-}
-
-AnalysisKey DXILResourceMDAnalysis::Key;
-
-char DXILResourceMDWrapper::ID = 0;
-INITIALIZE_PASS_BEGIN(DXILResourceMDWrapper, DEBUG_TYPE,
-                      "DXIL resource Information", true, true)
-INITIALIZE_PASS_END(DXILResourceMDWrapper, DEBUG_TYPE,
-                    "DXIL resource Information", true, true)
-
-bool DXILResourceMDWrapper::runOnModule(Module &M) {
-  Resources.collect(M);
-  return false;
-}
-
-DXILResourceMDWrapper::DXILResourceMDWrapper() : ModulePass(ID) {}
diff --git a/llvm/lib/Target/DirectX/DXILResourceAnalysis.h b/llvm/lib/Target/DirectX/DXILResourceAnalysis.h
deleted file mode 100644
index 0ad97dc1992f4..0000000000000
--- a/llvm/lib/Target/DirectX/DXILResourceAnalysis.h
+++ /dev/null
@@ -1,55 +0,0 @@
-//===- DXILResourceAnalysis.h   - DXIL Resource analysis-------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-///
-/// \file This file contains Analysis for information about DXIL resources.
-///
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_TARGET_DIRECTX_DXILRESOURCEANALYSIS_H
-#define LLVM_TARGET_DIRECTX_DXILRESOURCEANALYSIS_H
-
-#include "DXILResource.h"
-#include "llvm/IR/PassManager.h"
-#include "llvm/Pass.h"
-#include <memory>
-
-namespace llvm {
-/// Analysis pass that exposes the \c DXILResource for a module.
-class DXILResourceMDAnalysis
-    : public AnalysisInfoMixin<DXILResourceMDAnalysis> {
-  friend AnalysisInfoMixin<DXILResourceMDAnalysis>;
-  static AnalysisKey Key;
-
-public:
-  typedef dxil::Resources Result;
-  dxil::Resources run(Module &M, ModuleAnalysisManager &AM);
-};
-
-/// The legacy pass manager's analysis pass to compute DXIL resource
-/// information.
-class DXILResourceMDWrapper : public ModulePass {
-  dxil::Resources Resources;
-
-public:
-  static char ID; // Pass identification, replacement for typeid
-
-  DXILResourceMDWrapper();
-
-  dxil::Resources &getDXILResource() { return Resources; }
-  const dxil::Resources &getDXILResource() const { return Resources; }
-
-  /// Calculate the DXILResource for the module.
-  bool runOnModule(Module &M) override;
-
-  void getAnalysisUsage(AnalysisUsage &AU) const override {
-    AU.setPreservesAll();
-  }
-};
-} // namespace llvm
-
-#endif // LLVM_TARGET_DIRECTX_DXILRESOURCEANALYSIS_H
diff --git a/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp b/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
index 5fd5c226eef89..6da5a355f8390 100644
--- a/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
+++ b/llvm/lib/Target/DirectX/DXILTranslateMetadata.cpp
@@ -7,8 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "DXILTranslateMetadata.h"
-#include "DXILResource.h"
-#include "DXILResourceAnalysis.h"
 #include "DXILShaderFlags.h"
 #include "DirectX.h"
 #include "llvm/ADT/SmallVector.h"
@@ -75,8 +73,7 @@ enum class EntryPropsTag {
 } // namespace
 
 static NamedMDNode *emitResourceMetadata(Module &M, DXILBindingMap &DBM,
-                                         DXILResourceTypeMap &DRTM,
-                                         const dxil::Resources &MDResources) {
+                                         DXILResourceTypeMap &DRTM) {
   LLVMContext &Context = M.getContext();
 
   for (ResourceBindingInfo &RI : DBM)
@@ -99,18 +96,6 @@ static NamedMDNode *emitResourceMetadata(Module &M, DXILBindingMap &DBM,
   Metadata *SmpMD = Smps.empty() ? nullptr : MDNode::get(Context, Smps);
   bool HasResources = !DBM.empty();
 
-  if (MDResources.hasUAVs()) {
-    assert(!UAVMD && "Old and new UAV representations can't coexist");
-    UAVMD = MDResources.writeUAVs(M);
-    HasResources = true;
-  }
-
-  if (MDResources.hasCBuffers()) {
-    assert(!CBufMD && "Old and new cbuffer representations can't coexist");
-    CBufMD = MDResources.writeCBuffers(M);
-    HasResources = true;
-  }
-
   if (!HasResources)
     return nullptr;
 
@@ -336,7 +321,6 @@ static void translateBranchMetadata(Module &M) {
 
 static void translateMetadata(Module &M, DXILBindingMap &DBM,
                               DXILResourceTypeMap &DRTM,
-                              const Resources &MDResources,
                               const ModuleShaderFlags &ShaderFlags,
                               const ModuleMetadataInfo &MMDI) {
   LLVMContext &Ctx = M.getContext();
@@ -346,8 +330,7 @@ static void translateMetadata(Module &M, DXILBindingMap &DBM,
   emitValidatorVersionMD(M, MMDI);
   emitShaderModelVersionMD(M, MMDI);
   emitDXILVersionTupleMD(M, MMDI);
-  NamedMDNode *NamedResourceMD =
-      emitResourceMetadata(M, DBM, DRTM, MDResources);
+  NamedMDNode *NamedResourceMD = emitResourceMetadata(M, DBM, DRTM);
   auto *ResourceMD =
       (NamedResourceMD != nullptr) ? NamedResourceMD->getOperand(0) : nullptr;
   // FIXME: Add support to construct Signatures
@@ -401,11 +384,10 @@ PreservedAnalyses DXILTranslateMetadata::run(Module &M,
                                              ModuleAnalysisManager &MAM) {
   DXILBindingMap &DBM = MAM.getResult<DXILResourceBindingAnalysis>(M);
   DXILResourceTypeMap &DRTM = MAM.getResult<DXILResourceTypeAnalysis>(M);
-  const dxil::Resources &MDResources = MAM.getResult<DXILResourceMDAnalysis>(M);
   const ModuleShaderFlags &ShaderFlags = MAM.getResult<ShaderFlagsAnalysis>(M);
   const dxil::ModuleMetadataInfo MMDI = MAM.getResult<DXILMetadataAnalysis>(M);
 
-  translateMetadata(M, DBM, DRTM, MDResources, ShaderFlags, MMDI);
+  translateMetadata(M, DBM, DRTM, ShaderFlags, MMDI);
   translateBranchMetadata(M);
 
   return PreservedAnalyses::all();
@@ -422,11 +404,9 @@ class DXILTranslateMetadataLegacy : public ModulePass {
   void getAnalysisUsage(AnalysisUsage &AU) const override {
     AU.addRequired<DXILResourceTypeWrapperPass>();
     AU.addRequired<DXILResourceBindingWrapperPass>();
-    AU.addRequired<DXILResourceMDWrapper>();
     AU.addRequired<ShaderFlagsAnalysisWrapper>();
     AU.addRequired<DXILMetadataAnalysisWrapperPass>();
     AU.addPreserved<DXILResourceBindingWrapperPass>();
-    AU.addPreserved<DXILResourceMDWrapper>();
     AU.addPreserved<DXILMetadataAnalysisWrapperPass>();
     AU.addPreserved<ShaderFlagsAnalysisWrapper>();
   }
@@ -436,14 +416,12 @@ class DXILTranslateMetadataLegacy : public ModulePass {
         getAnalysis<DXILResourceBindingWrapperPass>().getBindingMap();
     DXILResourceTypeMap &DRTM =
         getAnalysis<DXILResourceTypeWrapperPass>().getResourceTypeMap();
-    const dxil::Resources &MDResources =
-        getAnalysis<DXILResourceMDWrapper>().getDXILResource();
     const ModuleShaderFlags &ShaderFlags =
         getAnalysis<ShaderFlagsAnalysisWrapper>().getShaderFlags();
     dxil::ModuleMetadataInfo MMDI =
         getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
 
-    translateMetadata(M, DBM, DRTM, MDResources, ShaderFlags, MMDI);
+    translateMetadata(M, DBM, DRTM, ShaderFlags, MMDI);
     translateBranchMetadata(M);
     return true;
   }
@@ -460,7 +438,6 @@ ModulePass *llvm::createDXILTranslateMetadataLegacyPass() {
 INITIALIZE_PASS_BEGIN(DXILTranslateMetadataLegacy, "dxil-translate-metadata",
                       "DXIL Translate Metadata", false, false)
 INITIALIZE_PASS_DEPENDENCY(DXILResourceBindingWrapperPass)
-INITIALIZE_PASS_DEPENDENCY(DXILResourceMDWrapper)
 INITIALIZE_PASS_DEPENDENCY(ShaderFlagsAnalysisWrapper)
 INITIALIZE_PASS_DEPENDENCY(DXILMetadataAnalysisWrapperPass)
 INITIALIZE_PASS_END(DXILTranslateMetadataLegacy, "dxil-translate-metadata",
diff --git a/llvm/lib/Target/DirectX/DirectX.h b/llvm/lib/Target/DirectX/DirectX.h
index 953ac3eb82098..42aa0da16e8aa 100644
--- a/llvm/lib/Target/DirectX/DirectX.h
+++ b/llvm/lib/Target/DirectX/DirectX.h
@@ -65,9 +65,6 @@ void initializeDXILTranslateMetadataLegacyPass(PassRegistry &);
 /// Pass to emit metadata for DXIL.
 ModulePass *createDXILTranslateMetadataLegacyPass();
 
-/// Initializer for DXILTranslateMetadata.
-void initializeDXILResourceMDWrapperPass(PassRegistry &);
-
 /// Pass to pretty print DXIL metadata.
 ModulePass *createDXILPrettyPrinterLegacyPass(raw_ostream &OS);
 
diff --git a/llvm/lib/Target/DirectX/DirectXPassRegistry.def b/llvm/lib/Target/DirectX/DirectXPassRegistry.def
index de5087ce1ae2f..aee0a4ff83d43 100644
--- a/llvm/lib/Target/DirectX/DirectXPassRegistry.def
+++ b/llvm/lib/Target/DirectX/DirectXPassRegistry.def
@@ -17,7 +17,6 @@
 #define MODULE_ANALYSIS(NAME, CREATE_PASS)
 #endif
 MODULE_ANALYSIS("dx-shader-flags", dxil::ShaderFlagsAnalysis())
-MODULE_ANALYSIS("dxil-resource-md", DXILResourceMDAnalysis())
 MODULE_ANALYSIS("dxil-root-signature-analysis", dxil::RootSignatureAnalysis())
 #undef MODULE_ANALYSIS
 
diff --git a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
index dda650b0f6e15..82dc1c6af562a 100644
--- a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
+++ b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
@@ -18,7 +18,6 @@
 #include "DXILOpLowering.h"
 #include "DXILPrettyPrinter.h"
 #include "DXILResourceAccess.h"
-#include "DXILResourceAnalysis.h"
 #include "DXILRootSignature.h"
 #include "DXILShaderFlags.h"
 #include "DXILTranslateMetadata.h"
@@ -60,7 +59,6 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTarget() {
   initializeDXILOpLoweringLegacyPass(*PR);
   initializeDXILResourceAccessLegacyPass(*PR);
   initializeDXILTranslateMetadataLegacyPass(*PR);
-  initializeDXILResourceMDWrapperPass(*PR);
   initializeShaderFlagsAnalysisWrapperPass(*PR);
   initializeRootSignatureAnalysisWrapperPass(*PR);
   initializeDXILFinalizeLinkageLegacyPass(*PR);
diff --git a/llvm/test/CodeGen/DirectX/llc-pipeline.ll b/llvm/test/CodeGen/DirectX/llc-pipeline.ll
index afbf1ff72ec7e..3a9af4d744f98 100644
--- a/llvm/test/CodeGen/DirectX/llc-pipeline.ll
+++ b/llvm/test/CodeGen/DirectX/llc-pipeline.ll
@@ -22,7 +22,6 @@
 ; CHECK-NEXT:     Dominator Tree Construction
 ; CHECK-NEXT:     Scalarize vector operations
 ; CHECK-NEXT:   DXIL Resource Binding Analysis
-; CHECK-NEXT:   DXIL resource Information
 ; CHECK-NEXT:   DXIL Module Metadata analysis
 ; CHECK-NEXT:   DXIL Shader Flag Analysis
 ; CHECK-NEXT:   DXIL Translate Metadata

>From c574bedb001f61f4bcdbf00613eec932028cf392 Mon Sep 17 00:00:00 2001
From: Helena Kotas <hekotas at microsoft.com>
Date: Fri, 7 Mar 2025 12:09:33 -0800
Subject: [PATCH 3/3] [HLSL] Remove old resource annotations

Fixes #114126
---
 clang/lib/CodeGen/CGDeclCXX.cpp               |   3 -
 clang/lib/CodeGen/CGHLSLRuntime.cpp           | 129 ------------------
 clang/lib/CodeGen/CGHLSLRuntime.h             |  15 --
 .../include/llvm/Frontend/HLSL/HLSLResource.h |  22 ---
 llvm/lib/Frontend/HLSL/HLSLResource.cpp       |  54 +-------
 5 files changed, 2 insertions(+), 221 deletions(-)

diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index f5950f03673a1..1ad34ae61f96a 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -1071,9 +1071,6 @@ void CodeGenFunction::GenerateCXXGlobalVarDeclInitFunc(llvm::Function *Fn,
     EmitCXXGlobalVarDeclInit(*D, Addr, PerformInit);
   }
 
-  if (getLangOpts().HLSL)
-    CGM.getHLSLRuntime().annotateHLSLResource(D, Addr);
-
   FinishFunction();
 }
 
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index dc34653e8f497..7ea23032b6519 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -260,135 +260,6 @@ void CGHLSLRuntime::finishCodeGen() {
   generateGlobalCtorDtorCalls();
 }
 
-void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
-                                                llvm::hlsl::ResourceClass RC,
-                                                llvm::hlsl::ResourceKind RK,
-                                                bool IsROV,
-                                                llvm::hlsl::ElementType ET,
-                                                BufferResBinding &Binding) {
-  llvm::Module &M = CGM.getModule();
-
-  NamedMDNode *ResourceMD = nullptr;
-  switch (RC) {
-  case llvm::hlsl::ResourceClass::UAV:
-    ResourceMD = M.getOrInsertNamedMetadata("hlsl.uavs");
-    break;
-  case llvm::hlsl::ResourceClass::SRV:
-    ResourceMD = M.getOrInsertNamedMetadata("hlsl.srvs");
-    break;
-  case llvm::hlsl::ResourceClass::CBuffer:
-    ResourceMD = M.getOrInsertNamedMetadata("hlsl.cbufs");
-    break;
-  default:
-    assert(false && "Unsupported buffer type!");
-    return;
-  }
-  assert(ResourceMD != nullptr &&
-         "ResourceMD must have been set by the switch above.");
-
-  llvm::hlsl::FrontendResource Res(
-      GV, RK, ET, IsROV, Binding.Reg.value_or(UINT_MAX), Binding.Space);
-  ResourceMD->addOperand(Res.getMetadata());
-}
-
-static llvm::hlsl::ElementType
-calculateElementType(const ASTContext &Context, const clang::Type *ResourceTy) {
-  using llvm::hlsl::ElementType;
-
-  // TODO: We may need to update this when we add things like ByteAddressBuffer
-  // that don't have a template parameter (or, indeed, an element type).
-  const auto *TST = ResourceTy->getAs<TemplateSpecializationType>();
-  assert(TST && "Resource types must be template specializations");
-  ArrayRef<TemplateArgument> Args = TST->template_arguments();
-  assert(!Args.empty() && "Resource has no element type");
-
-  // At this point we have a resource with an element type, so we can assume
-  // that it's valid or we would have diagnosed the error earlier.
-  QualType ElTy = Args[0].getAsType();
-
-  // We should either have a basic type or a vector of a basic type.
-  if (const auto *VecTy = ElTy->getAs<clang::VectorType>())
-    ElTy = VecTy->getElementType();
-
-  if (ElTy->isSignedIntegerType()) {
-    switch (Context.getTypeSize(ElTy)) {
-    case 16:
-      return ElementType::I16;
-    case 32:
-      return ElementType::I32;
-    case 64:
-      return ElementType::I64;
-    }
-  } else if (ElTy->isUnsignedIntegerType()) {
-    switch (Context.getTypeSize(ElTy)) {
-    case 16:
-      return ElementType::U16;
-    case 32:
-      return ElementType::U32;
-    case 64:
-      return ElementType::U64;
-    }
-  } else if (ElTy->isSpecificBuiltinType(BuiltinType::Half))
-    return ElementType::F16;
-  else if (ElTy->isSpecificBuiltinType(BuiltinType::Float))
-    return ElementType::F32;
-  else if (ElTy->isSpecificBuiltinType(BuiltinType::Double))
-    return ElementType::F64;
-
-  // TODO: We need to handle unorm/snorm float types here once we support them
-  llvm_unreachable("Invalid element type for resource");
-}
-
-void CGHLSLRuntime::annotateHLSLResource(const VarDecl *D, GlobalVariable *GV) {
-  const Type *Ty = D->getType()->getPointeeOrArrayElementType();
-  if (!Ty)
-    return;
-  const auto *RD = Ty->getAsCXXRecordDecl();
-  if (!RD)
-    return;
-  // the resource related attributes are on the handle member
-  // inside the record decl
-  for (auto *FD : RD->fields()) {
-    const auto *HLSLResAttr = FD->getAttr<HLSLResourceAttr>();
-    const HLSLAttributedResourceType *AttrResType =
-        dyn_cast<HLSLAttributedResourceType>(FD->getType().getTypePtr());
-    if (!HLSLResAttr || !AttrResType)
-      continue;
-
-    llvm::hlsl::ResourceClass RC = AttrResType->getAttrs().ResourceClass;
-    if (RC == llvm::hlsl::ResourceClass::UAV ||
-        RC == llvm::hlsl::ResourceClass::SRV)
-      // UAVs and SRVs have already been converted to use LLVM target types,
-      // we can disable generating of these resource annotations. This will
-      // enable progress on structured buffers with user defined types this
-      // resource annotations code does not handle and it crashes.
-      // This whole function is going to be removed as soon as cbuffers are
-      // converted to target types (llvm/llvm-project #114126).
-      return;
-
-    bool IsROV = AttrResType->getAttrs().IsROV;
-    llvm::hlsl::ResourceKind RK = HLSLResAttr->getResourceKind();
-    llvm::hlsl::ElementType ET = calculateElementType(CGM.getContext(), Ty);
-
-    BufferResBinding Binding(D->getAttr<HLSLResourceBindingAttr>());
-    addBufferResourceAnnotation(GV, RC, RK, IsROV, ET, Binding);
-  }
-}
-
-CGHLSLRuntime::BufferResBinding::BufferResBinding(
-    HLSLResourceBindingAttr *Binding) {
-  if (Binding) {
-    llvm::APInt RegInt(64, 0);
-    Binding->getSlot().substr(1).getAsInteger(10, RegInt);
-    Reg = RegInt.getLimitedValue();
-    llvm::APInt SpaceInt(64, 0);
-    Binding->getSpace().substr(5).getAsInteger(10, SpaceInt);
-    Space = SpaceInt.getLimitedValue();
-  } else {
-    Space = 0;
-  }
-}
-
 void clang::CodeGen::CGHLSLRuntime::setHLSLEntryAttributes(
     const FunctionDecl *FD, llvm::Function *Fn) {
   const auto *ShaderAttr = FD->getAttr<HLSLShaderAttr>();
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h
index a9da42324a038..717d0d294be81 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -125,15 +125,6 @@ class CGHLSLRuntime {
   // End of reserved area for HLSL intrinsic getters.
   //===----------------------------------------------------------------------===//
 
-  struct BufferResBinding {
-    // The ID like 2 in register(b2, space1).
-    std::optional<unsigned> Reg;
-    // The Space like 1 is register(b2, space1).
-    // Default value is 0.
-    unsigned Space;
-    BufferResBinding(HLSLResourceBindingAttr *Attr);
-  };
-
 protected:
   CodeGenModule &CGM;
 
@@ -148,7 +139,6 @@ class CGHLSLRuntime {
   convertHLSLSpecificType(const Type *T,
                           SmallVector<unsigned> *Packoffsets = nullptr);
 
-  void annotateHLSLResource(const VarDecl *D, llvm::GlobalVariable *GV);
   void generateGlobalCtorDtorCalls();
 
   void addBuffer(const HLSLBufferDecl *D);
@@ -169,11 +159,6 @@ class CGHLSLRuntime {
   void emitInitListOpaqueValues(CodeGenFunction &CGF, InitListExpr *E);
 
 private:
-  void addBufferResourceAnnotation(llvm::GlobalVariable *GV,
-                                   llvm::hlsl::ResourceClass RC,
-                                   llvm::hlsl::ResourceKind RK, bool IsROV,
-                                   llvm::hlsl::ElementType ET,
-                                   BufferResBinding &Binding);
   void emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,
                                     llvm::GlobalVariable *BufGV);
   llvm::Triple::ArchType getArch();
diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
index 989893bcaccec..f4ed6d552899f 100644
--- a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
@@ -13,37 +13,15 @@
 #ifndef LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
 #define LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
 
-#include "llvm/ADT/StringRef.h"
 #include "llvm/Support/DXILABI.h"
 
 namespace llvm {
-class GlobalVariable;
-class MDNode;
-
 namespace hlsl {
 
 // For now we use DXIL ABI enum values directly. This may change in the future.
 using dxil::ResourceClass;
-using dxil::ElementType;
 using dxil::ResourceKind;
 
-class FrontendResource {
-  MDNode *Entry;
-
-public:
-  FrontendResource(MDNode *E);
-  FrontendResource(GlobalVariable *GV, ResourceKind RK, ElementType ElTy,
-                   bool IsROV, uint32_t ResIndex, uint32_t Space);
-
-  GlobalVariable *getGlobalVariable();
-  StringRef getSourceType();
-  ResourceKind getResourceKind();
-  ElementType getElementType();
-  bool getIsROV();
-  uint32_t getResourceIndex();
-  uint32_t getSpace();
-  MDNode *getMetadata() { return Entry; }
-};
 } // namespace hlsl
 } // namespace llvm
 
diff --git a/llvm/lib/Frontend/HLSL/HLSLResource.cpp b/llvm/lib/Frontend/HLSL/HLSLResource.cpp
index 48310d4f28e67..970edb9710cb6 100644
--- a/llvm/lib/Frontend/HLSL/HLSLResource.cpp
+++ b/llvm/lib/Frontend/HLSL/HLSLResource.cpp
@@ -11,59 +11,9 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Frontend/HLSL/HLSLResource.h"
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/Metadata.h"
 
 using namespace llvm;
 using namespace llvm::hlsl;
 
-GlobalVariable *FrontendResource::getGlobalVariable() {
-  return cast<GlobalVariable>(
-      cast<ConstantAsMetadata>(Entry->getOperand(0))->getValue());
-}
-
-ResourceKind FrontendResource::getResourceKind() {
-  return static_cast<ResourceKind>(
-      cast<ConstantInt>(
-          cast<ConstantAsMetadata>(Entry->getOperand(1))->getValue())
-          ->getLimitedValue());
-}
-ElementType FrontendResource::getElementType() {
-  return static_cast<ElementType>(
-      cast<ConstantInt>(
-          cast<ConstantAsMetadata>(Entry->getOperand(2))->getValue())
-          ->getLimitedValue());
-}
-bool FrontendResource::getIsROV() {
-  return cast<ConstantInt>(
-             cast<ConstantAsMetadata>(Entry->getOperand(3))->getValue())
-      ->getLimitedValue();
-}
-uint32_t FrontendResource::getResourceIndex() {
-  return cast<ConstantInt>(
-             cast<ConstantAsMetadata>(Entry->getOperand(4))->getValue())
-      ->getLimitedValue();
-}
-uint32_t FrontendResource::getSpace() {
-  return cast<ConstantInt>(
-             cast<ConstantAsMetadata>(Entry->getOperand(5))->getValue())
-      ->getLimitedValue();
-}
-
-FrontendResource::FrontendResource(MDNode *E) : Entry(E) {
-  assert(Entry->getNumOperands() == 6 && "Unexpected metadata shape");
-}
-
-FrontendResource::FrontendResource(GlobalVariable *GV, ResourceKind RK,
-                                   ElementType ElTy, bool IsROV,
-                                   uint32_t ResIndex, uint32_t Space) {
-  auto &Ctx = GV->getContext();
-  IRBuilder<> B(Ctx);
-  Entry = MDNode::get(
-      Ctx, {ValueAsMetadata::get(GV),
-            ConstantAsMetadata::get(B.getInt32(static_cast<int>(RK))),
-            ConstantAsMetadata::get(B.getInt32(static_cast<int>(ElTy))),
-            ConstantAsMetadata::get(B.getInt1(IsROV)),
-            ConstantAsMetadata::get(B.getInt32(ResIndex)),
-            ConstantAsMetadata::get(B.getInt32(Space))});
-}
+// Intentionally empty; this file can be removed when more cpp files are added
+// to the HLSLFrontend lib.



More information about the cfe-commits mailing list