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
16using namespace llvm;
17
18cl::opt<bool> dxil::EmbedDebug("dx-embed-debug",
19 cl::desc("Embed PDB in shader container"));
20cl::opt<bool> dxil::SlimDebug("dx-slim-debug",
21 cl::desc("Generate slim PDB without ILDB part"));
22cl::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
28static cl::opt<bool>
29 StripDebug("dx-strip-debug",
30 cl::desc("Strip debug information from shader bytecode"));
31
32namespace {
33class DirectXContainerObjectWriter : public MCDXContainerTargetWriter {
34public:
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
48std::unique_ptr<MCObjectTargetWriter>
49llvm::createDXContainerTargetObjectWriter() {
50 return std::make_unique<DirectXContainerObjectWriter>();
51}
52