[llvm] r278703 - Local variables whose address is taken and passed on to a call are described

Wolfgang Pieb via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 15 11:18:26 PDT 2016


Author: wolfgangp
Date: Mon Aug 15 13:18:26 2016
New Revision: 278703

URL: http://llvm.org/viewvc/llvm-project?rev=278703&view=rev
Log:
Local variables whose address is taken and passed on to a call are described 
in debug info using their stack slots instead of as an indirection of param reg + 0
offset. This is done by detecting FrameIndexSDNodes in SelectionDAG and generating
FrameIndexDbgValues for them. This ultimately generates DBG_VALUEs with stack
location operands.

Differential Revision: http://reviews.llvm.org/D23283


Added:
    llvm/trunk/test/DebugInfo/X86/debug-loc-frame.ll
Modified:
    llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
    llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
    llvm/trunk/test/DebugInfo/AArch64/coalescing.ll
    llvm/trunk/test/DebugInfo/X86/array.ll
    llvm/trunk/test/DebugInfo/X86/bbjoin.ll
    llvm/trunk/test/DebugInfo/X86/dbg-value-const-byref.ll

Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=278703&r1=278702&r2=278703&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Mon Aug 15 13:18:26 2016
@@ -2155,6 +2155,11 @@ public:
   static bool classof(const Metadata *MD) {
     return MD->getMetadataID() == DIExpressionKind;
   }
+
+  /// \brief Is the first element a DW_OP_deref?.
+  bool startsWithDeref() const {
+    return getNumElements() > 0 && getElement(0) == dwarf::DW_OP_deref;
+  }
 };
 
 class DIObjCProperty : public DINode {

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=278703&r1=278702&r2=278703&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Mon Aug 15 13:18:26 2016
@@ -1020,8 +1020,7 @@ void SelectionDAGBuilder::resolveDanglin
     if (Val.getNode()) {
       if (!EmitFuncArgumentDbgValue(V, Variable, Expr, dl, Offset, false,
                                     Val)) {
-        SDV = DAG.getDbgValue(Variable, Expr, Val.getNode(), Val.getResNo(),
-                              false, Offset, dl, DbgSDNodeOrder);
+        SDV = getDbgValue(Val, Variable, Expr, Offset, dl, DbgSDNodeOrder);
         DAG.AddDbgValue(SDV, Val.getNode(), false);
       }
     } else
@@ -4742,6 +4741,32 @@ bool SelectionDAGBuilder::EmitFuncArgume
   return true;
 }
 
+/// Return the appropriate SDDbgValue based on N.
+SDDbgValue *SelectionDAGBuilder::getDbgValue(SDValue N,
+                                             DILocalVariable *Variable,
+                                             DIExpression *Expr, int64_t Offset,
+                                             DebugLoc dl,
+                                             unsigned DbgSDNodeOrder) {
+  SDDbgValue *SDV;
+  auto *FISDN = dyn_cast<FrameIndexSDNode>(N.getNode());
+  if (FISDN && Expr->startsWithDeref()) {
+    // Construct a FrameIndexDbgValue for FrameIndexSDNodes so we can describe
+    // stack slot locations as such instead of as indirectly addressed
+    // locations.
+    ArrayRef<uint64_t> TrailingElements(Expr->elements_begin() + 1,
+                                        Expr->elements_end());
+    DIExpression *DerefedDIExpr =
+        DIExpression::get(*DAG.getContext(), TrailingElements);
+    int FI = FISDN->getIndex();
+    SDV = DAG.getFrameIndexDbgValue(Variable, DerefedDIExpr, FI, 0, dl,
+                                    DbgSDNodeOrder);
+  } else {
+    SDV = DAG.getDbgValue(Variable, Expr, N.getNode(), N.getResNo(), false,
+                          Offset, dl, DbgSDNodeOrder);
+  }
+  return SDV;
+}
+
 // VisualStudio defines setjmp as _setjmp
 #if defined(_MSC_VER) && defined(setjmp) && \
                          !defined(setjmp_undefined_for_msvc)
@@ -4943,8 +4968,7 @@ SelectionDAGBuilder::visitIntrinsicCall(
       if (N.getNode()) {
         if (!EmitFuncArgumentDbgValue(V, Variable, Expression, dl, Offset,
                                       false, N)) {
-          SDV = DAG.getDbgValue(Variable, Expression, N.getNode(), N.getResNo(),
-                                false, Offset, dl, SDNodeOrder);
+          SDV = getDbgValue(N, Variable, Expression, Offset, dl, SDNodeOrder);
           DAG.AddDbgValue(SDV, N.getNode(), false);
         }
       } else if (!V->use_empty() ) {

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h?rev=278703&r1=278702&r2=278703&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h Mon Aug 15 13:18:26 2016
@@ -942,6 +942,11 @@ private:
   /// Update the DAG and DAG builder with the relevant information after
   /// a new root node has been created which could be a tail call.
   void updateDAGForMaybeTailCall(SDValue MaybeTC);
+
+  /// Return the appropriate SDDbgValue based on N.
+  SDDbgValue *getDbgValue(SDValue N, DILocalVariable *Variable,
+                          DIExpression *Expr, int64_t Offset, DebugLoc dl,
+                          unsigned DbgSDNodeOrder);
 };
 
 /// RegsForValue - This struct represents the registers (physical or virtual)

Modified: llvm/trunk/test/DebugInfo/AArch64/coalescing.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/AArch64/coalescing.ll?rev=278703&r1=278702&r2=278703&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/AArch64/coalescing.ll (original)
+++ llvm/trunk/test/DebugInfo/AArch64/coalescing.ll Mon Aug 15 13:18:26 2016
@@ -25,7 +25,8 @@ entry:
   ; CHECK-NEXT: DW_AT_location
   ; CHECK-NEXT: DW_AT_name {{.*}}"size"
   ; CHECK: .debug_loc contents:
-  ; CHECK: Location description: 70 00
+  ; Expecting the encoding for sp+12: DW_OP_breg31 0c
+  ; CHECK: Location description: 8f 0c
   ret void, !dbg !18
 }
 

Modified: llvm/trunk/test/DebugInfo/X86/array.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/array.ll?rev=278703&r1=278702&r2=278703&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/array.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/array.ll Mon Aug 15 13:18:26 2016
@@ -16,9 +16,7 @@
 ; Test that we only emit register-indirect locations for the array array.
 ; rdar://problem/14874886
 ;
-; FIXME: If we described this location as RSP-relative instead of RDI-relative
-; the live range would be larger.
-; CHECK:     ##DEBUG_VALUE: main:array <- [%RDI+0]
+; CHECK:     ##DEBUG_VALUE: main:array <- [%RSP+0]
 ; CHECK-NOT: ##DEBUG_VALUE: main:array <- %R{{.*}}
 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/bbjoin.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/bbjoin.ll?rev=278703&r1=278702&r2=278703&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/bbjoin.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/bbjoin.ll Mon Aug 15 13:18:26 2016
@@ -12,7 +12,7 @@
 ; CHECK: ![[X:.*]] = !DILocalVariable(name: "x",
 ; CHECK: bb.0.entry:
 ; CHECK:   DBG_VALUE 23, 0, ![[X]],
-; CHECK:   DBG_VALUE debug-use %rdi, debug-use _, ![[X]]
+; CHECK:   DBG_VALUE %rsp, 4, ![[X]]
 ; CHECK: bb.1.if.then:
 ; CHECK:   DBG_VALUE 43, 0, ![[X]],
 ; CHECK: bb.2.if.end:

Modified: llvm/trunk/test/DebugInfo/X86/dbg-value-const-byref.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/dbg-value-const-byref.ll?rev=278703&r1=278702&r2=278703&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/dbg-value-const-byref.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/dbg-value-const-byref.ll Mon Aug 15 13:18:26 2016
@@ -41,7 +41,8 @@
 ;         rdi+0
 ; CHECK: Beginning address offset: [[R1]]
 ; CHECK:    Ending address offset: [[R2:.*]]
-; CHECK:     Location description: 75 00
+; CHECK:     Location description: 77 04
+;         rsp+4
 ;
 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-apple-macosx10.9.0"

Added: llvm/trunk/test/DebugInfo/X86/debug-loc-frame.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/debug-loc-frame.ll?rev=278703&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/debug-loc-frame.ll (added)
+++ llvm/trunk/test/DebugInfo/X86/debug-loc-frame.ll Mon Aug 15 13:18:26 2016
@@ -0,0 +1,113 @@
+; REQUIRES: object-emission
+
+; Check that when variables are allocated on the stack we generate debug locations
+; for the stack location directly instead of generating a register+offset indirection.
+
+; RUN: %llc_dwarf -O2 -filetype=obj -disable-post-ra < %s | llvm-dwarfdump - | FileCheck %s
+;
+; int data = 17;
+; int sum  = 0;
+; int zero = 0;
+; int *ptr;
+;
+; extern void foo(int i, int *p);
+;
+; int main()
+; {
+;   int val;
+;   val = data;
+;   foo(1, &val);
+;   foo(2, &data);
+;   return zero;
+; }
+;
+; CHECK:      .debug_info contents
+; CHECK:      DW_TAG_subprogram
+; CHECK-NOT:  NULL
+; CHECK:      DW_TAG_variable
+; CHECK:      DW_AT_location [DW_FORM_sec_offset] ([[DEBUGLOCOFFSET:0x[0-9a-f]+]]){{[[:space:]].*}}"val"
+
+; See that 'val' has at least one location entry with a DW_op_breg? operand.
+; The DWARF DW_op_breg* ops are encoded from 0x70 to 0x8f, but checking for an
+; op in the range from 0x70 to 0x7f should suffice because that range covers
+; all integer GPRs.
+;
+; CHECK: .debug_loc contents:
+; CHECK-NOT: .debug{{.*}} contents
+; CHECK: [[DEBUGLOCOFFSET]]: Beginning
+; CHECK-NOT: {{0x[0-9a-f]+}}: Beginning
+; CHECK: Location description: 7{{[0-9a-f] .*}}
+
+; ModuleID = 'frame.c'
+source_filename = "frame.c"
+
+ at data = global i32 17, align 4
+ at sum = local_unnamed_addr global i32 0, align 4
+ at zero = local_unnamed_addr global i32 0, align 4
+ at ptr = common local_unnamed_addr global i32* null, align 8
+
+; Function Attrs: nounwind uwtable
+define i32 @main() local_unnamed_addr !dbg !13 {
+entry:
+  %val = alloca i32, align 4
+  %0 = bitcast i32* %val to i8*, !dbg !18
+  call void @llvm.lifetime.start(i64 4, i8* %0), !dbg !18
+  %1 = load i32, i32* @data, align 4, !dbg !19, !tbaa !20
+  tail call void @llvm.dbg.value(metadata i32 %1, i64 0, metadata !17, metadata !24), !dbg !25
+  store i32 %1, i32* %val, align 4, !dbg !26, !tbaa !20
+  tail call void @llvm.dbg.value(metadata i32* %val, i64 0, metadata !17, metadata !27), !dbg !25
+  call void @foo(i32 1, i32* nonnull %val), !dbg !28
+  call void @foo(i32 2, i32* nonnull @data), !dbg !29
+  %2 = load i32, i32* @zero, align 4, !dbg !30, !tbaa !20
+  call void @llvm.lifetime.end(i64 4, i8* %0), !dbg !31
+  ret i32 %2, !dbg !32
+}
+
+; Function Attrs: argmemonly nounwind
+declare void @llvm.lifetime.start(i64, i8* nocapture)
+
+declare void @foo(i32, i32*) local_unnamed_addr
+
+; Function Attrs: argmemonly nounwind
+declare void @llvm.lifetime.end(i64, i8* nocapture)
+
+; Function Attrs: nounwind readnone
+declare void @llvm.dbg.value(metadata, i64, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!10, !11}
+!llvm.ident = !{!12}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 273961)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3)
+!1 = !DIFile(filename: "frame.c", directory: "/home/user/test")
+!2 = !{}
+!3 = !{!4, !6, !7, !8}
+!4 = distinct !DIGlobalVariable(name: "data", scope: !0, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, variable: i32* @data)
+!5 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!6 = distinct !DIGlobalVariable(name: "sum", scope: !0, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, variable: i32* @sum)
+!7 = distinct !DIGlobalVariable(name: "zero", scope: !0, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, variable: i32* @zero)
+!8 = distinct !DIGlobalVariable(name: "ptr", scope: !0, file: !1, line: 4, type: !9, isLocal: false, isDefinition: true, variable: i32** @ptr)
+!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64, align: 64)
+!10 = !{i32 2, !"Dwarf Version", i32 4}
+!11 = !{i32 2, !"Debug Info Version", i32 3}
+!12 = !{!"clang version 3.9.0 (trunk 273961)"}
+!13 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 8, type: !14, isLocal: false, isDefinition: true, scopeLine: 9, isOptimized: true, unit: !0, variables: !16)
+!14 = !DISubroutineType(types: !15)
+!15 = !{!5}
+!16 = !{!17}
+!17 = !DILocalVariable(name: "val", scope: !13, file: !1, line: 10, type: !5)
+!18 = !DILocation(line: 10, column: 3, scope: !13)
+!19 = !DILocation(line: 11, column: 9, scope: !13)
+!20 = !{!21, !21, i64 0}
+!21 = !{!"int", !22, i64 0}
+!22 = !{!"omnipotent char", !23, i64 0}
+!23 = !{!"Simple C/C++ TBAA"}
+!24 = !DIExpression()
+!25 = !DILocation(line: 10, column: 7, scope: !13)
+!26 = !DILocation(line: 11, column: 7, scope: !13)
+!27 = !DIExpression(DW_OP_deref)
+!28 = !DILocation(line: 12, column: 3, scope: !13)
+!29 = !DILocation(line: 13, column: 3, scope: !13)
+!30 = !DILocation(line: 14, column: 10, scope: !13)
+!31 = !DILocation(line: 15, column: 1, scope: !13)
+!32 = !DILocation(line: 14, column: 3, scope: !13)




More information about the llvm-commits mailing list