https://github.com/kuilpd created https://github.com/llvm/llvm-project/pull/204832
Add the flag that removes ILDB part from the main DXContainer. >From 89fa2862e8aecdf82cf88d13b9a129ca56835620 Mon Sep 17 00:00:00 2001 From: Ilia Kuklin <[email protected]> Date: Fri, 19 Jun 2026 17:54:05 +0500 Subject: [PATCH] [Driver][DirectX] Add /Qstrip_debug flag --- clang/include/clang/Options/Options.td | 3 +++ clang/lib/Driver/ToolChains/Clang.cpp | 7 ++++++- clang/test/Driver/dxc_debug.hlsl | 2 ++ llvm/lib/MC/MCDXContainerWriter.cpp | 5 ++++- .../Target/DirectX/DXILWriter/DXILWriterPass.cpp | 10 +++++++--- .../CodeGen/DirectX/ContainerData/ContainerFlags.ll | 13 +++++++++++++ 6 files changed, 35 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index ceb430029aba1..a399265c20df6 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -9670,6 +9670,9 @@ def dxc_Zss : DXCFlag<"Zss">, HelpText<"Compute Shader Hash considering source information">; def dxc_Zsb : DXCFlag<"Zsb">, HelpText<"Compute Shader Hash considering only output binary">; +def dxc_Qstrip_debug + : DXCFlag<"Qstrip_debug">, + HelpText<"Strip debug information from shader container (specified with /Fo <file>)">; def dxil_validator_version : Option<["/", "-"], "validator-version", KIND_SEPARATE>, Group<dxc_Group>, Flags<[HelpHidden]>, Visibility<[DXCOption, ClangOption, CC1Option]>, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 1a4f4fcec2c9a..56d11886f5fab 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3857,7 +3857,8 @@ static void RenderHLSLOptions(const Driver &D, const ArgList &Args, bool HasDebug = Args.hasArg(options::OPT_g_Flag); bool Qembed_debug = Args.hasArg(options::OPT_dxc_Qembed_debug); Arg *Fd = Args.getLastArg(options::OPT_dxc_Fd); - if (HasDebug && !Fd && !Qembed_debug) { + bool Qstrip_debug = Args.hasArg(options::OPT_dxc_Qstrip_debug); + if (HasDebug && !Qstrip_debug && !Fd && !Qembed_debug) { D.Diag(diag::warn_drv_dxc_no_output_for_debug); Qembed_debug = true; } @@ -3873,6 +3874,10 @@ static void RenderHLSLOptions(const Driver &D, const ArgList &Args, CmdArgs.push_back("-mllvm"); CmdArgs.push_back(Args.MakeArgString("--dx-Fd=" + Twine(Fd->getValue()))); } + if (Args.hasArg(options::OPT_dxc_Qstrip_debug)) { + CmdArgs.push_back("-mllvm"); + CmdArgs.push_back("--dx-strip-debug"); + } } static void RenderOpenACCOptions(const Driver &D, const ArgList &Args, diff --git a/clang/test/Driver/dxc_debug.hlsl b/clang/test/Driver/dxc_debug.hlsl index d90be0bb5bad2..b24452180bbe2 100644 --- a/clang/test/Driver/dxc_debug.hlsl +++ b/clang/test/Driver/dxc_debug.hlsl @@ -6,6 +6,7 @@ // RUN: %clang_dxc -Tlib_6_7 -### -Zi /Fd %t.pdb %s 2>&1 | FileCheck %s -check-prefixes=CHECK,CHECK-FD // RUN: %clang_dxc -Tlib_6_7 -### -Zi -Fd=%t.pdb %s 2>&1 | FileCheck %s -check-prefixes=CHECK,CHECK-FD // RUN: %clang_dxc -Tlib_6_7 -### -Zi -Zss %s 2>&1 | FileCheck %s --check-prefix=CHECK,CHECK-ZSS +// RUN: %clang_dxc -Tlib_6_7 -### -Zi -Qstrip_debug %s 2>&1 | FileCheck %s --check-prefix=CHECK,CHECK-STRIP // RUN: %clang_dxc -Tlib_6_7 -### -Zi -gcodeview %s 2>&1 | FileCheck %s -check-prefixes=CHECK,CHECK-CV // RUN: %clang_dxc -Tlib_6_7 -### -Zi -gdwarf %s 2>&1 | FileCheck %s -check-prefixes=CHECK,CHECK-DWARF // RUN: %clang_dxc -Tlib_6_7 -### -gcodeview -Zi %s 2>&1 | FileCheck %s -check-prefixes=CHECK,CHECK-CV @@ -20,6 +21,7 @@ // CHECK-EMBED-SAME: --dx-embed-debug // CHECK-FD-SAME: --dx-Fd= // CHECK-ZSS-SAME: -dx-Zss +// CHECK-STRIP-SAME: --dx-strip-debug // Make sure dxc command line arguments are passed to clang invocation. // CHECK-SAME: -fdx-record-command-line // CHECK-CMD-SAME: --driver-mode=dxc -T lib_6_7 -### -g {{.*}}dxc_debug.hlsl diff --git a/llvm/lib/MC/MCDXContainerWriter.cpp b/llvm/lib/MC/MCDXContainerWriter.cpp index 994b90fbcb66b..99d4394eebaea 100644 --- a/llvm/lib/MC/MCDXContainerWriter.cpp +++ b/llvm/lib/MC/MCDXContainerWriter.cpp @@ -19,6 +19,9 @@ using namespace llvm; cl::opt<bool> EmbedDebug("dx-embed-debug", cl::desc("Embed PDB in shader container")); +cl::opt<bool> + StripDebug("dx-strip-debug", + cl::desc("Strip debug information from shader bytecode")); MCDXContainerTargetWriter::~MCDXContainerTargetWriter() = default; @@ -139,7 +142,7 @@ ArrayRef<MCDXContainerPart> DXContainerObjectWriter::collectParts() { bool DXContainerObjectWriter::shouldSkipSection(StringRef SectionName, size_t SectionSize) { // Do not write ILDB part if we're not embedding it. - if (!EmbedDebug && SectionName == "ILDB") + if (SectionName == "ILDB" && (!EmbedDebug || StripDebug)) return true; if (SectionName == "SRCI") return true; diff --git a/llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp index 9bbb87327d749..0278703c55d22 100644 --- a/llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp +++ b/llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp @@ -36,6 +36,7 @@ using namespace llvm; using namespace llvm::dxil; extern cl::opt<bool> EmbedDebug; +extern cl::opt<bool> StripDebug; extern cl::opt<std::string> PdbDebugPath; namespace { @@ -231,9 +232,12 @@ class EmbedDXILPass : public llvm::ModulePass { bool HasDebugInfo = !M.debug_compile_units().empty(); - // Enable EmbedDebug if there is debug info, but it is not being written - // to a PDB file. - if (HasDebugInfo && !EmbedDebug && PdbDebugPath.empty()) + // If both StripDebug and EmbedDebug are specified, StripDebug is ignored. + if (StripDebug && EmbedDebug) + StripDebug = false; + // Enable EmbedDebug if there is debug info, but it is not being stripped + // or written to a PDB file. + if (HasDebugInfo && !StripDebug && !EmbedDebug && PdbDebugPath.empty()) EmbedDebug = true; if (!HasDebugInfo && EmbedDebug) reportFatalUsageError( diff --git a/llvm/test/CodeGen/DirectX/ContainerData/ContainerFlags.ll b/llvm/test/CodeGen/DirectX/ContainerData/ContainerFlags.ll index 36eb5b0b1b8e3..24a42696f17ed 100644 --- a/llvm/test/CodeGen/DirectX/ContainerData/ContainerFlags.ll +++ b/llvm/test/CodeGen/DirectX/ContainerData/ContainerFlags.ll @@ -25,6 +25,19 @@ ; PDB-DAG: - Name: ILDB ; PDB-DAG: - Name: ILDN +;; Check that --dx-strip-debug strips ILDB from DXContainer, but still keeps ILDN part +; RUN: llc %S/Inputs/SourceInfo.ll --filetype=obj --dx-strip-debug -o %t.cso +; RUN: obj2yaml %t.cso | FileCheck %s --check-prefix=STRIP --implicit-check-not ILDB +; STRIP: Parts: +; STRIP-DAG: - Name: ILDN + +;; Check that --dx-strip-debug is ignored when provided along with --dx-embed-debug +; RUN: llc %S/Inputs/SourceInfo.ll --filetype=obj --dx-strip-debug --dx-embed-debug -o %t.cso +; RUN: obj2yaml %t.cso | FileCheck %s --check-prefix=STRIP-EMBED +; STRIP-EMBED: Parts: +; STRIP-EMBED-DAG: - Name: ILDB +; STRIP-EMBED-DAG: - Name: ILDN + ;; Check errors when trying to output debug info with no debug info present ; RUN: not llc %s --filetype=obj --dx-embed-debug -o %t.cso 2>&1 | FileCheck %s --check-prefix=ERROR-NODBG ; ERROR-NODBG: Missing debug info for embedding into the container _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
