9
9
#ifndef LLVM_ANALYSIS_DXILRESOURCE_H
10
10
#define LLVM_ANALYSIS_DXILRESOURCE_H
11
11
12
+ #include " llvm/ADT/MapVector.h"
13
+ #include " llvm/IR/PassManager.h"
12
14
#include " llvm/IR/Value.h"
15
+ #include " llvm/Pass.h"
13
16
#include " llvm/Support/DXILABI.h"
14
17
15
18
namespace llvm {
19
+ class CallInst ;
16
20
class MDTuple ;
17
21
18
22
namespace dxil {
@@ -47,7 +51,7 @@ class ResourceInfo {
47
51
48
52
struct StructInfo {
49
53
uint32_t Stride;
50
- Align Alignment;
54
+ MaybeAlign Alignment;
51
55
52
56
bool operator ==(const StructInfo &RHS) const {
53
57
return std::tie (Stride, Alignment) == std::tie (RHS.Stride , RHS.Alignment );
@@ -106,6 +110,11 @@ class ResourceInfo {
106
110
107
111
MSInfo MultiSample;
108
112
113
+ public:
114
+ ResourceInfo (dxil::ResourceClass RC, dxil::ResourceKind Kind, Value *Symbol,
115
+ StringRef Name)
116
+ : Symbol(Symbol), Name(Name), RC(RC), Kind(Kind) {}
117
+
109
118
// Conditions to check before accessing union members.
110
119
bool isUAV () const ;
111
120
bool isCBuffer () const ;
@@ -115,17 +124,53 @@ class ResourceInfo {
115
124
bool isFeedback () const ;
116
125
bool isMultiSample () const ;
117
126
118
- ResourceInfo (dxil::ResourceClass RC, dxil::ResourceKind Kind, Value *Symbol,
119
- StringRef Name)
120
- : Symbol(Symbol), Name(Name), RC(RC), Kind(Kind) {}
127
+ void bind (uint32_t UniqueID, uint32_t Space, uint32_t LowerBound,
128
+ uint32_t Size) {
129
+ Binding.UniqueID = UniqueID;
130
+ Binding.Space = Space;
131
+ Binding.LowerBound = LowerBound;
132
+ Binding.Size = Size;
133
+ }
134
+ void setUAV (bool GloballyCoherent, bool HasCounter, bool IsROV) {
135
+ assert (isUAV () && " Not a UAV" );
136
+ UAVFlags.GloballyCoherent = GloballyCoherent;
137
+ UAVFlags.HasCounter = HasCounter;
138
+ UAVFlags.IsROV = IsROV;
139
+ }
140
+ void setCBuffer (uint32_t Size) {
141
+ assert (isCBuffer () && " Not a CBuffer" );
142
+ CBufferSize = Size;
143
+ }
144
+ void setSampler (dxil::SamplerType Ty) {
145
+ SamplerTy = Ty;
146
+ }
147
+ void setStruct (uint32_t Stride, MaybeAlign Alignment) {
148
+ assert (isStruct () && " Not a Struct" );
149
+ Struct.Stride = Stride;
150
+ Struct.Alignment = Alignment;
151
+ }
152
+ void setTyped (dxil::ElementType ElementTy, uint32_t ElementCount) {
153
+ assert (isTyped () && " Not Typed" );
154
+ Typed.ElementTy = ElementTy;
155
+ Typed.ElementCount = ElementCount;
156
+ }
157
+ void setFeedback (dxil::SamplerFeedbackType Type) {
158
+ assert (isFeedback () && " Not Feedback" );
159
+ Feedback.Type = Type;
160
+ }
161
+ void setMultiSample (uint32_t Count) {
162
+ assert (isMultiSample () && " Not MultiSampled" );
163
+ MultiSample.Count = Count;
164
+ }
165
+
166
+ bool operator ==(const ResourceInfo &RHS) const ;
121
167
122
- public:
123
168
static ResourceInfo SRV (Value *Symbol, StringRef Name,
124
169
dxil::ElementType ElementTy, uint32_t ElementCount,
125
170
dxil::ResourceKind Kind);
126
171
static ResourceInfo RawBuffer (Value *Symbol, StringRef Name);
127
172
static ResourceInfo StructuredBuffer (Value *Symbol, StringRef Name,
128
- uint32_t Stride, Align Alignment);
173
+ uint32_t Stride, MaybeAlign Alignment);
129
174
static ResourceInfo Texture2DMS (Value *Symbol, StringRef Name,
130
175
dxil::ElementType ElementTy,
131
176
uint32_t ElementCount, uint32_t SampleCount);
@@ -141,9 +186,9 @@ class ResourceInfo {
141
186
static ResourceInfo RWRawBuffer (Value *Symbol, StringRef Name,
142
187
bool GloballyCoherent, bool IsROV);
143
188
static ResourceInfo RWStructuredBuffer (Value *Symbol, StringRef Name,
144
- uint32_t Stride,
145
- Align Alignment , bool GloballyCoherent ,
146
- bool IsROV, bool HasCounter);
189
+ uint32_t Stride, MaybeAlign Alignment,
190
+ bool GloballyCoherent , bool IsROV ,
191
+ bool HasCounter);
147
192
static ResourceInfo RWTexture2DMS (Value *Symbol, StringRef Name,
148
193
dxil::ElementType ElementTy,
149
194
uint32_t ElementCount, uint32_t SampleCount,
@@ -164,23 +209,60 @@ class ResourceInfo {
164
209
static ResourceInfo Sampler (Value *Symbol, StringRef Name,
165
210
dxil::SamplerType SamplerTy);
166
211
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
-
177
212
MDTuple *getAsMetadata (LLVMContext &Ctx) const ;
178
213
179
214
ResourceBinding getBinding () const { return Binding; }
180
215
std::pair<uint32_t , uint32_t > getAnnotateProps () const ;
181
216
};
182
217
183
218
} // namespace dxil
219
+
220
+ using DXILResourceMap = MapVector<CallInst *, dxil::ResourceInfo>;
221
+
222
+ class DXILResourceAnalysis : public AnalysisInfoMixin <DXILResourceAnalysis> {
223
+ friend AnalysisInfoMixin<DXILResourceAnalysis>;
224
+
225
+ static AnalysisKey Key;
226
+
227
+ public:
228
+ using Result = DXILResourceMap;
229
+
230
+ // / Gather resource info for the module \c M.
231
+ DXILResourceMap run (Module &M, ModuleAnalysisManager &AM);
232
+ };
233
+
234
+ // / Printer pass for the \c DXILResourceAnalysis results.
235
+ class DXILResourcePrinterPass : public PassInfoMixin <DXILResourcePrinterPass> {
236
+ raw_ostream &OS;
237
+
238
+ public:
239
+ explicit DXILResourcePrinterPass (raw_ostream &OS) : OS(OS) {}
240
+
241
+ PreservedAnalyses run (Module &M, ModuleAnalysisManager &AM);
242
+
243
+ static bool isRequired () { return true ; }
244
+ };
245
+
246
+ class DXILResourceWrapperPass : public ModulePass {
247
+ std::unique_ptr<DXILResourceMap> ResourceMap;
248
+
249
+ public:
250
+ static char ID; // Class identification, replacement for typeinfo
251
+
252
+ DXILResourceWrapperPass ();
253
+ ~DXILResourceWrapperPass () override ;
254
+
255
+ const DXILResourceMap &getResourceMap () const { return *ResourceMap; }
256
+ DXILResourceMap &getResourceMap () { return *ResourceMap; }
257
+
258
+ void getAnalysisUsage (AnalysisUsage &AU) const override ;
259
+ bool runOnModule (Module &M) override ;
260
+ void releaseMemory () override ;
261
+
262
+ void print (raw_ostream &OS, const Module *M) const override ;
263
+ void dump () const ;
264
+ };
265
+
184
266
} // namespace llvm
185
267
186
268
#endif // LLVM_ANALYSIS_DXILRESOURCE_H
0 commit comments