[llvm] [DirectX] Infrastructure to collect shader flags for each function (PR #112967)
Chris B via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 18 13:39:23 PST 2024
================
@@ -63,20 +106,64 @@ void ComputedShaderFlags::print(raw_ostream &OS) const {
OS << ";\n";
}
+/// Get the combined shader flag mask of all module functions.
+const ComputedShaderFlags DXILModuleShaderFlagsInfo::getCombinedFlags() const {
+ return CombinedSFMask;
+}
+
+/// Return the shader flags mask of the specified function Func, if one exists.
+/// else an error
+Expected<const ComputedShaderFlags &>
+DXILModuleShaderFlagsInfo::getShaderFlagsMask(const Function *Func) const {
+ std::pair<Function const *, ComputedShaderFlags> V{Func, {}};
+ const auto Iter = llvm::lower_bound(FunctionFlags, V);
+ if (Iter == FunctionFlags.end() || Iter->first != Func) {
+ return createStringError("Shader Flags information of Function '" +
+ Func->getName() + "' not found");
+ }
+ return Iter->second;
+}
+
+//===----------------------------------------------------------------------===//
+// ShaderFlagsAnalysis and ShaderFlagsAnalysisPrinterPass
+
+// Provide an explicit template instantiation for the static ID.
AnalysisKey ShaderFlagsAnalysis::Key;
-ComputedShaderFlags ShaderFlagsAnalysis::run(Module &M,
- ModuleAnalysisManager &AM) {
- return ComputedShaderFlags::computeFlags(M);
+DXILModuleShaderFlagsInfo ShaderFlagsAnalysis::run(Module &M,
+ ModuleAnalysisManager &AM) {
+ DXILModuleShaderFlagsInfo MSFI(M);
+ return MSFI;
}
PreservedAnalyses ShaderFlagsAnalysisPrinter::run(Module &M,
ModuleAnalysisManager &AM) {
- ComputedShaderFlags Flags = AM.getResult<ShaderFlagsAnalysis>(M);
- Flags.print(OS);
+ DXILModuleShaderFlagsInfo FlagsInfo = AM.getResult<ShaderFlagsAnalysis>(M);
+ for (const auto &F : M.getFunctionList()) {
+ if (F.isDeclaration())
+ continue;
+ OS << "; Shader Flags mask for Function: " << F.getName() << "\n";
+ auto SFMask = FlagsInfo.getShaderFlagsMask(&F);
+ if (Error E = SFMask.takeError()) {
+ M.getContext().diagnose(
+ DiagnosticInfoShaderFlags(M, toString(std::move(E))));
+ }
----------------
llvm-beanz wrote:
This should be done through a call to `llvm::handleAllErrors`. Something like:
```suggestion
if (!SFMask)
return handleAllErrors(std::move(E),
[&](std::unique_ptr<ErrorInfoBase> EIB) -> Error {
M.getContext().diagnose(errorToDiagnosticInfo(EIB);
return Error::success();
});
```
This handles arrays of errors so that your function can return more than one error.
https://github.com/llvm/llvm-project/pull/112967
More information about the llvm-commits
mailing list