[llvm-branch-commits] [llvm] [SPIRV][Debug Info] Fix debug info placement logic for DebugFunctionDefinition (PR #183121)
Manuel Carrasco via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Mar 10 05:39:17 PDT 2026
https://github.com/mgcarrasco updated https://github.com/llvm/llvm-project/pull/183121
>From fdcb884d949de702c7ae17cce04e8639ea27e379 Mon Sep 17 00:00:00 2001
From: Manuel Carrasco <Manuel.Carrasco at amd.com>
Date: Tue, 24 Feb 2026 09:18:12 -0600
Subject: [PATCH 1/5] [NFC][SPIRV] Extract helper functions in
SPIRVEmitNonSemanticDI
This commit extracts reusable helper functions to improve code
organization and reduce duplication. This is a pure refactoring
that does not change behavior.
These helpers will be used in subsequent commits to refactor
emitGlobalDI and add function-level debug info emission.
---
llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp
index 84c7ae458f49f..8a2d4fd929f22 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp
@@ -5,8 +5,8 @@
#include "SPIRVRegisterInfo.h"
#include "SPIRVTargetMachine.h"
#include "SPIRVUtils.h"
-#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVectorExtras.h"
>From cf4bd778e46543e7568677cbc9a8f801914b91df Mon Sep 17 00:00:00 2001
From: Manuel Carrasco <Manuel.Carrasco at amd.com>
Date: Tue, 24 Feb 2026 10:57:31 -0600
Subject: [PATCH 2/5] [SPIRV] Refactor NonSemantic debug info placement logic.
Refactor the logic for determining which NonSemantic.Shader.DebugInfo.100
instructions should be placed in the global section from a whitelist
to a blacklist approach.
---
llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp | 21 ++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index 923f59917cb10..40390ad7ebf3c 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -657,13 +657,20 @@ void SPIRVModuleAnalysis::processOtherInstrs(const Module &M) {
NonSemantic_Shader_DebugInfo_100) {
MachineOperand Ins = MI.getOperand(3);
namespace NS = SPIRV::NonSemanticExtInst;
- static constexpr int64_t GlobalNonSemanticDITy[] = {
- NS::DebugSource, NS::DebugCompilationUnit, NS::DebugInfoNone,
- NS::DebugTypeBasic, NS::DebugTypePointer};
- bool IsGlobalDI = false;
- for (unsigned Idx = 0; Idx < std::size(GlobalNonSemanticDITy); ++Idx)
- IsGlobalDI |= Ins.getImm() == GlobalNonSemanticDITy[Idx];
- if (IsGlobalDI)
+ // Debug info extension instructions other than DebugScope,
+ // DebugNoScope, DebugDeclare, DebugValue, DebugFunctionDefinition
+ // must appear between section 9 (types, constants, global variables)
+ // and section 10 (function declarations).
+ // DebugFunctionDefinition must appear in the entry basic block of an
+ // OpFunction, so it should not be moved to the global section.
+ static constexpr int64_t ExcludedFromGlobalDI[] = {
+ NS::DebugScope, NS::DebugNoScope, NS::DebugDeclare,
+ NS::DebugValue, NS::DebugFunctionDefinition};
+ bool IsExcluded = false;
+ for (unsigned Idx = 0; Idx < std::size(ExcludedFromGlobalDI); ++Idx)
+ IsExcluded |= Ins.getImm() == ExcludedFromGlobalDI[Idx];
+ // All other NonSemantic debug info instructions go to global section
+ if (!IsExcluded)
collectOtherInstr(MI, MAI, SPIRV::MB_NonSemanticGlobalDI, IS);
} else if (OpCode == SPIRV::OpName || OpCode == SPIRV::OpMemberName) {
collectOtherInstr(MI, MAI, SPIRV::MB_DebugNames, IS);
>From 1927d242a5ce00b1babe81f65d3be0e19aa0b762 Mon Sep 17 00:00:00 2001
From: Manuel Carrasco <Manuel.Carrasco at amd.com>
Date: Thu, 5 Mar 2026 08:20:09 -0600
Subject: [PATCH 3/5] [review] Improve comment.
---
llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp | 2 ++
1 file changed, 2 insertions(+)
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index 40390ad7ebf3c..12622f906db79 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -663,6 +663,8 @@ void SPIRVModuleAnalysis::processOtherInstrs(const Module &M) {
// and section 10 (function declarations).
// DebugFunctionDefinition must appear in the entry basic block of an
// OpFunction, so it should not be moved to the global section.
+ // See the "SPIR-V NonSemantic Shader DebugInfo Instructions / Binary
+ // Form" spec section.
static constexpr int64_t ExcludedFromGlobalDI[] = {
NS::DebugScope, NS::DebugNoScope, NS::DebugDeclare,
NS::DebugValue, NS::DebugFunctionDefinition};
>From becf44b6cfb30b954aa82bf9b1b2178ab837e788 Mon Sep 17 00:00:00 2001
From: Manuel Carrasco <Manuel.Carrasco at amd.com>
Date: Fri, 6 Mar 2026 04:23:12 -0600
Subject: [PATCH 4/5] [review] Simplify code.
---
llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index 12622f906db79..15c8dae89defd 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -668,9 +668,8 @@ void SPIRVModuleAnalysis::processOtherInstrs(const Module &M) {
static constexpr int64_t ExcludedFromGlobalDI[] = {
NS::DebugScope, NS::DebugNoScope, NS::DebugDeclare,
NS::DebugValue, NS::DebugFunctionDefinition};
- bool IsExcluded = false;
- for (unsigned Idx = 0; Idx < std::size(ExcludedFromGlobalDI); ++Idx)
- IsExcluded |= Ins.getImm() == ExcludedFromGlobalDI[Idx];
+ static_assert(is_sorted_constexpr(ExcludedFromGlobalDI));
+ bool IsExcluded = binary_search(ExcludedFromGlobalDI, Ins.getImm());
// All other NonSemantic debug info instructions go to global section
if (!IsExcluded)
collectOtherInstr(MI, MAI, SPIRV::MB_NonSemanticGlobalDI, IS);
>From 1d032608198d2f324c4983ecd82c3468b5d2e6f7 Mon Sep 17 00:00:00 2001
From: Manuel Carrasco <Manuel.Carrasco at amd.com>
Date: Fri, 6 Mar 2026 04:31:33 -0600
Subject: [PATCH 5/5] Fix format.
---
llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp
index 8a2d4fd929f22..84c7ae458f49f 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp
@@ -5,8 +5,8 @@
#include "SPIRVRegisterInfo.h"
#include "SPIRVTargetMachine.h"
#include "SPIRVUtils.h"
-#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVectorExtras.h"
More information about the llvm-branch-commits
mailing list