LLVM: lib/Target/DirectX/DXILRootSignature.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
33#include
34
35using namespace llvm;
37
39 unsigned int OpId) {
40 if (auto *CI =
42 return CI->getZExtValue();
43 return std::nullopt;
44}
45
51
54
55
56
57
58
59
60
61
62
63
64
65
66
68
70
71 NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
72 if (RootSignatureNode == nullptr)
73 return RSDMap;
74
75 bool AllowNullFunctions = false;
76 if (M.getTargetTriple().getEnvironment() ==
79 AllowNullFunctions = true;
80 }
81
82 for (const auto &RSDefNode : RootSignatureNode->operands()) {
83 if (RSDefNode->getNumOperands() != 3) {
84 reportError(Ctx, "Invalid Root Signature metadata - expected function, "
85 "signature, and version.");
86 continue;
87 }
88
89
91
92 if (!AllowNullFunctions) {
93 const MDOperand &FunctionPointerMdNode = RSDefNode->getOperand(0);
94 if (FunctionPointerMdNode == nullptr) {
96 Ctx, "Function associated with Root Signature definition is null.");
97 continue;
98 }
99
102 if (VAM == nullptr) {
103 reportError(Ctx, "First element of root signature is not a Value");
104 continue;
105 }
106
108 if (F == nullptr) {
109 reportError(Ctx, "First element of root signature is not a Function");
110 continue;
111 }
112 }
113
114 Metadata *RootElementListOperand = RSDefNode->getOperand(1).get();
115
116 if (RootElementListOperand == nullptr) {
117 reportError(Ctx, "Root Element mdnode is null.");
118 continue;
119 }
120
122 if (RootElementListNode == nullptr) {
123 reportError(Ctx, "Root Element is not a metadata node.");
124 continue;
125 }
127 if (!V.has_value()) {
128 reportError(Ctx, "Invalid RSDefNode value, expected constant int");
129 continue;
130 }
131
135
136 if (!RSDOrErr) {
138 Ctx->emitError(EIB.message());
139 });
140 continue;
141 }
142
143 auto &RSD = *RSDOrErr;
144
145
146
147
149
150
151 RSD.StaticSamplersOffset = 0u;
152
153 RSDMap.insert(std::make_pair(F, RSD));
154 }
155
156 return RSDMap;
157}
158
160
165
166
167
170
172
173 OS << "Root Signature Definitions"
174 << "\n";
176 auto It = RSDMap.find(&F);
177 if (It == RSDMap.end())
178 continue;
179 const auto &RS = It->second;
180 OS << "Definition for '" << F.getName() << "':\n";
181
182 OS << "Flags: " << format_hex(RS.Flags, 8) << "\n"
183 << "Version: " << RS.Version << "\n"
184 << "RootParametersOffset: " << RS.RootParameterOffset << "\n"
185 << "NumParameters: " << RS.ParametersContainer.size() << "\n";
186 for (size_t I = 0; I < RS.ParametersContainer.size(); I++) {
188
189 OS << "- Parameter Type: "
191 << " Shader Visibility: "
193 << "\n";
194 switch (Info.Type) {
195 case dxbc::RootParameterType::Constants32Bit: {
197 RS.ParametersContainer.getConstant(Info.Location);
198 OS << " Register Space: " << Constants.RegisterSpace << "\n"
199 << " Shader Register: " << Constants.ShaderRegister << "\n"
200 << " Num 32 Bit Values: " << Constants.Num32BitValues << "\n";
201 break;
202 }
203 case dxbc::RootParameterType::CBV:
204 case dxbc::RootParameterType::UAV:
205 case dxbc::RootParameterType::SRV: {
207 RS.ParametersContainer.getRootDescriptor(Info.Location);
208 OS << " Register Space: " << Descriptor.RegisterSpace << "\n"
209 << " Shader Register: " << Descriptor.ShaderRegister << "\n";
210 if (RS.Version > 1)
211 OS << " Flags: " << Descriptor.Flags << "\n";
212 break;
213 }
214 case dxbc::RootParameterType::DescriptorTable: {
216 RS.ParametersContainer.getDescriptorTable(Info.Location);
217 OS << " NumRanges: " << Table.Ranges.size() << "\n";
218
220 OS << " - Range Type: "
222 << " Register Space: " << Range.RegisterSpace << "\n"
223 << " Base Shader Register: " << Range.BaseShaderRegister << "\n"
224 << " Num Descriptors: " << Range.NumDescriptors << "\n"
225 << " Offset In Descriptors From Table Start: "
226 << Range.OffsetInDescriptorsFromTableStart << "\n";
227 if (RS.Version > 1)
228 OS << " Flags: " << Range.Flags << "\n";
229 }
230 break;
231 }
232 }
233 }
234 OS << "NumStaticSamplers: " << 0 << "\n";
235 OS << "StaticSamplersOffset: " << RS.StaticSamplersOffset << "\n";
236 }
238}
239
240
242 FuncToRsMap = std::make_unique(
244 return false;
245}
246
251
253
255 "dxil-root-signature-analysis",
256 "DXIL Root Signature Analysis", true, true)
258 "dxil-root-signature-analysis",
259 "DXIL Root Signature Analysis", true, true)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static std::optional< uint32_t > extractMdIntValue(MDNode *Node, unsigned int OpId)
Definition DXILRootSignature.cpp:38
static SmallDenseMap< const Function *, mcdxbc::RootSignatureDesc > analyzeModule(Module &M)
Definition DXILRootSignature.cpp:53
static bool reportError(LLVMContext *Ctx, Twine Message, DiagnosticSeverity Severity=DS_Error)
Definition DXILRootSignature.cpp:46
Module.h This file contains the declarations for the Module class.
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
void setPreservesAll()
Set by analyses that do not transform their input at all.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Base class for error info classes.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
This is an important class for using LLVM in a threaded context.
Tracking metadata reference owned by Metadata.
A Module instance is used to store all the information related to an LLVM module.
LLVM_ABI unsigned getNumOperands() const
iterator_range< op_iterator > operands()
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.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition DXILRootSignature.cpp:168
Wrapper pass for the legacy pass manager.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition DXILRootSignature.cpp:247
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
Definition DXILRootSignature.cpp:241
RootSignatureBindingInfo Result
Result run(Module &M, ModuleAnalysisManager &AM)
Definition DXILRootSignature.cpp:162
iterator find(const Function *F)
LLVM_ABI ArrayRef< EnumEntry< ShaderVisibility > > getShaderVisibility()
LLVM_ABI ArrayRef< EnumEntry< RootParameterType > > getRootParameterTypes()
LLVM_ABI StringRef getResourceClassName(ResourceClass RC)
std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > dyn_extract(Y &&MD)
Extract a Value from Metadata, if any.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
FormattedNumber format_hex(uint64_t N, unsigned Width, bool Upper=false)
format_hex - Output N as a fixed width hexadecimal.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
StringRef enumToStringRef(T Value, ArrayRef< EnumEntry< TEnum > > EnumValues)
Retrieves the Value's enum name.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
A special type used by analysis passes to provide an address that identifies that particular analysis...
SmallVector< DescriptorRange > Ranges