[llvm] r268698 - Make StringTableBuilder to cache hash values.
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Fri May 6 09:58:48 PDT 2016
It is amusing how useful this simple template is. How about we add it
to the programmers manual?
Cheers,
Rafael
On 5 May 2016 at 20:51, Rui Ueyama via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: ruiu
> Date: Thu May 5 19:51:58 2016
> New Revision: 268698
>
> URL: http://llvm.org/viewvc/llvm-project?rev=268698&view=rev
> Log:
> Make StringTableBuilder to cache hash values.
>
> This change seems to speed up LLD a bit if it has a lot of mergeable
> sections. The number is below. It's not too bad for a small patch.
>
> Time to link Clang (debug build):
>
> w/o patch 6.3696 seconds
> w/patch 6.2746 seconds (-1.5%)
>
> Differential Revision: http://reviews.llvm.org/D19933
>
> Modified:
> llvm/trunk/include/llvm/MC/StringTableBuilder.h
> llvm/trunk/lib/MC/StringTableBuilder.cpp
>
> Modified: llvm/trunk/include/llvm/MC/StringTableBuilder.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/StringTableBuilder.h?rev=268698&r1=268697&r2=268698&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/MC/StringTableBuilder.h (original)
> +++ llvm/trunk/include/llvm/MC/StringTableBuilder.h Thu May 5 19:51:58 2016
> @@ -23,7 +23,7 @@ public:
>
> private:
> SmallString<256> StringTable;
> - DenseMap<StringRef, size_t> StringIndexMap;
> + DenseMap<CachedHash<StringRef>, size_t> StringIndexMap;
> size_t Size = 0;
> Kind K;
> unsigned Alignment;
> @@ -57,7 +57,10 @@ public:
> /// after the table is finalized.
> size_t getOffset(StringRef S) const;
>
> - const DenseMap<StringRef, size_t> &getMap() const { return StringIndexMap; }
> + const DenseMap<CachedHash<StringRef>, size_t> &getMap() const {
> + return StringIndexMap;
> + }
> +
> size_t getSize() const { return Size; }
> void clear();
>
>
> Modified: llvm/trunk/lib/MC/StringTableBuilder.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/StringTableBuilder.cpp?rev=268698&r1=268697&r2=268698&view=diff
> ==============================================================================
> --- llvm/trunk/lib/MC/StringTableBuilder.cpp (original)
> +++ llvm/trunk/lib/MC/StringTableBuilder.cpp Thu May 5 19:51:58 2016
> @@ -34,11 +34,11 @@ StringTableBuilder::StringTableBuilder(K
> }
> }
>
> -typedef std::pair<StringRef, size_t> StringPair;
> +typedef std::pair<CachedHash<StringRef>, size_t> StringPair;
>
> // Returns the character at Pos from end of a string.
> static int charTailAt(StringPair *P, size_t Pos) {
> - StringRef S = P->first;
> + StringRef S = P->first.Val;
> if (Pos >= S.size())
> return -1;
> return (unsigned char)S[S.size() - Pos - 1];
> @@ -86,7 +86,7 @@ void StringTableBuilder::finalizeInOrder
> }
>
> void StringTableBuilder::finalizeStringTable(bool Optimize) {
> - typedef std::pair<StringRef, size_t> StringOffsetPair;
> + typedef std::pair<CachedHash<StringRef>, size_t> StringOffsetPair;
> std::vector<StringOffsetPair *> Strings;
> Strings.reserve(StringIndexMap.size());
> for (StringOffsetPair &P : StringIndexMap)
> @@ -121,7 +121,7 @@ void StringTableBuilder::finalizeStringT
>
> StringRef Previous;
> for (StringOffsetPair *P : Strings) {
> - StringRef S = P->first;
> + StringRef S = P->first.Val;
> if (K == WinCOFF)
> assert(S.size() > COFF::NameSize && "Short string in COFF string table!");
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list