[PATCH] D47663: Add a debug dump for DbgValueHistoryMap

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 1 15:22:59 PDT 2018


vsk created this revision.
vsk added a reviewer: aprantl.

This makes it easier to inspect the results of
DbgValueHistoryCalculator.


https://reviews.llvm.org/D47663

Files:
  lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp
  lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h
  lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
  test/DebugInfo/X86/dump-dbg-value-hist-calc.ll


Index: test/DebugInfo/X86/dump-dbg-value-hist-calc.ll
===================================================================
--- /dev/null
+++ test/DebugInfo/X86/dump-dbg-value-hist-calc.ll
@@ -0,0 +1,21 @@
+; REQUIRES: asserts
+; RUN: opt -S -o - -debugify %s \
+; RUN:   | %llc_dwarf -debug-only=dwarfdebug -o /dev/null 2>&1 \
+; RUN:   | FileCheck %s
+
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx"
+
+; CHECK: DbgValueHistoryMap:
+; CHECK-NEXT:  - 1 at <unknown location> --
+; CHECK-NEXT:    Begin: DBG_VALUE {{.*}} line no:1
+; CHECK-NEXT:    End  : CALL64pcrel32 @h{{.*}}:2:1
+
+define void @f() {
+entry:
+  %a = add i32 0, 0
+  %b = call i32 @h(i32 %a)
+  ret void
+}
+
+declare i32 @h(i32)
Index: lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
+++ lib/CodeGen/AsmPrinter/DebugHandlerBase.cpp
@@ -25,6 +25,8 @@
 
 using namespace llvm;
 
+#define DEBUG_TYPE "dwarfdebug"
+
 Optional<DbgVariableLocation>
 DbgVariableLocation::extractFromMachineInstruction(
     const MachineInstr &Instruction) {
@@ -190,6 +192,7 @@
   assert(DbgValues.empty() && "DbgValues map wasn't cleaned!");
   calculateDbgValueHistory(MF, Asm->MF->getSubtarget().getRegisterInfo(),
                            DbgValues);
+  LLVM_DEBUG(DbgValues.dump());
 
   // Request labels for the full history.
   for (const auto &I : DbgValues) {
Index: lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h
===================================================================
--- lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h
+++ lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h
@@ -52,6 +52,10 @@
   void clear() { VarInstrRanges.clear(); }
   InstrRangesMap::const_iterator begin() const { return VarInstrRanges.begin(); }
   InstrRangesMap::const_iterator end() const { return VarInstrRanges.end(); }
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+  void dump() const;
+#endif
 };
 
 void calculateDbgValueHistory(const MachineFunction *MF,
Index: lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp
+++ lib/CodeGen/AsmPrinter/DbgValueHistoryCalculator.cpp
@@ -269,3 +269,33 @@
     }
   }
 }
+
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+void DbgValueHistoryMap::dump() const {
+  dbgs() << "DbgValueHistoryMap:\n";
+  for (const auto &VarRangePair : *this) {
+    const InlinedVariable &Var = VarRangePair.first;
+    const InstrRanges &Ranges = VarRangePair.second;
+
+    const DILocalVariable *LocalVar = Var.first;
+    const DILocation *Location = Var.second;
+
+    dbgs() << " - " << LocalVar->getName() << " at ";
+
+    if (Location)
+      dbgs() << Location->getFilename() << ":" << Location->getLine() << ":"
+             << Location->getColumn();
+    else
+      dbgs() << "<unknown location>";
+
+    dbgs() << " --\n";
+
+    for (const InstrRange &Range : Ranges) {
+      dbgs() << "   Begin: " << *Range.first;
+      if (Range.second)
+        dbgs() << "   End  : " << *Range.second;
+      dbgs() << "\n";
+    }
+  }
+}
+#endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D47663.149570.patch
Type: text/x-patch
Size: 3240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180601/0ae69663/attachment.bin>


More information about the llvm-commits mailing list