1 //===- DXILTranslateMetadata.cpp - Pass to emit DXIL 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 //===----------------------------------------------------------------------===// 10 11 #include "DXILMetadata.h" 12 #include "DXILResource.h" 13 #include "DXILResourceAnalysis.h" 14 #include "DXILShaderFlags.h" 15 #include "DirectX.h" 16 #include "llvm/ADT/StringSet.h" 17 #include "llvm/ADT/Triple.h" 18 #include "llvm/IR/Constants.h" 19 #include "llvm/IR/Metadata.h" 20 #include "llvm/IR/Module.h" 21 #include "llvm/Pass.h" 22 23 using namespace llvm; 24 using namespace llvm::dxil; 25 26 namespace { 27 class DXILTranslateMetadata : public ModulePass { 28 public: 29 static char ID; // Pass identification, replacement for typeid 30 explicit DXILTranslateMetadata() : ModulePass(ID) {} 31 32 StringRef getPassName() const override { return "DXIL Metadata Emit"; } 33 34 void getAnalysisUsage(AnalysisUsage &AU) const override { 35 AU.setPreservesAll(); 36 AU.addRequired<DXILResourceWrapper>(); 37 AU.addRequired<ShaderFlagsAnalysisWrapper>(); 38 } 39 40 bool runOnModule(Module &M) override; 41 }; 42 43 } // namespace 44 45 bool DXILTranslateMetadata::runOnModule(Module &M) { 46 47 dxil::ValidatorVersionMD ValVerMD(M); 48 if (ValVerMD.isEmpty()) 49 ValVerMD.update(VersionTuple(1, 0)); 50 dxil::createShaderModelMD(M); 51 52 const dxil::Resources &Res = 53 getAnalysis<DXILResourceWrapper>().getDXILResource(); 54 Res.write(M); 55 56 const uint64_t Flags = 57 (uint64_t)(getAnalysis<ShaderFlagsAnalysisWrapper>().getShaderFlags()); 58 dxil::createEntryMD(M, Flags); 59 60 return false; 61 } 62 63 char DXILTranslateMetadata::ID = 0; 64 65 ModulePass *llvm::createDXILTranslateMetadataPass() { 66 return new DXILTranslateMetadata(); 67 } 68 69 INITIALIZE_PASS_BEGIN(DXILTranslateMetadata, "dxil-metadata-emit", 70 "DXIL Metadata Emit", false, false) 71 INITIALIZE_PASS_DEPENDENCY(DXILResourceWrapper) 72 INITIALIZE_PASS_DEPENDENCY(ShaderFlagsAnalysisWrapper) 73 INITIALIZE_PASS_END(DXILTranslateMetadata, "dxil-metadata-emit", 74 "DXIL Metadata Emit", false, false) 75