[llvm] r268698 - Make StringTableBuilder to cache hash values.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri May 6 10:11:46 PDT 2016


Maybe, but if this could improve performance in most cases, why don't we
make DenseMap to save StringRef's hash values even if we don't use that
wrapper?

On Fri, May 6, 2016 at 9:58 AM, Rafael EspĂ­ndola <rafael.espindola at gmail.com
> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160506/d5ffff06/attachment.html>


More information about the llvm-commits mailing list