[lld] r329106 - ELF: Use a vector of pairs to sort sections ordered using --symbol-ordering-file.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 3 12:45:10 PDT 2018


Author: pcc
Date: Tue Apr  3 12:45:10 2018
New Revision: 329106

URL: http://llvm.org/viewvc/llvm-project?rev=329106&view=rev
Log:
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

Modified:
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=329106&r1=329105&r2=329106&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Apr  3 12:45:10 2018
@@ -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(InputSectionDescri
 
   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,




More information about the llvm-commits mailing list