LLVM: include/llvm/Support/HashBuilder.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef LLVM_SUPPORT_HASHBUILDER_H
16#define LLVM_SUPPORT_HASHBUILDER_H
17
24
25#include
26#include
27#include
28
29namespace llvm {
30
37
38
40public:
41 template <typename HasherT_ = HasherT>
42 using HashResultTy = decltype(std::declval<HasherT_ &>().final());
43
45
46
47
48
49
50
52
53
54
55
56
57
62
63
67
68
72
73protected:
75
76 template <typename... ArgTypes>
78 : OptionalHasher(std::in_place, std::forward(Args)...),
79 Hasher(*OptionalHasher) {}
80
81private:
82 std::optional OptionalHasher;
83 HasherT &Hasher;
84};
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136template <typename HasherT, llvm::endianness Endianness>
138public:
140 template <typename... ArgTypes>
143
144
145 template
146 std::enable_if_t<hashbuilder_detail::IsHashableData::value, HashBuilder &>
150
151
152
153
154
155
156
157
158
159
160
161
162
163
165
166
167
168
173 Value.size() * sizeof(T)));
174 } else {
175 for (auto &V : Value)
177 }
178 return *this;
179 }
180
181
182
183
184
185
186
187
188
189
190
191
192
193
195
196
197
198
202 return *this;
203 }
204
205 template
207 decltype(addHash(std::declval<HashBuilder &>(), std::declval<T &>()));
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291 template
292 std::enable_if_t<is_detected<HasAddHashT, T>::value &&
296 addHash(*this, Value);
297 return *this;
298 }
299
300 template <typename T1, typename T2>
304
305 template <typename... Ts> HashBuilder &add(const std::tuple<Ts...> &Arg) {
306 std::apply([this](const auto &...Args) { this->add(Args...); }, Arg);
307 return *this;
308 }
309
310
311
312
313
314
315
316
317
318
319
320 template <typename... Ts>
321 std::enable_if_t<(sizeof...(Ts) > 1), HashBuilder &> add(const Ts &...Args) {
322 return (add(Args), ...);
323 }
324
325 template
330
334
335 template
337 return addRangeElementsImpl(
339 typename std::iterator_traits::iterator_category());
340 }
341
342 template
346
347 template
350
351 template
352 std::enable_if_t<is_detected<HasByteSwapT, T>::value, HashBuilder &>
356 sizeof(SwappedValue)));
357 return *this;
358 }
359
360private:
361
362
363 template
365 ForwardIteratorT Last,
366 std::forward_iterator_tag) {
367 using T = typename std::iterator_traits::value_type;
368 if constexpr (std::is_pointer_v &&
373 } else {
374 for (auto It = First; It != Last; ++It)
375 add(*It);
376 }
377 return *this;
378 }
379};
380
391
394}
395
396
397
398template
399std::enable_if_t<
407}
408
409#endif
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
void update(StringRef Data)
Forward to HasherT::update(ArrayRef<uint8_t>).
Definition HashBuilder.h:58
HashResultTy< HasherT_ > result()
Forward to HasherT::result() if available.
Definition HashBuilder.h:69
HashBuilderBase(HasherT &Hasher)
Definition HashBuilder.h:74
HashBuilderBase(ArgTypes &&...Args)
Definition HashBuilder.h:77
decltype(std::declval< HasherT_ & >().final()) HashResultTy
Definition HashBuilder.h:42
void update(ArrayRef< uint8_t > Data)
Forward to HasherT::update(ArrayRef<uint8_t>).
Definition HashBuilder.h:51
HasherT & getHasher()
Definition HashBuilder.h:44
Interface to help hash various types through a hasher type.
Definition HashBuilder.h:137
std::enable_if_t< is_detected< HasAddHashT, T >::value &&!hashbuilder_detail::IsHashableData< T >::value, HashBuilder & > add(const T &Value)
Implement hashing for user-defined structs.
Definition HashBuilder.h:295
HashBuilder & add(StringRef Value)
Support hashing StringRef.
Definition HashBuilder.h:194
std::enable_if_t< is_detected< HasByteSwapT, T >::value, HashBuilder & > adjustForEndiannessAndAdd(const T &Value)
Adjust Value for the target endianness and add it to the hash.
Definition HashBuilder.h:353
HashBuilder(HasherT &Hasher)
Definition HashBuilder.h:139
std::enable_if_t<(sizeof...(Ts) > 1), HashBuilder & > add(const Ts &...Args)
A convenenience variadic helper.
Definition HashBuilder.h:321
HashBuilder & addRangeElements(const RangeT &Range)
Definition HashBuilder.h:343
HashBuilder & addRange(const RangeT &Range)
Definition HashBuilder.h:331
HashBuilder & addRangeElements(ForwardIteratorT First, ForwardIteratorT Last)
Definition HashBuilder.h:336
decltype(addHash(std::declval< HashBuilder & >(), std::declval< T & >())) HasAddHashT
Definition HashBuilder.h:206
HashBuilder & add(const std::tuple< Ts... > &Arg)
Definition HashBuilder.h:305
HashBuilder & add(ArrayRef< T > Value)
Support hashing ArrayRef.
Definition HashBuilder.h:164
std::enable_if_t< hashbuilder_detail::IsHashableData< T >::value, HashBuilder & > add(T Value)
Implement hashing for hashable data types, e.g. integral or enum values.
Definition HashBuilder.h:147
HashBuilder & addRange(ForwardIteratorT First, ForwardIteratorT Last)
Definition HashBuilder.h:326
HashBuilder & add(const std::pair< T1, T2 > &Value)
Definition HashBuilder.h:301
decltype(support::endian::byte_swap( std::declval< T & >(), llvm::endianness::little)) HasByteSwapT
Definition HashBuilder.h:348
HashBuilder(ArgTypes &&...Args)
Definition HashBuilder.h:141
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
An opaque object representing a hash code.
void update(ArrayRef< uint8_t > Data)
Definition HashBuilder.h:385
hash_code Code
Definition HashBuilder.h:389
HashCodeHasher()
Definition HashBuilder.h:384
Metafunction that determines whether the given type is either an integral type or an enumeration type...
Definition HashBuilder.h:31
HashBuilder< hashbuilder_detail::HashCodeHasher, llvm::endianness::native > HashCodeHashBuilder
Definition HashBuilder.h:392
value_type byte_swap(value_type value, endianness endian)
This is an optimization pass for GlobalISel generic memory operations.
hash_code hash_value(const FixedPointSemantics &Val)
constexpr auto adl_begin(RangeT &&range) -> decltype(adl_detail::begin_impl(std::forward< RangeT >(range)))
Returns the begin iterator to range using std::begin and function found through Argument-Dependent Lo...
constexpr auto adl_end(RangeT &&range) -> decltype(adl_detail::end_impl(std::forward< RangeT >(range)))
Returns the end iterator to range using std::end and functions found through Argument-Dependent Looku...
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
ArrayRef(const T &OneElt) -> ArrayRef< T >
typename detail::detector< void, Op, Args... >::value_t is_detected
Detects if a given trait holds for some set of arguments 'Args'.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Implement std::hash so that hash_code can be used in STL containers.
Trait to indicate whether a type's bits can be hashed directly (after endianness correction).
Definition HashBuilder.h:34