[llvm] Add support for NSDI DebugScope, DebugNoScope and DebugInlinedAt (PR #218959)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 1 04:12:44 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-spir-v
Author: Manuel Carrasco (mgcarrasco)
<details>
<summary>Changes</summary>
Add support for NSDI [DebugScope](https://github.khronos.org/SPIRV-Registry/nonsemantic/NonSemantic.Shader.DebugInfo.html#DebugScope), [DebugNoScope](https://github.khronos.org/SPIRV-Registry/nonsemantic/NonSemantic.Shader.DebugInfo.html#DebugNoScope) and [DebugInlinedAt](https://github.khronos.org/SPIRV-Registry/nonsemantic/NonSemantic.Shader.DebugInfo.html#DebugInlinedAt).
DebugScope/DebugNoScope are region delimiters following the same region rule as DebugLine/DebugNoLine. The two regions are tracked separately because a DebugScope region could span several DebugLine regions, and either can skip emission on a cache miss.
DebugInlinedAt is not an region instruction, so it is emitted at module scope. We allow recursive traversal when building them to support chains.
The PR also adds a test showing a limitation in the DebugLine deduplication that is at the DILocation pointer level which may lead to duplicate opcodes. I can work on that on a following PR to keep things separate.
---
Patch is 52.62 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/218959.diff
21 Files Affected:
- (modified) llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp (+127-18)
- (modified) llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h (+33)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-call-before-alloca.ll (+2)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-calls.ll (+6)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-external-call.ll (+1)
- (added) llvm/test/CodeGen/SPIRV/debug-info/debug-inlined-at-recursive.ll (+83)
- (added) llvm/test/CodeGen/SPIRV/debug-info/debug-inlined-at.ll (+68)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/debug-line-block.ll (+4-1)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/debug-line-calls.ll (+2)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/debug-line-if-phi.ll (+4-1)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/debug-line-loop-merge.ll (+2)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/debug-line-loop.ll (+4-1)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/debug-line-selection-merge.ll (+4)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/debug-line-shared.ll (+1)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/debug-line.ll (+1)
- (modified) llvm/test/CodeGen/SPIRV/debug-info/debug-no-line.ll (+3)
- (added) llvm/test/CodeGen/SPIRV/debug-info/debug-scope-block.ll (+66)
- (added) llvm/test/CodeGen/SPIRV/debug-info/debug-scope-no-scope.ll (+55)
- (added) llvm/test/CodeGen/SPIRV/debug-info/debug-scope-same-line.ll (+63)
- (added) llvm/test/CodeGen/SPIRV/debug-info/debug-scope-shared.ll (+62)
- (added) llvm/test/CodeGen/SPIRV/debug-info/debug-scope.ll (+67)
``````````diff
diff --git a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
index dc4ec4e6fec7e..d244bffe53111 100644
--- a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
@@ -314,6 +314,7 @@ void SPIRVNonSemanticDebugHandler::beginModule(Module *M) {
DebugFunctionDeclarationRegs.clear();
DebugFunctionRegs.clear();
DebugLexicalBlockRegs.clear();
+ DebugInlinedAtRegs.clear();
ScopeToPathOpStringReg.clear();
CUToCompilationUnitDbgReg.clear();
DebugSourceRegByFileStr.clear();
@@ -740,6 +741,38 @@ std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugLexicalBlock(
ExtInstSetReg, Ops, MAI);
}
+MCRegister SPIRVNonSemanticDebugHandler::getOrEmitDebugInlinedAt(
+ const DILocation *IA, MCRegister VoidTypeReg, MCRegister I32TypeReg,
+ MCRegister ExtInstSetReg, SPIRV::ModuleAnalysisInfo &MAI) {
+ assert(IA && "IA must not be null in getOrEmitDebugInlinedAt");
+
+ if (MCRegister Cached = DebugInlinedAtRegs.lookup(IA))
+ return Cached;
+
+ auto ScopeRegOpt = resolveLexicalBlockParent(IA->getScope());
+ if (!ScopeRegOpt)
+ return MCRegister();
+
+ MCRegister LineReg =
+ emitOpConstantI32(static_cast<uint32_t>(IA->getLine()), I32TypeReg, MAI);
+
+ SmallVector<MCRegister, 3> Ops{LineReg, *ScopeRegOpt};
+ // Recurse before building this instruction's operands so an outer
+ // inlined-at link is always available.
+ if (const DILocation *Outer = IA->getInlinedAt()) {
+ MCRegister OuterReg = getOrEmitDebugInlinedAt(
+ Outer, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
+ if (!OuterReg.isValid())
+ return MCRegister();
+ Ops.push_back(OuterReg);
+ }
+
+ MCRegister Reg = emitExtInst(SPIRV::NonSemanticExtInst::DebugInlinedAt,
+ VoidTypeReg, ExtInstSetReg, Ops, MAI);
+ DebugInlinedAtRegs[IA] = Reg;
+ return Reg;
+}
+
std::optional<MCRegister>
SPIRVNonSemanticDebugHandler::emitDebugFunctionDeclaration(
const DISubprogram *SP, MCRegister VoidTypeReg, MCRegister I32TypeReg,
@@ -1216,6 +1249,7 @@ void SPIRVNonSemanticDebugHandler::resetPerFunctionDebugState() {
LastFunctionOpVariable = nullptr;
DebugFunctionDefinitionEmitted = false;
LastLineMI = nullptr;
+ LastScopeMI = nullptr;
}
void SPIRVNonSemanticDebugHandler::preparePerFunctionDebug(
@@ -1280,7 +1314,13 @@ void SPIRVNonSemanticDebugHandler::beginInstruction(const MachineInstr *MI) {
if (!DebugFunctionDefinitionEmitted)
return;
- emitDebugLineForInstruction(MI);
+
+ std::optional<const MachineInstr *> Target = resolveDebugLocTarget(MI);
+ if (!Target)
+ return;
+
+ emitDebugScopeForInstruction(*Target);
+ emitDebugLineForInstruction(*Target);
}
static bool isMergeInstruction(unsigned Opcode) {
@@ -1288,8 +1328,8 @@ static bool isMergeInstruction(unsigned Opcode) {
Opcode == SPIRV::OpLoopControlINTEL;
}
-static bool isDebugLineTarget(const MachineInstr *MI,
- SPIRV::ModuleAnalysisInfo &MAI) {
+static bool isDebugLocTarget(const MachineInstr *MI,
+ SPIRV::ModuleAnalysisInfo &MAI) {
if (MAI.getSkipEmission(MI))
return false;
switch (MI->getOpcode()) {
@@ -1317,25 +1357,23 @@ findAdjacentEmittedInstruction(const MachineInstr *MI,
return nullptr;
}
-void SPIRVNonSemanticDebugHandler::emitDebugLineForInstruction(
- const MachineInstr *MI) {
- assert(DebugFunctionDefinitionEmitted &&
- "DebugFunctionDefinition must be emitted");
+std::optional<const MachineInstr *>
+SPIRVNonSemanticDebugHandler::resolveDebugLocTarget(const MachineInstr *MI) {
assert(CurrentMAI && "CurrentMAI must be set");
-
SPIRV::ModuleAnalysisInfo &MAI = *CurrentMAI;
- // Structural opcodes don't require a DebugLine, other opcodes might have
- // already been emitted in the module scope.
- if (!isDebugLineTarget(MI, MAI))
- return;
+ // Structural opcodes don't require a DebugLine/DebugScope, other opcodes
+ // might have already been emitted in the module scope.
+ if (!isDebugLocTarget(MI, MAI))
+ return std::nullopt;
- // DebugLine can be emitted before a merge instruction, but not after it
- // (nothing may sit between the merge and its terminator). We can use either
- // the merge's or the terminator's debug info; we emit the terminator's one.
+ // DebugLine/DebugScope can be emitted before a merge instruction, but not
+ // after it (nothing may sit between the merge and its terminator). We can
+ // use either the merge's or the terminator's debug info; we emit the
+ // terminator's one.
const MachineInstr *Prev = findAdjacentEmittedInstruction(MI, MAI, false);
if (Prev && isMergeInstruction(Prev->getOpcode()))
- return;
+ return std::nullopt;
if (isMergeInstruction(MI->getOpcode())) {
// Use the terminator's debug info; when we reach it later, the check
@@ -1344,10 +1382,76 @@ void SPIRVNonSemanticDebugHandler::emitDebugLineForInstruction(
assert(MI && "Merge instruction must be followed by a terminator");
}
- // The range of DebugLine must be reset at each basic block boundary.
+ // Both regions are implicitly closed at each basic block boundary. They are
+ // tracked separately because a DebugScope region usually spans several
+ // DebugLine regions, and either one can skip emission on a cache miss.
if (LastLineMI && MI->getParent() != LastLineMI->getParent())
LastLineMI = nullptr;
+ if (LastScopeMI && MI->getParent() != LastScopeMI->getParent())
+ LastScopeMI = nullptr;
+
+ return MI;
+}
+
+void SPIRVNonSemanticDebugHandler::emitDebugScopeForInstruction(
+ const MachineInstr *MI) {
+ assert(DebugFunctionDefinitionEmitted &&
+ "DebugFunctionDefinition must be emitted");
+ assert(CurrentMAI && "CurrentMAI must be set");
+ SPIRV::ModuleAnalysisInfo &MAI = *CurrentMAI;
+ MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
+ MCRegister ExtInstSetReg = MAI.getExtInstSetReg(NSSet);
+
+ const DILocation *CurDL = MI->getDebugLoc().get();
+ if (!CurDL) {
+ // No location for the current instruction.
+ if (LastScopeMI) {
+ // Close the current DebugScope region.
+ emitExtInst(SPIRV::NonSemanticExtInst::DebugNoScope, VoidTypeReg,
+ ExtInstSetReg, {}, MAI);
+ LastScopeMI = nullptr;
+ }
+ return;
+ }
+
+ const DIScope *CurScope = CurDL->getScope();
+ const DILocation *CurInlinedAt = CurDL->getInlinedAt();
+
+ if (LastScopeMI) {
+ const DILocation *LastDL = LastScopeMI->getDebugLoc().get();
+ if (LastDL->getScope() == CurScope &&
+ LastDL->getInlinedAt() == CurInlinedAt)
+ return;
+ }
+
+ auto CurScopeRegOpt = resolveLexicalBlockParent(CurScope);
+ if (!CurScopeRegOpt)
+ return;
+
+ SmallVector<MCRegister, 2> Ops{*CurScopeRegOpt};
+ if (CurInlinedAt) {
+ // If the global emission did not include this inlined-at case, we skip it.
+ MCRegister InlinedReg = DebugInlinedAtRegs.lookup(CurInlinedAt);
+ if (!InlinedReg.isValid())
+ return;
+ Ops.push_back(InlinedReg);
+ }
+
+ // A new DebugScope region is needed.
+ emitExtInst(SPIRV::NonSemanticExtInst::DebugScope, VoidTypeReg, ExtInstSetReg,
+ Ops, MAI);
+
+ LastScopeMI = MI;
+}
+
+void SPIRVNonSemanticDebugHandler::emitDebugLineForInstruction(
+ const MachineInstr *MI) {
+ assert(DebugFunctionDefinitionEmitted &&
+ "DebugFunctionDefinition must be emitted");
+ assert(CurrentMAI && "CurrentMAI must be set");
+
+ SPIRV::ModuleAnalysisInfo &MAI = *CurrentMAI;
MCRegister VoidTypeReg = getOrEmitOpTypeVoidReg(MAI);
MCRegister ExtInstSetReg = MAI.getExtInstSetReg(NSSet);
@@ -1391,7 +1495,7 @@ void SPIRVNonSemanticDebugHandler::emitDebugLineForInstruction(
if (LastLineMI && MI->getDebugLoc() == LastLineMI->getDebugLoc())
return;
- // A new DebugLine region is needed. Emit it and update LastLineMI.
+ // A new DebugLine region is needed.
emitExtInst(SPIRV::NonSemanticExtInst::DebugLine, VoidTypeReg, ExtInstSetReg,
{SrcReg, LineReg, LineReg, ColStartReg, ColEndReg}, MAI);
@@ -1648,6 +1752,11 @@ void SPIRVNonSemanticDebugHandler::emitNonSemanticGlobalDebugInfo(
emitDebugGlobalVariable(GV, Info, VoidTypeReg, I32TypeReg, ExtInstSetReg,
MAI);
+ // Emit DebugInlinedAt allowing recursive inlining.
+ for (const DILocation *DL : UniqueDebugLocations)
+ if (const DILocation *IA = DL->getInlinedAt())
+ getOrEmitDebugInlinedAt(IA, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
+
for (const DILocation *DL : UniqueDebugLocations) {
emitOpConstantI32(DL->getLine(), I32TypeReg, MAI);
emitOpConstantI32(DL->getColumn(), I32TypeReg, MAI);
diff --git a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h
index 0b3c6fa0aa081..f579c0efad9a1 100644
--- a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h
+++ b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h
@@ -120,6 +120,9 @@ class SPIRVNonSemanticDebugHandler : public DebugHandlerBase {
// DebugLexicalBlock result id per emitted DILexicalBlock/DINamespace.
DenseMap<const DIScope *, MCRegister> DebugLexicalBlockRegs;
+ // DebugInlinedAt result id per DILocation used as an inlined-at chain link.
+ DenseMap<const DILocation *, MCRegister> DebugInlinedAtRegs;
+
// Path \c OpString result id per \c DIScope (CU, \c DIFile, declaration
// \c DISubprogram, …). Filled during \c emitNonSemanticDebugStrings() using
// \c getDebugFullPath + \c emitOpStringIfNew; section 10 uses it for
@@ -181,6 +184,8 @@ class SPIRVNonSemanticDebugHandler : public DebugHandlerBase {
const MachineInstr *LastLineMI = nullptr;
+ const MachineInstr *LastScopeMI = nullptr;
+
public:
explicit SPIRVNonSemanticDebugHandler(AsmPrinter &AP);
@@ -246,6 +251,16 @@ class SPIRVNonSemanticDebugHandler : public DebugHandlerBase {
void resetPerFunctionDebugState();
+ /// Resolve the instruction that a per-instruction DebugLine/DebugScope
+ /// update should attach to: \p MI adjusted forward past a merge
+ /// instruction to its terminator, or \c std::nullopt if \p MI is not a
+ /// valid attachment point (skip-emission, or one of the structural opcodes
+ /// that can never carry DebugLine/DebugScope: OpFunction,
+ /// OpFunctionParameter, OpFunctionEnd, OpLabel, OpPhi).
+ std::optional<const MachineInstr *>
+ resolveDebugLocTarget(const MachineInstr *MI);
+
+ void emitDebugScopeForInstruction(const MachineInstr *MI);
void emitDebugLineForInstruction(const MachineInstr *MI);
void preparePerFunctionDebug(const MachineFunction *MF);
void tryEmitDebugFunctionDefinition(SPIRV::ModuleAnalysisInfo &MAI);
@@ -521,6 +536,24 @@ class SPIRVNonSemanticDebugHandler : public DebugHandlerBase {
emitDebugLexicalBlock(const DIScope *S, MCRegister VoidTypeReg,
MCRegister I32TypeReg, MCRegister ExtInstSetReg,
SPIRV::ModuleAnalysisInfo &MAI);
+
+ /// Return a cached \c DebugInlinedAt id for \p IA, or emit one (recursing
+ /// into \c IA->getInlinedAt() first for the optional Inlined operand, so
+ /// outer frames are always emitted before the inner frame that references
+ /// them). Must run after \c DebugFunctionRegs and \c DebugLexicalBlockRegs
+ /// are populated, since the Scope operand is resolved through
+ /// \c resolveLexicalBlockParent. \c DebugInlinedAt is not in the spec's
+ /// in-block instruction list, so this is only ever called from
+ /// module-scope emission (\c emitNonSemanticGlobalDebugInfo), never from
+ /// per-instruction emission.
+ ///
+ /// \returns An invalid (default-constructed) \c MCRegister, and emits
+ /// nothing, if \p IA's Scope does not resolve.
+ MCRegister getOrEmitDebugInlinedAt(const DILocation *IA,
+ MCRegister VoidTypeReg,
+ MCRegister I32TypeReg,
+ MCRegister ExtInstSetReg,
+ SPIRV::ModuleAnalysisInfo &MAI);
};
} // namespace llvm
diff --git a/llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-call-before-alloca.ll b/llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-call-before-alloca.ll
index ed46c25d3ba20..8c3329316d931 100644
--- a/llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-call-before-alloca.ll
+++ b/llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-call-before-alloca.ll
@@ -33,6 +33,7 @@
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugFunctionDefinition [[DF]] [[CALLER]]
; CHECK-NEXT: OpFunctionCall
; CHECK-NEXT: OpStore
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugScope [[DF]]
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine
; CHECK-NEXT: OpReturnValue
; CHECK-NEXT: OpFunctionEnd
@@ -44,6 +45,7 @@
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugFunctionDefinition [[DF_NOARGS]] [[CALLER_NOARGS]]
; CHECK-NEXT: OpFunctionCall
; CHECK-NEXT: OpStore
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugScope [[DF_NOARGS]]
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine
; CHECK-NEXT: OpReturn
; CHECK-NEXT: OpFunctionEnd
diff --git a/llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-calls.ll b/llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-calls.ll
index 8db6cc586a01e..e577379311155 100644
--- a/llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-calls.ll
+++ b/llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-calls.ll
@@ -26,6 +26,7 @@
; CHECK-NEXT: OpFunctionParameter
; CHECK-NEXT: OpLabel
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugFunctionDefinition [[DF_LEAF]] [[LEAF]]
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugScope [[DF_LEAF]]
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine
; CHECK-NEXT: OpReturnValue
; CHECK-NEXT: OpFunctionEnd
@@ -39,10 +40,13 @@
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugFunctionDefinition [[DF_WITH]] [[WITH]]
; CHECK-NEXT: OpStore
; CHECK-NEXT: OpStore
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugScope [[DF_WITH]]
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine
; CHECK-NEXT: OpFunctionCall
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugNoScope
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugNoLine
; CHECK-NEXT: OpIAdd
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugScope [[DF_WITH]]
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine
; CHECK-NEXT: OpReturnValue
; CHECK-NEXT: OpFunctionEnd
@@ -52,6 +56,7 @@
; CHECK-NEXT: OpFunctionParameter
; CHECK-NEXT: OpLabel
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugFunctionDefinition [[DF_CALLER]] [[CALLER]]
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugScope [[DF_CALLER]]
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine
; CHECK-NEXT: OpFunctionCall
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine
@@ -64,6 +69,7 @@
; CHECK: [[ORCH]] = OpFunction %{{.*}} ; -- Begin function orchestrator
; CHECK-NEXT: OpLabel
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugFunctionDefinition [[DF_ORCH]] [[ORCH]]
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugScope [[DF_ORCH]]
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine
; CHECK-NEXT: OpFunctionCall
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine
diff --git a/llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-external-call.ll b/llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-external-call.ll
index bd0c6b56a7dd4..f72fe5c2b01f8 100644
--- a/llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-external-call.ll
+++ b/llvm/test/CodeGen/SPIRV/debug-info/debug-function-definition-external-call.ll
@@ -25,6 +25,7 @@
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugFunctionDefinition [[DF]] [[CALLER]]
; CHECK-NEXT: OpStore
; CHECK-NEXT: OpFunctionCall
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugScope [[DF]]
; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine
; CHECK-NEXT: OpReturnValue
; CHECK-NEXT: OpFunctionEnd
diff --git a/llvm/test/CodeGen/SPIRV/debug-info/debug-inlined-at-recursive.ll b/llvm/test/CodeGen/SPIRV/debug-info/debug-inlined-at-recursive.ll
new file mode 100644
index 0000000000000..a490cb80b6faa
--- /dev/null
+++ b/llvm/test/CodeGen/SPIRV/debug-info/debug-inlined-at-recursive.ll
@@ -0,0 +1,83 @@
+; RUN: llc --verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_KHR_non_semantic_info %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc --verify-machineinstrs --spirv-ext=+SPV_KHR_non_semantic_info -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; Exercise a two-level DebugInlinedAt chain.
+;
+; static inline __attribute__((always_inline)) int innermost(int x) {
+; return x * 3; // line 2
+; }
+; static inline __attribute__((always_inline)) int middle(int y) {
+; return innermost(y) ^ 7; // line 6, calls innermost at col 10
+; }
+; int top(int z) {
+; int r = middle(z); // line 10, calls middle at col 11
+; return r - 5; // line 11
+; }
+;
+
+; CHECK-DAG: [[EXT:%[0-9]+]] = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
+; CHECK-DAG: [[VOID:%[0-9]+]] = OpTypeVoid
+; CHECK-DAG: [[I32:%[0-9]+]] = OpTypeInt 32 0
+; CHECK-DAG: [[NAME_INNER:%[0-9]+]] = OpString "innermost"
+; CHECK-DAG: [[NAME_MID:%[0-9]+]] = OpString "middle"
+; CHECK-DAG: [[NAME_TOP:%[0-9]+]] = OpString "top"
+; CHECK-DAG: [[DS:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugSource
+; CHECK-DAG: [[DF_INNER:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugFunction [[NAME_INNER]]
+; CHECK-DAG: [[DF_MID:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugFunction [[NAME_MID]]
+; CHECK-DAG: [[DF_TOP:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugFunction [[NAME_TOP]]
+; CHECK-DAG: [[V6:%[0-9]+]] = OpConstant [[I32]] 6{{$}}
+; CHECK-DAG: [[V10:%[0-9]+]] = OpConstant [[I32]] 10{{$}}
+
+; CHECK: [[OUTER:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugInlinedAt [[V10]] [[DF_TOP]]
+; CHECK-NEXT: [[INNER:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugInlinedAt [[V6]] [[DF_MID]] [[OUTER]]
+
+; CHECK: [[TOP:%[0-9]+]] = OpFunction {{.*}} ; -- Begin function top
+; CHECK-NEXT: OpFunctionParameter
+; CHECK-NEXT: OpLabel
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugFunctionDefinition [[DF_TOP]] [[TOP]]
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugScope [[DF_INNER]] [[INNER]]
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine [[DS]]
+; CHECK-NEXT: OpIMul
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugScope [[DF_MID]] [[OUTER]]
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine [[DS]]
+; CHECK-NEXT: OpBitwiseXor
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugScope [[DF_TOP]]
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine [[DS]]
+; CHECK-NEXT: OpIAdd
+; CHECK-NEXT: OpExtInst [[VOID]] [[EXT]] DebugLine [[DS]]
+; CHECK-NEXT: OpReturnValue
+; CHECK-NEXT: OpFunctionEnd
+
+target triple = "spirv64-unknown-unknown"
+
+define spir_func i32 @top(i32 %z) !dbg !11 {
+entry:
+ %mul.i = mul nsw i32 %z, 3, !dbg !29
+ %xor.i = xor i32 %mul.i, 7, !dbg !30
+ %sub = add nsw i32 %xor.i, -5, !dbg !31
+ ret i32 %sub, !dbg !32
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "debug-inlined-at-recursive.c", directory: "/src")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+
+!11 = distinct !DISubprogram(name: "top", scope: !1, file: !1, line: 9, type: !12, scopeLine: 9, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0)
+!12 = !DISubroutineType(cc: DW_CC_LLVM_SpirFunction, types: !13)
+!13 = !{!14, !14}
+!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+
+!20 = distinct !DISubprogram(name: "middle", scope: !1, file: !1, line: 5, type: !12, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0)
+!25 = distinct !DISubprogram(name: "innermost", scope: !1, file: !1, line: 1, type: !12, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0)
+
+!23 = distinct !DILocation(l...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/218959
More information about the llvm-commits
mailing list