Skip to content

Commit 3771c6a

Browse files
author
git apple-llvm automerger
committed
Merge commit '86f48fbb1c31' from llvm.org/main into next
2 parents 4e91a2e + 86f48fb commit 3771c6a

File tree

1 file changed

+81
-59
lines changed

1 file changed

+81
-59
lines changed

compiler-rt/lib/sanitizer_common/sanitizer_dense_map_info.h

Lines changed: 81 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace __sanitizer {
1818
namespace detail {
1919

2020
/// Simplistic combination of 32-bit hash values into 32-bit hash values.
21-
static inline unsigned combineHashValue(unsigned a, unsigned b) {
21+
static constexpr unsigned combineHashValue(unsigned a, unsigned b) {
2222
u64 key = (u64)a << 32 | (u64)b;
2323
key += ~(key << 32);
2424
key ^= (key >> 22);
@@ -37,18 +37,19 @@ template <typename KeyT, typename ValueT>
3737
struct DenseMapPair {
3838
KeyT first = {};
3939
ValueT second = {};
40-
DenseMapPair() = default;
41-
DenseMapPair(const KeyT &f, const ValueT &s) : first(f), second(s) {}
40+
constexpr DenseMapPair() = default;
41+
constexpr DenseMapPair(const KeyT &f, const ValueT &s)
42+
: first(f), second(s) {}
4243

4344
template <typename KeyT2, typename ValueT2>
44-
DenseMapPair(KeyT2 &&f, ValueT2 &&s)
45+
constexpr DenseMapPair(KeyT2 &&f, ValueT2 &&s)
4546
: first(__sanitizer::forward<KeyT2>(f)),
4647
second(__sanitizer::forward<ValueT2>(s)) {}
4748

48-
DenseMapPair(const DenseMapPair &other) = default;
49-
DenseMapPair &operator=(const DenseMapPair &other) = default;
50-
DenseMapPair(DenseMapPair &&other) = default;
51-
DenseMapPair &operator=(DenseMapPair &&other) = default;
49+
constexpr DenseMapPair(const DenseMapPair &other) = default;
50+
constexpr DenseMapPair &operator=(const DenseMapPair &other) = default;
51+
constexpr DenseMapPair(DenseMapPair &&other) = default;
52+
constexpr DenseMapPair &operator=(DenseMapPair &&other) = default;
5253

5354
KeyT &getFirst() { return first; }
5455
const KeyT &getFirst() const { return first; }
@@ -60,8 +61,8 @@ struct DenseMapPair {
6061

6162
template <typename T>
6263
struct DenseMapInfo {
63-
// static inline T getEmptyKey();
64-
// static inline T getTombstoneKey();
64+
// static T getEmptyKey();
65+
// static T getTombstoneKey();
6566
// static unsigned getHashValue(const T &Val);
6667
// static bool isEqual(const T &LHS, const T &RHS);
6768
};
@@ -79,150 +80,171 @@ struct DenseMapInfo<T *> {
7980
// "Log2MaxAlign bits of alignment");
8081
static constexpr uptr Log2MaxAlign = 12;
8182

82-
static inline T *getEmptyKey() {
83+
static constexpr T *getEmptyKey() {
8384
uptr Val = static_cast<uptr>(-1);
8485
Val <<= Log2MaxAlign;
8586
return reinterpret_cast<T *>(Val);
8687
}
8788

88-
static inline T *getTombstoneKey() {
89+
static constexpr T *getTombstoneKey() {
8990
uptr Val = static_cast<uptr>(-2);
9091
Val <<= Log2MaxAlign;
9192
return reinterpret_cast<T *>(Val);
9293
}
9394

94-
static unsigned getHashValue(const T *PtrVal) {
95+
static constexpr unsigned getHashValue(const T *PtrVal) {
9596
return (unsigned((uptr)PtrVal) >> 4) ^ (unsigned((uptr)PtrVal) >> 9);
9697
}
9798

98-
static bool isEqual(const T *LHS, const T *RHS) { return LHS == RHS; }
99+
static constexpr bool isEqual(const T *LHS, const T *RHS) {
100+
return LHS == RHS;
101+
}
99102
};
100103

101104
// Provide DenseMapInfo for chars.
102105
template <>
103106
struct DenseMapInfo<char> {
104-
static inline char getEmptyKey() { return ~0; }
105-
static inline char getTombstoneKey() { return ~0 - 1; }
106-
static unsigned getHashValue(const char &Val) { return Val * 37U; }
107+
static constexpr char getEmptyKey() { return ~0; }
108+
static constexpr char getTombstoneKey() { return ~0 - 1; }
109+
static constexpr unsigned getHashValue(const char &Val) { return Val * 37U; }
107110

108-
static bool isEqual(const char &LHS, const char &RHS) { return LHS == RHS; }
111+
static constexpr bool isEqual(const char &LHS, const char &RHS) {
112+
return LHS == RHS;
113+
}
109114
};
110115

111116
// Provide DenseMapInfo for unsigned chars.
112117
template <>
113118
struct DenseMapInfo<unsigned char> {
114-
static inline unsigned char getEmptyKey() { return ~0; }
115-
static inline unsigned char getTombstoneKey() { return ~0 - 1; }
116-
static unsigned getHashValue(const unsigned char &Val) { return Val * 37U; }
119+
static constexpr unsigned char getEmptyKey() { return ~0; }
120+
static constexpr unsigned char getTombstoneKey() { return ~0 - 1; }
121+
static constexpr unsigned getHashValue(const unsigned char &Val) {
122+
return Val * 37U;
123+
}
117124

118-
static bool isEqual(const unsigned char &LHS, const unsigned char &RHS) {
125+
static constexpr bool isEqual(const unsigned char &LHS,
126+
const unsigned char &RHS) {
119127
return LHS == RHS;
120128
}
121129
};
122130

123131
// Provide DenseMapInfo for unsigned shorts.
124132
template <>
125133
struct DenseMapInfo<unsigned short> {
126-
static inline unsigned short getEmptyKey() { return 0xFFFF; }
127-
static inline unsigned short getTombstoneKey() { return 0xFFFF - 1; }
128-
static unsigned getHashValue(const unsigned short &Val) { return Val * 37U; }
134+
static constexpr unsigned short getEmptyKey() { return 0xFFFF; }
135+
static constexpr unsigned short getTombstoneKey() { return 0xFFFF - 1; }
136+
static constexpr unsigned getHashValue(const unsigned short &Val) {
137+
return Val * 37U;
138+
}
129139

130-
static bool isEqual(const unsigned short &LHS, const unsigned short &RHS) {
140+
static constexpr bool isEqual(const unsigned short &LHS,
141+
const unsigned short &RHS) {
131142
return LHS == RHS;
132143
}
133144
};
134145

135146
// Provide DenseMapInfo for unsigned ints.
136147
template <>
137148
struct DenseMapInfo<unsigned> {
138-
static inline unsigned getEmptyKey() { return ~0U; }
139-
static inline unsigned getTombstoneKey() { return ~0U - 1; }
140-
static unsigned getHashValue(const unsigned &Val) { return Val * 37U; }
149+
static constexpr unsigned getEmptyKey() { return ~0U; }
150+
static constexpr unsigned getTombstoneKey() { return ~0U - 1; }
151+
static constexpr unsigned getHashValue(const unsigned &Val) {
152+
return Val * 37U;
153+
}
141154

142-
static bool isEqual(const unsigned &LHS, const unsigned &RHS) {
155+
static constexpr bool isEqual(const unsigned &LHS, const unsigned &RHS) {
143156
return LHS == RHS;
144157
}
145158
};
146159

147160
// Provide DenseMapInfo for unsigned longs.
148161
template <>
149162
struct DenseMapInfo<unsigned long> {
150-
static inline unsigned long getEmptyKey() { return ~0UL; }
151-
static inline unsigned long getTombstoneKey() { return ~0UL - 1L; }
163+
static constexpr unsigned long getEmptyKey() { return ~0UL; }
164+
static constexpr unsigned long getTombstoneKey() { return ~0UL - 1L; }
152165

153-
static unsigned getHashValue(const unsigned long &Val) {
166+
static constexpr unsigned getHashValue(const unsigned long &Val) {
154167
return (unsigned)(Val * 37UL);
155168
}
156169

157-
static bool isEqual(const unsigned long &LHS, const unsigned long &RHS) {
170+
static constexpr bool isEqual(const unsigned long &LHS,
171+
const unsigned long &RHS) {
158172
return LHS == RHS;
159173
}
160174
};
161175

162176
// Provide DenseMapInfo for unsigned long longs.
163177
template <>
164178
struct DenseMapInfo<unsigned long long> {
165-
static inline unsigned long long getEmptyKey() { return ~0ULL; }
166-
static inline unsigned long long getTombstoneKey() { return ~0ULL - 1ULL; }
179+
static constexpr unsigned long long getEmptyKey() { return ~0ULL; }
180+
static constexpr unsigned long long getTombstoneKey() { return ~0ULL - 1ULL; }
167181

168-
static unsigned getHashValue(const unsigned long long &Val) {
182+
static constexpr unsigned getHashValue(const unsigned long long &Val) {
169183
return (unsigned)(Val * 37ULL);
170184
}
171185

172-
static bool isEqual(const unsigned long long &LHS,
173-
const unsigned long long &RHS) {
186+
static constexpr bool isEqual(const unsigned long long &LHS,
187+
const unsigned long long &RHS) {
174188
return LHS == RHS;
175189
}
176190
};
177191

178192
// Provide DenseMapInfo for shorts.
179193
template <>
180194
struct DenseMapInfo<short> {
181-
static inline short getEmptyKey() { return 0x7FFF; }
182-
static inline short getTombstoneKey() { return -0x7FFF - 1; }
183-
static unsigned getHashValue(const short &Val) { return Val * 37U; }
184-
static bool isEqual(const short &LHS, const short &RHS) { return LHS == RHS; }
195+
static constexpr short getEmptyKey() { return 0x7FFF; }
196+
static constexpr short getTombstoneKey() { return -0x7FFF - 1; }
197+
static constexpr unsigned getHashValue(const short &Val) { return Val * 37U; }
198+
static constexpr bool isEqual(const short &LHS, const short &RHS) {
199+
return LHS == RHS;
200+
}
185201
};
186202

187203
// Provide DenseMapInfo for ints.
188204
template <>
189205
struct DenseMapInfo<int> {
190-
static inline int getEmptyKey() { return 0x7fffffff; }
191-
static inline int getTombstoneKey() { return -0x7fffffff - 1; }
192-
static unsigned getHashValue(const int &Val) { return (unsigned)(Val * 37U); }
206+
static constexpr int getEmptyKey() { return 0x7fffffff; }
207+
static constexpr int getTombstoneKey() { return -0x7fffffff - 1; }
208+
static constexpr unsigned getHashValue(const int &Val) {
209+
return (unsigned)(Val * 37U);
210+
}
193211

194-
static bool isEqual(const int &LHS, const int &RHS) { return LHS == RHS; }
212+
static constexpr bool isEqual(const int &LHS, const int &RHS) {
213+
return LHS == RHS;
214+
}
195215
};
196216

197217
// Provide DenseMapInfo for longs.
198218
template <>
199219
struct DenseMapInfo<long> {
200-
static inline long getEmptyKey() {
220+
static constexpr long getEmptyKey() {
201221
return (1UL << (sizeof(long) * 8 - 1)) - 1UL;
202222
}
203223

204-
static inline long getTombstoneKey() { return getEmptyKey() - 1L; }
224+
static constexpr long getTombstoneKey() { return getEmptyKey() - 1L; }
205225

206-
static unsigned getHashValue(const long &Val) {
226+
static constexpr unsigned getHashValue(const long &Val) {
207227
return (unsigned)(Val * 37UL);
208228
}
209229

210-
static bool isEqual(const long &LHS, const long &RHS) { return LHS == RHS; }
230+
static constexpr bool isEqual(const long &LHS, const long &RHS) {
231+
return LHS == RHS;
232+
}
211233
};
212234

213235
// Provide DenseMapInfo for long longs.
214236
template <>
215237
struct DenseMapInfo<long long> {
216-
static inline long long getEmptyKey() { return 0x7fffffffffffffffLL; }
217-
static inline long long getTombstoneKey() {
238+
static constexpr long long getEmptyKey() { return 0x7fffffffffffffffLL; }
239+
static constexpr long long getTombstoneKey() {
218240
return -0x7fffffffffffffffLL - 1;
219241
}
220242

221-
static unsigned getHashValue(const long long &Val) {
243+
static constexpr unsigned getHashValue(const long long &Val) {
222244
return (unsigned)(Val * 37ULL);
223245
}
224246

225-
static bool isEqual(const long long &LHS, const long long &RHS) {
247+
static constexpr bool isEqual(const long long &LHS, const long long &RHS) {
226248
return LHS == RHS;
227249
}
228250
};
@@ -234,22 +256,22 @@ struct DenseMapInfo<detail::DenseMapPair<T, U>> {
234256
using FirstInfo = DenseMapInfo<T>;
235257
using SecondInfo = DenseMapInfo<U>;
236258

237-
static inline Pair getEmptyKey() {
259+
static constexpr Pair getEmptyKey() {
238260
return detail::DenseMapPair<T, U>(FirstInfo::getEmptyKey(),
239261
SecondInfo::getEmptyKey());
240262
}
241263

242-
static inline Pair getTombstoneKey() {
264+
static constexpr Pair getTombstoneKey() {
243265
return detail::DenseMapPair<T, U>(FirstInfo::getTombstoneKey(),
244266
SecondInfo::getTombstoneKey());
245267
}
246268

247-
static unsigned getHashValue(const Pair &PairVal) {
269+
static constexpr unsigned getHashValue(const Pair &PairVal) {
248270
return detail::combineHashValue(FirstInfo::getHashValue(PairVal.first),
249271
SecondInfo::getHashValue(PairVal.second));
250272
}
251273

252-
static bool isEqual(const Pair &LHS, const Pair &RHS) {
274+
static constexpr bool isEqual(const Pair &LHS, const Pair &RHS) {
253275
return FirstInfo::isEqual(LHS.first, RHS.first) &&
254276
SecondInfo::isEqual(LHS.second, RHS.second);
255277
}

0 commit comments

Comments
 (0)