[llvm-branch-commits] [llvm] [SPIRV] Drop the per-kind NSDI type vectors. (PR #229037)
Manuel Carrasco via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Oct 5 03:24:33 PDT 2026
https://github.com/mgcarrasco created https://github.com/llvm/llvm-project/pull/229037
The PR removes some containers NSDI impl required prior to the emission order change.
>From a128514e4d33cce413407962f28a52efa669ca23 Mon Sep 17 00:00:00 2001
From: Manuel Carrasco <Manuel.Carrasco at amd.com>
Date: Mon, 5 Oct 2026 05:22:02 -0500
Subject: [PATCH] [SPIRV] Drop the per-kind NSDI type vectors.
Replace partitionTypes and the seven type lists with the type list from DebugInfoFinder.
---
.../SPIRV/SPIRVNonSemanticDebugHandler.cpp | 134 ++++++------------
.../SPIRV/SPIRVNonSemanticDebugHandler.h | 18 +--
...ug-function-declaration-composite-scope.ll | 8 +-
3 files changed, 51 insertions(+), 109 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
index a01e861f1aa49..1c2a2d7b7e2a2 100644
--- a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.cpp
@@ -53,59 +53,6 @@ static std::optional<MCRegister> lookupOptReg(const MapT &Map,
return It->second;
}
-/// Partition \p Ty into \p BasicTypes, \p PointerTypes, \p SubroutineTypes,
-/// \p VectorTypes, \p ArrayTypes, \p CompositeTypes, and \p TypedefTypes for
-/// NSDI emission. Used when iterating DebugInfoFinder.types(); each DI node is
-/// seen once, so no recursion into pointer bases. Other composites and the
-/// remaining derived kinds are ignored because they are not yet supported.
-/// Only types that are supported (later used) are partitioned.
-static void
-partitionTypes(const DIType *Ty, SmallVector<const DIBasicType *> &BasicTypes,
- SmallVector<const DIDerivedType *> &PointerTypes,
- SmallVector<const DISubroutineType *> &SubroutineTypes,
- SmallVector<const DICompositeType *> &VectorTypes,
- SmallVector<const DICompositeType *> &ArrayTypes,
- SmallVector<const DICompositeType *> &CompositeTypes,
- SmallVector<const DIDerivedType *> &TypedefTypes) {
- if (const auto *BT = dyn_cast<DIBasicType>(Ty)) {
- BasicTypes.push_back(BT);
- return;
- }
- if (const auto *ST = dyn_cast<DISubroutineType>(Ty)) {
- SubroutineTypes.push_back(ST);
- return;
- }
- if (const auto *CT = dyn_cast<DICompositeType>(Ty)) {
- if (CT->getTag() == dwarf::DW_TAG_array_type) {
- // A vector is an array with DINode::FlagVector. A plain array is the
- // same tag without it. A matrix is also lowered to a DW_TAG_array_type
- // (two subranges), so it is indistinguishable from a 2D array here and
- // is emitted as a DebugTypeArray.
- //
- // FIXME: Emitting a matrix as a DebugTypeArray is valid but loses the
- // matrix shape. DWARF has no matrix tag, so distinguishing a matrix needs
- // a new DINode flag analogous to FlagVector, set on the array, plus a way
- // to carry column-major vs row-major traits. Array-of-vectors alone would
- // not disambiguate a matrix from a genuine array of vectors. Once the
- // frontend marks matrices, route them to a DebugTypeMatrix path here.
- if (CT->isVector())
- VectorTypes.push_back(CT);
- else
- ArrayTypes.push_back(CT);
- } else if (CT->getTag() == dwarf::DW_TAG_structure_type ||
- CT->getTag() == dwarf::DW_TAG_class_type ||
- CT->getTag() == dwarf::DW_TAG_union_type) {
- CompositeTypes.push_back(CT);
- }
- return;
- }
- const auto *DT = dyn_cast<DIDerivedType>(Ty);
- if (DT && DT->getTag() == dwarf::DW_TAG_pointer_type)
- PointerTypes.push_back(DT);
- else if (DT && DT->getTag() == dwarf::DW_TAG_typedef)
- TypedefTypes.push_back(DT);
-}
-
enum : uint32_t {
NSDIFlagIsProtected = 1u << 0,
NSDIFlagIsPrivate = 1u << 1,
@@ -382,13 +329,7 @@ void SPIRVNonSemanticDebugHandler::beginModule(Module *M) {
return;
CompileUnits.clear();
- BasicTypes.clear();
- PointerTypes.clear();
- SubroutineTypes.clear();
- VectorTypes.clear();
- ArrayTypes.clear();
- CompositeTypes.clear();
- TypedefTypes.clear();
+ DebugTypes.clear();
SubprogramDeclarations.clear();
SubprogramDefinitions.clear();
UniqueDebugLocations.clear();
@@ -455,10 +396,7 @@ void SPIRVNonSemanticDebugHandler::beginModule(Module *M) {
// Find all debug info types that may be referenced by NSDI instructions.
DebugInfoFinder Finder;
Finder.processModule(*M);
- llvm::for_each(Finder.types(), [&](DIType *Ty) {
- partitionTypes(Ty, BasicTypes, PointerTypes, SubroutineTypes, VectorTypes,
- ArrayTypes, CompositeTypes, TypedefTypes);
- });
+ DebugTypes.assign(Finder.types().begin(), Finder.types().end());
for (const DISubprogram *SP : Finder.subprograms()) {
if (SP->isDefinition())
@@ -940,6 +878,17 @@ SPIRVNonSemanticDebugHandler::emitDebugTypeForCompositeType(
MCRegister ExtInstSetReg, SPIRV::ModuleAnalysisInfo &MAI) {
switch (CT->getTag()) {
case dwarf::DW_TAG_array_type:
+ // A vector is an array with DINode::FlagVector. A plain array is the
+ // same tag without it. A matrix is also lowered to a DW_TAG_array_type
+ // (two subranges), so it is indistinguishable from a 2D array here and
+ // is emitted as a DebugTypeArray.
+ //
+ // FIXME: Emitting a matrix as a DebugTypeArray is valid but loses the
+ // matrix shape. DWARF has no matrix tag, so distinguishing a matrix needs
+ // a new DINode flag analogous to FlagVector, set on the array, plus a way
+ // to carry column-major vs row-major traits. Array-of-vectors alone would
+ // not disambiguate a matrix from a genuine array of vectors. Once the
+ // frontend marks matrices, route them to a DebugTypeMatrix path here.
if (CT->isVector())
return emitDebugTypeVector(CT, ExtInstSetReg, MAI);
return emitDebugTypeArray(CT, ExtInstSetReg, MAI);
@@ -1666,9 +1615,6 @@ void SPIRVNonSemanticDebugHandler::emitNonSemanticDebugStrings(
}
}
- for (const DIBasicType *BT : BasicTypes)
- emitOpStringIfNew(BT->getName(), MAI);
-
for (const DISubprogram *SP : concat<const DISubprogram *>(
SubprogramDeclarations, SubprogramDefinitions)) {
emitOpStringIfNew(SP->getName(), MAI);
@@ -1676,26 +1622,40 @@ void SPIRVNonSemanticDebugHandler::emitNonSemanticDebugStrings(
emitAndCacheScopePathOpStringReg(SP, MAI);
}
- // Cache the OpStrings each DebugTypeComposite and its DebugTypeMembers use:
- // the composite name, identifier (linkage name), and path, plus each member
- // name and path.
- for (const DICompositeType *CT : CompositeTypes) {
- emitOpStringIfNew(CT->getName(), MAI);
- emitOpStringIfNew(CT->getIdentifier(), MAI);
- emitAndCacheScopePathOpStringReg(CT->getFile(), MAI);
- for (const DINode *Element : CT->getElements()) {
- const auto *M = dyn_cast<DIDerivedType>(Element);
- if (!M || M->getTag() != dwarf::DW_TAG_member)
+ // Cache OpStrings for the kinds whose emitters call getCachedOpStringReg.
+ // Other finder types are skipped here; emitDebugScope reports them
+ // unsupported and never looks up a string.
+ for (const DIType *Ty : DebugTypes) {
+ if (const auto *BT = dyn_cast<DIBasicType>(Ty)) {
+ emitOpStringIfNew(BT->getName(), MAI);
+ continue;
+ }
+ if (const auto *CT = dyn_cast<DICompositeType>(Ty)) {
+ // Cache the OpStrings each DebugTypeComposite and its DebugTypeMembers
+ // use: the composite name, identifier (linkage name), and path, plus
+ // each member name and path. Arrays and vectors have no such strings.
+ if (CT->getTag() != dwarf::DW_TAG_structure_type &&
+ CT->getTag() != dwarf::DW_TAG_class_type &&
+ CT->getTag() != dwarf::DW_TAG_union_type)
continue;
- emitOpStringIfNew(M->getName(), MAI);
- emitAndCacheScopePathOpStringReg(M->getFile(), MAI);
+ emitOpStringIfNew(CT->getName(), MAI);
+ emitOpStringIfNew(CT->getIdentifier(), MAI);
+ emitAndCacheScopePathOpStringReg(CT->getFile(), MAI);
+ for (const DINode *Element : CT->getElements()) {
+ const auto *M = dyn_cast<DIDerivedType>(Element);
+ if (!M || M->getTag() != dwarf::DW_TAG_member)
+ continue;
+ emitOpStringIfNew(M->getName(), MAI);
+ emitAndCacheScopePathOpStringReg(M->getFile(), MAI);
+ }
+ continue;
+ }
+ // Cache the name and path OpStrings each DebugTypedef uses.
+ const auto *TD = dyn_cast<DIDerivedType>(Ty);
+ if (TD && TD->getTag() == dwarf::DW_TAG_typedef) {
+ emitOpStringIfNew(TD->getName(), MAI);
+ emitAndCacheScopePathOpStringReg(TD->getFile(), MAI);
}
- }
-
- // Cache the name and path OpStrings each DebugTypedef uses.
- for (const DIDerivedType *TD : TypedefTypes) {
- emitOpStringIfNew(TD->getName(), MAI);
- emitAndCacheScopePathOpStringReg(TD->getFile(), MAI);
}
for (const auto &[GV, _] : GlobalVariableDebugInfoMap) {
@@ -2357,9 +2317,7 @@ void SPIRVNonSemanticDebugHandler::emitNonSemanticGlobalDebugInfo(
for (const DIScope *S :
make_filter_range(LexicalBlocks, IsaPred<DINamespace>))
getOrCreateDebugScope(S);
- for (const DIType *Ty :
- concat<const DIType *>(BasicTypes, VectorTypes, PointerTypes, ArrayTypes,
- SubroutineTypes, TypedefTypes, CompositeTypes))
+ for (const DIType *Ty : DebugTypes)
getOrCreateDebugScope(Ty);
for (const DISubprogram *SP : concat<const DISubprogram *>(
SubprogramDeclarations, SubprogramDefinitions))
diff --git a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h
index 1cf75d2c640b3..a96ac8e33afed 100644
--- a/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h
+++ b/llvm/lib/Target/SPIRV/SPIRVNonSemanticDebugHandler.h
@@ -70,23 +70,7 @@ class SPIRVNonSemanticDebugHandler : public DebugHandlerBase {
SmallVector<CompileUnitInfo> CompileUnits;
int64_t DwarfVersion = 0;
- // DI types partitioned from DebugInfoFinder.types() in beginModule()
- // (basics, pointers, vectors, subroutine types NSDI v1 may emit).
- SmallVector<const DIBasicType *> BasicTypes;
- SmallVector<const DIDerivedType *> PointerTypes;
- SmallVector<const DISubroutineType *> SubroutineTypes;
- // DICompositeType nodes with DW_TAG_array_type and DINode::FlagVector,
- // partitioned from DebugInfoFinder.types() in beginModule().
- SmallVector<const DICompositeType *> VectorTypes;
- // DICompositeType nodes with DW_TAG_array_type that are not vectors,
- // partitioned in beginModule().
- SmallVector<const DICompositeType *> ArrayTypes;
- // DICompositeType nodes with DW_TAG_structure_type, DW_TAG_class_type, or
- // DW_TAG_union_type, partitioned in beginModule() for DebugTypeComposite.
- SmallVector<const DICompositeType *> CompositeTypes;
- // DIDerivedType nodes with DW_TAG_typedef, partitioned in beginModule() for
- // DebugTypedef emission.
- SmallVector<const DIDerivedType *> TypedefTypes;
+ SmallVector<const DIType *, 8> DebugTypes;
// NonSemantic debug instruction result id per emitted scope.
DenseMap<const DIScope *, MCRegister> DebugScopeRegs;
diff --git a/llvm/test/CodeGen/SPIRV/debug-info/debug-function-declaration-composite-scope.ll b/llvm/test/CodeGen/SPIRV/debug-info/debug-function-declaration-composite-scope.ll
index d1aa0016bffb8..bbd1304b80fcb 100644
--- a/llvm/test/CodeGen/SPIRV/debug-info/debug-function-declaration-composite-scope.ll
+++ b/llvm/test/CodeGen/SPIRV/debug-info/debug-function-declaration-composite-scope.ll
@@ -14,10 +14,10 @@
; CHECK-DAG: [[C0:%[0-9]+]] = OpConstant [[I32]] 0
; CHECK-DAG: [[DS:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugSource [[PATH]]
; CHECK-DAG: [[TF:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugTypeFunction [[C0]] [[VOID]]
-; CHECK: [[C1:%[0-9]+]] = OpConstant [[I32]] 1
-; CHECK: [[S:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugTypeComposite [[SNAME]] [[C1]]
-; CHECK: [[C2:%[0-9]+]] = OpConstant [[I32]] 2
-; CHECK: [[C128:%[0-9]+]] = OpConstant [[I32]] 128
+; CHECK-DAG: [[C1:%[0-9]+]] = OpConstant [[I32]] 1
+; CHECK-DAG: [[S:%[0-9]+]] = OpExtInst [[VOID]] [[EXT]] DebugTypeComposite [[SNAME]] [[C1]]
+; CHECK-DAG: [[C2:%[0-9]+]] = OpConstant [[I32]] 2
+; CHECK-DAG: [[C128:%[0-9]+]] = OpConstant [[I32]] 128
; CHECK: OpExtInst [[VOID]] [[EXT]] DebugFunctionDeclaration [[NAME]] [[TF]] [[DS]] [[C2]] [[C0]] [[S]] [[NAME]] [[C128]]
target triple = "spirv64-unknown-unknown"
More information about the llvm-branch-commits
mailing list