@@ -29,25 +29,18 @@ static bool reportError(Twine Message) {
29
29
return true ;
30
30
}
31
31
32
- static bool parseRootFlags (ModuleRootSignature *MRS, MDNode *RootFlagNode) {
32
+ bool ModuleRootSignature:: parseRootFlags (MDNode *RootFlagNode) {
33
33
34
34
if (RootFlagNode->getNumOperands () != 2 )
35
35
return reportError (" Invalid format for RootFlag Element" );
36
36
37
37
auto *Flag = mdconst::extract<ConstantInt>(RootFlagNode->getOperand (1 ));
38
- uint32_t Value = Flag->getZExtValue ();
38
+ this -> Flags = Flag->getZExtValue ();
39
39
40
- // Root Element validation, as specified:
41
- // https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
42
- if ((Value & ~0x80000fff ) != 0 )
43
- return reportError (" Invalid flag value for RootFlag" );
44
-
45
- MRS->Flags = Value;
46
40
return false ;
47
41
}
48
42
49
- static bool parseRootSignatureElement (ModuleRootSignature *MRS,
50
- MDNode *Element) {
43
+ bool ModuleRootSignature::parseRootSignatureElement (MDNode *Element) {
51
44
MDString *ElementText = cast<MDString>(Element->getOperand (0 ));
52
45
if (ElementText == nullptr )
53
46
return reportError (" Invalid format for Root Element" );
@@ -67,7 +60,7 @@ static bool parseRootSignatureElement(ModuleRootSignature *MRS,
67
60
switch (ElementKind) {
68
61
69
62
case RootSignatureElementKind::RootFlags: {
70
- return parseRootFlags (MRS, Element);
63
+ return parseRootFlags (Element);
71
64
break ;
72
65
}
73
66
@@ -131,19 +124,35 @@ bool ModuleRootSignature::parse(NamedMDNode *Root, const Function *EF) {
131
124
if (Element == nullptr )
132
125
return reportError (" Missing Root Element Metadata Node." );
133
126
134
- HasError = HasError || parseRootSignatureElement (this , Element);
127
+ HasError = HasError || parseRootSignatureElement (Element);
135
128
}
136
129
}
137
130
return HasError;
138
131
}
139
132
133
+ bool ModuleRootSignature::validateRootFlag () {
134
+ // Root Element validation, as specified:
135
+ // https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
136
+ if ((Flags & ~0x80000fff ) != 0 )
137
+ return reportError (" Invalid flag value for RootFlag" );
138
+
139
+ return false ;
140
+ }
141
+
142
+ bool ModuleRootSignature::validate () {
143
+ if (validateRootFlag ())
144
+ return reportError (" Invalid flag value for RootFlag" );
145
+
146
+ return false ;
147
+ }
148
+
140
149
ModuleRootSignature ModuleRootSignature::analyzeModule (Module &M,
141
150
const Function *F) {
142
151
ModuleRootSignature MRS;
143
152
144
153
NamedMDNode *RootSignatureNode = M.getNamedMetadata (" dx.rootsignatures" );
145
154
if (RootSignatureNode) {
146
- if (MRS.parse (RootSignatureNode, F))
155
+ if (MRS.parse (RootSignatureNode, F) || MRS. validate () )
147
156
llvm_unreachable (" Invalid Root Signature Metadata." );
148
157
}
149
158
@@ -176,7 +185,7 @@ bool RootSignatureAnalysisWrapper::runOnModule(Module &M) {
176
185
assert (MMI.EntryPropertyVec .size () == 1 );
177
186
178
187
const Function *EntryFunction = MMI.EntryPropertyVec [0 ].Entry ;
179
- this -> MRS = MRS = ModuleRootSignature::analyzeModule (M, EntryFunction);
188
+ MRS = ModuleRootSignature::analyzeModule (M, EntryFunction);
180
189
181
190
return false ;
182
191
}
0 commit comments