[llvm] r262247 - Fix PR26585 by improving the promotion of DBG_VALUEs to DW_AT_locations.

Pieb, Wolfgang via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 9 17:25:48 PST 2016


Hi, I noticed that with the following source:

/*========================*/
extern void use(void *, int *);

void foo(void *ptr) {
  int arr[100] = {1};
  use(ptr, arr);
}
/*========================*/

native linux, clang -O2 -march=btver2 -g -c foo.c

After the patch the location for 'ptr' becomes a single-entry location list rather than a DW_AT_location. Should validAtEntry() in DwarfDebug.cpp skip CFI instructions perhaps? I can file a PR if you like.

-- wolfgang

> -----Original Message-----
> From: llvm-commits [mailto:llvm-commits-bounces at lists.llvm.org] On
> Behalf Of Adrian Prantl via llvm-commits
> Sent: Monday, February 29, 2016 11:50 AM
> To: llvm-commits at lists.llvm.org
> Subject: [llvm] r262247 - Fix PR26585 by improving the promotion of
> DBG_VALUEs to DW_AT_locations.
> 
> Author: adrian
> Date: Mon Feb 29 13:49:46 2016
> New Revision: 262247
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=262247&view=rev
> Log:
> 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>
> 
> Added:
>     llvm/trunk/test/DebugInfo/X86/single-dbg_value.ll
> Modified:
>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>     llvm/trunk/test/DebugInfo/X86/PR26148.ll
>     llvm/trunk/test/DebugInfo/X86/parameters.ll
>     llvm/trunk/test/DebugInfo/X86/pieces-2.ll
>     llvm/trunk/test/DebugInfo/X86/pieces-3.ll
>     llvm/trunk/test/DebugInfo/X86/reference-argument.ll
>     llvm/trunk/test/DebugInfo/X86/subregisters.ll
> 
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=262247&r1=
> 262246&r2=262247&view=diff
> =======================================================================
> =======
> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Mon Feb 29
> 13:49:46
> +++ 2016
> @@ -935,6 +935,18 @@ DbgVariable *DwarfDebug::createConcreteV
>    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(Dwa
>      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;
>      }
> 
> Modified: llvm/trunk/test/DebugInfo/X86/PR26148.ll
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/test/DebugInfo/X86/PR26148.ll?rev=262247&r1=262246&r
> 2=262247&view=diff
> =======================================================================
> =======
> --- llvm/trunk/test/DebugInfo/X86/PR26148.ll (original)
> +++ llvm/trunk/test/DebugInfo/X86/PR26148.ll Mon Feb 29 13:49:46 2016
> @@ -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
> 
> Modified: llvm/trunk/test/DebugInfo/X86/parameters.ll
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/test/DebugInfo/X86/parameters.ll?rev=262247&r1=26224
> 6&r2=262247&view=diff
> =======================================================================
> =======
> --- llvm/trunk/test/DebugInfo/X86/parameters.ll (original)
> +++ llvm/trunk/test/DebugInfo/X86/parameters.ll Mon Feb 29 13:49:46
> 2016
> @@ -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
> 
> 
> Modified: llvm/trunk/test/DebugInfo/X86/pieces-2.ll
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/test/DebugInfo/X86/pieces-
> 2.ll?rev=262247&r1=262246&r2=262247&view=diff
> =======================================================================
> =======
> --- llvm/trunk/test/DebugInfo/X86/pieces-2.ll (original)
> +++ llvm/trunk/test/DebugInfo/X86/pieces-2.ll Mon Feb 29 13:49:46 2016
> @@ -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"
> 
> Modified: llvm/trunk/test/DebugInfo/X86/pieces-3.ll
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/test/DebugInfo/X86/pieces-
> 3.ll?rev=262247&r1=262246&r2=262247&view=diff
> =======================================================================
> =======
> --- llvm/trunk/test/DebugInfo/X86/pieces-3.ll (original)
> +++ llvm/trunk/test/DebugInfo/X86/pieces-3.ll Mon Feb 29 13:49:46 2016
> @@ -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"
> 
> Modified: llvm/trunk/test/DebugInfo/X86/reference-argument.ll
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/test/DebugInfo/X86/reference-
> argument.ll?rev=262247&r1=262246&r2=262247&view=diff
> =======================================================================
> =======
> --- llvm/trunk/test/DebugInfo/X86/reference-argument.ll (original)
> +++ llvm/trunk/test/DebugInfo/X86/reference-argument.ll Mon Feb 29
> +++ 13:49:46 2016
> @@ -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"
> 
> Added: llvm/trunk/test/DebugInfo/X86/single-dbg_value.ll
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/test/DebugInfo/X86/single-
> dbg_value.ll?rev=262247&view=auto
> =======================================================================
> =======
> --- llvm/trunk/test/DebugInfo/X86/single-dbg_value.ll (added)
> +++ llvm/trunk/test/DebugInfo/X86/single-dbg_value.ll Mon Feb 29
> +++ 13:49:46 2016
> @@ -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)
> 
> Modified: llvm/trunk/test/DebugInfo/X86/subregisters.ll
> URL: http://llvm.org/viewvc/llvm-
> project/llvm/trunk/test/DebugInfo/X86/subregisters.ll?rev=262247&r1=262
> 246&r2=262247&view=diff
> =======================================================================
> =======
> --- llvm/trunk/test/DebugInfo/X86/subregisters.ll (original)
> +++ llvm/trunk/test/DebugInfo/X86/subregisters.ll Mon Feb 29 13:49:46
> +++ 2016
> @@ -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;
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list