1 #ifndef TOOLS_LLVM_DWP_DWPSTRINGPOOL
2 #define TOOLS_LLVM_DWP_DWPSTRINGPOOL
4 #include "llvm/ADT/DenseMap.h"
5 #include "llvm/MC/MCSection.h"
6 #include "llvm/MC/MCStreamer.h"
12 struct CStrDenseMapInfo
{
13 static inline const char *getEmptyKey() {
14 return reinterpret_cast<const char *>(~static_cast<uintptr_t>(0));
16 static inline const char *getTombstoneKey() {
17 return reinterpret_cast<const char *>(~static_cast<uintptr_t>(1));
19 static unsigned getHashValue(const char *Val
) {
20 assert(Val
!= getEmptyKey() && "Cannot hash the empty key!");
21 assert(Val
!= getTombstoneKey() && "Cannot hash the tombstone key!");
22 return (unsigned)hash_value(StringRef(Val
));
24 static bool isEqual(const char *LHS
, const char *RHS
) {
25 if (RHS
== getEmptyKey())
26 return LHS
== getEmptyKey();
27 if (RHS
== getTombstoneKey())
28 return LHS
== getTombstoneKey();
29 return strcmp(LHS
, RHS
) == 0;
35 DenseMap
<const char *, uint32_t, CStrDenseMapInfo
> Pool
;
39 DWPStringPool(MCStreamer
&Out
, MCSection
*Sec
) : Out(Out
), Sec(Sec
) {}
41 uint32_t getOffset(const char *Str
, unsigned Length
) {
42 assert(strlen(Str
) + 1 == Length
&& "Ensure length hint is correct");
44 auto Pair
= Pool
.insert(std::make_pair(Str
, Offset
));
46 Out
.SwitchSection(Sec
);
47 Out
.EmitBytes(StringRef(Str
, Length
));
51 return Pair
.first
->second
;