[llvm] [DXIL][Analysis] Use setters for dxil::ResourceInfo initialization. NFC (PR #100696)
Justin Bogner via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 27 22:23:14 PDT 2024
https://github.com/bogner updated https://github.com/llvm/llvm-project/pull/100696
>From 0f93ca1b01c9bfcd7fb9ac08f17958e1d4c85451 Mon Sep 17 00:00:00 2001
From: Justin Bogner <mail at justinbogner.com>
Date: Thu, 25 Jul 2024 22:45:50 -0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
=?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.5-bogner
---
llvm/include/llvm/Analysis/DXILResource.h | 59 +++++++++++++++-----
llvm/lib/Analysis/DXILResource.cpp | 68 ++++++++---------------
2 files changed, 68 insertions(+), 59 deletions(-)
diff --git a/llvm/include/llvm/Analysis/DXILResource.h b/llvm/include/llvm/Analysis/DXILResource.h
index d4006ae10837c..dff0b7cfcd142 100644
--- a/llvm/include/llvm/Analysis/DXILResource.h
+++ b/llvm/include/llvm/Analysis/DXILResource.h
@@ -106,6 +106,11 @@ class ResourceInfo {
MSInfo MultiSample;
+public:
+ ResourceInfo(dxil::ResourceClass RC, dxil::ResourceKind Kind, Value *Symbol,
+ StringRef Name)
+ : Symbol(Symbol), Name(Name), RC(RC), Kind(Kind) {}
+
// Conditions to check before accessing union members.
bool isUAV() const;
bool isCBuffer() const;
@@ -115,11 +120,47 @@ class ResourceInfo {
bool isFeedback() const;
bool isMultiSample() const;
- ResourceInfo(dxil::ResourceClass RC, dxil::ResourceKind Kind, Value *Symbol,
- StringRef Name)
- : Symbol(Symbol), Name(Name), RC(RC), Kind(Kind) {}
+ void bind(uint32_t UniqueID, uint32_t Space, uint32_t LowerBound,
+ uint32_t Size) {
+ Binding.UniqueID = UniqueID;
+ Binding.Space = Space;
+ Binding.LowerBound = LowerBound;
+ Binding.Size = Size;
+ }
+ void setUAV(bool GloballyCoherent, bool HasCounter, bool IsROV) {
+ assert(isUAV() && "Not a UAV");
+ UAVFlags.GloballyCoherent = GloballyCoherent;
+ UAVFlags.HasCounter = HasCounter;
+ UAVFlags.IsROV = IsROV;
+ }
+ void setCBuffer(uint32_t Size) {
+ assert(isCBuffer() && "Not a CBuffer");
+ CBufferSize = Size;
+ }
+ void setSampler(dxil::SamplerType Ty) {
+ SamplerTy = Ty;
+ }
+ void setStruct(uint32_t Stride, Align Alignment) {
+ assert(isStruct() && "Not a Struct");
+ Struct.Stride = Stride;
+ Struct.Alignment = Alignment;
+ }
+ void setTyped(dxil::ElementType ElementTy, uint32_t ElementCount) {
+ assert(isTyped() && "Not Typed");
+ Typed.ElementTy = ElementTy;
+ Typed.ElementCount = ElementCount;
+ }
+ void setFeedback(dxil::SamplerFeedbackType Type) {
+ assert(isFeedback() && "Not Feedback");
+ Feedback.Type = Type;
+ }
+ void setMultiSample(uint32_t Count) {
+ assert(isMultiSample() && "Not MultiSampled");
+ MultiSample.Count = Count;
+ }
+
+ bool operator==(const ResourceInfo &RHS) const;
-public:
static ResourceInfo SRV(Value *Symbol, StringRef Name,
dxil::ElementType ElementTy, uint32_t ElementCount,
dxil::ResourceKind Kind);
@@ -164,16 +205,6 @@ class ResourceInfo {
static ResourceInfo Sampler(Value *Symbol, StringRef Name,
dxil::SamplerType SamplerTy);
- void bind(uint32_t UniqueID, uint32_t Space, uint32_t LowerBound,
- uint32_t Size) {
- Binding.UniqueID = UniqueID;
- Binding.Space = Space;
- Binding.LowerBound = LowerBound;
- Binding.Size = Size;
- }
-
- bool operator==(const ResourceInfo &RHS) const;
-
MDTuple *getAsMetadata(LLVMContext &Ctx) const;
ResourceBinding getBinding() const { return Binding; }
diff --git a/llvm/lib/Analysis/DXILResource.cpp b/llvm/lib/Analysis/DXILResource.cpp
index 72cba9d4373bb..1443fef8fc165 100644
--- a/llvm/lib/Analysis/DXILResource.cpp
+++ b/llvm/lib/Analysis/DXILResource.cpp
@@ -69,8 +69,7 @@ ResourceInfo ResourceInfo::SRV(Value *Symbol, StringRef Name,
ResourceInfo RI(ResourceClass::SRV, Kind, Symbol, Name);
assert(RI.isTyped() && !(RI.isStruct() || RI.isMultiSample()) &&
"Invalid ResourceKind for SRV constructor.");
- RI.Typed.ElementTy = ElementTy;
- RI.Typed.ElementCount = ElementCount;
+ RI.setTyped(ElementTy, ElementCount);
return RI;
}
@@ -83,8 +82,7 @@ ResourceInfo ResourceInfo::StructuredBuffer(Value *Symbol, StringRef Name,
uint32_t Stride, Align Alignment) {
ResourceInfo RI(ResourceClass::SRV, ResourceKind::StructuredBuffer, Symbol,
Name);
- RI.Struct.Stride = Stride;
- RI.Struct.Alignment = Alignment;
+ RI.setStruct(Stride, Alignment);
return RI;
}
@@ -93,9 +91,8 @@ ResourceInfo ResourceInfo::Texture2DMS(Value *Symbol, StringRef Name,
uint32_t ElementCount,
uint32_t SampleCount) {
ResourceInfo RI(ResourceClass::SRV, ResourceKind::Texture2DMS, Symbol, Name);
- RI.Typed.ElementTy = ElementTy;
- RI.Typed.ElementCount = ElementCount;
- RI.MultiSample.Count = SampleCount;
+ RI.setTyped(ElementTy, ElementCount);
+ RI.setMultiSample(SampleCount);
return RI;
}
@@ -105,9 +102,8 @@ ResourceInfo ResourceInfo::Texture2DMSArray(Value *Symbol, StringRef Name,
uint32_t SampleCount) {
ResourceInfo RI(ResourceClass::SRV, ResourceKind::Texture2DMSArray, Symbol,
Name);
- RI.Typed.ElementTy = ElementTy;
- RI.Typed.ElementCount = ElementCount;
- RI.MultiSample.Count = SampleCount;
+ RI.setTyped(ElementTy, ElementCount);
+ RI.setMultiSample(SampleCount);
return RI;
}
@@ -118,20 +114,15 @@ ResourceInfo ResourceInfo::UAV(Value *Symbol, StringRef Name,
ResourceInfo RI(ResourceClass::UAV, Kind, Symbol, Name);
assert(RI.isTyped() && !(RI.isStruct() || RI.isMultiSample()) &&
"Invalid ResourceKind for UAV constructor.");
- RI.Typed.ElementTy = ElementTy;
- RI.Typed.ElementCount = ElementCount;
- RI.UAVFlags.GloballyCoherent = GloballyCoherent;
- RI.UAVFlags.IsROV = IsROV;
- RI.UAVFlags.HasCounter = false;
+ RI.setTyped(ElementTy, ElementCount);
+ RI.setUAV(GloballyCoherent, /*HasCounter=*/false, IsROV);
return RI;
}
ResourceInfo ResourceInfo::RWRawBuffer(Value *Symbol, StringRef Name,
bool GloballyCoherent, bool IsROV) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::RawBuffer, Symbol, Name);
- RI.UAVFlags.GloballyCoherent = GloballyCoherent;
- RI.UAVFlags.IsROV = IsROV;
- RI.UAVFlags.HasCounter = false;
+ RI.setUAV(GloballyCoherent, /*HasCounter=*/false, IsROV);
return RI;
}
@@ -141,11 +132,8 @@ ResourceInfo ResourceInfo::RWStructuredBuffer(Value *Symbol, StringRef Name,
bool HasCounter) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::StructuredBuffer, Symbol,
Name);
- RI.Struct.Stride = Stride;
- RI.Struct.Alignment = Alignment;
- RI.UAVFlags.GloballyCoherent = GloballyCoherent;
- RI.UAVFlags.IsROV = IsROV;
- RI.UAVFlags.HasCounter = HasCounter;
+ RI.setStruct(Stride, Alignment);
+ RI.setUAV(GloballyCoherent, HasCounter, IsROV);
return RI;
}
@@ -155,12 +143,9 @@ ResourceInfo ResourceInfo::RWTexture2DMS(Value *Symbol, StringRef Name,
uint32_t SampleCount,
bool GloballyCoherent) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::Texture2DMS, Symbol, Name);
- RI.Typed.ElementTy = ElementTy;
- RI.Typed.ElementCount = ElementCount;
- RI.UAVFlags.GloballyCoherent = GloballyCoherent;
- RI.UAVFlags.IsROV = false;
- RI.UAVFlags.HasCounter = false;
- RI.MultiSample.Count = SampleCount;
+ RI.setTyped(ElementTy, ElementCount);
+ RI.setUAV(GloballyCoherent, /*HasCounter=*/false, /*IsROV=*/false);
+ RI.setMultiSample(SampleCount);
return RI;
}
@@ -171,12 +156,9 @@ ResourceInfo ResourceInfo::RWTexture2DMSArray(Value *Symbol, StringRef Name,
bool GloballyCoherent) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::Texture2DMSArray, Symbol,
Name);
- RI.Typed.ElementTy = ElementTy;
- RI.Typed.ElementCount = ElementCount;
- RI.UAVFlags.GloballyCoherent = GloballyCoherent;
- RI.UAVFlags.IsROV = false;
- RI.UAVFlags.HasCounter = false;
- RI.MultiSample.Count = SampleCount;
+ RI.setTyped(ElementTy, ElementCount);
+ RI.setUAV(GloballyCoherent, /*HasCounter=*/false, /*IsROV=*/false);
+ RI.setMultiSample(SampleCount);
return RI;
}
@@ -184,10 +166,8 @@ ResourceInfo ResourceInfo::FeedbackTexture2D(Value *Symbol, StringRef Name,
SamplerFeedbackType FeedbackTy) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::FeedbackTexture2D, Symbol,
Name);
- RI.UAVFlags.GloballyCoherent = false;
- RI.UAVFlags.IsROV = false;
- RI.UAVFlags.HasCounter = false;
- RI.Feedback.Type = FeedbackTy;
+ RI.setUAV(/*GloballyCoherent=*/false, /*HasCounter=*/false, /*IsROV=*/false);
+ RI.setFeedback(FeedbackTy);
return RI;
}
@@ -196,24 +176,22 @@ ResourceInfo::FeedbackTexture2DArray(Value *Symbol, StringRef Name,
SamplerFeedbackType FeedbackTy) {
ResourceInfo RI(ResourceClass::UAV, ResourceKind::FeedbackTexture2DArray,
Symbol, Name);
- RI.UAVFlags.GloballyCoherent = false;
- RI.UAVFlags.IsROV = false;
- RI.UAVFlags.HasCounter = false;
- RI.Feedback.Type = FeedbackTy;
+ RI.setUAV(/*GloballyCoherent=*/false, /*HasCounter=*/false, /*IsROV=*/false);
+ RI.setFeedback(FeedbackTy);
return RI;
}
ResourceInfo ResourceInfo::CBuffer(Value *Symbol, StringRef Name,
uint32_t Size) {
ResourceInfo RI(ResourceClass::CBuffer, ResourceKind::CBuffer, Symbol, Name);
- RI.CBufferSize = Size;
+ RI.setCBuffer(Size);
return RI;
}
ResourceInfo ResourceInfo::Sampler(Value *Symbol, StringRef Name,
SamplerType SamplerTy) {
ResourceInfo RI(ResourceClass::Sampler, ResourceKind::Sampler, Symbol, Name);
- RI.SamplerTy = SamplerTy;
+ RI.setSampler(SamplerTy);
return RI;
}
>From 42a4130f7616fe34a981e04fb831afdba6fa7217 Mon Sep 17 00:00:00 2001
From: Justin Bogner <mail at justinbogner.com>
Date: Sat, 27 Jul 2024 22:23:03 -0700
Subject: [PATCH 2/2] clang-format
Created using spr 1.3.5-bogner
---
llvm/include/llvm/Analysis/DXILResource.h | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/llvm/include/llvm/Analysis/DXILResource.h b/llvm/include/llvm/Analysis/DXILResource.h
index dff0b7cfcd142..2ca0ad9a75319 100644
--- a/llvm/include/llvm/Analysis/DXILResource.h
+++ b/llvm/include/llvm/Analysis/DXILResource.h
@@ -137,9 +137,7 @@ class ResourceInfo {
assert(isCBuffer() && "Not a CBuffer");
CBufferSize = Size;
}
- void setSampler(dxil::SamplerType Ty) {
- SamplerTy = Ty;
- }
+ void setSampler(dxil::SamplerType Ty) { SamplerTy = Ty; }
void setStruct(uint32_t Stride, Align Alignment) {
assert(isStruct() && "Not a Struct");
Struct.Stride = Stride;
More information about the llvm-commits
mailing list