14 #ifndef LLVM_ADT_DENSEMAPINFO_H
15 #define LLVM_ADT_DENSEMAPINFO_H
17 #include "llvm/PointerLikeTypeTraits.h"
18 #include "llvm/type_traits.h"
33 static inline T* getEmptyKey() {
34 uintptr_t Val =
static_cast<uintptr_t
>(-1);
35 Val <<= PointerLikeTypeTraits<T*>::NumLowBitsAvailable;
36 return reinterpret_cast<T*
>(Val);
38 static inline T* getTombstoneKey() {
39 uintptr_t Val =
static_cast<uintptr_t
>(-2);
40 Val <<= PointerLikeTypeTraits<T*>::NumLowBitsAvailable;
41 return reinterpret_cast<T*
>(Val);
43 static unsigned getHashValue(
const T *PtrVal) {
44 return (
unsigned((uintptr_t)PtrVal) >> 4) ^
45 (unsigned((uintptr_t)PtrVal) >> 9);
47 static bool isEqual(
const T *LHS,
const T *RHS) {
return LHS == RHS; }
52 static inline char getEmptyKey() {
return ~0; }
53 static inline char getTombstoneKey() {
return ~0 - 1; }
54 static unsigned getHashValue(
const char& Val) {
return Val * 37U; }
55 static bool isEqual(
const char &LHS,
const char &RHS) {
62 static inline unsigned getEmptyKey() {
return ~0U; }
63 static inline unsigned getTombstoneKey() {
return ~0U - 1; }
64 static unsigned getHashValue(
const unsigned& Val) {
return Val * 37U; }
65 static bool isEqual(
const unsigned& LHS,
const unsigned& RHS) {
72 static inline unsigned long getEmptyKey() {
return ~0UL; }
73 static inline unsigned long getTombstoneKey() {
return ~0UL - 1L; }
74 static unsigned getHashValue(
const unsigned long& Val) {
75 return (
unsigned)(Val * 37UL);
77 static bool isEqual(
const unsigned long& LHS,
const unsigned long& RHS) {
84 static inline unsigned long long getEmptyKey() {
return ~0ULL; }
85 static inline unsigned long long getTombstoneKey() {
return ~0ULL - 1ULL; }
86 static unsigned getHashValue(
const unsigned long long& Val) {
87 return (
unsigned)(Val * 37ULL);
89 static bool isEqual(
const unsigned long long& LHS,
90 const unsigned long long& RHS) {
97 static inline int getEmptyKey() {
return 0x7fffffff; }
98 static inline int getTombstoneKey() {
return -0x7fffffff - 1; }
99 static unsigned getHashValue(
const int& Val) {
return (
unsigned)(Val * 37U); }
100 static bool isEqual(
const int& LHS,
const int& RHS) {
107 static inline long getEmptyKey() {
108 return (1UL << (
sizeof(
long) * 8 - 1)) - 1UL;
110 static inline long getTombstoneKey() {
return getEmptyKey() - 1L; }
111 static unsigned getHashValue(
const long& Val) {
112 return (
unsigned)(Val * 37UL);
114 static bool isEqual(
const long& LHS,
const long& RHS) {
121 static inline long long getEmptyKey() {
return 0x7fffffffffffffffLL; }
122 static inline long long getTombstoneKey() {
return -0x7fffffffffffffffLL-1; }
123 static unsigned getHashValue(
const long long& Val) {
124 return (
unsigned)(Val * 37ULL);
126 static bool isEqual(
const long long& LHS,
127 const long long& RHS) {
133 template<
typename T,
typename U>
135 typedef std::pair<T, U> Pair;
139 static inline Pair getEmptyKey() {
140 return std::make_pair(FirstInfo::getEmptyKey(),
141 SecondInfo::getEmptyKey());
143 static inline Pair getTombstoneKey() {
144 return std::make_pair(FirstInfo::getTombstoneKey(),
145 SecondInfo::getTombstoneKey());
147 static unsigned getHashValue(
const Pair& PairVal) {
148 uint64_t key = (uint64_t)FirstInfo::getHashValue(PairVal.first) << 32
149 | (uint64_t)SecondInfo::getHashValue(PairVal.second);
158 return (
unsigned)key;
160 static bool isEqual(
const Pair &LHS,
const Pair &RHS) {
161 return FirstInfo::isEqual(LHS.first, RHS.first) &&
162 SecondInfo::isEqual(LHS.second, RHS.second);
Definition: DenseMapInfo.h:23