[ARM] Cortex-M4 schedule additions
[llvm-complete.git] / tools / llvm-dwp / DWPStringPool.h
blob7d41176b56197ec24fbd23bd17aeb2bbcdec986e
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"
7 #include <cassert>
9 namespace llvm {
10 class DWPStringPool {
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;
33 MCStreamer &Out;
34 MCSection *Sec;
35 DenseMap<const char *, uint32_t, CStrDenseMapInfo> Pool;
36 uint32_t Offset = 0;
38 public:
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));
45 if (Pair.second) {
46 Out.SwitchSection(Sec);
47 Out.EmitBytes(StringRef(Str, Length));
48 Offset += Length;
51 return Pair.first->second;
56 #endif