[llvm] [SPIRV] Migrate NSDI emission from a machine pass to DebugHandlerBase (PR #191212)
Diego Novillo via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 13 02:31:45 PDT 2026
================
@@ -0,0 +1,170 @@
+//===-- SPIRVNonSemanticDebugHandler.h - NSDI AsmPrinter handler -*- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares SPIRVNonSemanticDebugHandler, a DebugHandlerBase subclass
+// that emits NonSemantic.Shader.DebugInfo.100 instructions in the SPIR-V
+// AsmPrinter. It replaces SPIRVEmitNonSemanticDI, which was a
+// MachineFunctionPass, with a handler that controls instruction placement
+// directly instead of routing through SPIRVModuleAnalysis.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVNONSEMANTICDEBUGHANDLER_H
+#define LLVM_LIB_TARGET_SPIRV_SPIRVNONSEMANTICDEBUGHANDLER_H
+
+#include "MCTargetDesc/SPIRVBaseInfo.h"
+#include "SPIRVModuleAnalysis.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/CodeGen/DebugHandlerBase.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCRegister.h"
+
+namespace llvm {
+
+class SPIRVSubtarget;
+
+/// AsmPrinter handler that emits NonSemantic.Shader.DebugInfo.100 (NSDI)
+/// instructions for the SPIR-V backend. Registered with SPIRVAsmPrinter when
+/// the module contains debug info (llvm.dbg.cu).
+///
+/// Call sequence:
+/// beginModule() -- collect compile-unit metadata.
+/// prepareModuleOutput() -- add extension + ext inst set to MAI.
+/// emitNonSemanticGlobalDebugInfo() -- emit DebugSource,
+/// DebugCompilationUnit, DebugTypeBasic,
+/// DebugTypePointer.
+/// beginFunctionImpl() -- no-op (no per-function DI yet).
+/// endFunctionImpl() -- no-op.
+class SPIRVNonSemanticDebugHandler : public DebugHandlerBase {
+ struct CompileUnitInfo {
+ SmallString<128> FilePath;
+ unsigned SpirvSourceLanguage = 0; // NonSemantic.Shader.DebugInfo.100 source
+ // language code (section 4.3)
+ };
+ SmallVector<CompileUnitInfo> CompileUnits;
----------------
dnovillo wrote:
Agreed. Added a comment.
https://github.com/llvm/llvm-project/pull/191212
More information about the llvm-commits
mailing list