diff options
| author | Peter Collingbourne <peter@pcc.me.uk> | 2018-04-03 19:45:10 +0000 |
|---|---|---|
| committer | Peter Collingbourne <peter@pcc.me.uk> | 2018-04-03 19:45:10 +0000 |
| commit | bca630bd611de57c113b805627a40fb0066a4ed3 (patch) | |
| tree | cbe32039befddce076ef7f40edde2d0ede1a8270 | |
| parent | 81a87ba38bf2f68160af67b4b182fbf97e7f6570 (diff) | |
| download | bcm5719-llvm-bca630bd611de57c113b805627a40fb0066a4ed3.tar.gz bcm5719-llvm-bca630bd611de57c113b805627a40fb0066a4ed3.zip | |
ELF: Use a vector of pairs to sort sections ordered using --symbol-ordering-file.
This improved performance by 0.5-1% linking Chromium for Android.
Differential Revision: https://reviews.llvm.org/D45222
llvm-svn: 329106
| -rw-r--r-- | lld/ELF/Writer.cpp | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index e6489519e68..610e2656e7a 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1092,21 +1092,23 @@ static void sortISDBySectionOrder(InputSectionDescription *ISD, const DenseMap<const InputSectionBase *, int> &Order) { std::vector<InputSection *> UnorderedSections; - std::vector<InputSection *> OrderedSections; + std::vector<std::pair<InputSection *, int>> OrderedSections; uint64_t UnorderedSize = 0; for (InputSection *IS : ISD->Sections) { - if (!Order.count(IS)) { + auto I = Order.find(IS); + if (I == Order.end()) { UnorderedSections.push_back(IS); UnorderedSize += IS->getSize(); continue; } - OrderedSections.push_back(IS); + OrderedSections.push_back({IS, I->second}); } - std::sort(OrderedSections.begin(), OrderedSections.end(), - [&](InputSection *A, InputSection *B) { - return Order.lookup(A) < Order.lookup(B); - }); + std::sort( + OrderedSections.begin(), OrderedSections.end(), + [&](std::pair<InputSection *, int> A, std::pair<InputSection *, int> B) { + return A.second < B.second; + }); // Find an insertion point for the ordered section list in the unordered // section list. On targets with limited-range branches, this is the mid-point @@ -1147,10 +1149,12 @@ sortISDBySectionOrder(InputSectionDescription *ISD, std::copy(UnorderedSections.begin(), UnorderedSections.begin() + UnorderedInsPt, ISD->Sections.begin()); - std::copy(OrderedSections.begin(), OrderedSections.end(), - ISD->Sections.begin() + UnorderedInsPt); + std::vector<InputSection *>::iterator SectionsPos = + ISD->Sections.begin() + UnorderedInsPt; + for (std::pair<InputSection *, int> P : OrderedSections) + *SectionsPos++ = P.first; std::copy(UnorderedSections.begin() + UnorderedInsPt, UnorderedSections.end(), - ISD->Sections.begin() + UnorderedInsPt + OrderedSections.size()); + SectionsPos); } static void sortSection(OutputSection *Sec, |

