| 1 | //===- DirectXTargetMachine.h - DirectX Target Implementation ---*- 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 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef LLVM_LIB_TARGET_DIRECTX_DIRECTX_H |
| 12 | #define LLVM_LIB_TARGET_DIRECTX_DIRECTX_H |
| 13 | |
| 14 | #include "llvm/IR/Analysis.h" |
| 15 | #include "llvm/IR/PassManager.h" |
| 16 | #include "llvm/Support/CommandLine.h" |
| 17 | |
| 18 | namespace llvm { |
| 19 | namespace dxil { |
| 20 | extern cl::opt<bool> PdbInPrivate; |
| 21 | } // namespace dxil |
| 22 | |
| 23 | class AttributeMask; |
| 24 | class Function; |
| 25 | class FunctionPass; |
| 26 | class Module; |
| 27 | class ModulePass; |
| 28 | class PassRegistry; |
| 29 | class raw_ostream; |
| 30 | |
| 31 | /// Initializer for dxil writer pass |
| 32 | void initializeDXILWriterLegacyPass(PassRegistry &); |
| 33 | |
| 34 | /// Initializer for dxil embedder pass |
| 35 | void initializeDXILEmbedderLegacyPass(PassRegistry &); |
| 36 | |
| 37 | /// Initializer for DXIL-prepare |
| 38 | void initializeDXILPrepareModuleLegacyPass(PassRegistry &); |
| 39 | |
| 40 | /// Pass to convert modules into DXIL-compatable modules |
| 41 | class DXILPrepareModulePass |
| 42 | : public RequiredPassInfoMixin<DXILPrepareModulePass> { |
| 43 | public: |
| 44 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
| 45 | }; |
| 46 | |
| 47 | ModulePass *createDXILPrepareModuleLegacyPass(); |
| 48 | |
| 49 | /// Pass to downgrade debug information to forms supported by DXIL. |
| 50 | class DXILDebugInfoPass : public OptionalPassInfoMixin<DXILDebugInfoPass> { |
| 51 | public: |
| 52 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &); |
| 53 | }; |
| 54 | |
| 55 | /// Initializer for DXIL debug info lowering. |
| 56 | void initializeDXILDebugInfoLegacyPass(PassRegistry &); |
| 57 | |
| 58 | ModulePass *createDXILDebugInfoLegacyPass(); |
| 59 | |
| 60 | /// Pass to expand intrinsic operations that lack DXIL opCodes |
| 61 | class DXILIntrinsicExpansionPass |
| 62 | : public OptionalPassInfoMixin<DXILIntrinsicExpansionPass> { |
| 63 | public: |
| 64 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &); |
| 65 | }; |
| 66 | |
| 67 | /// Initializer for DXIL Intrinsic Expansion |
| 68 | void initializeDXILIntrinsicExpansionLegacyPass(PassRegistry &); |
| 69 | |
| 70 | ModulePass *createDXILIntrinsicExpansionLegacyPass(); |
| 71 | |
| 72 | /// Pass to translate loads in the cbuffer address space to cbuffer |
| 73 | /// load intrinsic. |
| 74 | class DXILCBufferAccessPass |
| 75 | : public OptionalPassInfoMixin<DXILCBufferAccessPass> { |
| 76 | public: |
| 77 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); |
| 78 | }; |
| 79 | |
| 80 | /// Initializer for DXIL CBuffer Access Pass |
| 81 | void initializeDXILCBufferAccessLegacyPass(PassRegistry &); |
| 82 | |
| 83 | ModulePass *createDXILCBufferAccessLegacyPass(); |
| 84 | |
| 85 | /// Pass to prepare vector data for DXIL by converting vector storage to |
| 86 | /// scalar arrays and lowering dynamically indexed vector accesses to |
| 87 | /// array accesses. |
| 88 | class DXILDataScalarizationPass |
| 89 | : public OptionalPassInfoMixin<DXILDataScalarizationPass> { |
| 90 | public: |
| 91 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &); |
| 92 | }; |
| 93 | |
| 94 | /// Initializer for DXIL Data Scalarization Pass |
| 95 | void initializeDXILDataScalarizationLegacyPass(PassRegistry &); |
| 96 | |
| 97 | ModulePass *createDXILDataScalarizationLegacyPass(); |
| 98 | |
| 99 | /// Pass to flatten arrays into a one dimensional DXIL legal form |
| 100 | class DXILFlattenArraysPass |
| 101 | : public OptionalPassInfoMixin<DXILFlattenArraysPass> { |
| 102 | public: |
| 103 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &); |
| 104 | }; |
| 105 | |
| 106 | /// Initializer for DXIL Array Flatten Pass |
| 107 | void initializeDXILFlattenArraysLegacyPass(PassRegistry &); |
| 108 | |
| 109 | ModulePass *createDXILFlattenArraysLegacyPass(); |
| 110 | |
| 111 | /// Pass to eliminate redundant stores and loads from handle globals. |
| 112 | class DXILForwardHandleAccessesPass |
| 113 | : public OptionalPassInfoMixin<DXILForwardHandleAccessesPass> { |
| 114 | public: |
| 115 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
| 116 | }; |
| 117 | |
| 118 | /// Initializer for DXIL Forward Handle Accesses Pass |
| 119 | void initializeDXILForwardHandleAccessesLegacyPass(PassRegistry &); |
| 120 | |
| 121 | FunctionPass *createDXILForwardHandleAccessesLegacyPass(); |
| 122 | |
| 123 | /// Pass to rewrite LLVM IR constructs unsupported by DXIL into |
| 124 | /// compatible forms. |
| 125 | class DXILLegalizePass : public OptionalPassInfoMixin<DXILLegalizePass> { |
| 126 | public: |
| 127 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM); |
| 128 | }; |
| 129 | |
| 130 | /// Initializer DXIL legalizationPass |
| 131 | void initializeDXILLegalizeLegacyPass(PassRegistry &); |
| 132 | |
| 133 | FunctionPass *createDXILLegalizeLegacyPass(); |
| 134 | |
| 135 | /// Pass to transform all llvm memory intrinsics to explicit loads and stores. |
| 136 | class DXILMemIntrinsicsPass |
| 137 | : public OptionalPassInfoMixin<DXILMemIntrinsicsPass> { |
| 138 | public: |
| 139 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &); |
| 140 | }; |
| 141 | |
| 142 | /// Initializer for DXIL Mem Intrinsics. |
| 143 | void initializeDXILMemIntrinsicsLegacyPass(PassRegistry &); |
| 144 | |
| 145 | ModulePass *createDXILMemIntrinsicsLegacyPass(); |
| 146 | |
| 147 | /// Pass to lowering LLVM intrinsic call to DXIL op function call. |
| 148 | class DXILOpLoweringPass : public OptionalPassInfoMixin<DXILOpLoweringPass> { |
| 149 | public: |
| 150 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
| 151 | }; |
| 152 | |
| 153 | /// Initializer for DXILOpLowering |
| 154 | void initializeDXILOpLoweringLegacyPass(PassRegistry &); |
| 155 | |
| 156 | ModulePass *createDXILOpLoweringLegacyPass(); |
| 157 | |
| 158 | /// Pass to remove unused DXIL resources and associated |
| 159 | /// global variables. |
| 160 | class DXILRemoveUnusedResourcesPass |
| 161 | : public OptionalPassInfoMixin<DXILRemoveUnusedResourcesPass> { |
| 162 | public: |
| 163 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
| 164 | }; |
| 165 | |
| 166 | /// Initializer for DXILRemoveUnusedResources |
| 167 | void initializeDXILRemoveUnusedResourcesLegacyPass(PassRegistry &); |
| 168 | |
| 169 | FunctionPass *createDXILRemoveUnusedResourcesLegacyPass(); |
| 170 | |
| 171 | /// Pass to replace pointers to DXIL resources with load and store |
| 172 | /// operations. |
| 173 | class DXILResourceAccessPass |
| 174 | : public OptionalPassInfoMixin<DXILResourceAccessPass> { |
| 175 | public: |
| 176 | PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); |
| 177 | }; |
| 178 | |
| 179 | /// Initializer for DXILResourceAccess |
| 180 | void initializeDXILResourceAccessLegacyPass(PassRegistry &); |
| 181 | |
| 182 | FunctionPass *createDXILResourceAccessLegacyPass(); |
| 183 | |
| 184 | /// Pass to assign register slots to resources without binding. |
| 185 | class DXILResourceImplicitBindingPass |
| 186 | : public OptionalPassInfoMixin<DXILResourceImplicitBindingPass> { |
| 187 | public: |
| 188 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &); |
| 189 | }; |
| 190 | |
| 191 | /// Initializer for DXILResourceImplicitBindingLegacyPass |
| 192 | void initializeDXILResourceImplicitBindingLegacyPass(PassRegistry &); |
| 193 | |
| 194 | ModulePass *createDXILResourceImplicitBindingLegacyPass(); |
| 195 | |
| 196 | /// Pass to emit metadata for DXIL, and to transforms existing LLVM |
| 197 | /// metadata to its DXIL equivalent. |
| 198 | class DXILTranslateMetadataPass |
| 199 | : public OptionalPassInfoMixin<DXILTranslateMetadataPass> { |
| 200 | public: |
| 201 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &); |
| 202 | }; |
| 203 | |
| 204 | /// Initializer for DXILTranslateMetadata. |
| 205 | void initializeDXILTranslateMetadataLegacyPass(PassRegistry &); |
| 206 | |
| 207 | ModulePass *createDXILTranslateMetadataLegacyPass(); |
| 208 | |
| 209 | /// Pass to pretty print DXIL metadata into IR |
| 210 | /// comments when printing assembly output. |
| 211 | class DXILPrettyPrinterPass |
| 212 | : public OptionalPassInfoMixin<DXILPrettyPrinterPass> { |
| 213 | raw_ostream &OS; |
| 214 | |
| 215 | public: |
| 216 | explicit DXILPrettyPrinterPass(raw_ostream &OS) : OS(OS) {} |
| 217 | |
| 218 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &); |
| 219 | }; |
| 220 | |
| 221 | ModulePass *createDXILPrettyPrinterLegacyPass(raw_ostream &OS); |
| 222 | |
| 223 | /// Initializer for DXILPrettyPrinter. |
| 224 | void initializeDXILPrettyPrinterLegacyPass(PassRegistry &); |
| 225 | |
| 226 | /// Pass for validating IR after optimizations are applied and before |
| 227 | /// lowering to DXIL. |
| 228 | class DXILPostOptimizationValidationPass |
| 229 | : public OptionalPassInfoMixin<DXILPostOptimizationValidationPass> { |
| 230 | public: |
| 231 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
| 232 | }; |
| 233 | |
| 234 | /// Initializer for DXILPostOptimizationValidation. |
| 235 | void initializeDXILPostOptimizationValidationLegacyPass(PassRegistry &); |
| 236 | |
| 237 | ModulePass *createDXILPostOptimizationValidationLegacyPass(); |
| 238 | |
| 239 | /// Initializer for dxil::ShaderFlagsAnalysisWrapper pass. |
| 240 | void initializeShaderFlagsAnalysisWrapperPass(PassRegistry &); |
| 241 | |
| 242 | /// Initializer for dxil::RootSignatureAnalysisWrapper pass. |
| 243 | void initializeRootSignatureAnalysisWrapperPass(PassRegistry &); |
| 244 | |
| 245 | /// Initializer for dxil::SignatureAnalysisWrapper pass. |
| 246 | void initializeSignatureAnalysisWrapperPass(PassRegistry &); |
| 247 | |
| 248 | /// Initializer for DXILContainerGlobals pass. |
| 249 | void initializeDXILContainerGlobalsLegacyPass(PassRegistry &); |
| 250 | |
| 251 | /// Pass for generating DXContainer part globals. |
| 252 | class DXILContainerGlobalsPass |
| 253 | : public RequiredPassInfoMixin<DXILContainerGlobalsPass> { |
| 254 | public: |
| 255 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
| 256 | }; |
| 257 | |
| 258 | ModulePass *createDXILContainerGlobalsLegacyPass(); |
| 259 | |
| 260 | /// Initializer for DXILContainerPDB pass. |
| 261 | void initializeDXILContainerPDBLegacyPass(PassRegistry &); |
| 262 | |
| 263 | /// Pass for emitting DirectX PDB files. |
| 264 | class DXILContainerPDBPass |
| 265 | : public RequiredPassInfoMixin<DXILContainerPDBPass> { |
| 266 | public: |
| 267 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); |
| 268 | }; |
| 269 | |
| 270 | ModulePass *createDXILContainerPDBLegacyPass(); |
| 271 | |
| 272 | /// Pass to update the linkage of functions to make sure only |
| 273 | /// shader entry points and exported functions are visible from |
| 274 | /// the module (have program linkage). All other functions will |
| 275 | /// be updated to have internal linkage. |
| 276 | class DXILFinalizeLinkagePass |
| 277 | : public RequiredPassInfoMixin<DXILFinalizeLinkagePass> { |
| 278 | public: |
| 279 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &); |
| 280 | }; |
| 281 | |
| 282 | /// Initializer for DXILFinalizeLinkage pass. |
| 283 | void initializeDXILFinalizeLinkageLegacyPass(PassRegistry &); |
| 284 | |
| 285 | ModulePass *createDXILFinalizeLinkageLegacyPass(); |
| 286 | } // namespace llvm |
| 287 | |
| 288 | #endif // LLVM_LIB_TARGET_DIRECTX_DIRECTX_H |
| 289 | |