| 1 | //===- DXILRootSignature.h - DXIL Root Signature helper objects -----------===// |
|---|---|
| 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 | /// \file This file contains helper objects and APIs for working with DXIL |
| 10 | /// Root Signatures. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #ifndef LLVM_LIB_TARGET_DIRECTX_DXILROOTSIGNATURE_H |
| 14 | #define LLVM_LIB_TARGET_DIRECTX_DXILROOTSIGNATURE_H |
| 15 | |
| 16 | #include "llvm/ADT/DenseMap.h" |
| 17 | #include "llvm/Analysis/DXILMetadataAnalysis.h" |
| 18 | #include "llvm/IR/DiagnosticInfo.h" |
| 19 | #include "llvm/IR/Metadata.h" |
| 20 | #include "llvm/IR/Module.h" |
| 21 | #include "llvm/IR/PassManager.h" |
| 22 | #include "llvm/MC/DXContainerRootSignature.h" |
| 23 | #include "llvm/Pass.h" |
| 24 | |
| 25 | namespace llvm { |
| 26 | namespace dxil { |
| 27 | |
| 28 | class RootSignatureBindingInfo { |
| 29 | private: |
| 30 | SmallDenseMap<const Function *, mcdxbc::RootSignatureDesc> FuncToRsMap; |
| 31 | |
| 32 | public: |
| 33 | using iterator = |
| 34 | SmallDenseMap<const Function *, mcdxbc::RootSignatureDesc>::iterator; |
| 35 | |
| 36 | RootSignatureBindingInfo() = default; |
| 37 | RootSignatureBindingInfo( |
| 38 | SmallDenseMap<const Function *, mcdxbc::RootSignatureDesc> Map) |
| 39 | : FuncToRsMap(Map) {}; |
| 40 | |
| 41 | iterator find(const Function *F) { return FuncToRsMap.find(Val: F); } |
| 42 | |
| 43 | iterator end() { return FuncToRsMap.end(); } |
| 44 | |
| 45 | bool empty() const { return FuncToRsMap.empty(); } |
| 46 | |
| 47 | mcdxbc::RootSignatureDesc *getDescForFunction(const Function *F) { |
| 48 | const auto FuncRs = find(F); |
| 49 | if (FuncRs == end()) |
| 50 | return nullptr; |
| 51 | return &FuncRs->second; |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> { |
| 56 | friend AnalysisInfoMixin<RootSignatureAnalysis>; |
| 57 | static AnalysisKey Key; |
| 58 | |
| 59 | public: |
| 60 | RootSignatureAnalysis() = default; |
| 61 | |
| 62 | using Result = RootSignatureBindingInfo; |
| 63 | |
| 64 | Result run(Module &M, ModuleAnalysisManager &AM); |
| 65 | }; |
| 66 | |
| 67 | /// Wrapper pass for the legacy pass manager. |
| 68 | /// |
| 69 | /// This is required because the passes that will depend on this are codegen |
| 70 | /// passes which run through the legacy pass manager. |
| 71 | class RootSignatureAnalysisWrapper : public ModulePass { |
| 72 | private: |
| 73 | std::unique_ptr<RootSignatureBindingInfo> FuncToRsMap; |
| 74 | |
| 75 | public: |
| 76 | static char ID; |
| 77 | RootSignatureAnalysisWrapper() : ModulePass(ID) {} |
| 78 | |
| 79 | RootSignatureBindingInfo &getRSInfo() { return *FuncToRsMap; } |
| 80 | |
| 81 | bool runOnModule(Module &M) override; |
| 82 | |
| 83 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 84 | }; |
| 85 | |
| 86 | /// Printer pass for RootSignatureAnalysis results. |
| 87 | class RootSignatureAnalysisPrinter |
| 88 | : public OptionalPassInfoMixin<RootSignatureAnalysisPrinter> { |
| 89 | raw_ostream &OS; |
| 90 | |
| 91 | public: |
| 92 | explicit RootSignatureAnalysisPrinter(raw_ostream &OS) : OS(OS) {} |
| 93 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); |
| 94 | }; |
| 95 | |
| 96 | } // namespace dxil |
| 97 | } // namespace llvm |
| 98 | #endif |
| 99 |