@@ -57,24 +57,13 @@ static bool parseRootSignatureElement(LLVMContext *Ctx,
5757 RootSignatureElementKind ElementKind =
5858 StringSwitch<RootSignatureElementKind>(ElementText->getString ())
5959 .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)
6760 .Default (RootSignatureElementKind::None);
6861
6962 switch (ElementKind) {
7063
7164 case RootSignatureElementKind::RootFlags:
7265 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 :
7867 return reportError (Ctx,
7968 " Invalid Root Element: " + ElementText->getString ());
8069 }
@@ -83,7 +72,7 @@ static bool parseRootSignatureElement(LLVMContext *Ctx,
8372}
8473
8574static bool parse (LLVMContext *Ctx, ModuleRootSignature *MRS, NamedMDNode *Root,
86- const Function *EF ) {
75+ const Function *EntryFunction ) {
8776 bool HasError = false ;
8877
8978 /* * Root Signature are specified as following in the metadata:
@@ -121,7 +110,7 @@ static bool parse(LLVMContext *Ctx, ModuleRootSignature *MRS, NamedMDNode *Root,
121110 continue ;
122111 }
123112
124- if (F != EF )
113+ if (F != EntryFunction )
125114 continue ;
126115
127116 // Get the Root Signature Description from the function signature pair.
@@ -133,8 +122,8 @@ static bool parse(LLVMContext *Ctx, ModuleRootSignature *MRS, NamedMDNode *Root,
133122 }
134123
135124 // 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 );
138127 if (Element == nullptr )
139128 return reportError (Ctx, " Missing Root Element Metadata Node." );
140129
@@ -145,20 +134,30 @@ static bool parse(LLVMContext *Ctx, ModuleRootSignature *MRS, NamedMDNode *Root,
145134}
146135
147136static bool validate (LLVMContext *Ctx, ModuleRootSignature *MRS) {
148- if (dxbc::RootSignatureValidations::validateRootFlag (MRS->Flags )) {
137+ if (! dxbc::RootSignatureValidations::isValidRootFlag (MRS->Flags )) {
149138 return reportError (Ctx, " Invalid Root Signature flag value" );
150139 }
151140 return false ;
152141}
153142
154143std::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+
157148 LLVMContext *Ctx = &M.getContext ();
158149
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+
159158 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))
162161 return std::nullopt ;
163162
164163 return MRS;
@@ -168,39 +167,16 @@ AnalysisKey RootSignatureAnalysis::Key;
168167
169168std::optional<ModuleRootSignature>
170169RootSignatureAnalysis::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);
185172}
186173
187174// ===----------------------------------------------------------------------===//
188175bool RootSignatureAnalysisWrapper::runOnModule (Module &M) {
189176
190177 dxil::ModuleMetadataInfo &MMI =
191178 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);
204180 return false ;
205181}
206182
0 commit comments