@@ -57,24 +57,13 @@ static bool parseRootSignatureElement(LLVMContext *Ctx,
57
57
RootSignatureElementKind ElementKind =
58
58
StringSwitch<RootSignatureElementKind>(ElementText->getString ())
59
59
.Case (" RootFlags" , RootSignatureElementKind::RootFlags)
60
- .Case (" RootConstants" , RootSignatureElementKind::RootConstants)
61
- .Case (" RootCBV" , RootSignatureElementKind::RootDescriptor)
62
- .Case (" RootSRV" , RootSignatureElementKind::RootDescriptor)
63
- .Case (" RootUAV" , RootSignatureElementKind::RootDescriptor)
64
- .Case (" Sampler" , RootSignatureElementKind::RootDescriptor)
65
- .Case (" DescriptorTable" , RootSignatureElementKind::DescriptorTable)
66
- .Case (" StaticSampler" , RootSignatureElementKind::StaticSampler)
67
60
.Default (RootSignatureElementKind::None);
68
61
69
62
switch (ElementKind) {
70
63
71
64
case RootSignatureElementKind::RootFlags:
72
65
return parseRootFlags (Ctx, MRS, Element);
73
- case RootSignatureElementKind::RootConstants:
74
- case RootSignatureElementKind::RootDescriptor:
75
- case RootSignatureElementKind::DescriptorTable:
76
- case RootSignatureElementKind::StaticSampler:
77
- case RootSignatureElementKind::None:
66
+ default :
78
67
return reportError (Ctx,
79
68
" Invalid Root Element: " + ElementText->getString ());
80
69
}
@@ -83,7 +72,7 @@ static bool parseRootSignatureElement(LLVMContext *Ctx,
83
72
}
84
73
85
74
static bool parse (LLVMContext *Ctx, ModuleRootSignature *MRS, NamedMDNode *Root,
86
- const Function *EF ) {
75
+ const Function *EntryFunction ) {
87
76
bool HasError = false ;
88
77
89
78
/* * Root Signature are specified as following in the metadata:
@@ -121,7 +110,7 @@ static bool parse(LLVMContext *Ctx, ModuleRootSignature *MRS, NamedMDNode *Root,
121
110
continue ;
122
111
}
123
112
124
- if (F != EF )
113
+ if (F != EntryFunction )
125
114
continue ;
126
115
127
116
// Get the Root Signature Description from the function signature pair.
@@ -133,8 +122,8 @@ static bool parse(LLVMContext *Ctx, ModuleRootSignature *MRS, NamedMDNode *Root,
133
122
}
134
123
135
124
// Loop through the Root Elements of the root signature.
136
- for (unsigned int Eid = 0 ; Eid < RS->getNumOperands (); Eid++ ) {
137
- MDNode *Element = dyn_cast<MDNode>(RS-> getOperand (Eid) );
125
+ for (const auto &Operand : RS->operands () ) {
126
+ MDNode *Element = dyn_cast<MDNode>(Operand );
138
127
if (Element == nullptr )
139
128
return reportError (Ctx, " Missing Root Element Metadata Node." );
140
129
@@ -145,20 +134,30 @@ static bool parse(LLVMContext *Ctx, ModuleRootSignature *MRS, NamedMDNode *Root,
145
134
}
146
135
147
136
static bool validate (LLVMContext *Ctx, ModuleRootSignature *MRS) {
148
- if (dxbc::RootSignatureValidations::validateRootFlag (MRS->Flags )) {
137
+ if (! dxbc::RootSignatureValidations::isValidRootFlag (MRS->Flags )) {
149
138
return reportError (Ctx, " Invalid Root Signature flag value" );
150
139
}
151
140
return false ;
152
141
}
153
142
154
143
std::optional<ModuleRootSignature>
155
- ModuleRootSignature::analyzeModule (Module &M, const Function *F) {
156
- ModuleRootSignature MRS;
144
+ ModuleRootSignature::analyzeModule (Module &M, ModuleMetadataInfo MMI) {
145
+ if (MMI.ShaderProfile == Triple::Library)
146
+ return std::nullopt;
147
+
157
148
LLVMContext *Ctx = &M.getContext ();
158
149
150
+ if (MMI.EntryPropertyVec .size () != 1 ) {
151
+ reportError (Ctx, " More than one entry function defined." );
152
+ return std::nullopt;
153
+ }
154
+
155
+ ModuleRootSignature MRS;
156
+ const Function *EntryFunction = MMI.EntryPropertyVec [0 ].Entry ;
157
+
159
158
NamedMDNode *RootSignatureNode = M.getNamedMetadata (" dx.rootsignatures" );
160
- if (RootSignatureNode == nullptr || parse (Ctx, &MRS, RootSignatureNode, F) ||
161
- validate (Ctx, &MRS))
159
+ if (RootSignatureNode == nullptr ||
160
+ parse (Ctx, &MRS, RootSignatureNode, EntryFunction) || validate (Ctx, &MRS))
162
161
return std::nullopt;
163
162
164
163
return MRS;
@@ -168,39 +167,16 @@ AnalysisKey RootSignatureAnalysis::Key;
168
167
169
168
std::optional<ModuleRootSignature>
170
169
RootSignatureAnalysis::run (Module &M, ModuleAnalysisManager &AM) {
171
- auto MMI = AM.getResult <DXILMetadataAnalysis>(M);
172
-
173
- if (MMI.ShaderProfile == Triple::Library)
174
- return std::nullopt;
175
-
176
- LLVMContext *Ctx = &M.getContext ();
177
-
178
- if (MMI.EntryPropertyVec .size () != 1 ) {
179
- reportError (Ctx, " More than one entry function defined." );
180
- return std::nullopt;
181
- }
182
-
183
- const Function *EntryFunction = MMI.EntryPropertyVec [0 ].Entry ;
184
- return ModuleRootSignature::analyzeModule (M, EntryFunction);
170
+ ModuleMetadataInfo MMI = AM.getResult <DXILMetadataAnalysis>(M);
171
+ return ModuleRootSignature::analyzeModule (M, MMI);
185
172
}
186
173
187
174
// ===----------------------------------------------------------------------===//
188
175
bool RootSignatureAnalysisWrapper::runOnModule (Module &M) {
189
176
190
177
dxil::ModuleMetadataInfo &MMI =
191
178
getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata ();
192
-
193
- if (MMI.ShaderProfile == Triple::Library)
194
- return false ;
195
-
196
- LLVMContext *Ctx = &M.getContext ();
197
- if (MMI.EntryPropertyVec .size () != 1 ) {
198
- reportError (Ctx, " More than one entry function defined." );
199
- return false ;
200
- }
201
-
202
- const Function *EntryFunction = MMI.EntryPropertyVec [0 ].Entry ;
203
- MRS = ModuleRootSignature::analyzeModule (M, EntryFunction);
179
+ MRS = ModuleRootSignature::analyzeModule (M, MMI);
204
180
return false ;
205
181
}
206
182
0 commit comments