diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -70,8 +70,6 @@ protected: CodeGenModule &CGM; - uint32_t ResourceCounters[static_cast( - hlsl::ResourceClass::NumClasses)] = {0}; llvm::Value *emitInputSemantic(llvm::IRBuilder<> &B, const ParmVarDecl &D, llvm::Type *Ty); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -196,7 +196,6 @@ hlsl::ResourceClass RC, llvm::hlsl::ResourceKind RK, BufferResBinding &Binding) { - uint32_t Counter = ResourceCounters[static_cast(RC)]++; llvm::Module &M = CGM.getModule(); NamedMDNode *ResourceMD = nullptr; @@ -219,7 +218,7 @@ "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/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl b/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl --- a/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl +++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-annotations.hlsl @@ -16,9 +16,9 @@ } // 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@M@hlsl@@A", !"RWBuffer", i32 0, i32 10, i32 -1, i32 0} -// CHECK-DAG: ![[Array]] = !{ptr @"?BufferArray@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", !"RWBuffer >", i32 1, i32 10, i32 -1, i32 0} -// CHECK-DAG: ![[SingleAllocated]] = !{ptr @"?Buffer2@@3V?$RWBuffer@M@hlsl@@A", !"RWBuffer", i32 2, i32 10, i32 3, i32 0} -// CHECK-DAG: ![[ArrayAllocated]] = !{ptr @"?BufferArray2@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", !"RWBuffer >", i32 3, i32 10, i32 4, i32 0} -// CHECK-DAG: ![[SingleSpace]] = !{ptr @"?Buffer3@@3V?$RWBuffer@M@hlsl@@A", !"RWBuffer", i32 4, i32 10, i32 3, i32 1} -// CHECK-DAG: ![[ArraySpace]] = !{ptr @"?BufferArray3@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", !"RWBuffer >", i32 5, i32 10, i32 4, i32 1} +// CHECK-DAG: ![[Single]] = !{ptr @"?Buffer1@@3V?$RWBuffer@M@hlsl@@A", !"RWBuffer", i32 10, i32 -1, i32 0} +// CHECK-DAG: ![[Array]] = !{ptr @"?BufferArray@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", !"RWBuffer >", i32 10, i32 -1, i32 0} +// CHECK-DAG: ![[SingleAllocated]] = !{ptr @"?Buffer2@@3V?$RWBuffer@M@hlsl@@A", !"RWBuffer", i32 10, i32 3, i32 0} +// CHECK-DAG: ![[ArrayAllocated]] = !{ptr @"?BufferArray2@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", !"RWBuffer >", i32 10, i32 4, i32 0} +// CHECK-DAG: ![[SingleSpace]] = !{ptr @"?Buffer3@@3V?$RWBuffer@M@hlsl@@A", !"RWBuffer", i32 10, i32 3, i32 1} +// CHECK-DAG: ![[ArraySpace]] = !{ptr @"?BufferArray3@@3PAV?$RWBuffer@T?$__vector@M$03@__clang@@@hlsl@@A", !"RWBuffer >", i32 10, i32 4, i32 1} diff --git a/clang/test/CodeGenHLSL/cbuf.hlsl b/clang/test/CodeGenHLSL/cbuf.hlsl --- a/clang/test/CodeGenHLSL/cbuf.hlsl +++ b/clang/test/CodeGenHLSL/cbuf.hlsl @@ -24,5 +24,5 @@ // 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 --- a/llvm/include/llvm/Frontend/HLSL/HLSLResource.h +++ b/llvm/include/llvm/Frontend/HLSL/HLSLResource.h @@ -51,15 +51,14 @@ 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 --- a/llvm/lib/Frontend/HLSL/HLSLResource.cpp +++ b/llvm/lib/Frontend/HLSL/HLSLResource.cpp @@ -27,34 +27,29 @@ return cast(Entry->getOperand(1))->getString(); } -Constant *FrontendResource::getID() { - return cast(Entry->getOperand(2))->getValue(); -} - uint32_t FrontendResource::FrontendResource::getResourceKind() { return cast( - cast(Entry->getOperand(3))->getValue()) + cast(Entry->getOperand(2))->getValue()) ->getLimitedValue(); } uint32_t FrontendResource::getResourceIndex() { return cast( - cast(Entry->getOperand(4))->getValue()) + cast(Entry->getOperand(3))->getValue()) ->getLimitedValue(); } uint32_t FrontendResource::getSpace() { return cast( - cast(Entry->getOperand(5))->getValue()) + cast(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(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 --- a/llvm/test/CodeGen/DirectX/UAVMetadata.ll +++ b/llvm/test/CodeGen/DirectX/UAVMetadata.ll @@ -37,16 +37,16 @@ !hlsl.uavs = !{!0, !1, !2, !3, !4, !5, !6, !7, !8, !9} -!0 = !{ptr @Zero, !"RWBuffer", i32 0, i32 10, i32 0, i32 0} -!1 = !{ptr @One, !"Buffer>", i32 1, i32 10, i32 1, i32 0} -!2 = !{ptr @Two, !"Buffer", i32 2, i32 10, i32 2, i32 0} -!3 = !{ptr @Three, !"Buffer", i32 3, i32 10, i32 3, i32 0} -!4 = !{ptr @Four, !"ByteAddressBuffer", i32 4, i32 11, i32 5, i32 0} -!5 = !{ptr @Five, !"StructuredBuffer", i32 5, i32 12, i32 6, i32 0} -!6 = !{ptr @Six, !"RasterizerOrderedBuffer", i32 6, i32 10, i32 7, i32 0} -!7 = !{ptr @Seven, !"RasterizerOrderedStructuredBuffer", i32 7, i32 12, i32 8, i32 0} -!8 = !{ptr @Eight, !"RasterizerOrderedByteAddressBuffer", i32 8, i32 11, i32 9, i32 0} -!9 = !{ptr @Nine, !"RWBuffer", i32 9, i32 10, i32 10, i32 2} +!0 = !{ptr @Zero, !"RWBuffer", i32 10, i32 0, i32 0} +!1 = !{ptr @One, !"Buffer>", i32 10, i32 1, i32 0} +!2 = !{ptr @Two, !"Buffer", i32 10, i32 2, i32 0} +!3 = !{ptr @Three, !"Buffer", i32 10, i32 3, i32 0} +!4 = !{ptr @Four, !"ByteAddressBuffer", i32 11, i32 5, i32 0} +!5 = !{ptr @Five, !"StructuredBuffer", i32 12, i32 6, i32 0} +!6 = !{ptr @Six, !"RasterizerOrderedBuffer", i32 10, i32 7, i32 0} +!7 = !{ptr @Seven, !"RasterizerOrderedStructuredBuffer", i32 12, i32 8, i32 0} +!8 = !{ptr @Eight, !"RasterizerOrderedByteAddressBuffer", i32 11, i32 9, i32 0} +!9 = !{ptr @Nine, !"RWBuffer", i32 10, i32 10, i32 2} ; CHECK: !dx.resources = !{[[ResList:[!][0-9]+]]}