[llvm] r270449 - llvm-dwp: Add an abstraction for the DWP string pool

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Tue May 24 08:39:41 PDT 2016


On Tue, May 24, 2016 at 4:54 AM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

> On 23 May 2016 at 12:32, David Blaikie via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
> > Author: dblaikie
> > Date: Mon May 23 11:32:11 2016
> > New Revision: 270449
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=270449&view=rev
> > Log:
> > llvm-dwp: Add an abstraction for the DWP string pool
> >
> > Also reference strings in the memory mapped file, reduces memory usage
> > on a large test case by 18.5%.
> >
> > Added:
> >     llvm/trunk/tools/llvm-dwp/DWPStringPool.h
> > Modified:
> >     llvm/trunk/tools/llvm-dwp/DWPError.h
> >     llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
> >
> > Modified: llvm/trunk/tools/llvm-dwp/DWPError.h
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/DWPError.h?rev=270449&r1=270448&r2=270449&view=diff
> >
> ==============================================================================
> > --- llvm/trunk/tools/llvm-dwp/DWPError.h (original)
> > +++ llvm/trunk/tools/llvm-dwp/DWPError.h Mon May 23 11:32:11 2016
> > @@ -1,6 +1,10 @@
> > +#ifndef TOOLS_LLVM_DWP_DWPERROR
> > +#define TOOLS_LLVM_DWP_DWPERROR
> > +
> >  #include "llvm/Support/Error.h"
> >  #include "llvm/Support/ErrorHandling.h"
> >  #include <string>
> > +
> >  namespace llvm {
> >  class DWPError : public ErrorInfo<DWPError> {
> >  public:
> > @@ -15,3 +19,5 @@ private:
> >    std::string Info;
> >  };
> >  }
> > +
> > +#endif
> >
> > Added: llvm/trunk/tools/llvm-dwp/DWPStringPool.h
> > URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/DWPStringPool.h?rev=270449&view=auto
> >
> ==============================================================================
> > --- llvm/trunk/tools/llvm-dwp/DWPStringPool.h (added)
> > +++ llvm/trunk/tools/llvm-dwp/DWPStringPool.h Mon May 23 11:32:11 2016
> > @@ -0,0 +1,54 @@
> > +#ifndef TOOLS_LLVM_DWP_DWPSTRINGPOOL
> > +#define TOOLS_LLVM_DWP_DWPSTRINGPOOL
> > +
> > +#include "llvm/ADT/DenseMap.h"
> > +#include "llvm/MC/MCSection.h"
> > +#include "llvm/MC/MCStreamer.h"
> > +#include <cassert>
> > +
> > +class DWPStringPool {
> > +
> > +  struct CStrDenseMapInfo {
> > +    static inline const char *getEmptyKey() {
> > +      return reinterpret_cast<const char *>(~static_cast<uintptr_t>(0));
> > +    }
> > +    static inline const char *getTombstoneKey() {
> > +      return reinterpret_cast<const char *>(~static_cast<uintptr_t>(1));
> > +    }
> > +    static unsigned getHashValue(const char *Val) {
> > +      assert(Val != getEmptyKey() && "Cannot hash the empty key!");
> > +      assert(Val != getTombstoneKey() && "Cannot hash the tombstone
> key!");
> > +      return (unsigned)hash_value(StringRef(Val));
> > +    }
> > +    static bool isEqual(const char *LHS, const char *RHS) {
> > +      if (RHS == getEmptyKey())
> > +        return LHS == getEmptyKey();
> > +      if (RHS == getTombstoneKey())
> > +        return LHS == getTombstoneKey();
> > +      return strcmp(LHS, RHS) == 0;
> > +    }
> > +  };
> > +
> > +  MCStreamer &Out;
> > +  MCSection *Sec;
> > +  DenseMap<const char *, uint32_t, CStrDenseMapInfo> Pool;
> > +  uint32_t Offset = 0;
>
> Can't you use a DenseMap of StringRef?
>

StringRef has a pointer and length - storing only a pointer is noticeably
smaller due to there being quite so many of these. I can double back &
check the numbers if you're curious.

- Dave


>
> Cheers,
> Rafael
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160524/54c44284/attachment.html>


More information about the llvm-commits mailing list