[lld] r317026 - Revert r316305: Remove a fast lookup table from MergeInputSection.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 31 12:14:06 PDT 2017


Author: ruiu
Date: Tue Oct 31 12:14:06 2017
New Revision: 317026

URL: http://llvm.org/viewvc/llvm-project?rev=317026&view=rev
Log:
Revert r316305: Remove a fast lookup table from MergeInputSection.

This reverts commit r316305 because performance regression was observed.

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/InputSection.h

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=317026&r1=317025&r2=317026&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue Oct 31 12:14:06 2017
@@ -968,9 +968,24 @@ uint64_t MergeInputSection::getOffset(ui
   if (!Live)
     return 0;
 
-  const SectionPiece &Piece = *getSectionPiece(Offset);
+  // Initialize OffsetMap lazily.
+  llvm::call_once(InitOffsetMap, [&] {
+    OffsetMap.reserve(Pieces.size());
+    for (size_t I = 0; I < Pieces.size(); ++I)
+      OffsetMap[Pieces[I].InputOff] = I;
+  });
+
+  // Find a string starting at a given offset.
+  auto It = OffsetMap.find(Offset);
+  if (It != OffsetMap.end())
+    return Pieces[It->second].OutputOff;
+
+  // If Offset is not at beginning of a section piece, it is not in the map.
+  // In that case we need to search from the original section piece vector.
+  const SectionPiece &Piece = *this->getSectionPiece(Offset);
   if (!Piece.Live)
     return 0;
+
   uint64_t Addend = Offset - Piece.InputOff;
   return Piece.OutputOff + Addend;
 }

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=317026&r1=317025&r2=317026&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Tue Oct 31 12:14:06 2017
@@ -263,6 +263,9 @@ private:
   void splitStrings(ArrayRef<uint8_t> A, size_t Size);
   void splitNonStrings(ArrayRef<uint8_t> A, size_t Size);
 
+  mutable llvm::DenseMap<uint32_t, uint32_t> OffsetMap;
+  mutable llvm::once_flag InitOffsetMap;
+
   llvm::DenseSet<uint64_t> LiveOffsets;
 };
 




More information about the llvm-commits mailing list