[PATCH] D115993: [ELF] Optimize RelocationSection<ELFT>::writeTo
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 18 18:57:53 PST 2021
MaskRay added a comment.
I have tried a serial radix sort whose performance is similar to the parallel qsort.
It has more code and needs to sacrifice the D62141 <https://reviews.llvm.org/D62141> ordering property (the property doesn't matter and can be sacrificed if justified):
// Sort by (!IsRelative,SymIndex). DT_REL[A]COUNT requires us to
// place R_*_RELATIVE first. SymIndex is to improve locality.
if (sort) {
unsigned num = symTab->getNumSymbols();
SmallVector<unsigned, 0> cnt(num);
for (const DynamicReloc &rel : relocs)
++cnt[rel.r_sym];
for (unsigned j = 0, i = 0; i != num; ++i) {
unsigned t = j + cnt[i];
cnt[i] = j;
j = t;
}
auto tmp = relocs;
unsigned j = 0, k = relocs.size();
for (const DynamicReloc &rel : relocs)
tmp[cnt[rel.r_sym]++] = rel;
j = 0;
for (const DynamicReloc &rel : tmp)
if (rel.type == target->relativeRel)
relocs[j++] = rel;
else
relocs[--k] = rel;
std::reverse(relocs.begin() + k, relocs.end());
}
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115993/new/
https://reviews.llvm.org/D115993
More information about the llvm-commits
mailing list