Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:12

0001 //=- DXILMetadataAnalysis.h - Representation of Module metadata --*- C++ -*-=//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_ANALYSIS_DXILMETADATA_H
0010 #define LLVM_ANALYSIS_DXILMETADATA_H
0011 
0012 #include "llvm/ADT/SmallVector.h"
0013 #include "llvm/IR/PassManager.h"
0014 #include "llvm/Pass.h"
0015 #include "llvm/Support/VersionTuple.h"
0016 #include "llvm/TargetParser/Triple.h"
0017 
0018 namespace llvm {
0019 
0020 class Function;
0021 namespace dxil {
0022 
0023 struct EntryProperties {
0024   const Function *Entry{nullptr};
0025   // Specific target shader stage may be specified for entry functions
0026   Triple::EnvironmentType ShaderStage{Triple::UnknownEnvironment};
0027   unsigned NumThreadsX{0}; // X component
0028   unsigned NumThreadsY{0}; // Y component
0029   unsigned NumThreadsZ{0}; // Z component
0030 
0031   EntryProperties(const Function *Fn = nullptr) : Entry(Fn) {};
0032 };
0033 
0034 struct ModuleMetadataInfo {
0035   VersionTuple DXILVersion{};
0036   VersionTuple ShaderModelVersion{};
0037   Triple::EnvironmentType ShaderProfile{Triple::UnknownEnvironment};
0038   VersionTuple ValidatorVersion{};
0039   SmallVector<EntryProperties> EntryPropertyVec{};
0040   void print(raw_ostream &OS) const;
0041 };
0042 
0043 } // namespace dxil
0044 
0045 // Module metadata analysis pass for new pass manager
0046 class DXILMetadataAnalysis : public AnalysisInfoMixin<DXILMetadataAnalysis> {
0047   friend AnalysisInfoMixin<DXILMetadataAnalysis>;
0048 
0049   static AnalysisKey Key;
0050 
0051 public:
0052   using Result = dxil::ModuleMetadataInfo;
0053   /// Gather module metadata info for the module \c M.
0054   dxil::ModuleMetadataInfo run(Module &M, ModuleAnalysisManager &AM);
0055 };
0056 
0057 /// Printer pass for the \c DXILMetadataAnalysis results.
0058 class DXILMetadataAnalysisPrinterPass
0059     : public PassInfoMixin<DXILMetadataAnalysisPrinterPass> {
0060   raw_ostream &OS;
0061 
0062 public:
0063   explicit DXILMetadataAnalysisPrinterPass(raw_ostream &OS) : OS(OS) {}
0064 
0065   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
0066 
0067   static bool isRequired() { return true; }
0068 };
0069 
0070 /// Legacy pass
0071 class DXILMetadataAnalysisWrapperPass : public ModulePass {
0072   std::unique_ptr<dxil::ModuleMetadataInfo> MetadataInfo;
0073 
0074 public:
0075   static char ID; // Class identification, replacement for typeinfo
0076 
0077   DXILMetadataAnalysisWrapperPass();
0078   ~DXILMetadataAnalysisWrapperPass() override;
0079 
0080   const dxil::ModuleMetadataInfo &getModuleMetadata() const {
0081     return *MetadataInfo;
0082   }
0083   dxil::ModuleMetadataInfo &getModuleMetadata() { return *MetadataInfo; }
0084 
0085   void getAnalysisUsage(AnalysisUsage &AU) const override;
0086   bool runOnModule(Module &M) override;
0087   void releaseMemory() override;
0088 
0089   void print(raw_ostream &OS, const Module *M) const override;
0090   void dump() const;
0091 };
0092 
0093 } // namespace llvm
0094 
0095 #endif // LLVM_ANALYSIS_DXILMETADATA_H