1//=- DXILMetadataAnalysis.h - Representation of Module metadata --*- C++ -*-=//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_ANALYSIS_DXILMETADATA_H
10#define LLVM_ANALYSIS_DXILMETADATA_H
11
12#include "llvm/ADT/SmallVector.h"
13#include "llvm/IR/PassManager.h"
14#include "llvm/Pass.h"
15#include "llvm/Support/VersionTuple.h"
16#include "llvm/TargetParser/Triple.h"
17
18namespace llvm {
19
20class Function;
21namespace dxil {
22
23struct EntryProperties {
24 const Function *Entry{nullptr};
25 // Specific target shader stage may be specified for entry functions
26 Triple::EnvironmentType ShaderStage{Triple::UnknownEnvironment};
27 unsigned NumThreadsX{0}; // X component
28 unsigned NumThreadsY{0}; // Y component
29 unsigned NumThreadsZ{0}; // Z component
30 unsigned WaveSizeMin{0}; // Minimum component
31 unsigned WaveSizeMax{0}; // Maximum component
32 unsigned WaveSizePref{0}; // Preferred component
33
34 EntryProperties(const Function *Fn = nullptr) : Entry(Fn) {};
35};
36
37struct ModuleMetadataInfo {
38 VersionTuple DXILVersion{};
39 VersionTuple ShaderModelVersion{};
40 Triple::EnvironmentType ShaderProfile{Triple::UnknownEnvironment};
41 VersionTuple ValidatorVersion{};
42 SmallVector<EntryProperties> EntryPropertyVec{};
43 void print(raw_ostream &OS) const;
44};
45
46} // namespace dxil
47
48// Module metadata analysis pass for new pass manager
49class DXILMetadataAnalysis : public AnalysisInfoMixin<DXILMetadataAnalysis> {
50 friend AnalysisInfoMixin<DXILMetadataAnalysis>;
51
52 static AnalysisKey Key;
53
54public:
55 using Result = dxil::ModuleMetadataInfo;
56 /// Gather module metadata info for the module \c M.
57 dxil::ModuleMetadataInfo run(Module &M, ModuleAnalysisManager &AM);
58};
59
60/// Printer pass for the \c DXILMetadataAnalysis results.
61class DXILMetadataAnalysisPrinterPass
62 : public PassInfoMixin<DXILMetadataAnalysisPrinterPass> {
63 raw_ostream &OS;
64
65public:
66 explicit DXILMetadataAnalysisPrinterPass(raw_ostream &OS) : OS(OS) {}
67
68 PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
69
70 static bool isRequired() { return true; }
71};
72
73/// Legacy pass
74class DXILMetadataAnalysisWrapperPass : public ModulePass {
75 std::unique_ptr<dxil::ModuleMetadataInfo> MetadataInfo;
76
77public:
78 static char ID; // Class identification, replacement for typeinfo
79
80 DXILMetadataAnalysisWrapperPass();
81 ~DXILMetadataAnalysisWrapperPass() override;
82
83 const dxil::ModuleMetadataInfo &getModuleMetadata() const {
84 return *MetadataInfo;
85 }
86 dxil::ModuleMetadataInfo &getModuleMetadata() { return *MetadataInfo; }
87
88 void getAnalysisUsage(AnalysisUsage &AU) const override;
89 bool runOnModule(Module &M) override;
90 void releaseMemory() override;
91
92 void print(raw_ostream &OS, const Module *M) const override;
93 void dump() const;
94};
95
96} // namespace llvm
97
98#endif // LLVM_ANALYSIS_DXILMETADATA_H
99