Skip to content

Commit c29ae5e

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.5-bogner
2 parents 70a9535 + d4af2a9 commit c29ae5e

File tree

9 files changed

+221
-106
lines changed

9 files changed

+221
-106
lines changed

llvm/include/llvm/Analysis/DXILResource.h

Lines changed: 101 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
#ifndef LLVM_ANALYSIS_DXILRESOURCE_H
1010
#define LLVM_ANALYSIS_DXILRESOURCE_H
1111

12+
#include "llvm/ADT/MapVector.h"
13+
#include "llvm/IR/PassManager.h"
1214
#include "llvm/IR/Value.h"
15+
#include "llvm/Pass.h"
1316
#include "llvm/Support/DXILABI.h"
1417

1518
namespace llvm {
19+
class CallInst;
1620
class MDTuple;
1721

1822
namespace dxil {
@@ -47,7 +51,7 @@ class ResourceInfo {
4751

4852
struct StructInfo {
4953
uint32_t Stride;
50-
Align Alignment;
54+
MaybeAlign Alignment;
5155

5256
bool operator==(const StructInfo &RHS) const {
5357
return std::tie(Stride, Alignment) == std::tie(RHS.Stride, RHS.Alignment);
@@ -106,6 +110,11 @@ class ResourceInfo {
106110

107111
MSInfo MultiSample;
108112

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+
109118
// Conditions to check before accessing union members.
110119
bool isUAV() const;
111120
bool isCBuffer() const;
@@ -115,17 +124,53 @@ class ResourceInfo {
115124
bool isFeedback() const;
116125
bool isMultiSample() const;
117126

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;
121167

122-
public:
123168
static ResourceInfo SRV(Value *Symbol, StringRef Name,
124169
dxil::ElementType ElementTy, uint32_t ElementCount,
125170
dxil::ResourceKind Kind);
126171
static ResourceInfo RawBuffer(Value *Symbol, StringRef Name);
127172
static ResourceInfo StructuredBuffer(Value *Symbol, StringRef Name,
128-
uint32_t Stride, Align Alignment);
173+
uint32_t Stride, MaybeAlign Alignment);
129174
static ResourceInfo Texture2DMS(Value *Symbol, StringRef Name,
130175
dxil::ElementType ElementTy,
131176
uint32_t ElementCount, uint32_t SampleCount);
@@ -141,9 +186,9 @@ class ResourceInfo {
141186
static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name,
142187
bool GloballyCoherent, bool IsROV);
143188
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);
147192
static ResourceInfo RWTexture2DMS(Value *Symbol, StringRef Name,
148193
dxil::ElementType ElementTy,
149194
uint32_t ElementCount, uint32_t SampleCount,
@@ -164,23 +209,60 @@ class ResourceInfo {
164209
static ResourceInfo Sampler(Value *Symbol, StringRef Name,
165210
dxil::SamplerType SamplerTy);
166211

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-
177212
MDTuple *getAsMetadata(LLVMContext &Ctx) const;
178213

179214
ResourceBinding getBinding() const { return Binding; }
180215
std::pair<uint32_t, uint32_t> getAnnotateProps() const;
181216
};
182217

183218
} // 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+
184266
} // namespace llvm
185267

186268
#endif // LLVM_ANALYSIS_DXILRESOURCE_H

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void initializeCycleInfoWrapperPassPass(PassRegistry &);
8282
void initializeDAEPass(PassRegistry&);
8383
void initializeDAHPass(PassRegistry&);
8484
void initializeDCELegacyPassPass(PassRegistry&);
85+
void initializeDXILResourceWrapperPassPass(PassRegistry &);
8586
void initializeDeadMachineInstructionElimPass(PassRegistry&);
8687
void initializeDebugifyMachineModulePass(PassRegistry &);
8788
void initializeDependenceAnalysisWrapperPassPass(PassRegistry&);

0 commit comments

Comments
 (0)