aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MachObjectWriter.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2025-07-01 00:21:12 -0700
committerGitHub <noreply@github.com>2025-07-01 00:21:12 -0700
commit9beb467d9213fe2becdb0f1469d99ca058189ac7 (patch)
treed3f5c57e5ad1673157f34c8162de93f7c9993ef7 /llvm/lib/MC/MachObjectWriter.cpp
parent7e830f76711f0dfc66780ea13cf780b8760b458b (diff)
downloadllvm-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/MachObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/MachObjectWriter.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index 2e671e0..eb7cb7d 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -807,8 +807,8 @@ uint64_t MachObjectWriter::writeObject() {
MCSection *CGProfileSection = getContext().getMachOSection(
"__LLVM", "__cg_profile", 0, SectionKind::getMetadata());
auto &Frag = cast<MCDataFragment>(*CGProfileSection->begin());
- Frag.getContents().clear();
- raw_svector_ostream OS(Frag.getContents());
+ Frag.clearContents();
+ raw_svector_ostream OS(Frag.getContentsForAppending());
for (const MCObjectWriter::CGProfileEntry &CGPE : CGProfile) {
uint32_t FromIndex = CGPE.From->getSymbol().getIndex();
uint32_t ToIndex = CGPE.To->getSymbol().getIndex();
@@ -816,6 +816,7 @@ uint64_t MachObjectWriter::writeObject() {
support::endian::write(OS, ToIndex, W.Endian);
support::endian::write(OS, CGPE.Count, W.Endian);
}
+ Frag.doneAppending();
}
unsigned NumSections = Asm.end() - Asm.begin();