<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 24, 2016 at 10:46 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">Nah, it is fine. Just surprised that computing strlen once didn't make<br>
it worth it.<br></blockquote><div><br></div><div>I've not really been measuring runtime, since we're hard up against memory limits for some large files - so I've just been optimizing for memory usage at the moment. Seeing how far down we can get it (turns out: not enough to matter in the case we care about - hence I'm just tidying up a few loose ends/trying to make the code a bit neater before shelving it for now (no doubt will come back to it within the next year or two))<br><br>So it's possible that the extra strlen computation does add significant runtime compared to caching it - but I've not checked that.<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>
Thanks,<br>
Rafael<br>
<div class="HOEnZb"><div class="h5"><br>
On 24 May 2016 at 11:39, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
><br>
><br>
> On Tue, May 24, 2016 at 4:54 AM, Rafael Espíndola<br>
> <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br>
>><br>
>> On 23 May 2016 at 12:32, David Blaikie via llvm-commits<br>
>> <<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:<br>
>> > <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>
>> > ==============================================================================<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:<br>
>> > <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>
>> > ==============================================================================<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<br>
>> > *>(~static_cast<uintptr_t>(0));<br>
>> > +    }<br>
>> > +    static inline const char *getTombstoneKey() {<br>
>> > +      return reinterpret_cast<const char<br>
>> > *>(~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<br>
>> > 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>
>> Can't you use a DenseMap of StringRef?<br>
><br>
><br>
> StringRef has a pointer and length - storing only a pointer is noticeably<br>
> smaller due to there being quite so many of these. I can double back & check<br>
> the numbers if you're curious.<br>
><br>
> - Dave<br>
><br>
>><br>
>><br>
>> Cheers,<br>
>> Rafael<br>
><br>
><br>
</div></div></blockquote></div><br></div></div>