xref: /freebsd/contrib/llvm-project/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
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 
18 namespace llvm {
19 
20 class Function;
21 namespace dxil {
22 
23 struct 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 
EntryEntryProperties31   EntryProperties(const Function *Fn = nullptr) : Entry(Fn) {};
32 };
33 
34 struct ModuleMetadataInfo {
35   VersionTuple DXILVersion{};
36   VersionTuple ShaderModelVersion{};
37   Triple::EnvironmentType ShaderProfile{Triple::UnknownEnvironment};
38   VersionTuple ValidatorVersion{};
39   SmallVector<EntryProperties> EntryPropertyVec{};
40   void print(raw_ostream &OS) const;
41 };
42 
43 } // namespace dxil
44 
45 // Module metadata analysis pass for new pass manager
46 class DXILMetadataAnalysis : public AnalysisInfoMixin<DXILMetadataAnalysis> {
47   friend AnalysisInfoMixin<DXILMetadataAnalysis>;
48 
49   static AnalysisKey Key;
50 
51 public:
52   using Result = dxil::ModuleMetadataInfo;
53   /// Gather module metadata info for the module \c M.
54   dxil::ModuleMetadataInfo run(Module &M, ModuleAnalysisManager &AM);
55 };
56 
57 /// Printer pass for the \c DXILMetadataAnalysis results.
58 class DXILMetadataAnalysisPrinterPass
59     : public PassInfoMixin<DXILMetadataAnalysisPrinterPass> {
60   raw_ostream &OS;
61 
62 public:
DXILMetadataAnalysisPrinterPass(raw_ostream & OS)63   explicit DXILMetadataAnalysisPrinterPass(raw_ostream &OS) : OS(OS) {}
64 
65   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
66 
isRequired()67   static bool isRequired() { return true; }
68 };
69 
70 /// Legacy pass
71 class DXILMetadataAnalysisWrapperPass : public ModulePass {
72   std::unique_ptr<dxil::ModuleMetadataInfo> MetadataInfo;
73 
74 public:
75   static char ID; // Class identification, replacement for typeinfo
76 
77   DXILMetadataAnalysisWrapperPass();
78   ~DXILMetadataAnalysisWrapperPass() override;
79 
getModuleMetadata()80   const dxil::ModuleMetadataInfo &getModuleMetadata() const {
81     return *MetadataInfo;
82   }
getModuleMetadata()83   dxil::ModuleMetadataInfo &getModuleMetadata() { return *MetadataInfo; }
84 
85   void getAnalysisUsage(AnalysisUsage &AU) const override;
86   bool runOnModule(Module &M) override;
87   void releaseMemory() override;
88 
89   void print(raw_ostream &OS, const Module *M) const override;
90   void dump() const;
91 };
92 
93 } // namespace llvm
94 
95 #endif // LLVM_ANALYSIS_DXILMETADATA_H
96