| 1 | //===-- DirectXContainerObjectWriter.cpp - DX object writer ----*- 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 | // This file contains DXContainer object writers for the DirectX backend. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "DirectXContainerObjectWriter.h" |
| 14 | #include "llvm/MC/MCDXContainerWriter.h" |
| 15 | |
| 16 | using namespace llvm; |
| 17 | |
| 18 | cl::opt<bool> dxil::EmbedDebug("dx-embed-debug" , |
| 19 | cl::desc("Embed PDB in shader container" )); |
| 20 | cl::opt<bool> dxil::SlimDebug("dx-slim-debug" , |
| 21 | cl::desc("Generate slim PDB without ILDB part" )); |
| 22 | cl::opt<std::string> dxil::PdbDebugPath( |
| 23 | "dx-pdb-path" , |
| 24 | cl::desc("Write debug information to the given file, or automatically " |
| 25 | "named file in directory when ending in '/'" ), |
| 26 | cl::value_desc("filename" )); |
| 27 | |
| 28 | static cl::opt<bool> |
| 29 | StripDebug("dx-strip-debug" , |
| 30 | cl::desc("Strip debug information from shader bytecode" )); |
| 31 | |
| 32 | namespace { |
| 33 | class DirectXContainerObjectWriter : public MCDXContainerTargetWriter { |
| 34 | public: |
| 35 | DirectXContainerObjectWriter() : MCDXContainerTargetWriter() {} |
| 36 | |
| 37 | // The ILDB part, present when the module has debug info, is embedded unless |
| 38 | // it is stripped or written to a PDB. -dx-embed-debug overrides the latter |
| 39 | // two, and slim debug omits ILDB from every output. |
| 40 | bool shouldSkipSection(StringRef SectionName) const override { |
| 41 | return SectionName == "ILDB" && |
| 42 | (dxil::SlimDebug || |
| 43 | (!dxil::EmbedDebug && (StripDebug || !dxil::PdbDebugPath.empty()))); |
| 44 | } |
| 45 | }; |
| 46 | } // namespace |
| 47 | |
| 48 | std::unique_ptr<MCObjectTargetWriter> |
| 49 | llvm::createDXContainerTargetObjectWriter() { |
| 50 | return std::make_unique<DirectXContainerObjectWriter>(); |
| 51 | } |
| 52 | |