/home/arjun/llvm-project/llvm/include/llvm/ADT/Hashing.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- llvm/ADT/Hashing.h - Utilities for hashing --------------*- C++ -*-===// |
2 | | // |
3 | | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | | // See https://llvm.org/LICENSE.txt for license information. |
5 | | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file implements the newly proposed standard C++ interfaces for hashing |
10 | | // arbitrary data and building hash functions for user-defined types. This |
11 | | // interface was originally proposed in N3333[1] and is currently under review |
12 | | // for inclusion in a future TR and/or standard. |
13 | | // |
14 | | // The primary interfaces provide are comprised of one type and three functions: |
15 | | // |
16 | | // -- 'hash_code' class is an opaque type representing the hash code for some |
17 | | // data. It is the intended product of hashing, and can be used to implement |
18 | | // hash tables, checksumming, and other common uses of hashes. It is not an |
19 | | // integer type (although it can be converted to one) because it is risky |
20 | | // to assume much about the internals of a hash_code. In particular, each |
21 | | // execution of the program has a high probability of producing a different |
22 | | // hash_code for a given input. Thus their values are not stable to save or |
23 | | // persist, and should only be used during the execution for the |
24 | | // construction of hashing datastructures. |
25 | | // |
26 | | // -- 'hash_value' is a function designed to be overloaded for each |
27 | | // user-defined type which wishes to be used within a hashing context. It |
28 | | // should be overloaded within the user-defined type's namespace and found |
29 | | // via ADL. Overloads for primitive types are provided by this library. |
30 | | // |
31 | | // -- 'hash_combine' and 'hash_combine_range' are functions designed to aid |
32 | | // programmers in easily and intuitively combining a set of data into |
33 | | // a single hash_code for their object. They should only logically be used |
34 | | // within the implementation of a 'hash_value' routine or similar context. |
35 | | // |
36 | | // Note that 'hash_combine_range' contains very special logic for hashing |
37 | | // a contiguous array of integers or pointers. This logic is *extremely* fast, |
38 | | // on a modern Intel "Gainestown" Xeon (Nehalem uarch) @2.2 GHz, these were |
39 | | // benchmarked at over 6.5 GiB/s for large keys, and <20 cycles/hash for keys |
40 | | // under 32-bytes. |
41 | | // |
42 | | //===----------------------------------------------------------------------===// |
43 | | |
44 | | #ifndef LLVM_ADT_HASHING_H |
45 | | #define LLVM_ADT_HASHING_H |
46 | | |
47 | | #include "llvm/Support/DataTypes.h" |
48 | | #include "llvm/Support/ErrorHandling.h" |
49 | | #include "llvm/Support/SwapByteOrder.h" |
50 | | #include "llvm/Support/type_traits.h" |
51 | | #include <algorithm> |
52 | | #include <cassert> |
53 | | #include <cstring> |
54 | | #include <string> |
55 | | #include <utility> |
56 | | |
57 | | namespace llvm { |
58 | | |
59 | | /// An opaque object representing a hash code. |
60 | | /// |
61 | | /// This object represents the result of hashing some entity. It is intended to |
62 | | /// be used to implement hashtables or other hashing-based data structures. |
63 | | /// While it wraps and exposes a numeric value, this value should not be |
64 | | /// trusted to be stable or predictable across processes or executions. |
65 | | /// |
66 | | /// In order to obtain the hash_code for an object 'x': |
67 | | /// \code |
68 | | /// using llvm::hash_value; |
69 | | /// llvm::hash_code code = hash_value(x); |
70 | | /// \endcode |
71 | | class hash_code { |
72 | | size_t value; |
73 | | |
74 | | public: |
75 | | /// Default construct a hash_code. |
76 | | /// Note that this leaves the value uninitialized. |
77 | | hash_code() = default; |
78 | | |
79 | | /// Form a hash code directly from a numerical value. |
80 | 0 | hash_code(size_t value) : value(value) {} |
81 | | |
82 | | /// Convert the hash code to its numerical value for use. |
83 | 0 | /*explicit*/ operator size_t() const { return value; } |
84 | | |
85 | 0 | friend bool operator==(const hash_code &lhs, const hash_code &rhs) { |
86 | 0 | return lhs.value == rhs.value; |
87 | 0 | } |
88 | 0 | friend bool operator!=(const hash_code &lhs, const hash_code &rhs) { |
89 | 0 | return lhs.value != rhs.value; |
90 | 0 | } |
91 | | |
92 | | /// Allow a hash_code to be directly run through hash_value. |
93 | 0 | friend size_t hash_value(const hash_code &code) { return code.value; } |
94 | | }; |
95 | | |
96 | | /// Compute a hash_code for any integer value. |
97 | | /// |
98 | | /// Note that this function is intended to compute the same hash_code for |
99 | | /// a particular value without regard to the pre-promotion type. This is in |
100 | | /// contrast to hash_combine which may produce different hash_codes for |
101 | | /// differing argument types even if they would implicit promote to a common |
102 | | /// type without changing the value. |
103 | | template <typename T> |
104 | | std::enable_if_t<is_integral_or_enum<T>::value, hash_code> hash_value(T value); |
105 | | |
106 | | /// Compute a hash_code for a pointer's address. |
107 | | /// |
108 | | /// N.B.: This hashes the *address*. Not the value and not the type. |
109 | | template <typename T> hash_code hash_value(const T *ptr); |
110 | | |
111 | | /// Compute a hash_code for a pair of objects. |
112 | | template <typename T, typename U> |
113 | | hash_code hash_value(const std::pair<T, U> &arg); |
114 | | |
115 | | /// Compute a hash_code for a standard string. |
116 | | template <typename T> |
117 | | hash_code hash_value(const std::basic_string<T> &arg); |
118 | | |
119 | | |
120 | | /// Override the execution seed with a fixed value. |
121 | | /// |
122 | | /// This hashing library uses a per-execution seed designed to change on each |
123 | | /// run with high probability in order to ensure that the hash codes are not |
124 | | /// attackable and to ensure that output which is intended to be stable does |
125 | | /// not rely on the particulars of the hash codes produced. |
126 | | /// |
127 | | /// That said, there are use cases where it is important to be able to |
128 | | /// reproduce *exactly* a specific behavior. To that end, we provide a function |
129 | | /// which will forcibly set the seed to a fixed value. This must be done at the |
130 | | /// start of the program, before any hashes are computed. Also, it cannot be |
131 | | /// undone. This makes it thread-hostile and very hard to use outside of |
132 | | /// immediately on start of a simple program designed for reproducible |
133 | | /// behavior. |
134 | | void set_fixed_execution_hash_seed(uint64_t fixed_value); |
135 | | |
136 | | |
137 | | // All of the implementation details of actually computing the various hash |
138 | | // code values are held within this namespace. These routines are included in |
139 | | // the header file mainly to allow inlining and constant propagation. |
140 | | namespace hashing { |
141 | | namespace detail { |
142 | | |
143 | 0 | inline uint64_t fetch64(const char *p) { |
144 | 0 | uint64_t result; |
145 | 0 | memcpy(&result, p, sizeof(result)); |
146 | 0 | if (sys::IsBigEndianHost) |
147 | 0 | sys::swapByteOrder(result); |
148 | 0 | return result; |
149 | 0 | } |
150 | | |
151 | 0 | inline uint32_t fetch32(const char *p) { |
152 | 0 | uint32_t result; |
153 | 0 | memcpy(&result, p, sizeof(result)); |
154 | 0 | if (sys::IsBigEndianHost) |
155 | 0 | sys::swapByteOrder(result); |
156 | 0 | return result; |
157 | 0 | } |
158 | | |
159 | | /// Some primes between 2^63 and 2^64 for various uses. |
160 | | static constexpr uint64_t k0 = 0xc3a5c85c97cb3127ULL; |
161 | | static constexpr uint64_t k1 = 0xb492b66fbe98f273ULL; |
162 | | static constexpr uint64_t k2 = 0x9ae16a3b2f90404fULL; |
163 | | static constexpr uint64_t k3 = 0xc949d7c7509e6557ULL; |
164 | | |
165 | | /// Bitwise right rotate. |
166 | | /// Normally this will compile to a single instruction, especially if the |
167 | | /// shift is a manifest constant. |
168 | 0 | inline uint64_t rotate(uint64_t val, size_t shift) { |
169 | 0 | // Avoid shifting by 64: doing so yields an undefined result. |
170 | 0 | return shift == 0 ? val : ((val >> shift) | (val << (64 - shift))); |
171 | 0 | } |
172 | | |
173 | 0 | inline uint64_t shift_mix(uint64_t val) { |
174 | 0 | return val ^ (val >> 47); |
175 | 0 | } |
176 | | |
177 | 0 | inline uint64_t hash_16_bytes(uint64_t low, uint64_t high) { |
178 | 0 | // Murmur-inspired hashing. |
179 | 0 | const uint64_t kMul = 0x9ddfea08eb382d69ULL; |
180 | 0 | uint64_t a = (low ^ high) * kMul; |
181 | 0 | a ^= (a >> 47); |
182 | 0 | uint64_t b = (high ^ a) * kMul; |
183 | 0 | b ^= (b >> 47); |
184 | 0 | b *= kMul; |
185 | 0 | return b; |
186 | 0 | } |
187 | | |
188 | 0 | inline uint64_t hash_1to3_bytes(const char *s, size_t len, uint64_t seed) { |
189 | 0 | uint8_t a = s[0]; |
190 | 0 | uint8_t b = s[len >> 1]; |
191 | 0 | uint8_t c = s[len - 1]; |
192 | 0 | uint32_t y = static_cast<uint32_t>(a) + (static_cast<uint32_t>(b) << 8); |
193 | 0 | uint32_t z = static_cast<uint32_t>(len) + (static_cast<uint32_t>(c) << 2); |
194 | 0 | return shift_mix(y * k2 ^ z * k3 ^ seed) * k2; |
195 | 0 | } |
196 | | |
197 | 0 | inline uint64_t hash_4to8_bytes(const char *s, size_t len, uint64_t seed) { |
198 | 0 | uint64_t a = fetch32(s); |
199 | 0 | return hash_16_bytes(len + (a << 3), seed ^ fetch32(s + len - 4)); |
200 | 0 | } |
201 | | |
202 | 0 | inline uint64_t hash_9to16_bytes(const char *s, size_t len, uint64_t seed) { |
203 | 0 | uint64_t a = fetch64(s); |
204 | 0 | uint64_t b = fetch64(s + len - 8); |
205 | 0 | return hash_16_bytes(seed ^ a, rotate(b + len, len)) ^ b; |
206 | 0 | } |
207 | | |
208 | 0 | inline uint64_t hash_17to32_bytes(const char *s, size_t len, uint64_t seed) { |
209 | 0 | uint64_t a = fetch64(s) * k1; |
210 | 0 | uint64_t b = fetch64(s + 8); |
211 | 0 | uint64_t c = fetch64(s + len - 8) * k2; |
212 | 0 | uint64_t d = fetch64(s + len - 16) * k0; |
213 | 0 | return hash_16_bytes(rotate(a - b, 43) + rotate(c ^ seed, 30) + d, |
214 | 0 | a + rotate(b ^ k3, 20) - c + len + seed); |
215 | 0 | } |
216 | | |
217 | 0 | inline uint64_t hash_33to64_bytes(const char *s, size_t len, uint64_t seed) { |
218 | 0 | uint64_t z = fetch64(s + 24); |
219 | 0 | uint64_t a = fetch64(s) + (len + fetch64(s + len - 16)) * k0; |
220 | 0 | uint64_t b = rotate(a + z, 52); |
221 | 0 | uint64_t c = rotate(a, 37); |
222 | 0 | a += fetch64(s + 8); |
223 | 0 | c += rotate(a, 7); |
224 | 0 | a += fetch64(s + 16); |
225 | 0 | uint64_t vf = a + z; |
226 | 0 | uint64_t vs = b + rotate(a, 31) + c; |
227 | 0 | a = fetch64(s + 16) + fetch64(s + len - 32); |
228 | 0 | z = fetch64(s + len - 8); |
229 | 0 | b = rotate(a + z, 52); |
230 | 0 | c = rotate(a, 37); |
231 | 0 | a += fetch64(s + len - 24); |
232 | 0 | c += rotate(a, 7); |
233 | 0 | a += fetch64(s + len - 16); |
234 | 0 | uint64_t wf = a + z; |
235 | 0 | uint64_t ws = b + rotate(a, 31) + c; |
236 | 0 | uint64_t r = shift_mix((vf + ws) * k2 + (wf + vs) * k0); |
237 | 0 | return shift_mix((seed ^ (r * k0)) + vs) * k2; |
238 | 0 | } |
239 | | |
240 | 0 | inline uint64_t hash_short(const char *s, size_t length, uint64_t seed) { |
241 | 0 | if (length >= 4 && length <= 8) |
242 | 0 | return hash_4to8_bytes(s, length, seed); |
243 | 0 | if (length > 8 && length <= 16) |
244 | 0 | return hash_9to16_bytes(s, length, seed); |
245 | 0 | if (length > 16 && length <= 32) |
246 | 0 | return hash_17to32_bytes(s, length, seed); |
247 | 0 | if (length > 32) |
248 | 0 | return hash_33to64_bytes(s, length, seed); |
249 | 0 | if (length != 0) |
250 | 0 | return hash_1to3_bytes(s, length, seed); |
251 | 0 | |
252 | 0 | return k2 ^ seed; |
253 | 0 | } |
254 | | |
255 | | /// The intermediate state used during hashing. |
256 | | /// Currently, the algorithm for computing hash codes is based on CityHash and |
257 | | /// keeps 56 bytes of arbitrary state. |
258 | | struct hash_state { |
259 | | uint64_t h0 = 0, h1 = 0, h2 = 0, h3 = 0, h4 = 0, h5 = 0, h6 = 0; |
260 | | |
261 | | /// Create a new hash_state structure and initialize it based on the |
262 | | /// seed and the first 64-byte chunk. |
263 | | /// This effectively performs the initial mix. |
264 | 0 | static hash_state create(const char *s, uint64_t seed) { |
265 | 0 | hash_state state = { |
266 | 0 | 0, seed, hash_16_bytes(seed, k1), rotate(seed ^ k1, 49), |
267 | 0 | seed * k1, shift_mix(seed), 0 }; |
268 | 0 | state.h6 = hash_16_bytes(state.h4, state.h5); |
269 | 0 | state.mix(s); |
270 | 0 | return state; |
271 | 0 | } |
272 | | |
273 | | /// Mix 32-bytes from the input sequence into the 16-bytes of 'a' |
274 | | /// and 'b', including whatever is already in 'a' and 'b'. |
275 | 0 | static void mix_32_bytes(const char *s, uint64_t &a, uint64_t &b) { |
276 | 0 | a += fetch64(s); |
277 | 0 | uint64_t c = fetch64(s + 24); |
278 | 0 | b = rotate(b + a + c, 21); |
279 | 0 | uint64_t d = a; |
280 | 0 | a += fetch64(s + 8) + fetch64(s + 16); |
281 | 0 | b += rotate(a, 44) + d; |
282 | 0 | a += c; |
283 | 0 | } |
284 | | |
285 | | /// Mix in a 64-byte buffer of data. |
286 | | /// We mix all 64 bytes even when the chunk length is smaller, but we |
287 | | /// record the actual length. |
288 | 0 | void mix(const char *s) { |
289 | 0 | h0 = rotate(h0 + h1 + h3 + fetch64(s + 8), 37) * k1; |
290 | 0 | h1 = rotate(h1 + h4 + fetch64(s + 48), 42) * k1; |
291 | 0 | h0 ^= h6; |
292 | 0 | h1 += h3 + fetch64(s + 40); |
293 | 0 | h2 = rotate(h2 + h5, 33) * k1; |
294 | 0 | h3 = h4 * k1; |
295 | 0 | h4 = h0 + h5; |
296 | 0 | mix_32_bytes(s, h3, h4); |
297 | 0 | h5 = h2 + h6; |
298 | 0 | h6 = h1 + fetch64(s + 16); |
299 | 0 | mix_32_bytes(s + 32, h5, h6); |
300 | 0 | std::swap(h2, h0); |
301 | 0 | } |
302 | | |
303 | | /// Compute the final 64-bit hash code value based on the current |
304 | | /// state and the length of bytes hashed. |
305 | 0 | uint64_t finalize(size_t length) { |
306 | 0 | return hash_16_bytes(hash_16_bytes(h3, h5) + shift_mix(h1) * k1 + h2, |
307 | 0 | hash_16_bytes(h4, h6) + shift_mix(length) * k1 + h0); |
308 | 0 | } |
309 | | }; |
310 | | |
311 | | |
312 | | /// A global, fixed seed-override variable. |
313 | | /// |
314 | | /// This variable can be set using the \see llvm::set_fixed_execution_seed |
315 | | /// function. See that function for details. Do not, under any circumstances, |
316 | | /// set or read this variable. |
317 | | extern uint64_t fixed_seed_override; |
318 | | |
319 | 0 | inline uint64_t get_execution_seed() { |
320 | 0 | // FIXME: This needs to be a per-execution seed. This is just a placeholder |
321 | 0 | // implementation. Switching to a per-execution seed is likely to flush out |
322 | 0 | // instability bugs and so will happen as its own commit. |
323 | 0 | // |
324 | 0 | // However, if there is a fixed seed override set the first time this is |
325 | 0 | // called, return that instead of the per-execution seed. |
326 | 0 | const uint64_t seed_prime = 0xff51afd7ed558ccdULL; |
327 | 0 | static uint64_t seed = fixed_seed_override ? fixed_seed_override : seed_prime; |
328 | 0 | return seed; |
329 | 0 | } |
330 | | |
331 | | |
332 | | /// Trait to indicate whether a type's bits can be hashed directly. |
333 | | /// |
334 | | /// A type trait which is true if we want to combine values for hashing by |
335 | | /// reading the underlying data. It is false if values of this type must |
336 | | /// first be passed to hash_value, and the resulting hash_codes combined. |
337 | | // |
338 | | // FIXME: We want to replace is_integral_or_enum and is_pointer here with |
339 | | // a predicate which asserts that comparing the underlying storage of two |
340 | | // values of the type for equality is equivalent to comparing the two values |
341 | | // for equality. For all the platforms we care about, this holds for integers |
342 | | // and pointers, but there are platforms where it doesn't and we would like to |
343 | | // support user-defined types which happen to satisfy this property. |
344 | | template <typename T> struct is_hashable_data |
345 | | : std::integral_constant<bool, ((is_integral_or_enum<T>::value || |
346 | | std::is_pointer<T>::value) && |
347 | | 64 % sizeof(T) == 0)> {}; |
348 | | |
349 | | // Special case std::pair to detect when both types are viable and when there |
350 | | // is no alignment-derived padding in the pair. This is a bit of a lie because |
351 | | // std::pair isn't truly POD, but it's close enough in all reasonable |
352 | | // implementations for our use case of hashing the underlying data. |
353 | | template <typename T, typename U> struct is_hashable_data<std::pair<T, U> > |
354 | | : std::integral_constant<bool, (is_hashable_data<T>::value && |
355 | | is_hashable_data<U>::value && |
356 | | (sizeof(T) + sizeof(U)) == |
357 | | sizeof(std::pair<T, U>))> {}; |
358 | | |
359 | | /// Helper to get the hashable data representation for a type. |
360 | | /// This variant is enabled when the type itself can be used. |
361 | | template <typename T> |
362 | | std::enable_if_t<is_hashable_data<T>::value, T> |
363 | 0 | get_hashable_data(const T &value) { |
364 | 0 | return value; |
365 | 0 | } Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIPN4mlir5BlockEEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueES7_E4typeERKS7_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIhEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueES4_E4typeERKS4_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIjEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueES4_E4typeERKS4_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIiEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueES4_E4typeERKS4_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIPKNS_12fltSemanticsEEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueES7_E4typeERKS7_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataImEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueES4_E4typeERKS4_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIlEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueES4_E4typeERKS4_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIPN4mlir7DialectEEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueES7_E4typeERKS7_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIPKN4mlir4TypeEEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueES8_E4typeERKS8_ |
366 | | /// Helper to get the hashable data representation for a type. |
367 | | /// This variant is enabled when we must first call hash_value and use the |
368 | | /// result as our data. |
369 | | template <typename T> |
370 | | std::enable_if_t<!is_hashable_data<T>::value, size_t> |
371 | 0 | get_hashable_data(const T &value) { |
372 | 0 | using ::llvm::hash_value; |
373 | 0 | return hash_value(value); |
374 | 0 | } Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataINS_9hash_codeEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS5_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIN4mlir9AttributeEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataISt4pairIN4mlir10IdentifierENS4_9AttributeEEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS9_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIN4mlir10IdentifierEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIN4mlir4TypeEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIN4mlir17FlatSymbolRefAttrEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataINS_8ArrayRefINS_9StringRefEEEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS7_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataINS_9StringRefEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS5_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIN4mlir10ShapedTypeEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataINS_8ArrayRefIcEEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIN4mlir20DenseIntElementsAttrEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIN4mlir17DenseElementsAttrEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIN4mlir8LocationEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIN4mlir10AffineExprEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIN4mlir13OperationNameEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIN4mlir21MutableDictionaryAttrEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIN4mlir5ValueEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ Unexecuted instantiation: _ZN4llvm7hashing6detail17get_hashable_dataIN4mlir9AffineMapEEENSt9enable_ifIXntsr16is_hashable_dataIT_EE5valueEmE4typeERKS6_ |
375 | | |
376 | | /// Helper to store data from a value into a buffer and advance the |
377 | | /// pointer into that buffer. |
378 | | /// |
379 | | /// This routine first checks whether there is enough space in the provided |
380 | | /// buffer, and if not immediately returns false. If there is space, it |
381 | | /// copies the underlying bytes of value into the buffer, advances the |
382 | | /// buffer_ptr past the copied bytes, and returns true. |
383 | | template <typename T> |
384 | | bool store_and_advance(char *&buffer_ptr, char *buffer_end, const T& value, |
385 | 0 | size_t offset = 0) { |
386 | 0 | size_t store_size = sizeof(value) - offset; |
387 | 0 | if (buffer_ptr + store_size > buffer_end) |
388 | 0 | return false; |
389 | 0 | const char *value_data = reinterpret_cast<const char *>(&value); |
390 | 0 | memcpy(buffer_ptr, value_data + offset, store_size); |
391 | 0 | buffer_ptr += store_size; |
392 | 0 | return true; |
393 | 0 | } Unexecuted instantiation: _ZN4llvm7hashing6detail17store_and_advanceIPN4mlir5BlockEEEbRPcS6_RKT_m Unexecuted instantiation: _ZN4llvm7hashing6detail17store_and_advanceIhEEbRPcS3_RKT_m Unexecuted instantiation: _ZN4llvm7hashing6detail17store_and_advanceIjEEbRPcS3_RKT_m Unexecuted instantiation: _ZN4llvm7hashing6detail17store_and_advanceIiEEbRPcS3_RKT_m Unexecuted instantiation: _ZN4llvm7hashing6detail17store_and_advanceImEEbRPcS3_RKT_m Unexecuted instantiation: _ZN4llvm7hashing6detail17store_and_advanceIPKNS_12fltSemanticsEEEbRPcS6_RKT_m Unexecuted instantiation: _ZN4llvm7hashing6detail17store_and_advanceIlEEbRPcS3_RKT_m Unexecuted instantiation: _ZN4llvm7hashing6detail17store_and_advanceIPN4mlir7DialectEEEbRPcS6_RKT_m Unexecuted instantiation: _ZN4llvm7hashing6detail17store_and_advanceIPKN4mlir4TypeEEEbRPcS7_RKT_m |
394 | | |
395 | | /// Implement the combining of integral values into a hash_code. |
396 | | /// |
397 | | /// This overload is selected when the value type of the iterator is |
398 | | /// integral. Rather than computing a hash_code for each object and then |
399 | | /// combining them, this (as an optimization) directly combines the integers. |
400 | | template <typename InputIteratorT> |
401 | 0 | hash_code hash_combine_range_impl(InputIteratorT first, InputIteratorT last) { |
402 | 0 | const uint64_t seed = get_execution_seed(); |
403 | 0 | char buffer[64], *buffer_ptr = buffer; |
404 | 0 | char *const buffer_end = std::end(buffer); |
405 | 0 | while (first != last && store_and_advance(buffer_ptr, buffer_end, |
406 | 0 | get_hashable_data(*first))) |
407 | 0 | ++first; |
408 | 0 | if (first == last) |
409 | 0 | return hash_short(buffer, buffer_ptr - buffer, seed); |
410 | 0 | assert(buffer_ptr == buffer_end); |
411 | 0 |
|
412 | 0 | hash_state state = state.create(buffer, seed); |
413 | 0 | size_t length = 64; |
414 | 0 | while (first != last) { |
415 | 0 | // Fill up the buffer. We don't clear it, which re-mixes the last round |
416 | 0 | // when only a partial 64-byte chunk is left. |
417 | 0 | buffer_ptr = buffer; |
418 | 0 | while (first != last && store_and_advance(buffer_ptr, buffer_end, |
419 | 0 | get_hashable_data(*first))) |
420 | 0 | ++first; |
421 | 0 |
|
422 | 0 | // Rotate the buffer if we did a partial fill in order to simulate doing |
423 | 0 | // a mix of the last 64-bytes. That is how the algorithm works when we |
424 | 0 | // have a contiguous byte sequence, and we want to emulate that here. |
425 | 0 | std::rotate(buffer, buffer_ptr, buffer_end); |
426 | 0 |
|
427 | 0 | // Mix this chunk into the current state. |
428 | 0 | state.mix(buffer); |
429 | 0 | length += buffer_ptr - buffer; |
430 | 0 | }; |
431 | 0 |
|
432 | 0 | return state.finalize(length); |
433 | 0 | } Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implINS_6detail27indexed_accessor_range_baseIN4mlir14SuccessorRangeEPNS5_12BlockOperandEPNS5_5BlockESA_SA_E8iteratorEEENS_9hash_codeET_SE_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implIPKN4mlir9AttributeEEENS_9hash_codeET_S8_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implIPKSt4pairIN4mlir10IdentifierENS4_9AttributeEEEENS_9hash_codeET_SB_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implIPKN4mlir17FlatSymbolRefAttrEEENS_9hash_codeET_S8_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implIPKNS_9StringRefEEENS_9hash_codeET_S7_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implIPKN4mlir8LocationEEENS_9hash_codeET_S8_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implIPKN4mlir10AffineExprEEENS_9hash_codeET_S8_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implINS_6detail27indexed_accessor_range_baseIN4mlir12OperandRangeEPNS5_9OpOperandENS5_5ValueES9_S9_E8iteratorEEENS_9hash_codeET_SD_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implIPKN4mlir9AffineMapEEENS_9hash_codeET_S8_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implIPKN4mlir4TypeEEENS_9hash_codeET_S8_ |
434 | | |
435 | | /// Implement the combining of integral values into a hash_code. |
436 | | /// |
437 | | /// This overload is selected when the value type of the iterator is integral |
438 | | /// and when the input iterator is actually a pointer. Rather than computing |
439 | | /// a hash_code for each object and then combining them, this (as an |
440 | | /// optimization) directly combines the integers. Also, because the integers |
441 | | /// are stored in contiguous memory, this routine avoids copying each value |
442 | | /// and directly reads from the underlying memory. |
443 | | template <typename ValueT> |
444 | | std::enable_if_t<is_hashable_data<ValueT>::value, hash_code> |
445 | 0 | hash_combine_range_impl(ValueT *first, ValueT *last) { |
446 | 0 | const uint64_t seed = get_execution_seed(); |
447 | 0 | const char *s_begin = reinterpret_cast<const char *>(first); |
448 | 0 | const char *s_end = reinterpret_cast<const char *>(last); |
449 | 0 | const size_t length = std::distance(s_begin, s_end); |
450 | 0 | if (length <= 64) |
451 | 0 | return hash_short(s_begin, length, seed); |
452 | 0 | |
453 | 0 | const char *s_aligned_end = s_begin + (length & ~63); |
454 | 0 | hash_state state = state.create(s_begin, seed); |
455 | 0 | s_begin += 64; |
456 | 0 | while (s_begin != s_aligned_end) { |
457 | 0 | state.mix(s_begin); |
458 | 0 | s_begin += 64; |
459 | 0 | } |
460 | 0 | if (length & 63) |
461 | 0 | state.mix(s_end - 64); |
462 | 0 |
|
463 | 0 | return state.finalize(length); |
464 | 0 | } Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implIKmEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueENS_9hash_codeEE4typeEPS5_S9_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implIKcEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueENS_9hash_codeEE4typeEPS5_S9_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implImEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueENS_9hash_codeEE4typeEPS4_S8_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implIKjEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueENS_9hash_codeEE4typeEPS5_S9_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implIKlEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueENS_9hash_codeEE4typeEPS5_S9_ Unexecuted instantiation: _ZN4llvm7hashing6detail23hash_combine_range_implIKbEENSt9enable_ifIXsr16is_hashable_dataIT_EE5valueENS_9hash_codeEE4typeEPS5_S9_ |
465 | | |
466 | | } // namespace detail |
467 | | } // namespace hashing |
468 | | |
469 | | |
470 | | /// Compute a hash_code for a sequence of values. |
471 | | /// |
472 | | /// This hashes a sequence of values. It produces the same hash_code as |
473 | | /// 'hash_combine(a, b, c, ...)', but can run over arbitrary sized sequences |
474 | | /// and is significantly faster given pointers and types which can be hashed as |
475 | | /// a sequence of bytes. |
476 | | template <typename InputIteratorT> |
477 | 0 | hash_code hash_combine_range(InputIteratorT first, InputIteratorT last) { |
478 | 0 | return ::llvm::hashing::detail::hash_combine_range_impl(first, last); |
479 | 0 | } Unexecuted instantiation: _ZN4llvm18hash_combine_rangeINS_6detail27indexed_accessor_range_baseIN4mlir14SuccessorRangeEPNS3_12BlockOperandEPNS3_5BlockES8_S8_E8iteratorEEENS_9hash_codeET_SC_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPKmEENS_9hash_codeET_S4_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPKcEENS_9hash_codeET_S4_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPmEENS_9hash_codeET_S3_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPKjEENS_9hash_codeET_S4_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPKlEENS_9hash_codeET_S4_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPKN4mlir9AttributeEEENS_9hash_codeET_S6_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPKSt4pairIN4mlir10IdentifierENS2_9AttributeEEEENS_9hash_codeET_S9_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPKN4mlir17FlatSymbolRefAttrEEENS_9hash_codeET_S6_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPKNS_9StringRefEEENS_9hash_codeET_S5_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPKN4mlir8LocationEEENS_9hash_codeET_S6_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPKN4mlir10AffineExprEEENS_9hash_codeET_S6_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPKbEENS_9hash_codeET_S4_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeINS_6detail27indexed_accessor_range_baseIN4mlir12OperandRangeEPNS3_9OpOperandENS3_5ValueES7_S7_E8iteratorEEENS_9hash_codeET_SB_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPKN4mlir9AffineMapEEENS_9hash_codeET_S6_ Unexecuted instantiation: _ZN4llvm18hash_combine_rangeIPKN4mlir4TypeEEENS_9hash_codeET_S6_ |
480 | | |
481 | | |
482 | | // Implementation details for hash_combine. |
483 | | namespace hashing { |
484 | | namespace detail { |
485 | | |
486 | | /// Helper class to manage the recursive combining of hash_combine |
487 | | /// arguments. |
488 | | /// |
489 | | /// This class exists to manage the state and various calls involved in the |
490 | | /// recursive combining of arguments used in hash_combine. It is particularly |
491 | | /// useful at minimizing the code in the recursive calls to ease the pain |
492 | | /// caused by a lack of variadic functions. |
493 | | struct hash_combine_recursive_helper { |
494 | | char buffer[64] = {}; |
495 | | hash_state state; |
496 | | const uint64_t seed; |
497 | | |
498 | | public: |
499 | | /// Construct a recursive hash combining helper. |
500 | | /// |
501 | | /// This sets up the state for a recursive hash combine, including getting |
502 | | /// the seed and buffer setup. |
503 | | hash_combine_recursive_helper() |
504 | 0 | : seed(get_execution_seed()) {} |
505 | | |
506 | | /// Combine one chunk of data into the current in-flight hash. |
507 | | /// |
508 | | /// This merges one chunk of data into the hash. First it tries to buffer |
509 | | /// the data. If the buffer is full, it hashes the buffer into its |
510 | | /// hash_state, empties it, and then merges the new chunk in. This also |
511 | | /// handles cases where the data straddles the end of the buffer. |
512 | | template <typename T> |
513 | 0 | char *combine_data(size_t &length, char *buffer_ptr, char *buffer_end, T data) { |
514 | 0 | if (!store_and_advance(buffer_ptr, buffer_end, data)) { |
515 | 0 | // Check for skew which prevents the buffer from being packed, and do |
516 | 0 | // a partial store into the buffer to fill it. This is only a concern |
517 | 0 | // with the variadic combine because that formation can have varying |
518 | 0 | // argument types. |
519 | 0 | size_t partial_store_size = buffer_end - buffer_ptr; |
520 | 0 | memcpy(buffer_ptr, &data, partial_store_size); |
521 | 0 |
|
522 | 0 | // If the store fails, our buffer is full and ready to hash. We have to |
523 | 0 | // either initialize the hash state (on the first full buffer) or mix |
524 | 0 | // this buffer into the existing hash state. Length tracks the *hashed* |
525 | 0 | // length, not the buffered length. |
526 | 0 | if (length == 0) { |
527 | 0 | state = state.create(buffer, seed); |
528 | 0 | length = 64; |
529 | 0 | } else { |
530 | 0 | // Mix this chunk into the current state and bump length up by 64. |
531 | 0 | state.mix(buffer); |
532 | 0 | length += 64; |
533 | 0 | } |
534 | 0 | // Reset the buffer_ptr to the head of the buffer for the next chunk of |
535 | 0 | // data. |
536 | 0 | buffer_ptr = buffer; |
537 | 0 |
|
538 | 0 | // Try again to store into the buffer -- this cannot fail as we only |
539 | 0 | // store types smaller than the buffer. |
540 | 0 | if (!store_and_advance(buffer_ptr, buffer_end, data, |
541 | 0 | partial_store_size)) |
542 | 0 | llvm_unreachable("buffer smaller than stored type"); |
543 | 0 | } |
544 | 0 | return buffer_ptr; |
545 | 0 | } Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper12combine_dataIhEEPcRmS4_S4_T_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper12combine_dataIjEEPcRmS4_S4_T_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper12combine_dataIiEEPcRmS4_S4_T_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper12combine_dataImEEPcRmS4_S4_T_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper12combine_dataIPKNS_12fltSemanticsEEEPcRmS7_S7_T_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper12combine_dataIlEEPcRmS4_S4_T_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper12combine_dataIPN4mlir7DialectEEEPcRmS7_S7_T_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper12combine_dataIPKN4mlir4TypeEEEPcRmS8_S8_T_ |
546 | | |
547 | | /// Recursive, variadic combining method. |
548 | | /// |
549 | | /// This function recurses through each argument, combining that argument |
550 | | /// into a single hash. |
551 | | template <typename T, typename ...Ts> |
552 | | hash_code combine(size_t length, char *buffer_ptr, char *buffer_end, |
553 | 0 | const T &arg, const Ts &...args) { |
554 | 0 | buffer_ptr = combine_data(length, buffer_ptr, buffer_end, get_hashable_data(arg)); |
555 | 0 |
|
556 | 0 | // Recurse to the next argument. |
557 | 0 | return combine(length, buffer_ptr, buffer_end, args...); |
558 | 0 | } Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIhJhjEEENS_9hash_codeEmPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIhJjEEENS_9hash_codeEmPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIjJEEENS_9hash_codeEmPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIhJhjiNS_9hash_codeEEEES4_mPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIhJjiNS_9hash_codeEEEES4_mPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIjJiNS_9hash_codeEEEES4_mPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIiJNS_9hash_codeEEEES4_mPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineINS_9hash_codeEJEEES4_mPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineINS_9hash_codeEJS4_EEES4_mPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIPKNS_12fltSemanticsEJEEENS_9hash_codeEmPcS8_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIjJmEEENS_9hash_codeEmPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineImJEEENS_9hash_codeEmPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIjJNS_9hash_codeEEEES4_mPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIlJiEEENS_9hash_codeEmPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIiJEEENS_9hash_codeEmPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIjJjEEENS_9hash_codeEmPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIN4mlir10IdentifierEJNS4_9AttributeEEEENS_9hash_codeEmPcS8_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIN4mlir9AttributeEJEEENS_9hash_codeEmPcS7_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIN4mlir4TypeEJNS_9hash_codeEEEES6_mPcS7_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineINS_9hash_codeEJNS_8ArrayRefINS_9StringRefEEEEEES4_mPcS8_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineINS_8ArrayRefINS_9StringRefEEEJEEENS_9hash_codeEmPcS8_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIN4mlir10ShapedTypeEJNS_9hash_codeEEEES6_mPcS7_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineINS_9hash_codeEJNS_8ArrayRefIcEEEEES4_mPcS7_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineINS_8ArrayRefIcEEJEEENS_9hash_codeEmPcS7_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIN4mlir4TypeEJPNS4_7DialectENS_9StringRefEEEENS_9hash_codeEmPcSA_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIPN4mlir7DialectEJNS_9StringRefEEEENS_9hash_codeEmPcS9_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineINS_9StringRefEJEEENS_9hash_codeEmPcS6_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIN4mlir4TypeEJNS4_20DenseIntElementsAttrENS4_17DenseElementsAttrEEEENS_9hash_codeEmPcS9_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIN4mlir20DenseIntElementsAttrEJNS4_17DenseElementsAttrEEEENS_9hash_codeEmPcS8_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIN4mlir17DenseElementsAttrEJEEENS_9hash_codeEmPcS7_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIjJjNS_9hash_codeEEEES4_mPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIjJjNS_9hash_codeES4_EEES4_mPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIjJNS_9hash_codeES4_EEES4_mPcS5_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIN4mlir13OperationNameEJNS4_21MutableDictionaryAttrEEEENS_9hash_codeEmPcS8_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIN4mlir21MutableDictionaryAttrEJEEENS_9hash_codeEmPcS7_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineINS_9hash_codeEJN4mlir4TypeEEEES4_mPcS7_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIN4mlir4TypeEJEEENS_9hash_codeEmPcS7_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineINS_9hash_codeEJPKN4mlir4TypeEEEES4_mPcS9_RKT_DpRKT0_ Unexecuted instantiation: _ZN4llvm7hashing6detail29hash_combine_recursive_helper7combineIPKN4mlir4TypeEJEEENS_9hash_codeEmPcS9_RKT_DpRKT0_ |
559 | | |
560 | | /// Base case for recursive, variadic combining. |
561 | | /// |
562 | | /// The base case when combining arguments recursively is reached when all |
563 | | /// arguments have been handled. It flushes the remaining buffer and |
564 | | /// constructs a hash_code. |
565 | 0 | hash_code combine(size_t length, char *buffer_ptr, char *buffer_end) { |
566 | 0 | // Check whether the entire set of values fit in the buffer. If so, we'll |
567 | 0 | // use the optimized short hashing routine and skip state entirely. |
568 | 0 | if (length == 0) |
569 | 0 | return hash_short(buffer, buffer_ptr - buffer, seed); |
570 | 0 | |
571 | 0 | // Mix the final buffer, rotating it if we did a partial fill in order to |
572 | 0 | // simulate doing a mix of the last 64-bytes. That is how the algorithm |
573 | 0 | // works when we have a contiguous byte sequence, and we want to emulate |
574 | 0 | // that here. |
575 | 0 | std::rotate(buffer, buffer_ptr, buffer_end); |
576 | 0 |
|
577 | 0 | // Mix this chunk into the current state. |
578 | 0 | state.mix(buffer); |
579 | 0 | length += buffer_ptr - buffer; |
580 | 0 |
|
581 | 0 | return state.finalize(length); |
582 | 0 | } |
583 | | }; |
584 | | |
585 | | } // namespace detail |
586 | | } // namespace hashing |
587 | | |
588 | | /// Combine values into a single hash_code. |
589 | | /// |
590 | | /// This routine accepts a varying number of arguments of any type. It will |
591 | | /// attempt to combine them into a single hash_code. For user-defined types it |
592 | | /// attempts to call a \see hash_value overload (via ADL) for the type. For |
593 | | /// integer and pointer types it directly combines their data into the |
594 | | /// resulting hash_code. |
595 | | /// |
596 | | /// The result is suitable for returning from a user's hash_value |
597 | | /// *implementation* for their user-defined type. Consumers of a type should |
598 | | /// *not* call this routine, they should instead call 'hash_value'. |
599 | 0 | template <typename ...Ts> hash_code hash_combine(const Ts &...args) { |
600 | 0 | // Recursively hash each argument using a helper class. |
601 | 0 | ::llvm::hashing::detail::hash_combine_recursive_helper helper; |
602 | 0 | return helper.combine(0, helper.buffer, helper.buffer + 64, args...); |
603 | 0 | } Unexecuted instantiation: _ZN4llvm12hash_combineIJhhjEEENS_9hash_codeEDpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJhhjiNS_9hash_codeEEEES1_DpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJNS_9hash_codeES1_EEES1_DpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJPKNS_12fltSemanticsEEEENS_9hash_codeEDpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJjmEEENS_9hash_codeEDpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJjNS_9hash_codeEEEES1_DpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJliEEENS_9hash_codeEDpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJjjEEENS_9hash_codeEDpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJN4mlir10IdentifierENS1_9AttributeEEEENS_9hash_codeEDpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJN4mlir4TypeENS_9hash_codeEEEES3_DpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJNS_9hash_codeENS_8ArrayRefINS_9StringRefEEEEEES1_DpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJN4mlir10ShapedTypeENS_9hash_codeEEEES3_DpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJNS_9hash_codeENS_8ArrayRefIcEEEEES1_DpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJN4mlir4TypeEPNS1_7DialectENS_9StringRefEEEENS_9hash_codeEDpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJN4mlir4TypeENS1_20DenseIntElementsAttrENS1_17DenseElementsAttrEEEENS_9hash_codeEDpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJjjNS_9hash_codeEEEES1_DpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJjjNS_9hash_codeES1_EEES1_DpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJN4mlir13OperationNameENS1_21MutableDictionaryAttrEEEENS_9hash_codeEDpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJNS_9hash_codeEN4mlir4TypeEEEES1_DpRKT_ Unexecuted instantiation: _ZN4llvm12hash_combineIJNS_9hash_codeEPKN4mlir4TypeEEEES1_DpRKT_ |
604 | | |
605 | | // Implementation details for implementations of hash_value overloads provided |
606 | | // here. |
607 | | namespace hashing { |
608 | | namespace detail { |
609 | | |
610 | | /// Helper to hash the value of a single integer. |
611 | | /// |
612 | | /// Overloads for smaller integer types are not provided to ensure consistent |
613 | | /// behavior in the presence of integral promotions. Essentially, |
614 | | /// "hash_value('4')" and "hash_value('0' + 4)" should be the same. |
615 | 0 | inline hash_code hash_integer_value(uint64_t value) { |
616 | 0 | // Similar to hash_4to8_bytes but using a seed instead of length. |
617 | 0 | const uint64_t seed = get_execution_seed(); |
618 | 0 | const char *s = reinterpret_cast<const char *>(&value); |
619 | 0 | const uint64_t a = fetch32(s); |
620 | 0 | return hash_16_bytes(seed + (a << 3), fetch32(s + 4)); |
621 | 0 | } |
622 | | |
623 | | } // namespace detail |
624 | | } // namespace hashing |
625 | | |
626 | | // Declared and documented above, but defined here so that any of the hashing |
627 | | // infrastructure is available. |
628 | | template <typename T> |
629 | 0 | std::enable_if_t<is_integral_or_enum<T>::value, hash_code> hash_value(T value) { |
630 | 0 | return ::llvm::hashing::detail::hash_integer_value( |
631 | 0 | static_cast<uint64_t>(value)); |
632 | 0 | } Unexecuted instantiation: _ZN4llvm10hash_valueIbEENSt9enable_ifIXsr19is_integral_or_enumIT_EE5valueENS_9hash_codeEE4typeES2_ Unexecuted instantiation: _ZN4llvm10hash_valueIjEENSt9enable_ifIXsr19is_integral_or_enumIT_EE5valueENS_9hash_codeEE4typeES2_ |
633 | | |
634 | | // Declared and documented above, but defined here so that any of the hashing |
635 | | // infrastructure is available. |
636 | 0 | template <typename T> hash_code hash_value(const T *ptr) { |
637 | 0 | return ::llvm::hashing::detail::hash_integer_value( |
638 | 0 | reinterpret_cast<uintptr_t>(ptr)); |
639 | 0 | } Unexecuted instantiation: _ZN4llvm10hash_valueIN4mlir6detail17AffineExprStorageEEENS_9hash_codeEPKT_ Unexecuted instantiation: _ZN4llvm10hash_valueIN4mlir6TypeID7StorageEEENS_9hash_codeEPKT_ Unexecuted instantiation: _ZN4llvm10hash_valueIN4mlir11TypeStorageEEENS_9hash_codeEPKT_ Unexecuted instantiation: _ZN4llvm10hash_valueIN4mlir16AttributeStorageEEENS_9hash_codeEPKT_ Unexecuted instantiation: _ZN4llvm10hash_valueIvEENS_9hash_codeEPKT_ Unexecuted instantiation: _ZN4llvm10hash_valueIN4mlir6detail16AffineMapStorageEEENS_9hash_codeEPKT_ Unexecuted instantiation: _ZN4llvm10hash_valueIN4mlir7DialectEEENS_9hash_codeEPKT_ Unexecuted instantiation: _ZN4llvm10hash_valueIN4mlir6detail17IntegerSetStorageEEENS_9hash_codeEPKT_ |
640 | | |
641 | | // Declared and documented above, but defined here so that any of the hashing |
642 | | // infrastructure is available. |
643 | | template <typename T, typename U> |
644 | 0 | hash_code hash_value(const std::pair<T, U> &arg) { |
645 | 0 | return hash_combine(arg.first, arg.second); |
646 | 0 | } |
647 | | |
648 | | // Declared and documented above, but defined here so that any of the hashing |
649 | | // infrastructure is available. |
650 | | template <typename T> |
651 | | hash_code hash_value(const std::basic_string<T> &arg) { |
652 | | return hash_combine_range(arg.begin(), arg.end()); |
653 | | } |
654 | | |
655 | | } // namespace llvm |
656 | | |
657 | | #endif |