[llvm-branch-commits] [llvm] [SPIRV][Debug Info] Fix debug info placement logic for DebugFunctionDefinition (PR #183121)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Feb 25 04:03:58 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-spir-v

Author: Manuel Carrasco (mgcarrasco)

<details>
<summary>Changes</summary>

This is one PR of a series that aim to introduce support for [DebugFunction](https://github.com/KhronosGroup/SPIRV-Registry/blob/main/nonsemantic/NonSemantic.Shader.DebugInfo.100.asciidoc#DebugFunction).

This PR refactors the logic for determining which NonSemantic.Shader.DebugInfo.100 instructions should be placed in the global section from a whitelist to a blacklist approach (following the spec) and fix the handling for `DebugFunctionDefinition`.


Stacked PRs:

- https://github.com/llvm/llvm-project/pull/183122
- [current] https://github.com/llvm/llvm-project/pull/183121
- https://github.com/llvm/llvm-project/pull/183117

---
Full diff: https://github.com/llvm/llvm-project/pull/183121.diff


1 Files Affected:

- (modified) llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp (+14-7) 


``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index 7a9dfc63a3f1b..94293114733ae 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);

``````````

</details>


https://github.com/llvm/llvm-project/pull/183121


More information about the llvm-branch-commits mailing list