[PATCH] D46145: Use a buffer when allocating relocations
Rafael Avila de Espindola via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 27 10:06:38 PDT 2018
espindola updated this revision to Diff 144365.
espindola added a comment.
Delete call to reserve.
The results are
master 765.5 total, 563.7 peak
with reserve 747.76 total, 545.3 peak
without reserve 747.63 total, 545.3 peak
https://reviews.llvm.org/D46145
Files:
ELF/Relocations.cpp
ELF/Writer.cpp
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -859,16 +859,29 @@
template <class ELFT>
void Writer<ELFT>::forEachRelSec(std::function<void(InputSectionBase &)> Fn) {
+ std::vector<Relocation> Buffer;
+
+ // We allocate a lot of relocations. By using a single buffer for
+ // all sections we ensure that the final vector in each section has
+ // the exact size.
+ auto WithBuffer = [&](InputSectionBase &Sec) {
+ swap(Sec.Relocations, Buffer);
+ Fn(Sec);
+ swap(Sec.Relocations, Buffer);
+ Sec.Relocations.insert(Sec.Relocations.end(), Buffer.begin(), Buffer.end());
+ Buffer.clear();
+ };
+
// Scan all relocations. Each relocation goes through a series
// of tests to determine if it needs special treatment, such as
// creating GOT, PLT, copy relocations, etc.
// Note that relocations for non-alloc sections are directly
// processed by InputSection::relocateNonAlloc.
for (InputSectionBase *IS : InputSections)
if (IS->Live && isa<InputSection>(IS) && (IS->Flags & SHF_ALLOC))
- Fn(*IS);
+ WithBuffer(*IS);
for (EhInputSection *ES : InX::EhFrame->Sections)
- Fn(*ES);
+ WithBuffer(*ES);
}
// This function generates assignments for predefined symbols (e.g. _end or
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -1015,10 +1015,6 @@
template <class ELFT, class RelTy>
static void scanRelocs(InputSectionBase &Sec, ArrayRef<RelTy> Rels) {
OffsetGetter GetOffset(Sec);
-
- // Not all relocations end up in Sec.Relocations, but a lot do.
- Sec.Relocations.reserve(Rels.size());
-
for (auto I = Rels.begin(), End = Rels.end(); I != End;)
scanReloc<ELFT>(Sec, GetOffset, I, End);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46145.144365.patch
Type: text/x-patch
Size: 1851 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180427/83e7a8f0/attachment.bin>
More information about the llvm-commits
mailing list