Author: Ilia Kuklin Date: 2026-07-17T15:22:16+05:00 New Revision: e8f9589942ecd93d94de2af2e875964693e55129
URL: https://github.com/llvm/llvm-project/commit/e8f9589942ecd93d94de2af2e875964693e55129 DIFF: https://github.com/llvm/llvm-project/commit/e8f9589942ecd93d94de2af2e875964693e55129.diff LOG: [Driver][DirectX] Add `/Qstrip_debug` flag (#204832) Add the flag that removes ILDB part from the main DXContainer. Added: Modified: clang/include/clang/Options/Options.td clang/lib/Driver/ToolChains/Clang.cpp clang/test/Driver/dxc_debug.hlsl llvm/lib/MC/MCDXContainerWriter.cpp llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp llvm/test/CodeGen/DirectX/ContainerData/ContainerFlags.ll Removed: ################################################################################ diff --git a/clang/include/clang/Options/Options.td b/clang/include/clang/Options/Options.td index 887c189363472..a1d45163fa354 100644 --- a/clang/include/clang/Options/Options.td +++ b/clang/include/clang/Options/Options.td @@ -9764,6 +9764,9 @@ def dxc_Zsb : DXCFlag<"Zsb">, def dxc_source_in_debug_module : DXCFlag<"Qsource_in_debug_module">, HelpText<"Embed source code into PDB debug module">; +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 0a0915b1ce615..f201bf9e36f1a 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -3986,6 +3986,10 @@ static void RenderHLSLOptions(const Driver &D, const ArgList &Args, CmdArgs.push_back("-mllvm"); CmdArgs.push_back("--dx-source-in-debug-module"); } + 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 6f37e59d4cf32..90a02f1d1c1c4 100644 --- a/clang/test/Driver/dxc_debug.hlsl +++ b/clang/test/Driver/dxc_debug.hlsl @@ -5,6 +5,7 @@ // RUN: %clang_dxc -Tlib_6_7 -### -Zi -Qembed_debug %s 2>&1 | FileCheck %s // 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 -Qsource_in_debug_module %s 2>&1 | FileCheck %s --check-prefix=CHECK,CHECK-SIDM +// 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 @@ -18,6 +19,7 @@ // Check that the flags are converted to their llc equivalents. // CHECK-ZSS-SAME: -dx-Zss // CHECK-SIDM-SAME: --dx-source-in-debug-module +// 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 c17b571d41ce3..9c61e4c1acb93 100644 --- a/llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp +++ b/llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp @@ -37,6 +37,7 @@ using namespace llvm; using namespace llvm::dxil; extern cl::opt<bool> EmbedDebug; +extern cl::opt<bool> StripDebug; extern cl::opt<std::string> PdbDebugPath; cl::opt<bool> SourceInDebugModule( "dx-source-in-debug-module", @@ -237,9 +238,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 1d14c32e58fae..4ea070951dd1e 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 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
