Skip to content

Commit 931524f

Browse files
committed
Fixes in DebugLine and lit test
1 parent 2af47fb commit 931524f

File tree

2 files changed

+143
-5
lines changed

2 files changed

+143
-5
lines changed

llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,8 @@ bool SPIRVEmitNonSemanticDI::emitGlobalDI(MachineFunction &MF, const Module *M,
603603
// pointed on from other DI types
604604
// DerivedType->getBaseType is null when pointer
605605
// is representing a void type
606-
if (DerivedType->getBaseType()) {
607-
const auto *BasicType =
608-
cast<DIBasicType>(DerivedType->getBaseType());
606+
if (const auto *BasicType = dyn_cast_if_present<DIBasicType>(
607+
DerivedType->getBaseType())) {
609608
const size_t BTIdx = emitDebugTypeBasic(BasicType, I32ZeroIdx,
610609
MIRBuilder, TM, LR);
611610
emitDebugTypePointer(DerivedType, BTIdx, I32ZeroIdx, MIRBuilder,
@@ -627,13 +626,13 @@ bool SPIRVEmitNonSemanticDI::emitLineDI(MachineFunction &MF,
627626
LiveRepository &LR) const {
628627
for (auto &MBB : MF) {
629628
for (auto &MI : MBB) {
630-
if (MI.isDebugValue()) {
629+
if (MI.getDebugLoc().get()) {
631630
MachineIRBuilder MIRBuilder(MBB, MI);
632631
DebugLoc DL = MI.getDebugLoc();
633632
const auto *File = cast<DISubprogram>(DL.getScope())->getFile();
634633
const size_t ScopeIdx = emitDebugSource(File, MIRBuilder, TM, LR);
635634
const size_t LineIdx = LR.push(DL.getLine(), MIRBuilder, TM);
636-
const size_t ColIdx = LR.push(DL.getLine(), MIRBuilder, TM);
635+
const size_t ColIdx = LR.push(DL.getCol(), MIRBuilder, TM);
637636
LR.push<DebugLine>({ScopeIdx, LineIdx, LineIdx, ColIdx, ColIdx},
638637
MIRBuilder, TM);
639638
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
; RUN: llc --verify-machineinstrs --spv-emit-nonsemantic-debug-info --spirv-ext=+SPV_KHR_non_semantic_info --print-after=spirv-nonsemantic-debug-info -O0 -mtriple=spirv64-unknown-unknown %s -o - 2>&1 | FileCheck %s --check-prefix=CHECK-MIR
2+
; RUN: llc --verify-machineinstrs --spv-emit-nonsemantic-debug-info --spirv-ext=+SPV_KHR_non_semantic_info -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s --check-prefix=CHECK-SPIRV
3+
; RUN: %if spirv-tools %{ llc --verify-machineinstrs --spv-emit-nonsemantic-debug-info --spirv-ext=+SPV_KHR_non_semantic_info -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
4+
5+
; CHECK-MIR-DAG: [[void:%[0-9]+\:[a-z\(\)0-9]+]] = OpTypeVoid
6+
; CHECK-MIR-DAG: [[i32:%[0-9]+\:[a-z\(\)0-9]+]] = OpTypeInt 32, 0
7+
; CHECK-MIR-DAG: [[i32_1:%[0-9]+\:[a-z\(\)0-9]+]] = OpConstantI [[i32]], 1
8+
; CHECK-MIR-DAG: [[i32_6:%[0-9]+\:[a-z\(\)0-9]+]] = OpConstantI [[i32]], 6
9+
; CHECK-MIR-DAG: [[i32_10:%[0-9]+\:[a-z\(\)0-9]+]] = OpConstantI [[i32]], 10
10+
; CHECK-MIR-DAG: [[i32_5:%[0-9]+\:[a-z\(\)0-9]+]] = OpConstantI [[i32]], 5
11+
; CHECK-MIR-DAG: [[i32_3:%[0-9]+\:[a-z\(\)0-9]+]] = OpConstantI [[i32]], 3
12+
; CHECK-MIR-DAG: [[i32_32:%[0-9]+\:[a-z\(\)0-9]+]] = OpConstantI [[i32]], 32
13+
; CHECK-MIR-DAG: [[i32_4:%[0-9]+\:[a-z\(\)0-9]+]] = OpConstantI [[i32]], 4
14+
; CHECK-MIR-DAG: [[i32_11:%[0-9]+\:[a-z\(\)0-9]+]] = OpConstantI [[i32]], 11
15+
; CHECK-MIR-DAG: [[i32_2:%[0-9]+\:[a-z\(\)0-9]+]] = OpConstantI [[i32]], 2
16+
; CHECK-MIR-DAG: [[i32_7:%[0-9]+\:[a-z\(\)0-9]+]] = OpConstantI [[i32]], 7
17+
; CHECK-MIR-DAG: [[i32_14:%[0-9]+\:[a-z\(\)0-9]+]] = OpConstantI [[i32]], 14
18+
; CHECK-MIR-DAG: [[file_scope:%[0-9]+\:[a-z\(\)0-9]+]] = OpExtInst [[void]], 3, 35
19+
; CHECK-MIR-DAG: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_1]], [[i32_1]], [[i32_14]], [[i32_14]]
20+
; CHECK-MIR-DAG: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_2]], [[i32_2]], [[i32_7]], [[i32_7]]
21+
; CHECK-MIR-DAG: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_2]], [[i32_2]], [[i32_11]], [[i32_11]]
22+
; CHECK-MIR-DAG: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_3]], [[i32_3]], [[i32_7]], [[i32_7]]
23+
; CHECK-MIR-DAG: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_4]], [[i32_4]], [[i32_7]], [[i32_7]]
24+
; CHECK-MIR-DAG: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_5]], [[i32_5]], [[i32_7]], [[i32_7]]
25+
; CHECK-MIR-DAG: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_6]], [[i32_6]], [[i32_10]], [[i32_10]]
26+
; CHECK-MIR-DAG: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_6]], [[i32_6]], [[i32_3]], [[i32_3]]
27+
;
28+
; CHECK-MIR-NOT: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_1]], [[i32_1]], [[i32_14]], [[i32_14]]
29+
; CHECK-MIR-NOT: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_2]], [[i32_2]], [[i32_7]], [[i32_7]]
30+
; CHECK-MIR-NOT: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_2]], [[i32_2]], [[i32_11]], [[i32_11]]
31+
; CHECK-MIR-NOT: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_3]], [[i32_3]], [[i32_7]], [[i32_7]]
32+
; CHECK-MIR-NOT: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_4]], [[i32_4]], [[i32_7]], [[i32_7]]
33+
; CHECK-MIR-NOT: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_5]], [[i32_5]], [[i32_7]], [[i32_7]]
34+
; CHECK-MIR-NOT: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_6]], [[i32_6]], [[i32_10]], [[i32_10]]
35+
; CHECK-MIR-NOT: OpExtInst [[void]], 3, 103, [[file_scope]], [[i32_6]], [[i32_6]], [[i32_3]], [[i32_3]]
36+
37+
; CHECK-SPIRV-DAG: [[nonsemantic_di:%[0-9]+]] = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
38+
; CHECK-SPIRV-DAG: [[i32:%[0-9]+]] = OpTypeInt 32 0
39+
; CHECK-SPIRV-DAG: [[void:%[0-9]+]] = OpTypeVoid
40+
; CHECK-SPIRV-DAG: [[i32_1:%[0-9]+]] = OpConstant [[i32]] 1
41+
; CHECK-SPIRV-DAG: [[i32_5:%[0-9]+]] = OpConstant [[i32]] 5
42+
; CHECK-SPIRV-DAG: [[i32_3:%[0-9]+]] = OpConstant [[i32]] 3
43+
; CHECK-SPIRV-DAG: [[i32_32:%[0-9]+]] = OpConstant [[i32]] 32
44+
; CHECK-SPIRV-DAG: [[i32_4:%[0-9]+]] = OpConstant [[i32]] 4
45+
; CHECK-SPIRV-DAG: [[i32_14:%[0-9]+]] = OpConstant [[i32]] 14
46+
; CHECK-SPIRV-DAG: [[i32_2:%[0-9]+]] = OpConstant [[i32]] 2
47+
; CHECK-SPIRV-DAG: [[i32_7:%[0-9]+]] = OpConstant [[i32]] 7
48+
; CHECK-SPIRV-DAG: [[i32_11:%[0-9]+]] = OpConstant [[i32]] 11
49+
; CHECK-SPIRV-DAG: [[i32_6:%[0-9]+]] = OpConstant [[i32]] 6
50+
; CHECK-SPIRV-DAG: [[i32_10:%[0-9]+]] = OpConstant [[i32]] 10
51+
; CHECK-SPIRV: [[file_source:%[0-9]+]] = OpExtInst [[void]] [[nonsemantic_di]] DebugSource
52+
; CHECK-SPIRV: OpExtInst [[void]] [[nonsemantic_di]] DebugLine [[file_source]] [[i32_1]] [[i32_1]] [[i32_14]] [[i32_14]]
53+
; CHECK-SPIRV: OpExtInst [[void]] [[nonsemantic_di]] DebugLine [[file_source]] [[i32_2]] [[i32_2]] [[i32_7]] [[i32_7]]
54+
; CHECK-SPIRV: OpExtInst [[void]] [[nonsemantic_di]] DebugLine [[file_source]] [[i32_2]] [[i32_2]] [[i32_11]] [[i32_11]]
55+
; CHECK-SPIRV: OpLoad
56+
; CHECK-SPIRV: OpIAdd
57+
; CHECK-SPIRV: OpStore
58+
; CHECK-SPIRV: OpExtInst [[void]] [[nonsemantic_di]] DebugLine [[file_source]] [[i32_3]] [[i32_3]] [[i32_7]] [[i32_7]]
59+
; CHECK-SPIRV: OpExtInst [[void]] [[nonsemantic_di]] DebugLine [[file_source]] [[i32_3]] [[i32_3]] [[i32_11]] [[i32_11]]
60+
; CHECK-SPIRV: OpLoad
61+
; CHECK-SPIRV: OpIAdd
62+
; CHECK-SPIRV: OpStore
63+
; CHECK-SPIRV: OpExtInst [[void]] [[nonsemantic_di]] DebugLine [[file_source]] [[i32_4]] [[i32_4]] [[i32_7]] [[i32_7]]
64+
; CHECK-SPIRV: OpExtInst [[void]] [[nonsemantic_di]] DebugLine [[file_source]] [[i32_4]] [[i32_4]] [[i32_11]] [[i32_11]]
65+
; CHECK-SPIRV: OpLoad
66+
; CHECK-SPIRV: OpIAdd
67+
; CHECK-SPIRV: OpStore
68+
; CHECK-SPIRV: OpExtInst [[void]] [[nonsemantic_di]] DebugLine [[file_source]] [[i32_5]] [[i32_5]] [[i32_7]] [[i32_7]]
69+
; CHECK-SPIRV: OpExtInst [[void]] [[nonsemantic_di]] DebugLine [[file_source]] [[i32_5]] [[i32_5]] [[i32_11]] [[i32_11]]
70+
; CHECK-SPIRV: OpLoad
71+
; CHECK-SPIRV: OpIAdd
72+
; CHECK-SPIRV: OpStore
73+
; CHECK-SPIRV: OpExtInst [[void]] [[nonsemantic_di]] DebugLine [[file_source]] [[i32_6]] [[i32_6]] [[i32_10]] [[i32_10]]
74+
; CHECK-SPIRV: OpLoad
75+
; CHECK-SPIRV: OpExtInst [[void]] [[nonsemantic_di]] DebugLine [[file_source]] [[i32_6]] [[i32_6]] [[i32_3]] [[i32_3]]
76+
77+
define dso_local spir_func i32 @test(i32 noundef %a) #0 !dbg !6 {
78+
entry:
79+
%a.addr = alloca i32, align 4
80+
%b = alloca i32, align 4
81+
%c = alloca i32, align 4
82+
%d = alloca i32, align 4
83+
%e = alloca i32, align 4
84+
store i32 %a, ptr %a.addr, align 4
85+
#dbg_declare(ptr %a.addr, !12, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !13)
86+
#dbg_declare(ptr %b, !14, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !15)
87+
%0 = load i32, ptr %a.addr, align 4, !dbg !16
88+
%add = add nsw i32 %0, 1, !dbg !17
89+
store i32 %add, ptr %b, align 4, !dbg !15
90+
#dbg_declare(ptr %c, !18, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !19)
91+
%1 = load i32, ptr %b, align 4, !dbg !20
92+
%add1 = add nsw i32 %1, 1, !dbg !21
93+
store i32 %add1, ptr %c, align 4, !dbg !19
94+
#dbg_declare(ptr %d, !22, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !23)
95+
%2 = load i32, ptr %c, align 4, !dbg !24
96+
%add2 = add nsw i32 %2, 1, !dbg !25
97+
store i32 %add2, ptr %d, align 4, !dbg !23
98+
#dbg_declare(ptr %e, !26, !DIExpression(DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef), !27)
99+
%3 = load i32, ptr %d, align 4, !dbg !28
100+
%add3 = add nsw i32 %3, 1, !dbg !29
101+
store i32 %add3, ptr %e, align 4, !dbg !27
102+
%4 = load i32, ptr %e, align 4, !dbg !30
103+
ret i32 %4, !dbg !31
104+
}
105+
106+
!llvm.dbg.cu = !{!0}
107+
!llvm.module.flags = !{!2, !3, !4}
108+
109+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version XX.X.Xgit (GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG 9999999999999999999999999999999999999999)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
110+
!1 = !DIFile(filename: "YYYYYYY", directory: "/XXXXXXXXXXXXXXXX/XXXXXXXXXXXXXXXX/XXXXXXXXXXX", checksumkind: CSK_MD5, checksum: "66666666666666666666666666666666")
111+
!2 = !{i32 7, !"Dwarf Version", i32 5}
112+
!3 = !{i32 2, !"Debug Info Version", i32 3}
113+
!4 = !{i32 1, !"wchar_size", i32 4}
114+
!6 = distinct !DISubprogram(name: "test", scope: !7, file: !7, line: 1, type: !8, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !11)
115+
!7 = !DIFile(filename: "ZZZZZ", directory: "YYYYYYYYY/YYYYYYYYYYYY/YYYYYYYYYYYYY/YYYYYYYYY", checksumkind: CSK_MD5, checksum: "77777777777777777777777777777777")
116+
!8 = !DISubroutineType(cc: DW_CC_LLVM_SpirFunction, types: !9)
117+
!9 = !{!10, !10}
118+
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
119+
!11 = !{}
120+
!12 = !DILocalVariable(name: "a", arg: 1, scope: !6, file: !7, line: 1, type: !10)
121+
!13 = !DILocation(line: 1, column: 14, scope: !6)
122+
!14 = !DILocalVariable(name: "b", scope: !6, file: !7, line: 2, type: !10)
123+
!15 = !DILocation(line: 2, column: 7, scope: !6)
124+
!16 = !DILocation(line: 2, column: 11, scope: !6)
125+
!17 = !DILocation(line: 2, column: 13, scope: !6)
126+
!18 = !DILocalVariable(name: "c", scope: !6, file: !7, line: 3, type: !10)
127+
!19 = !DILocation(line: 3, column: 7, scope: !6)
128+
!20 = !DILocation(line: 3, column: 11, scope: !6)
129+
!21 = !DILocation(line: 3, column: 13, scope: !6)
130+
!22 = !DILocalVariable(name: "d", scope: !6, file: !7, line: 4, type: !10)
131+
!23 = !DILocation(line: 4, column: 7, scope: !6)
132+
!24 = !DILocation(line: 4, column: 11, scope: !6)
133+
!25 = !DILocation(line: 4, column: 13, scope: !6)
134+
!26 = !DILocalVariable(name: "e", scope: !6, file: !7, line: 5, type: !10)
135+
!27 = !DILocation(line: 5, column: 7, scope: !6)
136+
!28 = !DILocation(line: 5, column: 11, scope: !6)
137+
!29 = !DILocation(line: 5, column: 13, scope: !6)
138+
!30 = !DILocation(line: 6, column: 10, scope: !6)
139+
!31 = !DILocation(line: 6, column: 3, scope: !6)

0 commit comments

Comments
 (0)