diff options
author | Fangrui Song <i@maskray.me> | 2025-07-01 00:21:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-01 00:21:12 -0700 |
commit | 9beb467d9213fe2becdb0f1469d99ca058189ac7 (patch) | |
tree | d3f5c57e5ad1673157f34c8162de93f7c9993ef7 /llvm/lib/MC/MCCodeView.cpp | |
parent | 7e830f76711f0dfc66780ea13cf780b8760b458b (diff) | |
download | llvm-9beb467d9213fe2becdb0f1469d99ca058189ac7.zip llvm-9beb467d9213fe2becdb0f1469d99ca058189ac7.tar.gz llvm-9beb467d9213fe2becdb0f1469d99ca058189ac7.tar.bz2 |
MC: Store fragment content and fixups out-of-line
Moved `Contents` and `Fixups` SmallVector storage to MCSection, enabling
trivial destructors for most fragment subclasses and eliminating the need
for MCFragment::destroy in ~MCSection.
For appending content to the current section, use
getContentsForAppending. During assembler relaxation, prefer
setContents/setFixups, which may involve copying and reduce the benefits
of https://reviews.llvm.org/D145791.
Moving only Contents out-of-line caused a slight performance regression
(Alexis Engelke's 2024 prototype). By also moving Fragments out-of-line,
fragment destructors become trivial, resulting in
neglgible instructions:u increase for "stage2-O0-g" and [large max-rss decrease](https://llvm-compile-time-tracker.com/compare.php?from=84e82746c3ff63ec23a8b85e9efd4f7fccf92590&to=555a28c0b2f8250a9cf86fd267a04b0460283e15&stat=max-rss&linkStats=on)
for the "stage1-ReleaseLTO-g (link only)" benchmark.
(
An older version using fewer inline functions: https://llvm-compile-time-tracker.com/compare.php?from=bb982e733cfcda7e4cfb0583544f68af65211ed1&to=f12d55f97c47717d438951ecddecf8ebd28c296b&linkStats=on
)
Now using plain SmallVector in MCSection for storage, with potential for
future allocator optimizations, such as allocating `Contents` as the
trailing object of MCDataFragment. (GNU Assembler uses gnulib's obstack
for fragment management.)
Co-authored-by: Alexis Engelke <engelke@in.tum.de>
Pull Request: https://github.com/llvm/llvm-project/pull/146307
Diffstat (limited to 'llvm/lib/MC/MCCodeView.cpp')
-rw-r--r-- | llvm/lib/MC/MCCodeView.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/llvm/lib/MC/MCCodeView.cpp b/llvm/lib/MC/MCCodeView.cpp index e8f0427..5d79143 100644 --- a/llvm/lib/MC/MCCodeView.cpp +++ b/llvm/lib/MC/MCCodeView.cpp @@ -510,8 +510,7 @@ void CodeViewContext::encodeInlineLineTable(const MCAssembler &Asm, MCCVFunctionInfo *SiteInfo = getCVFunctionInfo(Frag.SiteFuncId); - SmallVectorImpl<char> &Buffer = Frag.getContents(); - Buffer.clear(); // Clear old contents if we went through relaxation. + SmallVector<char, 0> Buffer; for (const MCCVLoc &Loc : Locs) { // Exit early if our line table would produce an oversized InlineSiteSym // record. Account for the ChangeCodeLength annotation emitted after the @@ -604,15 +603,14 @@ void CodeViewContext::encodeInlineLineTable(const MCAssembler &Asm, compressAnnotation(BinaryAnnotationsOpCode::ChangeCodeLength, Buffer); compressAnnotation(std::min(EndSymLength, LocAfterLength), Buffer); + Frag.setContents(Buffer); } void CodeViewContext::encodeDefRange(const MCAssembler &Asm, MCCVDefRangeFragment &Frag) { MCContext &Ctx = Asm.getContext(); - SmallVectorImpl<char> &Contents = Frag.getContents(); - Contents.clear(); - SmallVectorImpl<MCFixup> &Fixups = Frag.getFixups(); - Fixups.clear(); + SmallVector<char, 0> Contents; + SmallVector<MCFixup, 0> Fixups; raw_svector_ostream OS(Contents); // Compute all the sizes up front. @@ -692,4 +690,7 @@ void CodeViewContext::encodeDefRange(const MCAssembler &Asm, GapStartOffset += GapSize + RangeSize; } } + + Frag.setContents(Contents); + Frag.setFixups(Fixups); } |