[clang] 4c7218e - [HLSL] Remove unused frontend-generated ID

Chris Bieneman via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 21 10:41:20 PDT 2022


Author: Chris Bieneman
Date: 2022-10-21T12:41:09-05:00
New Revision: 4c7218e7702651bb8dd2ef7734ca05ac0ada32fd

URL: https://github.com/llvm/llvm-project/commit/4c7218e7702651bb8dd2ef7734ca05ac0ada32fd
DIFF: https://github.com/llvm/llvm-project/commit/4c7218e7702651bb8dd2ef7734ca05ac0ada32fd.diff

LOG: [HLSL] Remove unused frontend-generated ID

As @python3kgae pointed out we're going to want to assign these IDs
after optimization so that we can remove unused resrouces. This patch
just removes the unused ID value from the frontend metadata, clang code
generation, and updates associated test cases.

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D136271

Added: 
    

Modified: 
    clang/lib/CodeGen/CGHLSLRuntime.cpp
    clang/lib/CodeGen/CGHLSLRuntime.h
    clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
    clang/test/CodeGenHLSL/cbuf.hlsl
    llvm/include/llvm/Frontend/HLSL/HLSLResource.h
    llvm/lib/Frontend/HLSL/HLSLResource.cpp
    llvm/test/CodeGen/DirectX/UAVMetadata.ll

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index f64fdfade9f4f..5882f491d5972 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -197,7 +197,6 @@ void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
                                                 llvm::hlsl::ResourceClass RC,
                                                 llvm::hlsl::ResourceKind RK,
                                                 BufferResBinding &Binding) {
-  uint32_t Counter = ResourceCounters[static_cast<uint32_t>(RC)]++;
   llvm::Module &M = CGM.getModule();
 
   NamedMDNode *ResourceMD = nullptr;
@@ -220,7 +219,7 @@ void CGHLSLRuntime::addBufferResourceAnnotation(llvm::GlobalVariable *GV,
          "ResourceMD must have been set by the switch above.");
 
   llvm::hlsl::FrontendResource Res(
-      GV, TyName, Counter, RK, Binding.Reg.value_or(UINT_MAX), Binding.Space);
+      GV, TyName, RK, Binding.Reg.value_or(UINT_MAX), Binding.Space);
   ResourceMD->addOperand(Res.getMetadata());
 }
 

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h
index 107b0d6d12854..976f925ed1c84 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -70,8 +70,6 @@ class CGHLSLRuntime {
 
 protected:
   CodeGenModule &CGM;
-  uint32_t ResourceCounters[static_cast<uint32_t>(
-      llvm::hlsl::ResourceClass::NumClasses)] = {0};
 
   llvm::Value *emitInputSemantic(llvm::IRBuilder<> &B, const ParmVarDecl &D,
                                  llvm::Type *Ty);

diff  --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl b/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
index f35e704e45799..77091f8390a15 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl
@@ -16,9 +16,9 @@ void main() {
 }
 
 // CHECK: !hlsl.uavs = !{![[Single:[0-9]+]], ![[Array:[0-9]+]], ![[SingleAllocated:[0-9]+]], ![[ArrayAllocated:[0-9]+]], ![[SingleSpace:[0-9]+]], ![[ArraySpace:[0-9]+]]}
-// CHECK-DAG: ![[Single]] = !{ptr @"?Buffer1@@3V?$RWBuffer at M@hlsl@@A", !"RWBuffer<float>", i32 0, i32 10, i32 -1, i32 0}
-// CHECK-DAG: ![[Array]] = !{ptr @"?BufferArray@@3PAV?$RWBuffer at T?$__vector at M$03 at __clang@@@hlsl@@A", !"RWBuffer<vector<float, 4> >", i32 1, i32 10, i32 -1, i32 0}
-// CHECK-DAG: ![[SingleAllocated]] = !{ptr @"?Buffer2@@3V?$RWBuffer at M@hlsl@@A", !"RWBuffer<float>", i32 2, i32 10, i32 3, i32 0}
-// CHECK-DAG: ![[ArrayAllocated]] = !{ptr @"?BufferArray2@@3PAV?$RWBuffer at T?$__vector at M$03 at __clang@@@hlsl@@A", !"RWBuffer<vector<float, 4> >", i32 3, i32 10, i32 4, i32 0}
-// CHECK-DAG: ![[SingleSpace]] = !{ptr @"?Buffer3@@3V?$RWBuffer at M@hlsl@@A", !"RWBuffer<float>", i32 4, i32 10, i32 3, i32 1}
-// CHECK-DAG: ![[ArraySpace]] = !{ptr @"?BufferArray3@@3PAV?$RWBuffer at T?$__vector at M$03 at __clang@@@hlsl@@A", !"RWBuffer<vector<float, 4> >", i32 5, i32 10, i32 4, i32 1}
+// CHECK-DAG: ![[Single]] = !{ptr @"?Buffer1@@3V?$RWBuffer at M@hlsl@@A", !"RWBuffer<float>", i32 10, i32 -1, i32 0}
+// CHECK-DAG: ![[Array]] = !{ptr @"?BufferArray@@3PAV?$RWBuffer at T?$__vector at M$03 at __clang@@@hlsl@@A", !"RWBuffer<vector<float, 4> >", i32 10, i32 -1, i32 0}
+// CHECK-DAG: ![[SingleAllocated]] = !{ptr @"?Buffer2@@3V?$RWBuffer at M@hlsl@@A", !"RWBuffer<float>", i32 10, i32 3, i32 0}
+// CHECK-DAG: ![[ArrayAllocated]] = !{ptr @"?BufferArray2@@3PAV?$RWBuffer at T?$__vector at M$03 at __clang@@@hlsl@@A", !"RWBuffer<vector<float, 4> >", i32 10, i32 4, i32 0}
+// CHECK-DAG: ![[SingleSpace]] = !{ptr @"?Buffer3@@3V?$RWBuffer at M@hlsl@@A", !"RWBuffer<float>", i32 10, i32 3, i32 1}
+// CHECK-DAG: ![[ArraySpace]] = !{ptr @"?BufferArray3@@3PAV?$RWBuffer at T?$__vector at M$03 at __clang@@@hlsl@@A", !"RWBuffer<vector<float, 4> >", i32 10, i32 4, i32 1}

diff  --git a/clang/test/CodeGenHLSL/cbuf.hlsl b/clang/test/CodeGenHLSL/cbuf.hlsl
index 2a98912b7eeea..92c883943d03e 100644
--- a/clang/test/CodeGenHLSL/cbuf.hlsl
+++ b/clang/test/CodeGenHLSL/cbuf.hlsl
@@ -24,5 +24,5 @@ float foo() {
 
 // CHECK: !hlsl.cbufs = !{![[CBMD:[0-9]+]]}
 // CHECK: !hlsl.srvs = !{![[TBMD:[0-9]+]]}
-// CHECK: ![[CBMD]] = !{ptr @[[CB]], !"A.cb.ty", i32 0, i32 13, i32 0, i32 2}
-// CHECK: ![[TBMD]] = !{ptr @[[TB]], !"A.tb.ty", i32 0, i32 15, i32 2, i32 1}
+// CHECK: ![[CBMD]] = !{ptr @[[CB]], !"A.cb.ty", i32 13, i32 0, i32 2}
+// CHECK: ![[TBMD]] = !{ptr @[[TB]], !"A.tb.ty", i32 15, i32 2, i32 1}

diff  --git a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
index 09a566ae4f318..b0c20312f2a7b 100644
--- a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h
@@ -60,15 +60,14 @@ class FrontendResource {
 
 public:
   FrontendResource(MDNode *E) : Entry(E) {
-    assert(Entry->getNumOperands() == 6 && "Unexpected metadata shape");
+    assert(Entry->getNumOperands() == 5 && "Unexpected metadata shape");
   }
 
-  FrontendResource(GlobalVariable *GV, StringRef TypeStr, uint32_t Counter,
-                   ResourceKind RK, uint32_t ResIndex, uint32_t Space);
+  FrontendResource(GlobalVariable *GV, StringRef TypeStr, ResourceKind RK,
+                   uint32_t ResIndex, uint32_t Space);
 
   GlobalVariable *getGlobalVariable();
   StringRef getSourceType();
-  Constant *getID();
   uint32_t getResourceKind();
   uint32_t getResourceIndex();
   uint32_t getSpace();

diff  --git a/llvm/lib/Frontend/HLSL/HLSLResource.cpp b/llvm/lib/Frontend/HLSL/HLSLResource.cpp
index fbd86f5dba167..59f730d8a495d 100644
--- a/llvm/lib/Frontend/HLSL/HLSLResource.cpp
+++ b/llvm/lib/Frontend/HLSL/HLSLResource.cpp
@@ -27,34 +27,29 @@ StringRef FrontendResource::getSourceType() {
   return cast<MDString>(Entry->getOperand(1))->getString();
 }
 
-Constant *FrontendResource::getID() {
-  return cast<ConstantAsMetadata>(Entry->getOperand(2))->getValue();
-}
-
 uint32_t FrontendResource::FrontendResource::getResourceKind() {
   return cast<ConstantInt>(
-             cast<ConstantAsMetadata>(Entry->getOperand(3))->getValue())
+             cast<ConstantAsMetadata>(Entry->getOperand(2))->getValue())
       ->getLimitedValue();
 }
 uint32_t FrontendResource::getResourceIndex() {
   return cast<ConstantInt>(
-             cast<ConstantAsMetadata>(Entry->getOperand(4))->getValue())
+             cast<ConstantAsMetadata>(Entry->getOperand(3))->getValue())
       ->getLimitedValue();
 }
 uint32_t FrontendResource::getSpace() {
   return cast<ConstantInt>(
-             cast<ConstantAsMetadata>(Entry->getOperand(5))->getValue())
+             cast<ConstantAsMetadata>(Entry->getOperand(4))->getValue())
       ->getLimitedValue();
 }
 
 FrontendResource::FrontendResource(GlobalVariable *GV, StringRef TypeStr,
-                                   uint32_t Counter, ResourceKind RK,
-                                   uint32_t ResIndex, uint32_t Space) {
+                                   ResourceKind RK, uint32_t ResIndex,
+                                   uint32_t Space) {
   auto &Ctx = GV->getContext();
   IRBuilder<> B(Ctx);
   Entry = MDNode::get(
       Ctx, {ValueAsMetadata::get(GV), MDString::get(Ctx, TypeStr),
-            ConstantAsMetadata::get(B.getInt32(Counter)),
             ConstantAsMetadata::get(B.getInt32(static_cast<int>(RK))),
             ConstantAsMetadata::get(B.getInt32(ResIndex)),
             ConstantAsMetadata::get(B.getInt32(Space))});

diff  --git a/llvm/test/CodeGen/DirectX/UAVMetadata.ll b/llvm/test/CodeGen/DirectX/UAVMetadata.ll
index c51358790710a..3520c0be73510 100644
--- a/llvm/test/CodeGen/DirectX/UAVMetadata.ll
+++ b/llvm/test/CodeGen/DirectX/UAVMetadata.ll
@@ -37,16 +37,16 @@ target triple = "dxil-pc-shadermodel6.0-compute"
 
 !hlsl.uavs = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9}
 
-!0 = !{ptr @Zero, !"RWBuffer<half>", i32 0, i32 10, i32 0, i32 0}
-!1 = !{ptr @One, !"Buffer<vector<float,4>>", i32 1, i32 10, i32 1, i32 0}
-!2 = !{ptr @Two, !"Buffer<double>", i32 2, i32 10, i32 2, i32 0}
-!3 = !{ptr @Three, !"Buffer<bool>", i32 3, i32 10, i32 3, i32 0}
-!4 = !{ptr @Four, !"ByteAddressBuffer<int16_t>", i32 4, i32 11, i32 5, i32 0}
-!5 = !{ptr @Five, !"StructuredBuffer<uint16_t>", i32 5, i32 12, i32 6, i32 0}
-!6 = !{ptr @Six, !"RasterizerOrderedBuffer<int32_t>", i32 6, i32 10, i32 7, i32 0}
-!7 = !{ptr @Seven, !"RasterizerOrderedStructuredBuffer<uint32_t>", i32 7, i32 12, i32 8, i32 0}
-!8 = !{ptr @Eight, !"RasterizerOrderedByteAddressBuffer<int64_t>", i32 8, i32 11, i32 9, i32 0}
-!9 = !{ptr @Nine, !"RWBuffer<uint64_t>", i32 9, i32 10, i32 10, i32 2}
+!0 = !{ptr @Zero, !"RWBuffer<half>", i32 10, i32 0, i32 0}
+!1 = !{ptr @One, !"Buffer<vector<float,4>>", i32 10, i32 1, i32 0}
+!2 = !{ptr @Two, !"Buffer<double>", i32 10, i32 2, i32 0}
+!3 = !{ptr @Three, !"Buffer<bool>", i32 10, i32 3, i32 0}
+!4 = !{ptr @Four, !"ByteAddressBuffer<int16_t>", i32 11, i32 5, i32 0}
+!5 = !{ptr @Five, !"StructuredBuffer<uint16_t>", i32 12, i32 6, i32 0}
+!6 = !{ptr @Six, !"RasterizerOrderedBuffer<int32_t>", i32 10, i32 7, i32 0}
+!7 = !{ptr @Seven, !"RasterizerOrderedStructuredBuffer<uint32_t>", i32 12, i32 8, i32 0}
+!8 = !{ptr @Eight, !"RasterizerOrderedByteAddressBuffer<int64_t>", i32 11, i32 9, i32 0}
+!9 = !{ptr @Nine, !"RWBuffer<uint64_t>", i32 10, i32 10, i32 2}
 
 ; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}
 


        


More information about the cfe-commits mailing list