Skip to content

Commit 34d0865

Browse files
vmaksimoChenyang-L
authored andcommitted
Adjust TypeInheritance for NonSemantic spec (#2039)
It does not have Child parameter comparing to OpenCL specification. https://github.com/KhronosGroup/SPIRV-Registry/blob/main/nonsemantic/NonSemantic.Shader.DebugInfo.100.asciidoc#DebugTypeInheritance Original commit: KhronosGroup/SPIRV-LLVM-Translator@6bd34c8
1 parent 7e710ae commit 34d0865

File tree

5 files changed

+129
-24
lines changed

5 files changed

+129
-24
lines changed

llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,16 +1045,20 @@ LLVMToSPIRVDbgTran::transDbgMemberTypeNonSemantic(const DIDerivedType *MT) {
10451045

10461046
SPIRVEntry *LLVMToSPIRVDbgTran::transDbgInheritance(const DIDerivedType *DT) {
10471047
using namespace SPIRVDebug::Operand::TypeInheritance;
1048-
SPIRVWordVec Ops(OperandCount);
1049-
Ops[ChildIdx] = transDbgEntry(DT->getScope())->getId();
1050-
Ops[ParentIdx] = transDbgEntry(DT->getBaseType())->getId();
1051-
ConstantInt *Offset = getUInt(M, DT->getOffsetInBits());
1052-
Ops[OffsetIdx] = SPIRVWriter->transValue(Offset, nullptr)->getId();
1048+
const SPIRVWord Offset = isNonSemanticDebugInfo() ? 1 : 0;
1049+
SPIRVWordVec Ops(OperandCount - Offset);
1050+
// There is no Child operand in NonSemantic debug spec
1051+
if (!isNonSemanticDebugInfo())
1052+
Ops[ChildIdx] = transDbgEntry(DT->getScope())->getId();
1053+
Ops[ParentIdx - Offset] = transDbgEntry(DT->getBaseType())->getId();
1054+
ConstantInt *OffsetInBits = getUInt(M, DT->getOffsetInBits());
1055+
Ops[OffsetIdx - Offset] =
1056+
SPIRVWriter->transValue(OffsetInBits, nullptr)->getId();
10531057
ConstantInt *Size = getUInt(M, DT->getSizeInBits());
1054-
Ops[SizeIdx] = SPIRVWriter->transValue(Size, nullptr)->getId();
1055-
Ops[FlagsIdx] = transDebugFlags(DT);
1058+
Ops[SizeIdx - Offset] = SPIRVWriter->transValue(Size, nullptr)->getId();
1059+
Ops[FlagsIdx - Offset] = transDebugFlags(DT);
10561060
if (isNonSemanticDebugInfo())
1057-
transformToConstant(Ops, {FlagsIdx});
1061+
transformToConstant(Ops, {FlagsIdx - Offset});
10581062
return BM->addDebugInfo(SPIRVDebug::TypeInheritance, getVoidTy(), Ops);
10591063
}
10601064

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,11 @@ SPIRVToLLVMDbgTran::transTypeComposite(const SPIRVExtInst *DebugInst) {
537537
transTypeMember(SPVMemberInst, DebugInst, cast<DIScope>(CT));
538538
EltTys.push_back(MemberMD);
539539
DebugInstCache[SPVMemberInst] = MemberMD;
540+
} else if (MemberInst->getExtOp() == SPIRVDebug::TypeInheritance) {
541+
auto *SPVMemberInst = BM->get<SPIRVExtInst>(Ops[I]);
542+
DINode *MemberMD = transTypeInheritance(SPVMemberInst, cast<DIType>(CT));
543+
EltTys.push_back(MemberMD);
544+
DebugInstCache[SPVMemberInst] = MemberMD;
540545
} else {
541546
EltTys.emplace_back(transDebugInst(BM->get<SPIRVExtInst>(Ops[I])));
542547
}
@@ -1142,25 +1147,35 @@ DINode *SPIRVToLLVMDbgTran::transTypedef(const SPIRVExtInst *DebugInst) {
11421147
return getDIBuilder(DebugInst).createTypedef(Ty, Alias, File, LineNo, Scope);
11431148
}
11441149

1145-
DINode *
1146-
SPIRVToLLVMDbgTran::transTypeInheritance(const SPIRVExtInst *DebugInst) {
1150+
DINode *SPIRVToLLVMDbgTran::transTypeInheritance(const SPIRVExtInst *DebugInst,
1151+
DIType *ChildClass) {
1152+
if (isNonSemanticDebugInfo(DebugInst->getExtSetKind()) && !ChildClass) {
1153+
// Will be translated later when processing TypeMember's parent
1154+
return nullptr;
1155+
}
11471156
using namespace SPIRVDebug::Operand::TypeInheritance;
11481157
const SPIRVWordVec &Ops = DebugInst->getArguments();
1149-
assert(Ops.size() >= OperandCount && "Invalid number of operands");
1158+
assert(Ops.size() >= MinOperandCount && "Invalid number of operands");
1159+
// No Child operand for NonSemantic debug spec
1160+
SPIRVWord Offset = isNonSemanticDebugInfo(DebugInst->getExtSetKind()) ? 1 : 0;
11501161
DIType *Parent =
1151-
transDebugInst<DIType>(BM->get<SPIRVExtInst>(Ops[ParentIdx]));
1152-
DIType *Child = transDebugInst<DIType>(BM->get<SPIRVExtInst>(Ops[ChildIdx]));
1162+
transDebugInst<DIType>(BM->get<SPIRVExtInst>(Ops[ParentIdx - Offset]));
1163+
DIType *Child =
1164+
isNonSemanticDebugInfo(DebugInst->getExtSetKind())
1165+
? ChildClass
1166+
: transDebugInst<DIType>(BM->get<SPIRVExtInst>(Ops[ChildIdx]));
11531167
DINode::DIFlags Flags = DINode::FlagZero;
1154-
SPIRVWord SPIRVFlags =
1155-
getConstantValueOrLiteral(Ops, FlagsIdx, DebugInst->getExtSetKind());
1168+
SPIRVWord SPIRVFlags = getConstantValueOrLiteral(Ops, FlagsIdx - Offset,
1169+
DebugInst->getExtSetKind());
11561170
if ((SPIRVFlags & SPIRVDebug::FlagAccess) == SPIRVDebug::FlagIsPublic)
11571171
Flags |= llvm::DINode::FlagPublic;
11581172
if ((SPIRVFlags & SPIRVDebug::FlagAccess) == SPIRVDebug::FlagIsProtected)
11591173
Flags |= llvm::DINode::FlagProtected;
11601174
if ((SPIRVFlags & SPIRVDebug::FlagAccess) == SPIRVDebug::FlagIsPrivate)
11611175
Flags |= llvm::DINode::FlagPrivate;
1162-
uint64_t Offset = BM->get<SPIRVConstant>(Ops[OffsetIdx])->getZExtIntValue();
1163-
return getDIBuilder(DebugInst).createInheritance(Child, Parent, Offset, 0,
1176+
uint64_t OffsetVal =
1177+
BM->get<SPIRVConstant>(Ops[OffsetIdx - Offset])->getZExtIntValue();
1178+
return getDIBuilder(DebugInst).createInheritance(Child, Parent, OffsetVal, 0,
11641179
Flags);
11651180
}
11661181

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ class SPIRVToLLVMDbgTran {
166166

167167
DINode *transTypedef(const SPIRVExtInst *DebugInst);
168168

169-
DINode *transTypeInheritance(const SPIRVExtInst *DebugInst);
169+
DINode *transTypeInheritance(const SPIRVExtInst *DebugInst,
170+
DIType *ChildClass = nullptr);
170171

171172
DINode *transImportedEntry(const SPIRVExtInst *DebugInst);
172173

llvm-spirv/lib/SPIRV/libSPIRV/SPIRV.debug.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,12 +501,14 @@ enum {
501501

502502
namespace TypeInheritance {
503503
enum {
504-
ChildIdx = 0,
505-
ParentIdx = 1,
506-
OffsetIdx = 2,
507-
SizeIdx = 3,
508-
FlagsIdx = 4,
509-
OperandCount = 5
504+
ChildIdx = 0,
505+
ParentIdx = 1,
506+
OffsetIdx = 2,
507+
SizeIdx = 3,
508+
FlagsIdx = 4,
509+
// NonSemantic
510+
MinOperandCount = 4,
511+
OperandCount = 5
510512
};
511513
}
512514

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -spirv-text -o %t.spt
3+
; RUN: FileCheck %s --input-file %t.spt --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-OCL
4+
; RUN: llvm-spirv %t.bc -o %t.spv
5+
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc
6+
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
7+
; RUN: FileCheck %s --input-file %t.rev.ll --check-prefix CHECK-LLVM
8+
9+
; RUN: llvm-spirv %t.bc -spirv-text --spirv-debug-info-version=nonsemantic-shader-100 -o %t.spt
10+
; RUN: FileCheck %s --input-file %t.spt --check-prefixes=CHECK-SPIRV,CHECK-SPIRV-NONSEM
11+
; RUN: llvm-spirv %t.bc --spirv-debug-info-version=nonsemantic-shader-100 -o %t.spv
12+
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.rev.bc
13+
; RUN: llvm-dis %t.rev.bc -o %t.rev.ll
14+
; RUN: FileCheck %s --input-file %t.rev.ll --check-prefix CHECK-LLVM
15+
16+
; CHECK-SPIRV: String [[#Str_C:]] "C"
17+
; CHECK-SPIRV: String [[#Str_B:]] "B"
18+
; CHECK-SPIRV: String [[#Str_A:]] "A"
19+
20+
; CHECK-SPIRV: [[#Class_A:]] [[#]] DebugTypeComposite [[#Str_A]]
21+
22+
; CHECK-SPIRV-OCL: [[#B_inherits_A:]] [[#]] DebugTypeInheritance [[#Class_B:]] [[#Class_A]] [[#]] [[#]] [[#]] {{$}}
23+
; CHECK-SPIRV-NONSEM: [[#B_inherits_A:]] [[#]] DebugTypeInheritance [[#Class_A]] [[#]] [[#]] [[#]] {{$}}
24+
; CHECK-SPIRV: [[#Class_B:]] [[#]] DebugTypeComposite [[#Str_B]] {{.*}} [[#B_inherits_A]]
25+
26+
; CHECK-SPIRV-OCL: [[#C_inherits_B:]] [[#]] DebugTypeInheritance [[#Class_C:]] [[#Class_B]] [[#]] [[#]] [[#]] {{$}}
27+
; CHECK-SPIRV-NONSEM: [[#C_inherits_B:]] [[#]] DebugTypeInheritance [[#Class_B]] [[#]] [[#]] [[#]] {{$}}
28+
; CHECK-SPIRV: [[#Class_C:]] [[#]] DebugTypeComposite [[#Str_C]] {{.*}} [[#C_inherits_B]]
29+
30+
; CHECK-LLVM: ![[#Class_C:]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "C"{{.*}}identifier: "_ZTS1C")
31+
; CHECK-LLVM: !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[#Class_C]], baseType: ![[#Class_B:]]
32+
; CHECK-LLVM: ![[#Class_B]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "B"{{.*}}identifier: "_ZTS1B")
33+
; CHECK-LLVM: !DIDerivedType(tag: DW_TAG_inheritance, scope: ![[#Class_B]], baseType: ![[#Class_A:]]
34+
; CHECK-LLVM: ![[#Class_A]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: "A"{{.*}}identifier: "_ZTS1A")
35+
36+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
37+
target triple = "spir64-unknown-unknown"
38+
39+
%class.C = type { i8 }
40+
41+
; Function Attrs: mustprogress noinline nounwind optnone uwtable
42+
define dso_local noundef i32 @_Z3foov() #0 !dbg !10 {
43+
%1 = alloca %class.C, align 1
44+
call void @llvm.dbg.declare(metadata ptr %1, metadata !16, metadata !DIExpression()), !dbg !24
45+
ret i32 0, !dbg !25
46+
}
47+
48+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
49+
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
50+
51+
attributes #0 = { mustprogress noinline nounwind optnone uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
52+
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
53+
54+
!llvm.dbg.cu = !{!0}
55+
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
56+
!llvm.ident = !{!9}
57+
58+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 17.0.0 (https://github.com/llvm/llvm-project.git 1f8a33c19c79fd4649a07eb70ea394c60a8ce316)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
59+
!1 = !DIFile(filename: "/app/example.cpp", directory: "/app")
60+
!2 = !{i32 7, !"Dwarf Version", i32 4}
61+
!3 = !{i32 2, !"Debug Info Version", i32 3}
62+
!4 = !{i32 1, !"wchar_size", i32 4}
63+
!5 = !{i32 8, !"PIC Level", i32 2}
64+
!6 = !{i32 7, !"PIE Level", i32 2}
65+
!7 = !{i32 7, !"uwtable", i32 2}
66+
!8 = !{i32 7, !"frame-pointer", i32 2}
67+
!9 = !{!"clang version 17.0.0 (https://github.com/llvm/llvm-project.git 1f8a33c19c79fd4649a07eb70ea394c60a8ce316)"}
68+
!10 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !11, file: !11, line: 4, type: !12, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !15)
69+
!11 = !DIFile(filename: "example.cpp", directory: "/app")
70+
!12 = !DISubroutineType(types: !13)
71+
!13 = !{!14}
72+
!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
73+
!15 = !{}
74+
!16 = !DILocalVariable(name: "c", scope: !10, file: !11, line: 7, type: !17)
75+
!17 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "C", file: !11, line: 3, size: 8, flags: DIFlagTypePassByValue, elements: !18, identifier: "_ZTS1C")
76+
!18 = !{!19}
77+
!19 = !DIDerivedType(tag: DW_TAG_inheritance, scope: !17, baseType: !20, flags: DIFlagPublic, extraData: i32 0)
78+
!20 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "B", file: !11, line: 2, size: 8, flags: DIFlagTypePassByValue, elements: !21, identifier: "_ZTS1B")
79+
!21 = !{!22}
80+
!22 = !DIDerivedType(tag: DW_TAG_inheritance, scope: !20, baseType: !23, flags: DIFlagPublic, extraData: i32 0)
81+
!23 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "A", file: !11, line: 1, size: 8, flags: DIFlagTypePassByValue, elements: !15, identifier: "_ZTS1A")
82+
!24 = !DILocation(line: 7, column: 11, scope: !10)
83+
!25 = !DILocation(line: 8, column: 3, scope: !10)

0 commit comments

Comments
 (0)