[PATCH] D16569: Emit line 0 line information for interesting 'orphan' instructions

Frederic Riss via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 25 19:02:06 PST 2016


friss created this revision.
friss added reviewers: aprantl, dblaikie, echristo, probinson.
friss added a subscriber: llvm-commits.

There will always be instructions with no line information attached.
One example is the LocalArea constants generated by FastISel, but it's
by far not the only one. Compiler generated code will have no line info
and might get inlined. SelectionDAG is full of nodes that won't have
any line information (because they could be shared).

Multiple attempts have been made over time to fix the FastISel issue,
but none have felt satisfactory enough to be commited. As the prolem
is much more general than just FastISel, this patch addresses it
at line table emission time rather than instruction selection time.

It also doesn't try to give accurate line information for these
instructions, but rather marks them with a 0 line information so that
the debugger can safely ignore them.

The implemented heuristic will add a line 0 information to every insn
missing a line information and either:
 - at the beginning of a basic-block
 - after a call
 - first instruction after a label

The first 2 conditions handle the FastISel case, while the later enforces
that any instruction referenced by anything (including debug info) has
line information.

The initial measurments on line table size show an impact between 5% and 15%
(the latter is for a control-flow heavy code eg. ASANified).

There was already an option to use line 0 information for all the instructions
with no debug locations. The commit history for this code show that it was
disabled because it caused issues with GDB and with the line table size. Note
that this code was unconditionaly emitting those line 0 informations and not
using a heuristic to find intersting instructions like this one.

http://reviews.llvm.org/D16569

Files:
  lib/CodeGen/AsmPrinter/DwarfDebug.cpp
  lib/CodeGen/AsmPrinter/DwarfDebug.h

Index: lib/CodeGen/AsmPrinter/DwarfDebug.h
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfDebug.h
+++ lib/CodeGen/AsmPrinter/DwarfDebug.h
@@ -242,6 +242,8 @@
   /// debug info.
   DebugLoc PrevInstLoc;
   MCSymbol *PrevLabel;
+  const MachineBasicBlock *CurBB;
+  bool LastWasCall;
 
   /// This location indicates end of function prologue and beginning of
   /// function body.
Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp
===================================================================
--- lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1032,7 +1032,13 @@
 
         const MDNode *Scope = DL.getScope();
         recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags);
-      } else if (UnknownLocations) {
+      } else if (UnknownLocations || PrevLabel || LastWasCall ||
+                 CurBB != MI->getParent()) {
+        // We want to ensure that any instruction starting a block or
+        // referenced from somewhere else (eg. debug information) has
+        // a source location. Instead of making up a location from the
+        // surrounding instructions, just use a line 0 location that
+        // the debugger will ignore.
         PrevInstLoc = DL;
         recordSourceLine(0, 0, nullptr, 0);
       }
@@ -1063,8 +1069,11 @@
   assert(CurMI != nullptr);
   // Don't create a new label after DBG_VALUE instructions.
   // They don't generate code.
-  if (!CurMI->isDebugValue())
+  if (!CurMI->isDebugValue()) {
     PrevLabel = nullptr;
+    CurBB = CurMI->getParent();
+    LastWasCall = CurMI->isCall();
+  }
 
   DenseMap<const MachineInstr *, MCSymbol *>::iterator I =
       LabelsAfterInsn.find(CurMI);
@@ -1207,6 +1216,8 @@
 
   PrevInstLoc = DebugLoc();
   PrevLabel = Asm->getFunctionBegin();
+  CurBB = nullptr;
+  LastWasCall = false;
 
   // Record beginning of function.
   PrologEndLoc = findPrologueEndLoc(MF);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16569.45943.patch
Type: text/x-patch
Size: 1945 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160126/8d7ffb36/attachment.bin>


More information about the llvm-commits mailing list