Skip to content

Commit 8f2852e

Browse files
committed
[MC][DebugInfo] Emit linetable entries with known offsets immediately
DWARF linetable entries are usually emitted as a sequence of MCDwarfLineAddrFragment fragments containing the line-number difference and an MCExpr describing the instruction-range the linetable entry covers. These then get relaxed during assembly emission. However, a large number of these instruction-range expressions are ranges within a fixed MCDataFragment, i.e. a range over fixed-size instructions that are not subject to relaxation at a later stage. Thus, we can compute the address-delta immediately, and not spend time and memory describing that computation so it can be deferred.
1 parent 3b4f9c5 commit 8f2852e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,22 @@ void MCObjectStreamer::emitDwarfAdvanceLineAddr(int64_t LineDelta,
464464
Label, PointerSize);
465465
return;
466466
}
467+
468+
// If the two labels are within the same fragment and it's a plain data
469+
// fragment, then the address-offset is already a fixed constant and is not
470+
// relaxable. Emit the advance-line-addr data immediately to save time and
471+
// memory.
472+
MCFragment *LastFrag = LastLabel->getFragment();
473+
if (LastFrag->getKind() == MCFragment::FT_Data &&
474+
Label->getFragment() == LastFrag) {
475+
uint64_t AddrDelta = Label->getOffset() - LastLabel->getOffset();
476+
SmallString<16> Tmp;
477+
MCDwarfLineAddr::encode(getContext(), Assembler->getDWARFLinetableParams(),
478+
LineDelta, AddrDelta, Tmp);
479+
emitBytes(Tmp);
480+
return;
481+
}
482+
467483
const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel, SMLoc());
468484
insert(getContext().allocFragment<MCDwarfLineAddrFragment>(LineDelta,
469485
*AddrDelta));

0 commit comments

Comments
 (0)