[llvm] [DXIL][Analysis] Move dxil::ResourceInfo union initialization into setters (PR #100696)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 25 22:46:32 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Justin Bogner (bogner)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/100696.diff
2 Files Affected:
- (modified) llvm/include/llvm/Analysis/DXILResource.h (+45-14)
- (modified) llvm/lib/Analysis/DXILResource.cpp (+23-45)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/100696
More information about the llvm-commits
mailing list