https://github.com/mgcarrasco updated https://github.com/llvm/llvm-project/pull/183121
>From 61b6fee314c87302cad94d06535e6cec8f05532d Mon Sep 17 00:00:00 2001 From: Manuel Carrasco <[email protected]> Date: Tue, 24 Feb 2026 09:18:12 -0600 Subject: [PATCH 1/4] [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 6cbe15f5fa429..1c2877d796b13 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 31822c8075110d5a1efdc38b786fceea92335cb7 Mon Sep 17 00:00:00 2001 From: Manuel Carrasco <[email protected]> Date: Tue, 24 Feb 2026 10:57:31 -0600 Subject: [PATCH 2/4] [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 82640e488575ff1f9458a5f9b40ecdfb3828e531 Mon Sep 17 00:00:00 2001 From: Manuel Carrasco <[email protected]> Date: Thu, 5 Mar 2026 08:20:09 -0600 Subject: [PATCH 3/4] [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 b082354b2d6c41f99da7cb679b1b1f07ed76bf89 Mon Sep 17 00:00:00 2001 From: Manuel Carrasco <[email protected]> Date: Fri, 6 Mar 2026 04:23:12 -0600 Subject: [PATCH 4/4] [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); _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
