[llvm-branch-commits] [llvm] [SPIRV][Debug Info] Fix debug info placement logic for DebugFunctionDefinition (PR #183121)
Juan Manuel Martinez CaamaƱo via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Feb 25 08:56:12 PST 2026
================
@@ -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];
----------------
jmmartinez wrote:
I suppose this code is a sort of `is_contained(ExcludedFromGlobalDI, Ins.getImm())`, right?
I would use this trick:
```suggestion
static constexpr int64_t ExcludedFromGlobalDI[] = {
NS::DebugScope, NS::DebugNoScope, NS::DebugDeclare,
NS::DebugValue, NS::DebugFunctionDefinition};
static_assert(is_sorted_constexpr(ExcludedFromGlobalDI));
bool IsExcluded = binary_search(ExcludedFromGlobalDI, Ins.getImm());
```
https://github.com/llvm/llvm-project/pull/183121
More information about the llvm-branch-commits
mailing list