LLVM: lib/Target/DirectX/DXILPrettyPrinter.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
19
20using namespace llvm;
21
23 switch (RC) {
25 return "texture";
27 return "UAV";
29 return "cbuffer";
31 return "sampler";
32 }
34}
35
37 switch (RC) {
39 return "t";
41 return "u";
43 return "cb";
45 return "s";
46 }
48}
49
54 return "i1";
56 return "i16";
58 return "u16";
60 return "i32";
62 return "u32";
64 return "i64";
66 return "u64";
68 return "f16";
70 return "f32";
72 return "f64";
74 return "snorm_f16";
76 return "unorm_f16";
78 return "snorm_f32";
80 return "unorm_f32";
82 return "snorm_f64";
84 return "unorm_f64";
86 return "p32i8";
88 return "p32u8";
91 }
94 return "struct";
96 return "NA";
97 return "byte";
98}
99
101 switch (RK) {
103 return "1d";
105 return "2d";
107 return "3d";
109 return "cube";
111 return "1darray";
113 return "2darray";
115 return "cubearray";
117 return "tbuffer";
119 return "fbtex2d";
121 return "fbtex2darray";
123 return "2dMS";
125 return "2darrayMS";
135 }
137}
138
139namespace {
140struct FormatResourceDimension
142 FormatResourceDimension(const dxil::ResourceTypeInfo &RI, bool HasCounter)
143 : llvm::FormatAdapter<const dxil::ResourceTypeInfo &>(RI),
144 HasCounter(HasCounter) {}
145
146 bool HasCounter;
147
148 void format(llvm::raw_ostream &OS, StringRef Style) override {
150 switch (RK) {
151 default: {
153 if (Item.isMultiSample())
154 OS << Item.getMultiSampleCount();
155 break;
156 }
157 case dxil::ResourceKind::RawBuffer:
158 case dxil::ResourceKind::StructuredBuffer:
159 if (!Item.isUAV())
160 OS << "r/o";
161 else if (HasCounter)
162 OS << "r/w+cnt";
163 else
164 OS << "r/w";
165 break;
166 case dxil::ResourceKind::TypedBuffer:
167 OS << "buf";
168 break;
169 case dxil::ResourceKind::CBuffer:
170 OS << "NA";
171 break;
172 case dxil::ResourceKind::RTAccelerationStructure:
173
174 llvm_unreachable("RTAccelerationStructure printing is not implemented");
175 }
176 }
177};
178
179struct FormatBindingID
182
183 explicit FormatBindingID(const dxil::ResourceInfo &RI,
184 const dxil::ResourceTypeInfo &RTI)
185 : llvm::FormatAdapter<const dxil::ResourceInfo &>(RI),
186 RC(RTI.getResourceClass()) {}
187
188 void format(llvm::raw_ostream &OS, StringRef Style) override {
190 }
191};
192
193struct FormatBindingLocation
196
197 explicit FormatBindingLocation(const dxil::ResourceInfo &RI,
198 const dxil::ResourceTypeInfo &RTI)
199 : llvm::FormatAdapter<const dxil::ResourceInfo &>(RI),
200 RC(RTI.getResourceClass()) {}
201
202 void format(llvm::raw_ostream &OS, StringRef Style) override {
203 const auto &Binding = Item.getBinding();
206 OS << ",space" << Binding.Space;
207 }
208};
209
210struct FormatBindingSize
212 explicit FormatBindingSize(const dxil::ResourceInfo &RI)
213 : llvm::FormatAdapter<const dxil::ResourceInfo &>(RI) {}
214
215 void format(llvm::raw_ostream &OS, StringRef Style) override {
216 uint32_t Size = Item.getBinding().Size;
217 if (Size == std::numeric_limits<uint32_t>::max())
218 OS << "unbounded";
219 else
221 }
222};
223
224}
225
228
229 OS << ";\n; Resource Bindings:\n;\n";
230 OS << formatv("; {0,-30} {1,10} {2,7} {3,11} {4,7} {5,14} {6,9}\n", "Name",
231 "Type", "Format", "Dim", "ID", "HLSL Bind", "Count");
233 "; {0,-+30} {1,-+10} {2,-+7} {3,-+11} {4,-+7} {5,-+14} {6,-+9}\n", "", "",
234 "", "", "", "", "");
235
236
239
244 FormatResourceDimension Dim(RTI, RI.hasCounter());
245 FormatBindingID ID(RI, RTI);
246 FormatBindingLocation Bind(RI, RTI);
247 FormatBindingSize Count(RI);
248 OS << formatv("; {0,-30} {1,10} {2,7} {3,11} {4,7} {5,14} {6,9}\n", Name,
250 }
251 OS << ";\n";
252}
253
261
262namespace {
264 raw_ostream &OS;
265
266public:
267 static char ID;
268
270
271 StringRef getPassName() const override {
272 return "DXIL Metadata Pretty Printer";
273 }
274
275 bool runOnModule(Module &M) override;
276 void getAnalysisUsage(AnalysisUsage &AU) const override {
278 AU.addRequired();
279 AU.addRequired();
280 }
281};
282}
283
284char DXILPrettyPrinterLegacy::ID = 0;
286 "DXIL Metadata Pretty Printer", true, true)
290 "DXIL Metadata Pretty Printer", true, true)
291
292bool DXILPrettyPrinterLegacy::runOnModule(Module &M) {
294 getAnalysis().getResourceMap();
296 getAnalysis().getResourceTypeMap();
298 return false;
299}
300
302 return new DXILPrettyPrinterLegacy(OS);
303}
static StringRef getTextureDimName(dxil::ResourceKind RK)
Definition DXILPrettyPrinter.cpp:100
static void prettyPrintResources(raw_ostream &OS, const DXILResourceMap &DRM, DXILResourceTypeMap &DRTM)
Definition DXILPrettyPrinter.cpp:226
static StringRef getRCPrefix(dxil::ResourceClass RC)
Definition DXILPrettyPrinter.cpp:36
static StringRef getFormatName(const dxil::ResourceTypeInfo &RI)
Definition DXILPrettyPrinter.cpp:50
static StringRef getRCName(dxil::ResourceClass RC)
Definition DXILPrettyPrinter.cpp:22
DXIL Resource Implicit Binding
This header defines various interfaces for pass management in LLVM.
Machine Check Debug Module
ModuleAnalysisManager MAM
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &)
Definition DXILPrettyPrinter.cpp:254
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
StringRef - Represent a constant reference to a string, i.e.
LLVM_ABI std::string upper() const
Convert the given ASCII string to uppercase.
The instances of the Type class are immutable: once they are created, they are never changed.
dxil::ResourceClass getResourceClass() const
LLVM_ABI bool isSampler() const
LLVM_ABI bool isTyped() const
LLVM_ABI bool isCBuffer() const
LLVM_ABI TypedInfo getTyped() const
LLVM_ABI bool isStruct() const
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
ResourceKind
The kind of resource for an SRV or UAV resource.
@ RTAccelerationStructure
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
FunctionAddr VTableAddr Count
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
ModulePass * createDXILPrettyPrinterLegacyPass(raw_ostream &OS)
Pass to pretty print DXIL metadata.
Definition DXILPrettyPrinter.cpp:301
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
dxil::ElementType DXILStorageTy