[llvm] r270449 - llvm-dwp: Add an abstraction for the DWP string pool
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Tue May 24 04:54:11 PDT 2016
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?
Cheers,
Rafael
More information about the llvm-commits
mailing list