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

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 3 12:24:26 PDT 2018


pcc created this revision.
pcc added reviewers: ruiu, espindola.
Herald added subscribers: mgrang, arichardson, emaste.

This improved performance by 0.5-1% linking Chromium for Android.


https://reviews.llvm.org/D45222

Files:
  lld/ELF/Writer.cpp


Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -1092,21 +1092,23 @@
 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 @@
 
   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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45222.140843.patch
Type: text/x-patch
Size: 2055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180403/15299c22/attachment.bin>


More information about the llvm-commits mailing list