2929using namespace llvm ;
3030using namespace llvm ::dxil;
3131
32- bool ModuleRootSignature::reportError (Twine Message,
33- DiagnosticSeverity Severity) {
32+ LLVMContext *Ctx;
33+
34+ static bool reportError (Twine Message, DiagnosticSeverity Severity = DS_Error) {
3435 Ctx->diagnose (DiagnosticInfoGeneric (Message, Severity));
3536 return true ;
3637}
3738
38- bool ModuleRootSignature:: parseRootFlags (MDNode *RootFlagNode) {
39+ static bool parseRootFlags (ModuleRootSignature *MRS, MDNode *RootFlagNode) {
3940
4041 if (RootFlagNode->getNumOperands () != 2 )
4142 return reportError (" Invalid format for RootFlag Element" );
4243
4344 auto *Flag = mdconst::extract<ConstantInt>(RootFlagNode->getOperand (1 ));
44- this ->Flags = Flag->getZExtValue ();
45+ MRS ->Flags = Flag->getZExtValue ();
4546
4647 return false ;
4748}
4849
49- bool ModuleRootSignature::parseRootSignatureElement (MDNode *Element) {
50+ static bool parseRootSignatureElement (ModuleRootSignature *MRS,
51+ MDNode *Element) {
5052 MDString *ElementText = cast<MDString>(Element->getOperand (0 ));
5153 if (ElementText == nullptr )
5254 return reportError (" Invalid format for Root Element" );
@@ -65,24 +67,21 @@ bool ModuleRootSignature::parseRootSignatureElement(MDNode *Element) {
6567
6668 switch (ElementKind) {
6769
68- case RootSignatureElementKind::RootFlags: {
69- return parseRootFlags (Element);
70- break ;
71- }
72-
70+ case RootSignatureElementKind::RootFlags:
71+ return parseRootFlags (MRS, Element);
7372 case RootSignatureElementKind::RootConstants:
7473 case RootSignatureElementKind::RootDescriptor:
7574 case RootSignatureElementKind::DescriptorTable:
7675 case RootSignatureElementKind::StaticSampler:
7776 case RootSignatureElementKind::None:
7877 return reportError (" Invalid Root Element: " + ElementText->getString ());
79- break ;
8078 }
8179
8280 return true ;
8381}
8482
85- bool ModuleRootSignature::parse (NamedMDNode *Root, const Function *EF) {
83+ static bool parse (ModuleRootSignature *MRS, NamedMDNode *Root,
84+ const Function *EF) {
8685 bool HasError = false ;
8786
8887 /* * Root Signature are specified as following in the metadata:
@@ -93,7 +92,7 @@ bool ModuleRootSignature::parse(NamedMDNode *Root, const Function *EF) {
9392
9493 So for each MDNode inside dx.rootsignatures NamedMDNode
9594 (the Root parameter of this function), the parsing process needs
96- to loop through each of it's operand and process the pairs function
95+ to loop through each of its operands and process the function,
9796 signature pair.
9897 */
9998
@@ -126,35 +125,36 @@ bool ModuleRootSignature::parse(NamedMDNode *Root, const Function *EF) {
126125 if (Element == nullptr )
127126 return reportError (" Missing Root Element Metadata Node." );
128127
129- HasError = HasError || parseRootSignatureElement (Element);
128+ HasError = HasError || parseRootSignatureElement (MRS, Element);
130129 }
131130 }
132131 return HasError;
133132}
134133
135- bool ModuleRootSignature:: validate () {
136- if (dxbc::RootSignatureValidations::validateRootFlag (Flags)) {
134+ static bool validate (ModuleRootSignature *MRS ) {
135+ if (dxbc::RootSignatureValidations::validateRootFlag (MRS-> Flags )) {
137136 return reportError (" Invalid Root Signature flag value" );
138137 }
139138 return false ;
140139}
141140
142- OptionalRootSignature ModuleRootSignature::analyzeModule (Module &M,
143- const Function *F) {
144- ModuleRootSignature MRS (&M.getContext ());
141+ std::optional<ModuleRootSignature>
142+ ModuleRootSignature::analyzeModule (Module &M, const Function *F) {
143+ ModuleRootSignature MRS;
144+ Ctx = &M.getContext ();
145145
146146 NamedMDNode *RootSignatureNode = M.getNamedMetadata (" dx.rootsignatures" );
147- if (RootSignatureNode == nullptr || MRS. parse (RootSignatureNode, F) ||
148- MRS. validate ())
147+ if (RootSignatureNode == nullptr || parse (&MRS, RootSignatureNode, F) ||
148+ validate (&MRS ))
149149 return std::nullopt ;
150150
151151 return MRS;
152152}
153153
154154AnalysisKey RootSignatureAnalysis::Key;
155155
156- OptionalRootSignature RootSignatureAnalysis::run (Module &M,
157- ModuleAnalysisManager &AM) {
156+ std::optional<ModuleRootSignature>
157+ RootSignatureAnalysis::run (Module &M, ModuleAnalysisManager &AM) {
158158 auto MMI = AM.getResult <DXILMetadataAnalysis>(M);
159159
160160 if (MMI.ShaderProfile == Triple::Library)
0 commit comments