[lld] r316305 - Remove a fast lookup table from MergeInputSection.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 22 16:02:07 PDT 2017
Author: ruiu
Date: Sun Oct 22 16:02:07 2017
New Revision: 316305
URL: http://llvm.org/viewvc/llvm-project?rev=316305&view=rev
Log:
Remove a fast lookup table from MergeInputSection.
We used to have a map from section piece offsets to section pieces
as a cache for binary search. But I found that the map took quite a
large amount of memory and didn't make linking faster. So, in this
patch, I removed the map.
This patch saves 566 MiB of RAM (2.019 GiB -> 1.453 GiB) when linking
clang with debug info, and the link time is 4% faster in that test case.
Thanks for Sean Silva for pointing this out.
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=316305&r1=316304&r2=316305&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Sun Oct 22 16:02:07 2017
@@ -963,27 +963,12 @@ const SectionPiece *MergeInputSection::g
// Because contents of a mergeable section is not contiguous in output,
// it is not just an addition to a base output offset.
uint64_t MergeInputSection::getOffset(uint64_t Offset) const {
- if (!this->Live)
+ if (!Live)
return 0;
- // 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);
+ const SectionPiece &Piece = *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=316305&r1=316304&r2=316305&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Sun Oct 22 16:02:07 2017
@@ -269,9 +269,6 @@ 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