Skip to content

Commit d4af2a9

Browse files
committed
[𝘀𝗽𝗿] changes to main this commit is based on
Created using spr 1.3.5-bogner [skip ci]
1 parent 70a9535 commit d4af2a9

File tree

6 files changed

+92
-105
lines changed

6 files changed

+92
-105
lines changed

llvm/include/llvm/Analysis/DXILResource.h

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ResourceInfo {
4747

4848
struct StructInfo {
4949
uint32_t Stride;
50-
Align Alignment;
50+
MaybeAlign Alignment;
5151

5252
bool operator==(const StructInfo &RHS) const {
5353
return std::tie(Stride, Alignment) == std::tie(RHS.Stride, RHS.Alignment);
@@ -106,6 +106,11 @@ class ResourceInfo {
106106

107107
MSInfo MultiSample;
108108

109+
public:
110+
ResourceInfo(dxil::ResourceClass RC, dxil::ResourceKind Kind, Value *Symbol,
111+
StringRef Name)
112+
: Symbol(Symbol), Name(Name), RC(RC), Kind(Kind) {}
113+
109114
// Conditions to check before accessing union members.
110115
bool isUAV() const;
111116
bool isCBuffer() const;
@@ -115,17 +120,53 @@ class ResourceInfo {
115120
bool isFeedback() const;
116121
bool isMultiSample() const;
117122

118-
ResourceInfo(dxil::ResourceClass RC, dxil::ResourceKind Kind, Value *Symbol,
119-
StringRef Name)
120-
: Symbol(Symbol), Name(Name), RC(RC), Kind(Kind) {}
123+
void bind(uint32_t UniqueID, uint32_t Space, uint32_t LowerBound,
124+
uint32_t Size) {
125+
Binding.UniqueID = UniqueID;
126+
Binding.Space = Space;
127+
Binding.LowerBound = LowerBound;
128+
Binding.Size = Size;
129+
}
130+
void setUAV(bool GloballyCoherent, bool HasCounter, bool IsROV) {
131+
assert(isUAV() && "Not a UAV");
132+
UAVFlags.GloballyCoherent = GloballyCoherent;
133+
UAVFlags.HasCounter = HasCounter;
134+
UAVFlags.IsROV = IsROV;
135+
}
136+
void setCBuffer(uint32_t Size) {
137+
assert(isCBuffer() && "Not a CBuffer");
138+
CBufferSize = Size;
139+
}
140+
void setSampler(dxil::SamplerType Ty) {
141+
SamplerTy = Ty;
142+
}
143+
void setStruct(uint32_t Stride, MaybeAlign Alignment) {
144+
assert(isStruct() && "Not a Struct");
145+
Struct.Stride = Stride;
146+
Struct.Alignment = Alignment;
147+
}
148+
void setTyped(dxil::ElementType ElementTy, uint32_t ElementCount) {
149+
assert(isTyped() && "Not Typed");
150+
Typed.ElementTy = ElementTy;
151+
Typed.ElementCount = ElementCount;
152+
}
153+
void setFeedback(dxil::SamplerFeedbackType Type) {
154+
assert(isFeedback() && "Not Feedback");
155+
Feedback.Type = Type;
156+
}
157+
void setMultiSample(uint32_t Count) {
158+
assert(isMultiSample() && "Not MultiSampled");
159+
MultiSample.Count = Count;
160+
}
161+
162+
bool operator==(const ResourceInfo &RHS) const;
121163

122-
public:
123164
static ResourceInfo SRV(Value *Symbol, StringRef Name,
124165
dxil::ElementType ElementTy, uint32_t ElementCount,
125166
dxil::ResourceKind Kind);
126167
static ResourceInfo RawBuffer(Value *Symbol, StringRef Name);
127168
static ResourceInfo StructuredBuffer(Value *Symbol, StringRef Name,
128-
uint32_t Stride, Align Alignment);
169+
uint32_t Stride, MaybeAlign Alignment);
129170
static ResourceInfo Texture2DMS(Value *Symbol, StringRef Name,
130171
dxil::ElementType ElementTy,
131172
uint32_t ElementCount, uint32_t SampleCount);
@@ -141,9 +182,9 @@ class ResourceInfo {
141182
static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name,
142183
bool GloballyCoherent, bool IsROV);
143184
static ResourceInfo RWStructuredBuffer(Value *Symbol, StringRef Name,
144-
uint32_t Stride,
145-
Align Alignment, bool GloballyCoherent,
146-
bool IsROV, bool HasCounter);
185+
uint32_t Stride, MaybeAlign Alignment,
186+
bool GloballyCoherent, bool IsROV,
187+
bool HasCounter);
147188
static ResourceInfo RWTexture2DMS(Value *Symbol, StringRef Name,
148189
dxil::ElementType ElementTy,
149190
uint32_t ElementCount, uint32_t SampleCount,
@@ -164,16 +205,6 @@ class ResourceInfo {
164205
static ResourceInfo Sampler(Value *Symbol, StringRef Name,
165206
dxil::SamplerType SamplerTy);
166207

167-
void bind(uint32_t UniqueID, uint32_t Space, uint32_t LowerBound,
168-
uint32_t Size) {
169-
Binding.UniqueID = UniqueID;
170-
Binding.Space = Space;
171-
Binding.LowerBound = LowerBound;
172-
Binding.Size = Size;
173-
}
174-
175-
bool operator==(const ResourceInfo &RHS) const;
176-
177208
MDTuple *getAsMetadata(LLVMContext &Ctx) const;
178209

179210
ResourceBinding getBinding() const { return Binding; }

llvm/lib/Analysis/DXILResource.cpp

Lines changed: 29 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ ResourceInfo ResourceInfo::SRV(Value *Symbol, StringRef Name,
6969
ResourceInfo RI(ResourceClass::SRV, Kind, Symbol, Name);
7070
assert(RI.isTyped() && !(RI.isStruct() || RI.isMultiSample()) &&
7171
"Invalid ResourceKind for SRV constructor.");
72-
RI.Typed.ElementTy = ElementTy;
73-
RI.Typed.ElementCount = ElementCount;
72+
RI.setTyped(ElementTy, ElementCount);
7473
return RI;
7574
}
7675

@@ -80,11 +79,11 @@ ResourceInfo ResourceInfo::RawBuffer(Value *Symbol, StringRef Name) {
8079
}
8180

8281
ResourceInfo ResourceInfo::StructuredBuffer(Value *Symbol, StringRef Name,
83-
uint32_t Stride, Align Alignment) {
82+
uint32_t Stride,
83+
MaybeAlign Alignment) {
8484
ResourceInfo RI(ResourceClass::SRV, ResourceKind::StructuredBuffer, Symbol,
8585
Name);
86-
RI.Struct.Stride = Stride;
87-
RI.Struct.Alignment = Alignment;
86+
RI.setStruct(Stride, Alignment);
8887
return RI;
8988
}
9089

@@ -93,9 +92,8 @@ ResourceInfo ResourceInfo::Texture2DMS(Value *Symbol, StringRef Name,
9392
uint32_t ElementCount,
9493
uint32_t SampleCount) {
9594
ResourceInfo RI(ResourceClass::SRV, ResourceKind::Texture2DMS, Symbol, Name);
96-
RI.Typed.ElementTy = ElementTy;
97-
RI.Typed.ElementCount = ElementCount;
98-
RI.MultiSample.Count = SampleCount;
95+
RI.setTyped(ElementTy, ElementCount);
96+
RI.setMultiSample(SampleCount);
9997
return RI;
10098
}
10199

@@ -105,9 +103,8 @@ ResourceInfo ResourceInfo::Texture2DMSArray(Value *Symbol, StringRef Name,
105103
uint32_t SampleCount) {
106104
ResourceInfo RI(ResourceClass::SRV, ResourceKind::Texture2DMSArray, Symbol,
107105
Name);
108-
RI.Typed.ElementTy = ElementTy;
109-
RI.Typed.ElementCount = ElementCount;
110-
RI.MultiSample.Count = SampleCount;
106+
RI.setTyped(ElementTy, ElementCount);
107+
RI.setMultiSample(SampleCount);
111108
return RI;
112109
}
113110

@@ -118,34 +115,27 @@ ResourceInfo ResourceInfo::UAV(Value *Symbol, StringRef Name,
118115
ResourceInfo RI(ResourceClass::UAV, Kind, Symbol, Name);
119116
assert(RI.isTyped() && !(RI.isStruct() || RI.isMultiSample()) &&
120117
"Invalid ResourceKind for UAV constructor.");
121-
RI.Typed.ElementTy = ElementTy;
122-
RI.Typed.ElementCount = ElementCount;
123-
RI.UAVFlags.GloballyCoherent = GloballyCoherent;
124-
RI.UAVFlags.IsROV = IsROV;
125-
RI.UAVFlags.HasCounter = false;
118+
RI.setTyped(ElementTy, ElementCount);
119+
RI.setUAV(GloballyCoherent, /*HasCounter=*/false, IsROV);
126120
return RI;
127121
}
128122

129123
ResourceInfo ResourceInfo::RWRawBuffer(Value *Symbol, StringRef Name,
130124
bool GloballyCoherent, bool IsROV) {
131125
ResourceInfo RI(ResourceClass::UAV, ResourceKind::RawBuffer, Symbol, Name);
132-
RI.UAVFlags.GloballyCoherent = GloballyCoherent;
133-
RI.UAVFlags.IsROV = IsROV;
134-
RI.UAVFlags.HasCounter = false;
126+
RI.setUAV(GloballyCoherent, /*HasCounter=*/false, IsROV);
135127
return RI;
136128
}
137129

138130
ResourceInfo ResourceInfo::RWStructuredBuffer(Value *Symbol, StringRef Name,
139-
uint32_t Stride, Align Alignment,
131+
uint32_t Stride,
132+
MaybeAlign Alignment,
140133
bool GloballyCoherent, bool IsROV,
141134
bool HasCounter) {
142135
ResourceInfo RI(ResourceClass::UAV, ResourceKind::StructuredBuffer, Symbol,
143136
Name);
144-
RI.Struct.Stride = Stride;
145-
RI.Struct.Alignment = Alignment;
146-
RI.UAVFlags.GloballyCoherent = GloballyCoherent;
147-
RI.UAVFlags.IsROV = IsROV;
148-
RI.UAVFlags.HasCounter = HasCounter;
137+
RI.setStruct(Stride, Alignment);
138+
RI.setUAV(GloballyCoherent, HasCounter, IsROV);
149139
return RI;
150140
}
151141

@@ -155,12 +145,9 @@ ResourceInfo ResourceInfo::RWTexture2DMS(Value *Symbol, StringRef Name,
155145
uint32_t SampleCount,
156146
bool GloballyCoherent) {
157147
ResourceInfo RI(ResourceClass::UAV, ResourceKind::Texture2DMS, Symbol, Name);
158-
RI.Typed.ElementTy = ElementTy;
159-
RI.Typed.ElementCount = ElementCount;
160-
RI.UAVFlags.GloballyCoherent = GloballyCoherent;
161-
RI.UAVFlags.IsROV = false;
162-
RI.UAVFlags.HasCounter = false;
163-
RI.MultiSample.Count = SampleCount;
148+
RI.setTyped(ElementTy, ElementCount);
149+
RI.setUAV(GloballyCoherent, /*HasCounter=*/false, /*IsROV=*/false);
150+
RI.setMultiSample(SampleCount);
164151
return RI;
165152
}
166153

@@ -171,23 +158,18 @@ ResourceInfo ResourceInfo::RWTexture2DMSArray(Value *Symbol, StringRef Name,
171158
bool GloballyCoherent) {
172159
ResourceInfo RI(ResourceClass::UAV, ResourceKind::Texture2DMSArray, Symbol,
173160
Name);
174-
RI.Typed.ElementTy = ElementTy;
175-
RI.Typed.ElementCount = ElementCount;
176-
RI.UAVFlags.GloballyCoherent = GloballyCoherent;
177-
RI.UAVFlags.IsROV = false;
178-
RI.UAVFlags.HasCounter = false;
179-
RI.MultiSample.Count = SampleCount;
161+
RI.setTyped(ElementTy, ElementCount);
162+
RI.setUAV(GloballyCoherent, /*HasCounter=*/false, /*IsROV=*/false);
163+
RI.setMultiSample(SampleCount);
180164
return RI;
181165
}
182166

183167
ResourceInfo ResourceInfo::FeedbackTexture2D(Value *Symbol, StringRef Name,
184168
SamplerFeedbackType FeedbackTy) {
185169
ResourceInfo RI(ResourceClass::UAV, ResourceKind::FeedbackTexture2D, Symbol,
186170
Name);
187-
RI.UAVFlags.GloballyCoherent = false;
188-
RI.UAVFlags.IsROV = false;
189-
RI.UAVFlags.HasCounter = false;
190-
RI.Feedback.Type = FeedbackTy;
171+
RI.setUAV(/*GloballyCoherent=*/false, /*HasCounter=*/false, /*IsROV=*/false);
172+
RI.setFeedback(FeedbackTy);
191173
return RI;
192174
}
193175

@@ -196,24 +178,22 @@ ResourceInfo::FeedbackTexture2DArray(Value *Symbol, StringRef Name,
196178
SamplerFeedbackType FeedbackTy) {
197179
ResourceInfo RI(ResourceClass::UAV, ResourceKind::FeedbackTexture2DArray,
198180
Symbol, Name);
199-
RI.UAVFlags.GloballyCoherent = false;
200-
RI.UAVFlags.IsROV = false;
201-
RI.UAVFlags.HasCounter = false;
202-
RI.Feedback.Type = FeedbackTy;
181+
RI.setUAV(/*GloballyCoherent=*/false, /*HasCounter=*/false, /*IsROV=*/false);
182+
RI.setFeedback(FeedbackTy);
203183
return RI;
204184
}
205185

206186
ResourceInfo ResourceInfo::CBuffer(Value *Symbol, StringRef Name,
207187
uint32_t Size) {
208188
ResourceInfo RI(ResourceClass::CBuffer, ResourceKind::CBuffer, Symbol, Name);
209-
RI.CBufferSize = Size;
189+
RI.setCBuffer(Size);
210190
return RI;
211191
}
212192

213193
ResourceInfo ResourceInfo::Sampler(Value *Symbol, StringRef Name,
214194
SamplerType SamplerTy) {
215195
ResourceInfo RI(ResourceClass::Sampler, ResourceKind::Sampler, Symbol, Name);
216-
RI.SamplerTy = SamplerTy;
196+
RI.setSampler(SamplerTy);
217197
return RI;
218198
}
219199

@@ -306,7 +286,8 @@ MDTuple *ResourceInfo::getAsMetadata(LLVMContext &Ctx) const {
306286

307287
std::pair<uint32_t, uint32_t> ResourceInfo::getAnnotateProps() const {
308288
uint32_t ResourceKind = llvm::to_underlying(Kind);
309-
uint32_t AlignLog2 = isStruct() ? Log2(Struct.Alignment) : 0;
289+
uint32_t AlignLog2 =
290+
isStruct() && Struct.Alignment ? Log2(*Struct.Alignment) : 0;
310291
bool IsUAV = isUAV();
311292
bool IsROV = IsUAV && UAVFlags.IsROV;
312293
bool IsGloballyCoherent = IsUAV && UAVFlags.GloballyCoherent;

llvm/lib/Target/DirectX/DXILResourceAnalysis.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,6 @@ using namespace llvm;
1818

1919
#define DEBUG_TYPE "dxil-resource-analysis"
2020

21-
dxil::Resources DXILResourceAnalysis::run(Module &M,
22-
ModuleAnalysisManager &AM) {
23-
dxil::Resources R;
24-
R.collect(M);
25-
return R;
26-
}
27-
28-
AnalysisKey DXILResourceAnalysis::Key;
29-
30-
PreservedAnalyses DXILResourcePrinterPass::run(Module &M,
31-
ModuleAnalysisManager &AM) {
32-
dxil::Resources Res = AM.getResult<DXILResourceAnalysis>(M);
33-
Res.print(OS);
34-
return PreservedAnalyses::all();
35-
}
36-
3721
char DXILResourceWrapper::ID = 0;
3822
INITIALIZE_PASS_BEGIN(DXILResourceWrapper, DEBUG_TYPE,
3923
"DXIL resource Information", true, true)

llvm/lib/Target/DirectX/DXILResourceAnalysis.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,6 @@
1919
#include <memory>
2020

2121
namespace llvm {
22-
/// Analysis pass that exposes the \c DXILResource for a module.
23-
class DXILResourceAnalysis : public AnalysisInfoMixin<DXILResourceAnalysis> {
24-
friend AnalysisInfoMixin<DXILResourceAnalysis>;
25-
static AnalysisKey Key;
26-
27-
public:
28-
typedef dxil::Resources Result;
29-
dxil::Resources run(Module &M, ModuleAnalysisManager &AM);
30-
};
31-
32-
/// Printer pass for the \c DXILResourceAnalysis results.
33-
class DXILResourcePrinterPass : public PassInfoMixin<DXILResourcePrinterPass> {
34-
raw_ostream &OS;
35-
36-
public:
37-
explicit DXILResourcePrinterPass(raw_ostream &OS) : OS(OS) {}
38-
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
39-
static bool isRequired() { return true; }
40-
};
41-
4222
/// The legacy pass manager's analysis pass to compute DXIL resource
4323
/// information.
4424
class DXILResourceWrapper : public ModulePass {

llvm/lib/Target/DirectX/DirectXPassRegistry.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
#define MODULE_ANALYSIS(NAME, CREATE_PASS)
1818
#endif
1919
MODULE_ANALYSIS("dx-shader-flags", dxil::ShaderFlagsAnalysis())
20-
MODULE_ANALYSIS("dxil-resource", DXILResourceAnalysis())
2120
#undef MODULE_ANALYSIS
2221

2322
#ifndef MODULE_PASS
2423
#define MODULE_PASS(NAME, CREATE_PASS)
2524
#endif
2625
// TODO: rename to print<foo> after NPM switch
2726
MODULE_PASS("print-dx-shader-flags", dxil::ShaderFlagsAnalysisPrinter(dbgs()))
28-
MODULE_PASS("print-dxil-resource", DXILResourcePrinterPass(dbgs()))
2927
#undef MODULE_PASS

llvm/unittests/Analysis/DXILResourceTest.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,19 @@ TEST(DXILResource, AnnotationsAndMetadata) {
151151
EXPECT_MDEQ(
152152
MD, TestMD.get(0, Symbol, "Buffer0", 0, 0, 1, 12, 0, TestMD.get(1, 16)));
153153

154+
// StructuredBuffer<float3> Buffer1 : register(t1);
155+
Symbol = UndefValue::get(StructType::create(
156+
Context, {Floatx3Ty}, "class.StructuredBuffer<vector<float, 3> >"));
157+
Resource = ResourceInfo::StructuredBuffer(Symbol, "Buffer1",
158+
/*Stride=*/12, {});
159+
Resource.bind(1, 0, 1, 1);
160+
Props = Resource.getAnnotateProps();
161+
EXPECT_EQ(Props.first, 0x0000000cU);
162+
EXPECT_EQ(Props.second, 0x0000000cU);
163+
MD = Resource.getAsMetadata(Context);
164+
EXPECT_MDEQ(
165+
MD, TestMD.get(1, Symbol, "Buffer1", 0, 1, 1, 12, 0, TestMD.get(1, 12)));
166+
154167
// Texture2D<float4> ColorMapTexture : register(t2);
155168
Symbol = UndefValue::get(StructType::create(
156169
Context, {Floatx4Ty}, "class.Texture2D<vector<float, 4> >"));

0 commit comments

Comments
 (0)