[PATCH] D31330: [ELF] - Speedup --gdb-index read address area implementation.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 24 07:03:49 PDT 2017


grimar created this revision.
Herald added a subscriber: aprantl.

Previous implementation was ineffective.
For each range it did a search among all input sections of a file.

Patch sorts range vector returned by DWARF parser and allows
to do a single iteration through input sections.

That change speedups link time with --gdb-index for producing llc
binary from: 19.2 to 16.49 seconds. Its about 15%.


https://reviews.llvm.org/D31330

Files:
  ELF/SyntheticSections.cpp


Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -1697,29 +1697,39 @@
   return Ret;
 }
 
-static InputSectionBase *findSection(ArrayRef<InputSectionBase *> Arr,
-                                     uint64_t Offset) {
-  for (InputSectionBase *S : Arr)
-    if (S && S != &InputSection::Discarded)
-      if (Offset >= S->getOffsetInFile() &&
-          Offset < S->getOffsetInFile() + S->getSize())
-        return S;
-  return nullptr;
-}
-
 static std::vector<AddressEntry>
 readAddressArea(DWARFContext &Dwarf, InputSection *Sec, size_t CurrentCU) {
+  typedef std::pair<uint64_t, uint64_t> Range;
+
   std::vector<AddressEntry> Ret;
 
   for (std::unique_ptr<DWARFCompileUnit> &CU : Dwarf.compile_units()) {
     DWARFAddressRangesVector Ranges;
     CU->collectAddressRanges(Ranges);
 
+    std::sort(Ranges.begin(), Ranges.end(),
+              [](Range &A, Range &B) { return A.first < B.first; });
+
     ArrayRef<InputSectionBase *> Sections = Sec->File->getSections();
-    for (std::pair<uint64_t, uint64_t> &R : Ranges)
-      if (InputSectionBase *S = findSection(Sections, R.first))
+    auto It = Ranges.begin();
+    for (InputSectionBase *S : Sections) {
+      if (!S || S == &InputSection::Discarded)
+        continue;
+
+      while (It != Ranges.end()) {
+        const Range &R = *It;
+        bool Inside = R.first >= S->getOffsetInFile() &&
+                      R.first < S->getOffsetInFile() + S->getSize();
+        if (!Inside)
+          break;
+
         Ret.push_back({S, R.first - S->getOffsetInFile(),
                        R.second - S->getOffsetInFile(), CurrentCU});
+        ++It;
+      }
+      if (It == Ranges.end())
+        break;
+    }
     ++CurrentCU;
   }
   return Ret;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31330.92936.patch
Type: text/x-patch
Size: 1840 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170324/370fd311/attachment-0001.bin>


More information about the llvm-commits mailing list