[llvm] r369966 - [DWARF] Pick the DWARF5 OP_entry_value opcode on Darwin

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 26 13:53:12 PDT 2019


Author: vedantk
Date: Mon Aug 26 13:53:12 2019
New Revision: 369966

URL: http://llvm.org/viewvc/llvm-project?rev=369966&view=rev
Log:
[DWARF] Pick the DWARF5 OP_entry_value opcode on Darwin

Use the GNU extension for OP_entry_value consistently (i.e. whenever GNU
extensions are used for TAG_call_site).

Added:
    llvm/trunk/test/DebugInfo/MIR/X86/DW_OP_entry_value.mir
Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp?rev=369966&r1=369965&r2=369966&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp Mon Aug 26 13:53:12 2019
@@ -892,9 +892,13 @@ void DwarfCompileUnit::constructAbstract
     ContextCU->addDIEEntry(*AbsDef, dwarf::DW_AT_object_pointer, *ObjectPointer);
 }
 
+/// Whether to use the GNU analog for a DWARF5 tag, attribute, or location atom.
+static bool useGNUAnalogForDwarf5Feature(DwarfDebug *DD) {
+  return DD->getDwarfVersion() == 4 && DD->tuneForGDB();
+}
+
 dwarf::Tag DwarfCompileUnit::getDwarf5OrGNUCallSiteTag(dwarf::Tag Tag) const {
-  bool ApplyGNUExtensions = DD->getDwarfVersion() == 4 && DD->tuneForGDB();
-  if (!ApplyGNUExtensions)
+  if (!useGNUAnalogForDwarf5Feature(DD))
     return Tag;
   switch (Tag) {
   case dwarf::DW_TAG_call_site:
@@ -908,8 +912,7 @@ dwarf::Tag DwarfCompileUnit::getDwarf5Or
 
 dwarf::Attribute
 DwarfCompileUnit::getDwarf5OrGNUCallSiteAttr(dwarf::Attribute Attr) const {
-  bool ApplyGNUExtensions = DD->getDwarfVersion() == 4 && DD->tuneForGDB();
-  if (!ApplyGNUExtensions)
+  if (!useGNUAnalogForDwarf5Feature(DD))
     return Attr;
   switch (Attr) {
   case dwarf::DW_AT_call_all_calls:
@@ -929,6 +932,18 @@ DwarfCompileUnit::getDwarf5OrGNUCallSite
   }
 }
 
+dwarf::LocationAtom
+DwarfCompileUnit::getDwarf5OrGNULocationAtom(dwarf::LocationAtom Loc) const {
+  if (!useGNUAnalogForDwarf5Feature(DD))
+    return Loc;
+  switch (Loc) {
+  case dwarf::DW_OP_entry_value:
+    return dwarf::DW_OP_GNU_entry_value;
+  default:
+    llvm_unreachable("DWARF5 location atom with no GNU analog");
+  }
+}
+
 DIE &DwarfCompileUnit::constructCallSiteEntryDIE(
     DIE &ScopeDIE, const DISubprogram *CalleeSP, bool IsTail,
     const MCSymbol *PCAddr, const MCExpr *PCOffset, unsigned CallReg) {

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h?rev=369966&r1=369965&r2=369966&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfCompileUnit.h Mon Aug 26 13:53:12 2019
@@ -234,6 +234,9 @@ public:
   /// GNU attribute if needed.
   dwarf::Attribute getDwarf5OrGNUCallSiteAttr(dwarf::Attribute Attr) const;
 
+  /// This takes a DWARF 5 location atom and either returns it or a GNU analog.
+  dwarf::LocationAtom getDwarf5OrGNULocationAtom(dwarf::LocationAtom Loc) const;
+
   /// Construct a call site entry DIE describing a call within \p Scope to a
   /// callee described by \p CalleeSP.
   /// \p IsTail specifies whether the call is a tail call.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp?rev=369966&r1=369965&r2=369966&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfExpression.cpp Mon Aug 26 13:53:12 2019
@@ -311,10 +311,7 @@ void DwarfExpression::addEntryValueExpre
   assert(!isMemoryLocation() &&
          "We don't support entry values of memory locations yet");
 
-  if (DwarfVersion >= 5)
-    emitOp(dwarf::DW_OP_entry_value);
-  else
-    emitOp(dwarf::DW_OP_GNU_entry_value);
+  emitOp(CU.getDwarf5OrGNULocationAtom(dwarf::DW_OP_entry_value));
   emitUnsigned(Op->getArg(0));
 }
 

Added: llvm/trunk/test/DebugInfo/MIR/X86/DW_OP_entry_value.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/MIR/X86/DW_OP_entry_value.mir?rev=369966&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/MIR/X86/DW_OP_entry_value.mir (added)
+++ llvm/trunk/test/DebugInfo/MIR/X86/DW_OP_entry_value.mir Mon Aug 26 13:53:12 2019
@@ -0,0 +1,81 @@
+# RUN: llc -debug-entry-values -mtriple=x86_64-apple-darwin -o %t %s -filetype=obj
+# RUN: llvm-dwarfdump %t | FileCheck %s
+#
+# int global;
+# int foo(int p, int q, int r) {
+#   global = p + 1;
+#   asm __volatile("" : : : "edi", "esi", "edx");
+#   return 123;
+# }
+
+# CHECK: DW_TAG_formal_parameter
+# CHECK:   DW_OP_entry_value
+
+--- |
+  ; ModuleID = 'multiple-param-dbg-value-entry.ll'
+  source_filename = "multiple-param-dbg-value-entry.c"
+  target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+  @global = common dso_local local_unnamed_addr global i32 0, align 4, !dbg !0
+
+  define dso_local i32 @foo(i32 %p, i32 %q, i32 %r) local_unnamed_addr !dbg !11 {
+  entry:
+    call void @llvm.dbg.value(metadata i32 %p, metadata !15, metadata !DIExpression()), !dbg !18
+    call void @llvm.dbg.value(metadata i32 %q, metadata !16, metadata !DIExpression()), !dbg !18
+    call void @llvm.dbg.value(metadata i32 %r, metadata !17, metadata !DIExpression()), !dbg !18
+    %add = add nsw i32 %p, 1, !dbg !18
+    store i32 %add, i32* @global, align 4, !dbg !18
+    tail call void asm sideeffect "", "~{edi},~{esi},~{edx},~{dirflag},~{fpsr},~{flags}"(), !dbg !18, !srcloc !19
+    ret i32 123, !dbg !18
+  }
+
+  ; Function Attrs: nounwind readnone speculatable
+  declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+  !llvm.dbg.cu = !{!2}
+  !llvm.module.flags = !{!7, !8, !9}
+  !llvm.ident = !{!10}
+
+  !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+  !1 = distinct !DIGlobalVariable(name: "global", scope: !2, file: !3, line: 8, type: !6, isLocal: false, isDefinition: true)
+  !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 9.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None)
+  !3 = !DIFile(filename: "multiple-param-dbg-value-entry.c", directory: "/")
+  !4 = !{}
+  !5 = !{!0}
+  !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+  !7 = !{i32 2, !"Dwarf Version", i32 4}
+  !8 = !{i32 2, !"Debug Info Version", i32 3}
+  !9 = !{i32 1, !"wchar_size", i32 4}
+  !10 = !{!"clang version 9.0.0 "}
+  !11 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 9, type: !12, scopeLine: 9, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !14)
+  !12 = !DISubroutineType(types: !13)
+  !13 = !{!6, !6, !6, !6}
+  !14 = !{!15, !16, !17}
+  !15 = !DILocalVariable(name: "p", arg: 1, scope: !11, file: !3, line: 9, type: !6, flags: DIFlagArgumentNotModified)
+  !16 = !DILocalVariable(name: "q", arg: 2, scope: !11, file: !3, line: 9, type: !6, flags: DIFlagArgumentNotModified)
+  !17 = !DILocalVariable(name: "r", arg: 3, scope: !11, file: !3, line: 9, type: !6, flags: DIFlagArgumentNotModified)
+  !18 = !DILocation(line: 9, column: 13, scope: !11)
+  !19 = !{i32 213}
+
+...
+---
+name:            foo
+alignment:       4
+tracksRegLiveness: true
+liveins:
+  - { reg: '$edi' }
+body:             |
+  bb.0.entry:
+    liveins: $edi
+
+    DBG_VALUE $edi, $noreg, !15, !DIExpression(), debug-location !18
+    DBG_VALUE $edi, $noreg, !15, !DIExpression(), debug-location !18
+    DBG_VALUE $esi, $noreg, !16, !DIExpression(), debug-location !18
+    DBG_VALUE $edx, $noreg, !17, !DIExpression(), debug-location !18
+    renamable $edi = nsw INC32r killed renamable $edi, implicit-def dead $eflags, debug-location !18
+    MOV32mr $rip, 1, $noreg, @global, $noreg, killed renamable $edi, debug-location !18 :: (store 4 into @global)
+    INLINEASM &"", 1, 12, implicit-def dead early-clobber $edi, 12, implicit-def dead early-clobber $esi, 12, implicit-def dead early-clobber $edx, 12, implicit-def dead early-clobber $df, 12, implicit-def dead early-clobber $fpsw, 12, implicit-def dead early-clobber $eflags, !19, debug-location !18
+    $eax = MOV32ri 123, debug-location !18
+    RETQ killed $eax, debug-location !18
+
+...




More information about the llvm-commits mailing list