[llvm] [DirectX] Add slim debug support (PR #204459)

Vladislav Dzhidzhoev via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 9 07:11:55 PDT 2026


https://github.com/dzhidzhoev updated https://github.com/llvm/llvm-project/pull/204459

>From 6898a170212ecfcd17e20b7c5eeb1e142baa2551 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Tue, 16 Jun 2026 05:43:51 +0200
Subject: [PATCH] [clang][Driver][DirectX] Add /Zs flag support

When DXC is called with `/Zs` flag, it emits "slim" debug info.
It means that ILDB section is omitted from the main DXContainer
output and from the output PDB file.

This patch reimplements similar behavior in llc and Clang.

`/Zs` flag has completely different meaning for clang-cl driver. It is an
alias for `-fsyntax-only` there.
`/Zs` flag description in TableGen was generalized, so as not to trigger
`-fsyntax-only` or `-g`. Thus, Driver checks for `-fsyntax-only` were
replaced with `isSyntaxOnly()` helper function calls.
---
 llvm/include/llvm/MC/MCDXContainerWriter.h    |  6 +-----
 llvm/lib/MC/MCDXContainerWriter.cpp           | 12 +++++++++++
 .../DirectX/DXILWriter/DXILWriterPass.cpp     |  7 +++++--
 .../DirectX/ContainerData/ContainerFlags.ll   | 20 +++++++++++++++++++
 4 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/llvm/include/llvm/MC/MCDXContainerWriter.h b/llvm/include/llvm/MC/MCDXContainerWriter.h
index 1df38b6ff906b..8461bb5f1e1b5 100644
--- a/llvm/include/llvm/MC/MCDXContainerWriter.h
+++ b/llvm/include/llvm/MC/MCDXContainerWriter.h
@@ -49,11 +49,7 @@ class LLVM_ABI MCDXContainerBaseWriter {
     llvm_unreachable("Unimplemented");
   }
 
-  virtual bool shouldSkipSection(StringRef SectionName, size_t SectionSize) {
-    // Skip empty and auxiliary sections.
-    return SectionSize == 0 || SectionName == PdbFileNameSectionName ||
-           SectionName == ModuleHashSectionName;
-  }
+  virtual bool shouldSkipSection(StringRef SectionName, size_t SectionSize);
 
 public:
   MCDXContainerBaseWriter() {}
diff --git a/llvm/lib/MC/MCDXContainerWriter.cpp b/llvm/lib/MC/MCDXContainerWriter.cpp
index 994b90fbcb66b..96df9103a1e26 100644
--- a/llvm/lib/MC/MCDXContainerWriter.cpp
+++ b/llvm/lib/MC/MCDXContainerWriter.cpp
@@ -19,11 +19,23 @@ using namespace llvm;
 
 cl::opt<bool> EmbedDebug("dx-embed-debug",
                          cl::desc("Embed PDB in shader container"));
+cl::opt<bool> SlimDebug("dx-slim-debug",
+                        cl::desc("Generate slim PDB without ILDB part"));
 
 MCDXContainerTargetWriter::~MCDXContainerTargetWriter() = default;
 
 MCDXContainerBaseWriter::~MCDXContainerBaseWriter() = default;
 
+bool MCDXContainerBaseWriter::shouldSkipSection(StringRef SectionName,
+                                                size_t SectionSize) {
+  // Skip empty and auxiliary sections.
+  if (SectionSize == 0 || SectionName == PdbFileNameSectionName ||
+      SectionName == ModuleHashSectionName)
+    return true;
+  // Slim debug omits ILDB from all DXContainer outputs.
+  return SlimDebug && SectionName == "ILDB";
+}
+
 void MCDXContainerBaseWriter::write(raw_ostream &OS, const Triple &TT) {
   ArrayRef<MCDXContainerPart> Parts = collectParts();
 
diff --git a/llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp
index 9bbb87327d749..f7869fb6b75cd 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> SlimDebug;
 extern cl::opt<std::string> PdbDebugPath;
 
 namespace {
@@ -231,14 +232,16 @@ class EmbedDXILPass : public llvm::ModulePass {
 
     bool HasDebugInfo = !M.debug_compile_units().empty();
 
+    if (SlimDebug && EmbedDebug)
+      reportFatalUsageError("/Qembed_debug is not compatible with /Zs");
+
     // Enable EmbedDebug if there is debug info, but it is not being written
     // to a PDB file.
-    if (HasDebugInfo && !EmbedDebug && PdbDebugPath.empty())
+    if (HasDebugInfo && !SlimDebug && PdbDebugPath.empty())
       EmbedDebug = true;
     if (!HasDebugInfo && EmbedDebug)
       reportFatalUsageError(
           "Missing debug info for embedding into the container");
-    // TODO: move this check to DXContainerPDB.cpp when /Zs is implemented.
     if (!HasDebugInfo && !PdbDebugPath.empty())
       reportFatalUsageError("Missing debug info for writing to the PDB file");
 
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/ContainerFlags.ll b/llvm/test/CodeGen/DirectX/ContainerData/ContainerFlags.ll
index 1d14c32e58fae..bc9c7c80d19d7 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/ContainerFlags.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/ContainerFlags.ll
@@ -31,6 +31,26 @@
 ; RUN: not llc %s --filetype=obj --dx-pdb-path=%t.pdb -o %t.cso 2>&1 | FileCheck %s --check-prefix=ERROR-NODBG-PDB
 ; ERROR-NODBG-PDB: Missing debug info for writing to the PDB file
 
+;; Check that slim debug (-dx-slim-debug) omits ILDB from container and companion PDB
+; RUN: llc %S/Inputs/SourceInfo.ll --filetype=obj -dx-slim-debug --dx-pdb-path=%t.pdb -o %t.cso
+; RUN: obj2yaml %t.cso | FileCheck %s --check-prefix=SLIM --implicit-check-not=ILDB
+; RUN: llvm-pdbutil pdb2yaml --dxcontainer %t.pdb | FileCheck %s --check-prefix=SLIM --implicit-check-not=ILDB
+
+; SLIM: Parts:
+; SLIM:   - Name:             HASH
+; SLIM:   - Name:             ILDN
+
+;; Check that /Zss can still hash from ILDB when /Zs omits it from output
+; RUN: llc %S/Inputs/SourceInfo.ll --filetype=obj -dx-slim-debug -dx-Zss -o %t.slim.cso
+; RUN: obj2yaml %t.slim.cso | FileCheck %s --check-prefix=SLIM-ZSS --implicit-check-not=ILDB
+; SLIM-ZSS:   - Name:            HASH
+; SLIM-ZSS:     Hash:
+; SLIM-ZSS:       IncludesSource:  true
+
+;; Check that slim debug and embed debug are mutually exclusive
+; RUN: not llc %S/Inputs/SourceInfo.ll --filetype=obj -dx-slim-debug --dx-embed-debug -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERROR-ZS-EMBED
+; ERROR-ZS-EMBED: /Qembed_debug is not compatible with /Zs
+
 target triple = "dxil-unknown-shadermodel6.5-library"
 
 define i32 @foo(i32 %a) {



More information about the llvm-commits mailing list