Fix PR26585 by improving the promotion of DBG_VALUEs to DW_AT_locations.

When a variable is described by a single DBG_VALUE instruction we can
often use a more efficient inline DW_AT_location instead of using a
location list.

This commit makes the heuristic that decides when to apply this
optimization stricter by also verifying that the DBG_VALUE is live at the
entry of the function (instead of just checking that it is valid until
the end of the function).

<rdar://problem/24611008>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@262247 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Adrian Prantl 2016-02-29 19:49:46 +00:00
parent b9de197a7a
commit be45c68b8b
8 changed files with 127 additions and 21 deletions

View File

@ -935,6 +935,18 @@ DbgVariable *DwarfDebug::createConcreteVariable(LexicalScope &Scope,
return ConcreteVariables.back().get();
}
// Determine whether this DBG_VALUE is valid at the beginning of the function.
static bool validAtEntry(const MachineInstr *MInsn) {
auto MBB = MInsn->getParent();
// Is it in the entry basic block?
if (!MBB->pred_empty())
return false;
for (MachineBasicBlock::const_reverse_iterator I(MInsn); I != MBB->rend(); ++I)
if (!(I->isDebugValue() || I->getFlag(MachineInstr::FrameSetup)))
return false;
return true;
}
// Find variables for each lexical scope.
void DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU,
const DISubprogram *SP,
@ -967,8 +979,11 @@ void DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU,
const MachineInstr *MInsn = Ranges.front().first;
assert(MInsn->isDebugValue() && "History must begin with debug value");
// Check if the first DBG_VALUE is valid for the rest of the function.
if (Ranges.size() == 1 && Ranges.front().second == nullptr) {
// Check if there is a single DBG_VALUE, valid throughout the function.
// A single constant is also considered valid for the entire function.
if (Ranges.size() == 1 &&
(MInsn->getOperand(0).isImm() ||
(validAtEntry(MInsn) && Ranges.front().second == nullptr))) {
RegVar->initializeDbgValue(MInsn);
continue;
}

View File

@ -19,7 +19,7 @@
; AS in 26163, we expect two ranges (as opposed to one), the first one being zero sized
;
;
; CHECK: 0x00000000: Beginning address offset: 0x0000000000000004
; CHECK: 0x00000025: Beginning address offset: 0x0000000000000004
; CHECK: Ending address offset: 0x0000000000000004
; CHECK: Location description: 10 03 55 93 04
; CHECK: Beginning address offset: 0x0000000000000004

View File

@ -25,15 +25,19 @@
; CHECK: debug_info contents
; 0x74 is DW_OP_breg4, showing that the parameter is accessed indirectly
; (with a zero offset) from the register parameter
; CHECK: DW_AT_location{{.*}}(<0x0{{.}}> 74 00
; CHECK: DW_AT_location [DW_FORM_data4] ([[F_LOC:0x[0-9]*]])
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name{{.*}} = "f"
;
; CHECK: DW_AT_location{{.*}}([[G_LOC:0x[0-9]*]])
; CHECK-NOT: DW_TAG
; CHECK: DW_AT_name{{.*}} = "g"
;
; CHECK: debug_loc contents
; CHECK-NEXT: [[G_LOC]]: Beginning
; CHECK: [[F_LOC]]: Beginning
; CHECK-NEXT: Ending
; CHECK-NEXT: Location description: 74 00
; CHECK: [[G_LOC]]: Beginning
; CHECK-NEXT: Ending
; CHECK-NEXT: Location description: 74 00

View File

@ -17,10 +17,15 @@
;
;
; CHECK: DW_TAG_variable [4]
; rax, piece 0x00000004
; CHECK-NEXT: DW_AT_location [DW_FORM_block1]{{.*}}50 93 04
; CHECK-NEXT: DW_AT_location [DW_FORM_data4] ([[LOC:.*]])
; CHECK-NEXT: DW_AT_name {{.*}}"i1"
;
; CHECK: .debug_loc
; CHECK: [[LOC]]: Beginning address offset: 0x0000000000000004
; CHECK-NEXT: Ending address offset: 0x0000000000000005
; rax, piece 0x00000004
; CHECK-NEXT: Location description: 50 93 04
;
; ModuleID = '/Volumes/Data/llvm/test/DebugInfo/X86/sroasplit-1.ll'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.9.0"

View File

@ -16,19 +16,22 @@
; }
;
; CHECK: DW_TAG_formal_parameter [3]
; CHECK-NEXT: DW_AT_location [DW_FORM_data4] ([[LOC:.*]])
; CHECK-NEXT: DW_AT_location [DW_FORM_data4] ([[LOC1:.*]])
; CHECK-NEXT: DW_AT_name {{.*}}"outer"
; CHECK: DW_TAG_variable
; rsi, piece 0x00000004
; CHECK-NEXT: DW_AT_location [DW_FORM_block1] {{.*}} 54 93 04
; CHECK-NEXT: DW_AT_location [DW_FORM_data4] ([[LOC2:.*]])
; CHECK-NEXT: "i1"
;
; CHECK: .debug_loc
; CHECK: [[LOC]]:
; CHECK: Beginning address offset: 0x0000000000000000
; CHECK: Ending address offset: 0x0000000000000008
; rdi, piece 0x00000008, piece 0x00000004, rsi, piece 0x00000004
; CHECK: Location description: 55 93 08 93 04 54 93 04
; CHECK: [[LOC1]]: Beginning address offset: 0x0000000000000000
; CHECK: Ending address offset: 0x0000000000000008
; rdi, piece 0x00000008, piece 0x00000004, rsi, piece 0x00000004
; CHECK-NEXT: Location description: 55 93 08 93 04 54 93 04
; CHECK: [[LOC2]]: Beginning address offset: 0x0000000000000004
; CHECK-NEXT: Ending address offset: 0x0000000000000008
; rsi, piece 0x00000004
; CHECK-NEXT: Location description: 54 93 04
;
; ModuleID = '/Volumes/Data/llvm/test/DebugInfo/X86/sroasplit-2.ll'
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"

View File

@ -1,8 +1,9 @@
; RUN: llc -mtriple=x86_64-apple-macosx10.9.0 -filetype=obj -O0 < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
; RUN: llc -mtriple=x86_64-apple-macosx10.9.0 -filetype=obj -O0 < %s | llvm-dwarfdump -debug-dump=all - | FileCheck %s
; ModuleID = 'aggregate-indirect-arg.cpp'
; extracted from debuginfo-tests/aggregate-indirect-arg.cpp
; v should be a pointer.
; CHECK: .debug_info contents:
; CHECK: DW_TAG_subprogram
; CHECK: DW_AT_specification {{.*}} "_ZN1A3fooE4SVal"
; CHECK-NOT: DW_TAG_subprogram
@ -10,9 +11,11 @@
; CHECK: DW_AT_name {{.*}} "this"
; CHECK-NOT: DW_TAG_subprogram
; CHECK: DW_TAG_formal_parameter
; rsi+0
; CHECK-NEXT: DW_AT_location [DW_FORM_block1] (<0x02> 74 00{{ *}})
; CHECK-NEXT: DW_AT_location [DW_FORM_data4] (0x00000000)
; CHECK-NEXT: DW_AT_name {{.*}} "v"
; CHECK: .debug_loc contents:
; rsi+0
; CHECK: Location description: 74 00
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.9.0"

View File

@ -0,0 +1,71 @@
; RUN: %llc_dwarf -stop-after=livedebugvalues -o /dev/null %s 2>&1 \
; RUN: | FileCheck %s --check-prefix=SANITY
; RUN: %llc_dwarf -march=x86-64 -o - %s -filetype=obj \
; RUN: | llvm-dwarfdump -debug-dump=all - | FileCheck %s
;
; CHECK: .debug_info contents:
; CHECK: DW_TAG_variable
; CHECK-NEXT: DW_AT_location [DW_FORM_data4]
; CHECK-NEXT: DW_AT_name{{.*}}"a"
; CHECK: .debug_loc contents:
; rax, piece 0x00000004
; CHECK: Location description: 50 93 04
; SANITY: DBG_VALUE
; SANITY-NOT: DBG_VALUE
; ModuleID = 'test.ll'
; Compiled with -O:
; void h(int);
; int g();
; void f() {
; h(0);
; int a = g();
; h(a);
; }
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx"
; Function Attrs: nounwind ssp uwtable
define void @f() #0 !dbg !4 {
entry:
tail call void @h(i32 0) #2, !dbg !14
%call = tail call i32 (...) @g() #2, !dbg !15
tail call void @llvm.dbg.value(metadata i32 %call, i64 0, metadata !8, metadata !16), !dbg !17
tail call void @h(i32 %call) #2, !dbg !18
ret void, !dbg !19
}
declare void @h(i32)
declare i32 @g(...)
; Function Attrs: nounwind readnone
declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1
attributes #0 = { nounwind ssp uwtable "no-frame-pointer-elim"="true" }
attributes #1 = { nounwind readnone }
attributes #2 = { nounwind }
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!10, !11, !12}
!llvm.ident = !{!13}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3)
!1 = !DIFile(filename: "test.c", directory: "/Volumes/Data/llvm")
!2 = !{}
!3 = !{!4}
!4 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, variables: !7)
!5 = !DISubroutineType(types: !6)
!6 = !{null}
!7 = !{!8}
!8 = !DILocalVariable(name: "a", scope: !4, file: !1, line: 5, type: !9)
!9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!10 = !{i32 2, !"Dwarf Version", i32 2}
!11 = !{i32 2, !"Debug Info Version", i32 3}
!12 = !{i32 1, !"PIC Level", i32 2}
!13 = !{!"clang version 3.9.0 "}
!14 = !DILocation(line: 4, column: 3, scope: !4)
!15 = !DILocation(line: 5, column: 11, scope: !4)
!16 = !DIExpression()
!17 = !DILocation(line: 5, column: 7, scope: !4)
!18 = !DILocation(line: 6, column: 3, scope: !4)
!19 = !DILocation(line: 7, column: 1, scope: !4)

View File

@ -6,8 +6,13 @@
;
; rdar://problem/16015314
;
; CHECK: DW_AT_location [DW_FORM_block1] (<0x03> 54 93 04 )
; CHECK: DW_AT_name [DW_FORM_strp]{{.*}} "a"
; CHECK: .debug_info contents:
; CHECK: DW_TAG_variable
; CHECK-NEXT: DW_AT_location [DW_FORM_data4] (0x00000000)
; CHECK-NEXT: DW_AT_name [DW_FORM_strp]{{.*}} "a"
; CHECK: .debug_loc contents:
; rsi, piece 0x00000004
; CHECK: Location description: 54 93 04
;
; struct bar {
; int a;