29
29
using namespace llvm ;
30
30
using namespace llvm ::dxil;
31
31
32
- bool ModuleRootSignature::reportError (Twine Message,
33
- DiagnosticSeverity Severity) {
32
+ LLVMContext *Ctx;
33
+
34
+ static bool reportError (Twine Message, DiagnosticSeverity Severity = DS_Error) {
34
35
Ctx->diagnose (DiagnosticInfoGeneric (Message, Severity));
35
36
return true ;
36
37
}
37
38
38
- bool ModuleRootSignature:: parseRootFlags (MDNode *RootFlagNode) {
39
+ static bool parseRootFlags (ModuleRootSignature *MRS, MDNode *RootFlagNode) {
39
40
40
41
if (RootFlagNode->getNumOperands () != 2 )
41
42
return reportError (" Invalid format for RootFlag Element" );
42
43
43
44
auto *Flag = mdconst::extract<ConstantInt>(RootFlagNode->getOperand (1 ));
44
- this ->Flags = Flag->getZExtValue ();
45
+ MRS ->Flags = Flag->getZExtValue ();
45
46
46
47
return false ;
47
48
}
48
49
49
- bool ModuleRootSignature::parseRootSignatureElement (MDNode *Element) {
50
+ static bool parseRootSignatureElement (ModuleRootSignature *MRS,
51
+ MDNode *Element) {
50
52
MDString *ElementText = cast<MDString>(Element->getOperand (0 ));
51
53
if (ElementText == nullptr )
52
54
return reportError (" Invalid format for Root Element" );
@@ -65,24 +67,21 @@ bool ModuleRootSignature::parseRootSignatureElement(MDNode *Element) {
65
67
66
68
switch (ElementKind) {
67
69
68
- case RootSignatureElementKind::RootFlags: {
69
- return parseRootFlags (Element);
70
- break ;
71
- }
72
-
70
+ case RootSignatureElementKind::RootFlags:
71
+ return parseRootFlags (MRS, Element);
73
72
case RootSignatureElementKind::RootConstants:
74
73
case RootSignatureElementKind::RootDescriptor:
75
74
case RootSignatureElementKind::DescriptorTable:
76
75
case RootSignatureElementKind::StaticSampler:
77
76
case RootSignatureElementKind::None:
78
77
return reportError (" Invalid Root Element: " + ElementText->getString ());
79
- break ;
80
78
}
81
79
82
80
return true ;
83
81
}
84
82
85
- bool ModuleRootSignature::parse (NamedMDNode *Root, const Function *EF) {
83
+ static bool parse (ModuleRootSignature *MRS, NamedMDNode *Root,
84
+ const Function *EF) {
86
85
bool HasError = false ;
87
86
88
87
/* * Root Signature are specified as following in the metadata:
@@ -93,7 +92,7 @@ bool ModuleRootSignature::parse(NamedMDNode *Root, const Function *EF) {
93
92
94
93
So for each MDNode inside dx.rootsignatures NamedMDNode
95
94
(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,
97
96
signature pair.
98
97
*/
99
98
@@ -126,35 +125,36 @@ bool ModuleRootSignature::parse(NamedMDNode *Root, const Function *EF) {
126
125
if (Element == nullptr )
127
126
return reportError (" Missing Root Element Metadata Node." );
128
127
129
- HasError = HasError || parseRootSignatureElement (Element);
128
+ HasError = HasError || parseRootSignatureElement (MRS, Element);
130
129
}
131
130
}
132
131
return HasError;
133
132
}
134
133
135
- bool ModuleRootSignature:: validate () {
136
- if (dxbc::RootSignatureValidations::validateRootFlag (Flags)) {
134
+ static bool validate (ModuleRootSignature *MRS ) {
135
+ if (dxbc::RootSignatureValidations::validateRootFlag (MRS-> Flags )) {
137
136
return reportError (" Invalid Root Signature flag value" );
138
137
}
139
138
return false ;
140
139
}
141
140
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 ();
145
145
146
146
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 ))
149
149
return std::nullopt;
150
150
151
151
return MRS;
152
152
}
153
153
154
154
AnalysisKey RootSignatureAnalysis::Key;
155
155
156
- OptionalRootSignature RootSignatureAnalysis::run (Module &M,
157
- ModuleAnalysisManager &AM) {
156
+ std::optional<ModuleRootSignature>
157
+ RootSignatureAnalysis::run (Module &M, ModuleAnalysisManager &AM) {
158
158
auto MMI = AM.getResult <DXILMetadataAnalysis>(M);
159
159
160
160
if (MMI.ShaderProfile == Triple::Library)
0 commit comments