[lld] r288757 - Inline MergeInputSection::getData().
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 5 18:19:30 PST 2016
Author: ruiu
Date: Mon Dec 5 20:19:30 2016
New Revision: 288757
URL: http://llvm.org/viewvc/llvm-project?rev=288757&view=rev
Log:
Inline MergeInputSection::getData().
This change seems to make LLD 0.6% faster when linking Clang with
debug info. I don't want us to have lots of local optimizations,
but this function is very hot, and the improvement is small but
not negligible, so I think it's worth doing.
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=288757&r1=288756&r2=288757&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Mon Dec 5 20:19:30 2016
@@ -719,16 +719,6 @@ void MergeInputSection<ELFT>::splitStrin
}
}
-// Returns I'th piece's data.
-template <class ELFT>
-CachedHashStringRef MergeInputSection<ELFT>::getData(size_t I) const {
- size_t End =
- (Pieces.size() - 1 == I) ? this->Data.size() : Pieces[I + 1].InputOff;
- const SectionPiece &P = Pieces[I];
- StringRef S = toStringRef(this->Data.slice(P.InputOff, End - P.InputOff));
- return {S, Hashes[I]};
-}
-
// Split non-SHF_STRINGS section. Such section is a sequence of
// fixed size records.
template <class ELFT>
Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=288757&r1=288756&r2=288757&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Mon Dec 5 20:19:30 2016
@@ -194,7 +194,21 @@ public:
// Splittable sections are handled as a sequence of data
// rather than a single large blob of data.
std::vector<SectionPiece> Pieces;
- llvm::CachedHashStringRef getData(size_t Idx) const;
+
+ // Returns I'th piece's data. This function is very hot when
+ // string merging is enabled, so we want to inline.
+ LLVM_ATTRIBUTE_ALWAYS_INLINE
+ llvm::CachedHashStringRef getData(size_t I) const {
+ size_t Begin = Pieces[I].InputOff;
+ size_t End;
+ if (Pieces.size() - 1 == I)
+ End = this->Data.size();
+ else
+ End = Pieces[I + 1].InputOff;
+
+ StringRef S = {(const char *)(this->Data.data() + Begin), End - Begin};
+ return {S, Hashes[I]};
+ }
// Returns the SectionPiece at a given input section offset.
SectionPiece *getSectionPiece(uintX_t Offset);
More information about the llvm-commits
mailing list