summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
diff options
context:
space:
mode:
authorMatthias Braun <matze@braunis.de>2018-10-05 18:29:24 +0000
committerMatthias Braun <matze@braunis.de>2018-10-05 18:29:24 +0000
commitfb43114ba25f81b3c22a8cb27c532b559100d63a (patch)
tree59a0834b1c4c5c00e20b1f63dccdb5a0ba7f17a2 /llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
parent90fc1007425b3e0a46146eaba1afcde8f2787e5c (diff)
downloadbcm5719-llvm-fb43114ba25f81b3c22a8cb27c532b559100d63a.tar.gz
bcm5719-llvm-fb43114ba25f81b3c22a8cb27c532b559100d63a.zip
DwarfDebug: Pick next location in case of missing location at block begin
Context: Compiler generated instructions do not have a debug location assigned to them. However emitting 0-line records for all of them bloats the line tables for very little benefit so we usually avoid doing that. Not emitting anything will lead to the previous debug location getting applied to the locationless instructions. This is not desirable for block begin and after labels. Previously we would emit simply emit line-0 records in this case, this patch changes the behavior to do a forward search for a debug location in these cases before emitting a line-0 record to further reduce line table bloat. Inspired by the discussion in https://reviews.llvm.org/D52862 llvm-svn: 343874
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp112
1 files changed, 71 insertions, 41 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 6c6a861306d..ede606131ff 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -1313,6 +1313,49 @@ void DwarfDebug::collectEntityInfo(DwarfCompileUnit &TheCU,
}
}
+static const DebugLoc &
+findNextDebugLoc(MachineBasicBlock::const_iterator MBBI,
+ MachineBasicBlock::const_iterator MBBE) {
+ static DebugLoc NoLocation;
+ for ( ; MBBI != MBBE; ++MBBI) {
+ if (MBBI->isDebugInstr())
+ continue;
+ const DebugLoc &DL = MBBI->getDebugLoc();
+ if (DL)
+ return DL;
+ }
+ return NoLocation;
+}
+
+void DwarfDebug::emitDebugLoc(const DebugLoc &DL) {
+ unsigned LastAsmLine =
+ Asm->OutStreamer->getContext().getCurrentDwarfLoc().getLine();
+
+ // We have an explicit location, different from the previous location.
+ // Don't repeat a line-0 record, but otherwise emit the new location.
+ // (The new location might be an explicit line 0, which we do emit.)
+ unsigned Line = DL.getLine();
+ if (PrevInstLoc && Line == 0 && LastAsmLine == 0)
+ return;
+ unsigned Flags = 0;
+ if (DL == PrologEndLoc) {
+ Flags |= DWARF2_FLAG_PROLOGUE_END | DWARF2_FLAG_IS_STMT;
+ PrologEndLoc = DebugLoc();
+ }
+ // If the line changed, we call that a new statement; unless we went to
+ // line 0 and came back, in which case it is not a new statement.
+ unsigned OldLine = PrevInstLoc ? PrevInstLoc.getLine() : LastAsmLine;
+ if (Line && Line != OldLine)
+ Flags |= DWARF2_FLAG_IS_STMT;
+
+ const MDNode *Scope = DL.getScope();
+ recordSourceLine(Line, DL.getCol(), Scope, Flags);
+
+ // If we're not at line 0, remember this location.
+ if (Line)
+ PrevInstLoc = DL;
+}
+
// Process beginning of an instruction.
void DwarfDebug::beginInstruction(const MachineInstr *MI) {
DebugHandlerBase::beginInstruction(MI);
@@ -1352,54 +1395,41 @@ void DwarfDebug::beginInstruction(const MachineInstr *MI) {
// If we have already emitted a line-0 record, don't repeat it.
if (LastAsmLine == 0)
return;
+ // By default we emit nothing to avoid line table bloat. However at the
+ // beginning of a basic block or after a label it is undesirable to let
+ // the previous location unchanged. In these cases do a forward search for
+ // the next valid debug location.
+ if (UnknownLocations == Default) {
+ const MachineBasicBlock &MBB = *MI->getParent();
+ if (!PrevLabel && PrevInstBB == &MBB)
+ return;
+
+ const DebugLoc &NextDL = findNextDebugLoc(MI->getIterator(), MBB.end());
+ if (NextDL) {
+ emitDebugLoc(NextDL);
+ return;
+ }
+ }
+
+ // We should emit a line-0 record.
// If user said Don't Do That, don't do that.
if (UnknownLocations == Disable)
return;
- // See if we have a reason to emit a line-0 record now.
- // Reasons to emit a line-0 record include:
- // - User asked for it (UnknownLocations).
- // - Instruction has a label, so it's referenced from somewhere else,
- // possibly debug information; we want it to have a source location.
- // - Instruction is at the top of a block; we don't want to inherit the
- // location from the physically previous (maybe unrelated) block.
- if (UnknownLocations == Enable || PrevLabel ||
- (PrevInstBB && PrevInstBB != MI->getParent())) {
- // Preserve the file and column numbers, if we can, to save space in
- // the encoded line table.
- // Do not update PrevInstLoc, it remembers the last non-0 line.
- const MDNode *Scope = nullptr;
- unsigned Column = 0;
- if (PrevInstLoc) {
- Scope = PrevInstLoc.getScope();
- Column = PrevInstLoc.getCol();
- }
- recordSourceLine(/*Line=*/0, Column, Scope, /*Flags=*/0);
+ // Emit a line-0 record now.
+ // Preserve the file and column numbers, if we can, to save space in
+ // the encoded line table.
+ // Do not update PrevInstLoc, it remembers the last non-0 line.
+ const MDNode *Scope = nullptr;
+ unsigned Column = 0;
+ if (PrevInstLoc) {
+ Scope = PrevInstLoc.getScope();
+ Column = PrevInstLoc.getCol();
}
+ recordSourceLine(/*Line=*/0, Column, Scope, /*Flags=*/0);
return;
}
- // We have an explicit location, different from the previous location.
- // Don't repeat a line-0 record, but otherwise emit the new location.
- // (The new location might be an explicit line 0, which we do emit.)
- if (PrevInstLoc && DL.getLine() == 0 && LastAsmLine == 0)
- return;
- unsigned Flags = 0;
- if (DL == PrologEndLoc) {
- Flags |= DWARF2_FLAG_PROLOGUE_END | DWARF2_FLAG_IS_STMT;
- PrologEndLoc = DebugLoc();
- }
- // If the line changed, we call that a new statement; unless we went to
- // line 0 and came back, in which case it is not a new statement.
- unsigned OldLine = PrevInstLoc ? PrevInstLoc.getLine() : LastAsmLine;
- if (DL.getLine() && DL.getLine() != OldLine)
- Flags |= DWARF2_FLAG_IS_STMT;
-
- const MDNode *Scope = DL.getScope();
- recordSourceLine(DL.getLine(), DL.getCol(), Scope, Flags);
-
- // If we're not at line 0, remember this location.
- if (DL.getLine())
- PrevInstLoc = DL;
+ emitDebugLoc(DL);
}
static DebugLoc findPrologueEndLoc(const MachineFunction *MF) {
OpenPOWER on IntegriCloud