<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 24, 2016 at 4:54 AM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 23 May 2016 at 12:32, David Blaikie via llvm-commits<br>
<div><div class="h5"><<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br>
> Author: dblaikie<br>
> Date: Mon May 23 11:32:11 2016<br>
> New Revision: 270449<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=270449&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=270449&view=rev</a><br>
> Log:<br>
> llvm-dwp: Add an abstraction for the DWP string pool<br>
><br>
> Also reference strings in the memory mapped file, reduces memory usage<br>
> on a large test case by 18.5%.<br>
><br>
> Added:<br>
>     llvm/trunk/tools/llvm-dwp/DWPStringPool.h<br>
> Modified:<br>
>     llvm/trunk/tools/llvm-dwp/DWPError.h<br>
>     llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp<br>
><br>
> Modified: llvm/trunk/tools/llvm-dwp/DWPError.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/DWPError.h?rev=270449&r1=270448&r2=270449&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/DWPError.h?rev=270449&r1=270448&r2=270449&view=diff</a><br>
> ==============================================================================<br>
> --- llvm/trunk/tools/llvm-dwp/DWPError.h (original)<br>
> +++ llvm/trunk/tools/llvm-dwp/DWPError.h Mon May 23 11:32:11 2016<br>
> @@ -1,6 +1,10 @@<br>
> +#ifndef TOOLS_LLVM_DWP_DWPERROR<br>
> +#define TOOLS_LLVM_DWP_DWPERROR<br>
> +<br>
>  #include "llvm/Support/Error.h"<br>
>  #include "llvm/Support/ErrorHandling.h"<br>
>  #include <string><br>
> +<br>
>  namespace llvm {<br>
>  class DWPError : public ErrorInfo<DWPError> {<br>
>  public:<br>
> @@ -15,3 +19,5 @@ private:<br>
>    std::string Info;<br>
>  };<br>
>  }<br>
> +<br>
> +#endif<br>
><br>
> Added: llvm/trunk/tools/llvm-dwp/DWPStringPool.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/DWPStringPool.h?rev=270449&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/DWPStringPool.h?rev=270449&view=auto</a><br>
> ==============================================================================<br>
> --- llvm/trunk/tools/llvm-dwp/DWPStringPool.h (added)<br>
> +++ llvm/trunk/tools/llvm-dwp/DWPStringPool.h Mon May 23 11:32:11 2016<br>
> @@ -0,0 +1,54 @@<br>
> +#ifndef TOOLS_LLVM_DWP_DWPSTRINGPOOL<br>
> +#define TOOLS_LLVM_DWP_DWPSTRINGPOOL<br>
> +<br>
> +#include "llvm/ADT/DenseMap.h"<br>
> +#include "llvm/MC/MCSection.h"<br>
> +#include "llvm/MC/MCStreamer.h"<br>
> +#include <cassert><br>
> +<br>
> +class DWPStringPool {<br>
> +<br>
> +  struct CStrDenseMapInfo {<br>
> +    static inline const char *getEmptyKey() {<br>
> +      return reinterpret_cast<const char *>(~static_cast<uintptr_t>(0));<br>
> +    }<br>
> +    static inline const char *getTombstoneKey() {<br>
> +      return reinterpret_cast<const char *>(~static_cast<uintptr_t>(1));<br>
> +    }<br>
> +    static unsigned getHashValue(const char *Val) {<br>
> +      assert(Val != getEmptyKey() && "Cannot hash the empty key!");<br>
> +      assert(Val != getTombstoneKey() && "Cannot hash the tombstone key!");<br>
> +      return (unsigned)hash_value(StringRef(Val));<br>
> +    }<br>
> +    static bool isEqual(const char *LHS, const char *RHS) {<br>
> +      if (RHS == getEmptyKey())<br>
> +        return LHS == getEmptyKey();<br>
> +      if (RHS == getTombstoneKey())<br>
> +        return LHS == getTombstoneKey();<br>
> +      return strcmp(LHS, RHS) == 0;<br>
> +    }<br>
> +  };<br>
> +<br>
> +  MCStreamer &Out;<br>
> +  MCSection *Sec;<br>
> +  DenseMap<const char *, uint32_t, CStrDenseMapInfo> Pool;<br>
> +  uint32_t Offset = 0;<br>
<br>
</div></div>Can't you use a DenseMap of StringRef?<br></blockquote><div><br></div><div>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.<br><br>- Dave</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Cheers,<br>
Rafael<br>
</blockquote></div><br></div></div>