20
20
#include " llvm/IR/DiagnosticInfo.h"
21
21
#include " llvm/IR/Function.h"
22
22
#include " llvm/IR/LLVMContext.h"
23
+ #include " llvm/IR/Metadata.h"
23
24
#include " llvm/IR/Module.h"
24
25
#include " llvm/InitializePasses.h"
25
26
#include " llvm/Pass.h"
@@ -63,9 +64,6 @@ static bool parseRootSignatureElement(LLVMContext *Ctx,
63
64
64
65
case RootSignatureElementKind::RootFlags:
65
66
return parseRootFlags (Ctx, MRS, Element);
66
- default :
67
- return reportError (Ctx,
68
- " Invalid Root Element: " + ElementText->getString ());
69
67
}
70
68
71
69
return true ;
@@ -95,8 +93,14 @@ static bool parse(LLVMContext *Ctx, ModuleRootSignature *MRS, NamedMDNode *Root,
95
93
continue ;
96
94
}
97
95
96
+ const MDOperand &FunctionPointerMdNode = Node->getOperand (0 );
97
+ if (FunctionPointerMdNode == nullptr ) {
98
+ // Function was pruned during compilation.
99
+ continue ;
100
+ }
101
+
98
102
ValueAsMetadata *VAM =
99
- llvm::dyn_cast<ValueAsMetadata>(Node-> getOperand ( 0 ) .get ());
103
+ llvm::dyn_cast<ValueAsMetadata>(FunctionPointerMdNode .get ());
100
104
if (VAM == nullptr ) {
101
105
HasError =
102
106
reportError (Ctx, " First element of root signature is not a value" );
@@ -140,24 +144,26 @@ static bool validate(LLVMContext *Ctx, ModuleRootSignature *MRS) {
140
144
return false ;
141
145
}
142
146
143
- std::optional<ModuleRootSignature>
144
- ModuleRootSignature::analyzeModule (Module &M, ModuleMetadataInfo MMI) {
145
- if (MMI.ShaderProfile == Triple::Library)
146
- return std::nullopt;
147
+ static const Function *getEntryFunction (Module &M, ModuleMetadataInfo MMI) {
147
148
148
149
LLVMContext *Ctx = &M.getContext ();
149
-
150
150
if (MMI.EntryPropertyVec .size () != 1 ) {
151
151
reportError (Ctx, " More than one entry function defined." );
152
- return std::nullopt ;
152
+ return nullptr ;
153
153
}
154
+ return MMI.EntryPropertyVec [0 ].Entry ;
155
+ }
156
+
157
+ std::optional<ModuleRootSignature>
158
+ ModuleRootSignature::analyzeModule (Module &M, const Function *F) {
159
+
160
+ LLVMContext *Ctx = &M.getContext ();
154
161
155
162
ModuleRootSignature MRS;
156
- const Function *EntryFunction = MMI.EntryPropertyVec [0 ].Entry ;
157
163
158
164
NamedMDNode *RootSignatureNode = M.getNamedMetadata (" dx.rootsignatures" );
159
- if (RootSignatureNode == nullptr ||
160
- parse (Ctx, &MRS, RootSignatureNode, EntryFunction) || validate (Ctx, &MRS))
165
+ if (RootSignatureNode == nullptr || parse (Ctx, &MRS, RootSignatureNode, F) ||
166
+ validate (Ctx, &MRS))
161
167
return std::nullopt;
162
168
163
169
return MRS;
@@ -168,15 +174,18 @@ AnalysisKey RootSignatureAnalysis::Key;
168
174
std::optional<ModuleRootSignature>
169
175
RootSignatureAnalysis::run (Module &M, ModuleAnalysisManager &AM) {
170
176
ModuleMetadataInfo MMI = AM.getResult <DXILMetadataAnalysis>(M);
171
- return ModuleRootSignature::analyzeModule (M, MMI);
177
+ if (MMI.ShaderProfile == Triple::Library)
178
+ return std::nullopt;
179
+ return ModuleRootSignature::analyzeModule (M, getEntryFunction (M, MMI));
172
180
}
173
181
174
182
// ===----------------------------------------------------------------------===//
175
183
bool RootSignatureAnalysisWrapper::runOnModule (Module &M) {
176
-
177
184
dxil::ModuleMetadataInfo &MMI =
178
185
getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata ();
179
- MRS = ModuleRootSignature::analyzeModule (M, MMI);
186
+ if (MMI.ShaderProfile == Triple::Library)
187
+ return false ;
188
+ MRS = ModuleRootSignature::analyzeModule (M, getEntryFunction (M, MMI));
180
189
return false ;
181
190
}
182
191
0 commit comments