Skip to content

Commit 0368b42

Browse files
committed
[entry values] ARM: Add a describeLoadedValue override (PR45025)
As a narrow stopgap for the assertion failure described in PR45025, add a describeLoadedValue override to ARMBaseInstrInfo and use it to detect copies in which the forwarding reg is a super/sub reg of the copy destination. For the moment this is unsupported. Several follow ups are possible: 1) Handle VORRq. At the moment, we do not, because isCopyInstrImpl returns early when !MI.isMoveReg(). 2) In the case where forwarding reg is a super-reg of the copy destination, we should be able to describe the forwarding reg as a subreg within the copy destination. I'm not 100% sure about this, but it looks like that's what's done in AArch64InstrInfo. 3) In the case where the forwarding reg is a sub-reg of the copy destination, maybe we could describe the forwarding reg using the copy destinaion and a DW_OP_LLVM_fragment (I guess this should be possible after D75036). https://bugs.llvm.org/show_bug.cgi?id=45025 rdar://59772698 Differential Revision: https://reviews.llvm.org/D75273
1 parent 52f889a commit 0368b42

File tree

5 files changed

+237
-0
lines changed

5 files changed

+237
-0
lines changed

llvm/lib/CodeGen/TargetInstrInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,11 @@ TargetInstrInfo::describeLoadedValue(const MachineInstr &MI,
11501150
if (auto DestSrc = isCopyInstr(MI)) {
11511151
Register DestReg = DestSrc->Destination->getReg();
11521152

1153+
// If the copy destination is the forwarding reg, describe the forwarding
1154+
// reg using the copy source as the backup location. Example:
1155+
//
1156+
// x0 = MOV x7
1157+
// call callee(x0) ; x0 described as x7
11531158
if (Reg == DestReg)
11541159
return ParamLoadedValue(*DestSrc->Source, Expr);
11551160

llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,36 @@ ARMBaseInstrInfo::isCopyInstrImpl(const MachineInstr &MI) const {
10271027
return DestSourcePair{MI.getOperand(0), MI.getOperand(1)};
10281028
}
10291029

1030+
Optional<ParamLoadedValue>
1031+
ARMBaseInstrInfo::describeLoadedValue(const MachineInstr &MI,
1032+
Register Reg) const {
1033+
if (auto DstSrcPair = isCopyInstrImpl(MI)) {
1034+
Register DstReg = DstSrcPair->Destination->getReg();
1035+
1036+
// TODO: We don't handle cases where the forwarding reg is narrower/wider
1037+
// than the copy registers. Consider for example:
1038+
//
1039+
// s16 = VMOVS s0
1040+
// s17 = VMOVS s1
1041+
// call @callee(d0)
1042+
//
1043+
// We'd like to describe the call site value of d0 as d8, but this requires
1044+
// gathering and merging the descriptions for the two VMOVS instructions.
1045+
//
1046+
// We also don't handle the reverse situation, where the forwarding reg is
1047+
// narrower than the copy destination:
1048+
//
1049+
// d8 = VMOVD d0
1050+
// call @callee(s1)
1051+
//
1052+
// We need to produce a fragment description (the call site value of s1 is
1053+
// /not/ just d8).
1054+
if (DstReg != Reg)
1055+
return None;
1056+
}
1057+
return TargetInstrInfo::describeLoadedValue(MI, Reg);
1058+
}
1059+
10301060
const MachineInstrBuilder &
10311061
ARMBaseInstrInfo::AddDReg(MachineInstrBuilder &MIB, unsigned Reg,
10321062
unsigned SubIdx, unsigned State,

llvm/lib/Target/ARM/ARMBaseInstrInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ class ARMBaseInstrInfo : public ARMGenInstrInfo {
105105
Optional<DestSourcePair>
106106
isCopyInstrImpl(const MachineInstr &MI) const override;
107107

108+
/// Specialization of \ref TargetInstrInfo::describeLoadedValue, used to
109+
/// enhance debug entry value descriptions for ARM targets.
110+
Optional<ParamLoadedValue> describeLoadedValue(const MachineInstr &MI,
111+
Register Reg) const override;
112+
108113
public:
109114
// Return whether the target has an explicit NOP encoding.
110115
bool hasNOP() const;
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# RUN: llc -O1 -debug-entry-values -filetype=obj -mtriple thumbv7em-apple-unknown-macho -start-after=machineverifier %s -o %t.o
2+
# RUN: llvm-dwarfdump %t.o | FileCheck %s
3+
4+
# Crash test, reduced from:
5+
#
6+
# a(float);
7+
# b(double c) {
8+
# d();
9+
# a(c);
10+
# }
11+
#
12+
# Some minor surgery was performed on the MIR to remove a call to a truncating
13+
# cast builtin between the calls to "d" and "a", and to force d0 as the copy dst
14+
# and s0 as the forwarding reg.
15+
#
16+
# This was done to test the case where the copy dst (d0) is a super-reg of the
17+
# forwarding reg (s0).
18+
19+
# CHECK: DW_TAG_GNU_call_site
20+
# CHECK-NEXT: DW_AT_abstract_origin {{.*}} "a"
21+
# CHECK-NOT: call_site_parameter
22+
23+
--- |
24+
target datalayout = "e-m:o-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
25+
target triple = "thumbv7em-apple-unknown-macho"
26+
; Function Attrs: nounwind optsize uwtable
27+
define arm_aapcs_vfpcc i32 @b(double %c) local_unnamed_addr #0 !dbg !16 {
28+
entry:
29+
call void @llvm.dbg.value(metadata double %c, metadata !21, metadata !DIExpression()), !dbg !22
30+
%call = tail call arm_aapcs_vfpcc i32 bitcast (i32 (...)* @d to i32 ()*)(), !dbg !23
31+
%conv = fptrunc double %c to float, !dbg !24
32+
%call1 = tail call arm_aapcs_vfpcc i32 @a(float %conv), !dbg !25
33+
ret i32 undef, !dbg !26
34+
}
35+
declare arm_aapcs_vfpcc i32 @d(...) local_unnamed_addr #0
36+
declare !dbg !4 arm_aapcs_vfpcc i32 @a(float) local_unnamed_addr #0
37+
declare void @llvm.dbg.value(metadata, metadata, metadata)
38+
declare void @llvm.stackprotector(i8*, i8**)
39+
40+
attributes #0 = { "disable-tail-calls"="false" "frame-pointer"="all" }
41+
42+
!llvm.dbg.cu = !{!0}
43+
!llvm.module.flags = !{!10, !11, !12, !13, !14}
44+
!llvm.ident = !{!15}
45+
46+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 ([email protected]:apple/llvm-project.git 6203ec90d0bb0fd705fc0ad00ee263e5579aa709)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None)
47+
!1 = !DIFile(filename: "jnyn_freeBSD.c", directory: "/Users/vsk/tmp/jnyn")
48+
!2 = !{}
49+
!3 = !{!4}
50+
!4 = !DISubprogram(name: "a", scope: !5, file: !5, line: 1, type: !6, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
51+
!5 = !DIFile(filename: "unreduced2.c", directory: "/Users/vsk/tmp/jnyn")
52+
!6 = !DISubroutineType(types: !7)
53+
!7 = !{!8, !9}
54+
!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
55+
!9 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
56+
!10 = !{i32 7, !"Dwarf Version", i32 4}
57+
!11 = !{i32 2, !"Debug Info Version", i32 3}
58+
!12 = !{i32 1, !"wchar_size", i32 4}
59+
!13 = !{i32 1, !"min_enum_size", i32 4}
60+
!14 = !{i32 7, !"PIC Level", i32 2}
61+
!15 = !{!"clang version 10.0.0 ([email protected]:apple/llvm-project.git 6203ec90d0bb0fd705fc0ad00ee263e5579aa709)"}
62+
!16 = distinct !DISubprogram(name: "b", scope: !5, file: !5, line: 2, type: !17, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !20)
63+
!17 = !DISubroutineType(types: !18)
64+
!18 = !{!8, !19}
65+
!19 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)
66+
!20 = !{!21}
67+
!21 = !DILocalVariable(name: "c", arg: 1, scope: !16, file: !5, line: 2, type: !19)
68+
!22 = !DILocation(line: 0, scope: !16)
69+
!23 = !DILocation(line: 3, column: 3, scope: !16)
70+
!24 = !DILocation(line: 4, column: 5, scope: !16)
71+
!25 = !DILocation(line: 4, column: 3, scope: !16)
72+
!26 = !DILocation(line: 5, column: 1, scope: !16)
73+
74+
...
75+
---
76+
name: b
77+
callSites:
78+
- { bb: 0, offset: 12, fwdArgRegs: [] }
79+
- { bb: 0, offset: 15, fwdArgRegs:
80+
- { arg: 0, reg: '$s0' } }
81+
body: |
82+
bb.0.entry:
83+
liveins: $d0, $lr, $d8
84+
85+
DBG_VALUE $d0, $noreg, !21, !DIExpression(), debug-location !22
86+
frame-setup tPUSH 14, $noreg, $r7, killed $lr, implicit-def $sp, implicit $sp
87+
frame-setup CFI_INSTRUCTION def_cfa_offset 8
88+
frame-setup CFI_INSTRUCTION offset $lr, -4
89+
frame-setup CFI_INSTRUCTION offset $r7, -8
90+
$r7 = frame-setup tMOVr $sp, 14, $noreg
91+
frame-setup CFI_INSTRUCTION def_cfa_register $r7
92+
$sp = frame-setup VSTMDDB_UPD $sp, 14, $noreg, killed $d8
93+
frame-setup CFI_INSTRUCTION offset $d8, -16
94+
$s16 = VMOVS killed $s0, 14, $noreg
95+
$s17 = VMOVS killed $s1, 14, $noreg, implicit-def $d8
96+
DBG_VALUE $d8, $noreg, !21, !DIExpression(), debug-location !22
97+
tBL 14, $noreg, @d, csr_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $r0, debug-location !23
98+
$d0 = VMOVD killed $d8, 14, $noreg, debug-location !24
99+
DBG_VALUE $d0, $noreg, !21, !DIExpression(), debug-location !22
100+
tTAILJMPd @a, 14, $noreg, implicit $sp, implicit $sp, implicit killed $s0, debug-location !25
101+
102+
...
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# RUN: llc -O1 -debug-entry-values -filetype=obj -mtriple thumbv7em-apple-unknown-macho -start-after=machineverifier %s -o %t.o
2+
# RUN: llvm-dwarfdump %t.o | FileCheck %s
3+
4+
# Crash test, reduced from:
5+
#
6+
# a(double);
7+
# b(double c) {
8+
# d();
9+
# a(c);
10+
# }
11+
12+
# CHECK: DW_TAG_GNU_call_site
13+
# CHECK-NEXT: DW_AT_abstract_origin {{.*}} "a"
14+
# CHECK-NOT: call_site_parameter
15+
16+
--- |
17+
; ModuleID = 'unreduced.c'
18+
source_filename = "unreduced.c"
19+
target datalayout = "e-m:o-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
20+
target triple = "thumbv7em-apple-unknown-macho"
21+
; Function Attrs: nounwind optsize uwtable
22+
define arm_aapcs_vfpcc i32 @b(double %c) local_unnamed_addr #0 !dbg !16 {
23+
entry:
24+
call void @llvm.dbg.value(metadata double %c, metadata !18, metadata !DIExpression()), !dbg !19
25+
%call = tail call arm_aapcs_vfpcc i32 bitcast (i32 (...)* @d to i32 ()*)(), !dbg !20
26+
%call1 = tail call arm_aapcs_vfpcc i32 @a(double %c), !dbg !21
27+
ret i32 undef, !dbg !22
28+
}
29+
declare arm_aapcs_vfpcc i32 @d(...) local_unnamed_addr #0
30+
declare !dbg !4 arm_aapcs_vfpcc i32 @a(double) local_unnamed_addr #0
31+
declare void @llvm.dbg.value(metadata, metadata, metadata)
32+
declare void @llvm.stackprotector(i8*, i8**)
33+
34+
attributes #0 = { "disable-tail-calls"="false" "frame-pointer"="all" }
35+
36+
!llvm.dbg.cu = !{!0}
37+
!llvm.module.flags = !{!10, !11, !12, !13, !14}
38+
!llvm.ident = !{!15}
39+
40+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0 ([email protected]:apple/llvm-project.git 6203ec90d0bb0fd705fc0ad00ee263e5579aa709)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, nameTableKind: None)
41+
!1 = !DIFile(filename: "jnyn_freeBSD.c", directory: "/Users/vsk/tmp/jnyn")
42+
!2 = !{}
43+
!3 = !{!4}
44+
!4 = !DISubprogram(name: "a", scope: !5, file: !5, line: 1, type: !6, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
45+
!5 = !DIFile(filename: "unreduced.c", directory: "/Users/vsk/tmp/jnyn")
46+
!6 = !DISubroutineType(types: !7)
47+
!7 = !{!8, !9}
48+
!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
49+
!9 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)
50+
!10 = !{i32 7, !"Dwarf Version", i32 4}
51+
!11 = !{i32 2, !"Debug Info Version", i32 3}
52+
!12 = !{i32 1, !"wchar_size", i32 4}
53+
!13 = !{i32 1, !"min_enum_size", i32 4}
54+
!14 = !{i32 7, !"PIC Level", i32 2}
55+
!15 = !{!"clang version 10.0.0 ([email protected]:apple/llvm-project.git 6203ec90d0bb0fd705fc0ad00ee263e5579aa709)"}
56+
!16 = distinct !DISubprogram(name: "b", scope: !5, file: !5, line: 2, type: !6, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !17)
57+
!17 = !{!18}
58+
!18 = !DILocalVariable(name: "c", arg: 1, scope: !16, file: !5, line: 2, type: !9)
59+
!19 = !DILocation(line: 0, scope: !16)
60+
!20 = !DILocation(line: 3, column: 3, scope: !16)
61+
!21 = !DILocation(line: 4, column: 3, scope: !16)
62+
!22 = !DILocation(line: 5, column: 1, scope: !16)
63+
64+
...
65+
---
66+
name: b
67+
callSites:
68+
- { bb: 0, offset: 12, fwdArgRegs: [] }
69+
- { bb: 0, offset: 18, fwdArgRegs:
70+
- { arg: 0, reg: '$d0' } }
71+
body: |
72+
bb.0.entry:
73+
liveins: $d0, $lr, $d8
74+
75+
DBG_VALUE $d0, $noreg, !18, !DIExpression(), debug-location !19
76+
frame-setup tPUSH 14, $noreg, $r7, killed $lr, implicit-def $sp, implicit $sp
77+
frame-setup CFI_INSTRUCTION def_cfa_offset 8
78+
frame-setup CFI_INSTRUCTION offset $lr, -4
79+
frame-setup CFI_INSTRUCTION offset $r7, -8
80+
$r7 = frame-setup tMOVr $sp, 14, $noreg
81+
frame-setup CFI_INSTRUCTION def_cfa_register $r7
82+
$sp = frame-setup VSTMDDB_UPD $sp, 14, $noreg, killed $d8
83+
frame-setup CFI_INSTRUCTION offset $d8, -16
84+
$s16 = VMOVS killed $s0, 14, $noreg
85+
$s17 = VMOVS killed $s1, 14, $noreg, implicit-def $d8
86+
DBG_VALUE $d8, $noreg, !18, !DIExpression(), debug-location !19
87+
tBL 14, $noreg, @d, csr_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def dead $r0, debug-location !20
88+
$s0 = VMOVS killed $s16, 14, $noreg, debug-location !21
89+
$s1 = VMOVS killed $s17, 14, $noreg, implicit-def $d0, debug-location !21
90+
DBG_VALUE $d0, $noreg, !18, !DIExpression(), debug-location !19
91+
$sp = VLDMDIA_UPD $sp, 14, $noreg, def $d8, debug-location !21
92+
$sp = t2LDMIA_UPD $sp, 14, $noreg, def $r7, def $lr, debug-location !21
93+
tTAILJMPd @a, 14, $noreg, implicit $sp, implicit $sp, implicit killed $d0, debug-location !21
94+
95+
...

0 commit comments

Comments
 (0)