Skip to content

Commit 63d6e3e

Browse files
quic-santdasdzhidzhoevOCHyams
authored
[DebugInfo] Assign best possible debugloc to bundle (llvm#164573)
The debug info attached to the BUNDLE is the first instruction in the BUNDLE, even if a better debug info (line:column) is present in the later instructions of the bundle. The patch tries to get a better debug info first. If not, then a worse debug info without line number is chosen. --------- Co-authored-by: Vladislav Dzhidzhoev <[email protected]> Co-authored-by: Orlando Cazalet-Hyams <[email protected]>
1 parent 3426f9c commit 63d6e3e

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

llvm/lib/CodeGen/MachineInstrBundle.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,21 @@ llvm::createUnpackMachineBundles(
8383
return new UnpackMachineBundles(std::move(Ftor));
8484
}
8585

86-
/// Return the first found DebugLoc that has a DILocation, given a range of
87-
/// instructions. The search range is from FirstMI to LastMI (exclusive). If no
88-
/// DILocation is found, then an empty location is returned.
86+
/// Return the first DebugLoc that has line number information, given a
87+
/// range of instructions. The search range is from FirstMI to LastMI
88+
/// (exclusive). Otherwise return the first DILocation or an empty location if
89+
/// there are none.
8990
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI,
9091
MachineBasicBlock::instr_iterator LastMI) {
91-
for (auto MII = FirstMI; MII != LastMI; ++MII)
92-
if (MII->getDebugLoc())
93-
return MII->getDebugLoc();
94-
return DebugLoc();
92+
DebugLoc DL;
93+
for (auto MII = FirstMI; MII != LastMI; ++MII) {
94+
if (DebugLoc MIIDL = MII->getDebugLoc()) {
95+
if (MIIDL.getLine() != 0)
96+
return MIIDL;
97+
DL = MIIDL.get();
98+
}
99+
}
100+
return DL;
95101
}
96102

97103
/// Check if target reg is contained in given lists, which are:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not "Hexagon" in config.root.targets:
2+
config.unsupported = True
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# RUN: llc -mtriple=hexagon -run-pass hexagon-packetizer %s -o - | FileCheck %s
2+
3+
# CHECK-LABEL: name: factorial
4+
5+
# The first bundle in bb.0 should have debug-location !19 (line 9),
6+
# not !18 (line 0) from the DBG_VALUE instructions.
7+
# CHECK: bb.0:
8+
# CHECK: BUNDLE {{.*}}line: 9
9+
10+
--- |
11+
define void @factorial() { ret void }
12+
13+
!llvm.dbg.cu = !{!2}
14+
!llvm.module.flags = !{!6, !7}
15+
16+
!2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "test", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
17+
!3 = !DIFile(filename: "fact.c", directory: "/test")
18+
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
19+
!6 = !{i32 2, !"Debug Info Version", i32 3}
20+
!7 = !{i32 1, !"wchar_size", i32 4}
21+
!12 = distinct !DISubprogram(name: "factorial", scope: !3, file: !3, line: 6, type: !13, scopeLine: 7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)
22+
!13 = !DISubroutineType(types: !14)
23+
!14 = !{!5, !5}
24+
!16 = !DILocalVariable(name: "i", arg: 1, scope: !12, file: !3, line: 6, type: !5)
25+
!18 = !DILocation(line: 0, scope: !12)
26+
!19 = !DILocation(line: 9, column: 9, scope: !12)
27+
!21 = !DILocation(line: 9, column: 7, scope: !12)
28+
29+
...
30+
---
31+
name: factorial
32+
alignment: 16
33+
tracksRegLiveness: true
34+
body: |
35+
bb.0:
36+
liveins: $r0
37+
38+
DBG_VALUE $r0, $noreg, !16, !DIExpression(), debug-location !18
39+
$r2 = A2_tfr $r0
40+
DBG_VALUE $r2, $noreg, !16, !DIExpression(), debug-location !18
41+
renamable $p0 = C2_cmpeqi killed $r0, 1, debug-location !19
42+
renamable $r0 = A2_tfrsi 1
43+
J2_jumpt killed $p0, %bb.1, implicit-def $pc, debug-location !21
44+
45+
bb.1:
46+
PS_jmpret $r31, implicit-def dead $pc
47+
48+
...

0 commit comments

Comments
 (0)