Skip to content

Commit ccf5125

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 96de843 commit ccf5125

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
@@ -462,6 +462,22 @@ void MCObjectStreamer::emitDwarfAdvanceLineAddr(int64_t LineDelta,
462462
Label, PointerSize);
463463
return;
464464
}
465+
466+
// If the two labels are within the same fragment and it's a plain data
467+
// fragment, then the address-offset is already a fixed constant and is not
468+
// relaxable. Emit the advance-line-addr data immediately to save time and
469+
// memory.
470+
MCFragment *LastFrag = LastLabel->getFragment();
471+
if (LastFrag->getKind() == MCFragment::FT_Data &&
472+
Label->getFragment() == LastFrag) {
473+
uint64_t AddrDelta = Label->getOffset() - LastLabel->getOffset();
474+
SmallString<16> Tmp;
475+
MCDwarfLineAddr::encode(getContext(), Assembler->getDWARFLinetableParams(),
476+
LineDelta, AddrDelta, Tmp);
477+
emitBytes(Tmp);
478+
return;
479+
}
480+
465481
const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel, SMLoc());
466482
insert(getContext().allocFragment<MCDwarfLineAddrFragment>(LineDelta,
467483
*AddrDelta));

0 commit comments

Comments
 (0)