[llvm-branch-commits] [llvm] [SPIRV] Move the emission of some remaining cases under getOrCreateDebugScope. (PR #229487)
Manuel Carrasco via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Oct 8 03:31:50 PDT 2026
https://github.com/mgcarrasco updated https://github.com/llvm/llvm-project/pull/229487
>From 479dfcd469675932b6cfb3e7341766f299832a8d Mon Sep 17 00:00:00 2001
From: Manuel Carrasco <Manuel.Carrasco at amd.com>
Date: Tue, 6 Oct 2026 08:27:04 -0500
Subject: [PATCH 1/2] [SPIRV] Resolve a static member declaration through
getOrCreateDebugScope.
---
llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
index e63785c343c2c..bc9592ba11690 100644
--- a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
@@ -1302,9 +1302,10 @@ std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugGlobalVariable(
std::optional<MCRegister> StaticMemberRegOpt;
if (const DIDerivedType *SM = GV->getStaticDataMemberDeclaration()) {
- StaticMemberRegOpt = lookupOptReg(DebugScopeRegs, SM);
- if (!StaticMemberRegOpt)
+ EmitResult StaticMember = getOrCreateDebugScope(SM);
+ if (!StaticMember)
return std::nullopt;
+ StaticMemberRegOpt = StaticMember.Reg;
}
MCRegister NameReg = getCachedOpStringReg(GV->getName());
>From b0f7d6266f6516544def8f6fb5f5502d409b5aee Mon Sep 17 00:00:00 2001
From: Manuel Carrasco <Manuel.Carrasco at amd.com>
Date: Tue, 6 Oct 2026 08:39:33 -0500
Subject: [PATCH 2/2] [SPIRV] Emit DebugTypeMember through
getOrCreateDebugScope.
---
.../SPIRV/SPIRVNonSemanticDebugHandler.cpp | 19 ++++++++------
.../SPIRV/SPIRVNonSemanticDebugHandler.h | 13 +++++-----
...ebug-global-variable-skip-static-member.ll | 25 ++++++++++++++-----
3 files changed, 36 insertions(+), 21 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
index bc9592ba11690..3ed9eefd6d34a 100644
--- a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
@@ -896,6 +896,8 @@ SPIRVNonSemanticDebugHandler::emitDebugTypeForDerivedType(
return emitDebugTypePointer(DT, ExtInstSetReg, MAI);
case dwarf::DW_TAG_typedef:
return emitDebugTypedef(DT, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
+ case dwarf::DW_TAG_member:
+ return emitDebugTypeMember(DT, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI);
default:
return EmitResult::unsupported();
}
@@ -1461,15 +1463,16 @@ SPIRVNonSemanticDebugHandler::emitDebugTypeArray(
ExtInstSetReg, Ops, MAI));
}
-std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugTypeMember(
+SPIRVNonSemanticDebugHandler::EmitResult
+SPIRVNonSemanticDebugHandler::emitDebugTypeMember(
const DIDerivedType *M, MCRegister VoidTypeReg, MCRegister I32TypeReg,
MCRegister ExtInstSetReg, SPIRV::ModuleAnalysisInfo &MAI) {
EmitResult Ty = getOrCreateDebugScope(M->getBaseType());
if (!Ty)
- return std::nullopt;
+ return Ty;
if (!isUInt<32>(M->getOffsetInBits()) || !isUInt<32>(M->getSizeInBits()))
- return std::nullopt;
+ return EmitResult::unsupported();
MCRegister NameReg = getCachedOpStringReg(M->getName());
MCRegister FileStrReg = getCachedScopePathOpStringReg(
@@ -1496,10 +1499,10 @@ std::optional<MCRegister> SPIRVNonSemanticDebugHandler::emitDebugTypeMember(
// available but is not emitted as the optional Value operand, and under DWARF
// 5 a static member is tagged DW_TAG_variable, which the caller's member loop
// skips.
- return emitExtInst(
+ return EmitResult::emitted(emitExtInst(
SPIRV::NonSemanticExtInst::DebugTypeMember, VoidTypeReg, ExtInstSetReg,
{NameReg, Ty.Reg, SrcReg, LineReg, ColReg, OffsetReg, SizeReg, FlagsReg},
- MAI);
+ MAI));
}
SPIRVNonSemanticDebugHandler::EmitResult
@@ -1520,9 +1523,9 @@ SPIRVNonSemanticDebugHandler::emitDebugTypeComposite(
const auto *M = dyn_cast<DIDerivedType>(Element);
if (!M || M->getTag() != dwarf::DW_TAG_member)
continue;
- if (auto MemberReg =
- emitDebugTypeMember(M, VoidTypeReg, I32TypeReg, ExtInstSetReg, MAI))
- MemberRegs.push_back(*MemberReg);
+ EmitResult Member = getOrCreateDebugScope(M);
+ if (Member)
+ MemberRegs.push_back(Member.Reg);
}
MCRegister NameReg = getCachedOpStringReg(CT->getName());
diff --git a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h
index 0a7690efbab7b..efbabd280ea24 100644
--- a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h
+++ b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h
@@ -607,13 +607,12 @@ class SPIRVNonSemanticDebugHandler : public DebugHandlerBase {
/// Size, Flags. NonSemantic \c DebugTypeMember carries no Parent operand: the
/// enclosing \c DebugTypeComposite references its members, not the reverse.
///
- /// \returns The result id register on success. Returns \c std::nullopt and
- /// emits nothing if \p M's type cannot be emitted.
- std::optional<MCRegister> emitDebugTypeMember(const DIDerivedType *M,
- MCRegister VoidTypeReg,
- MCRegister I32TypeReg,
- MCRegister ExtInstSetReg,
- SPIRV::ModuleAnalysisInfo &MAI);
+ /// \returns Emitted with the result id on success. Returns the base's status
+ /// and emits nothing if \p M's type cannot be emitted.
+ EmitResult emitDebugTypeMember(const DIDerivedType *M, MCRegister VoidTypeReg,
+ MCRegister I32TypeReg,
+ MCRegister ExtInstSetReg,
+ SPIRV::ModuleAnalysisInfo &MAI);
/// Emit \c DebugTypeComposite for the struct, class, or union \p CT, after a
/// \c DebugTypeMember for each data member whose type can be emitted. A
diff --git a/llvm/test/CodeGen/SPIRV/debug-info/debug-global-variable-skip-static-member.ll b/llvm/test/CodeGen/SPIRV/debug-info/debug-global-variable-skip-static-member.ll
index f8b4cc38c8951..a6fee1e937c4b 100644
--- a/llvm/test/CodeGen/SPIRV/debug-info/debug-global-variable-skip-static-member.ll
+++ b/llvm/test/CodeGen/SPIRV/debug-info/debug-global-variable-skip-static-member.ll
@@ -1,14 +1,27 @@
; RUN: llc --verify-machineinstrs --spirv-ext=+SPV_KHR_non_semantic_info -O0 -mtriple=spirv64-unknown-unknown %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 %}
-; A DIGlobalVariable that is the definition of a static data member. Its
-; declaration DIDerivedType (DW_TAG_member) is not emitted into DebugTypeRegs
-; (member types are not supported yet), so the Static Member Declaration operand
-; cannot be resolved and the whole DebugGlobalVariable is skipped.
+; A DIGlobalVariable that is the definition of a static data member. The
+; declaration is a DW_TAG_member, so getOrCreateDebugScope emits it as
+; DebugTypeMember. DebugGlobalVariable names that id. Its Flags operand is
+; FlagStaticMember (512).
; CHECK-DAG: [[EXT:%[0-9]+]] = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
-; CHECK-DAG: OpExtInst {{.*}} DebugCompilationUnit
-; CHECK-NOT: DebugGlobalVariable
+; CHECK-DAG: [[VOID:%[0-9]+]] = OpTypeVoid
+; CHECK-DAG: [[I32T:%[0-9]+]] = OpTypeInt 32 0
+; CHECK-DAG: [[NAME:%[0-9]+]] = OpString "member"
+; CHECK-DAG: [[STR_INT:%[0-9]+]] = OpString "int"
+; CHECK-DAG: [[C0:%[0-9]+]] = OpConstant [[I32T]] 0{{$}}
+; CHECK-DAG: [[C8:%[0-9]+]] = OpConstant [[I32T]] 8{{$}}
+; CHECK-DAG: [[C32:%[0-9]+]] = OpConstant [[I32T]] 32{{$}}
+; CHECK-DAG: [[C42:%[0-9]+]] = OpConstant [[I32T]] 42{{$}}
+; CHECK-DAG: [[C512:%[0-9]+]] = OpConstant [[I32T]] 512{{$}}
+; CHECK-DAG: [[DS:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugSource
+; CHECK-DAG: [[CU:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugCompilationUnit
+; CHECK-DAG: [[DTI:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugTypeBasic [[STR_INT]]
+; CHECK-DAG: [[MEM:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugTypeMember [[NAME]] [[DTI]] [[DS]] {{%[0-9]+}} [[C0]] [[C0]] [[C0]] [[C512]]
+; CHECK-DAG: [[GV:%[0-9]+]] = OpVariable {{.*}} CrossWorkgroup
+; CHECK-DAG: OpExtInst [[VOID]] [[EXT]] DebugGlobalVariable [[NAME]] [[DTI]] [[DS]] [[C42]] [[C0]] [[CU]] [[NAME]] [[GV]] [[C8]] [[MEM]]
target triple = "spirv64-unknown-unknown"
More information about the llvm-branch-commits
mailing list