44 #ifndef LLVM_ADT_HASHING_H 45 #define LLVM_ADT_HASHING_H 83 operator size_t()
const {
return value; }
86 return lhs.value == rhs.value;
89 return lhs.value != rhs.value;
103 template <
typename T>
104 typename std::enable_if<is_integral_or_enum<T>::value,
hash_code>
::type 113 template <
typename T,
typename U>
117 template <
typename T>
146 memcpy(&result, p,
sizeof(result));
154 memcpy(&result, p,
sizeof(result));
161 static const uint64_t
k0 = 0xc3a5c85c97cb3127ULL;
162 static const uint64_t
k1 = 0xb492b66fbe98f273ULL;
163 static const uint64_t
k2 = 0x9ae16a3b2f90404fULL;
164 static const uint64_t
k3 = 0xc949d7c7509e6557ULL;
169 inline uint64_t
rotate(uint64_t val,
size_t shift) {
171 return shift == 0 ? val : ((val >> shift) | (val << (64 - shift)));
175 return val ^ (val >> 47);
180 const uint64_t kMul = 0x9ddfea08eb382d69ULL;
181 uint64_t a = (low ^ high) * kMul;
183 uint64_t b = (high ^ a) * kMul;
191 uint8_t b = s[len >> 1];
192 uint8_t c = s[len - 1];
205 uint64_t b =
fetch64(s + len - 8);
215 a +
rotate(b ^ k3, 20) - c + len + seed);
221 uint64_t b =
rotate(a + z, 52);
222 uint64_t c =
rotate(a, 37);
227 uint64_t vs = b +
rotate(a, 31) + c;
236 uint64_t ws = b +
rotate(a, 31) + c;
237 uint64_t r =
shift_mix((vf + ws) * k2 + (wf + vs) * k0);
241 inline uint64_t
hash_short(
const char *s,
size_t length, uint64_t seed) {
242 if (length >= 4 && length <= 8)
244 if (length > 8 && length <= 16)
246 if (length > 16 && length <= 32)
260 uint64_t h0 = 0, h1 = 0, h2 = 0, h3 = 0, h4 = 0, h5 = 0, h6 = 0;
279 b =
rotate(b + a + c, 21);
297 mix_32_bytes(s, h3, h4);
300 mix_32_bytes(s + 32, h5, h6);
327 const uint64_t seed_prime = 0xff51afd7ed558ccdULL;
346 : std::integral_constant<bool, ((is_integral_or_enum<T>::value ||
347 std::is_pointer<T>::value) &&
348 64 % sizeof(T) == 0)> {};
355 : std::integral_constant<bool, (is_hashable_data<T>::value &&
356 is_hashable_data<U>::value &&
357 (sizeof(T) + sizeof(U)) ==
358 sizeof(std::pair<T, U>))> {};
362 template <
typename T>
363 typename std::enable_if<is_hashable_data<T>::value,
T>
::type 370 template <
typename T>
371 typename std::enable_if<!is_hashable_data<T>::value,
size_t>
::type 384 template <
typename T>
387 size_t store_size =
sizeof(value) - offset;
388 if (buffer_ptr + store_size > buffer_end)
390 const char *value_data =
reinterpret_cast<const char *
>(&value);
391 memcpy(buffer_ptr, value_data + offset, store_size);
392 buffer_ptr += store_size;
401 template <
typename InputIteratorT>
404 char buffer[64], *buffer_ptr = buffer;
405 char *
const buffer_end =
std::end(buffer);
410 return hash_short(buffer, buffer_ptr - buffer, seed);
411 assert(buffer_ptr == buffer_end);
415 while (first != last) {
430 length += buffer_ptr - buffer;
444 template <
typename ValueT>
445 typename std::enable_if<is_hashable_data<ValueT>::value,
hash_code>
::type 448 const char *s_begin =
reinterpret_cast<const char *
>(
first);
449 const char *s_end =
reinterpret_cast<const char *
>(last);
450 const size_t length = std::distance(s_begin, s_end);
454 const char *s_aligned_end = s_begin + (length & ~63);
457 while (s_begin != s_aligned_end) {
462 state.mix(s_end - 64);
464 return state.finalize(length);
477 template <
typename InputIteratorT>
495 char buffer[64] = {};
513 template <
typename T>
514 char *
combine_data(
size_t &length,
char *buffer_ptr,
char *buffer_end,
T data) {
520 size_t partial_store_size = buffer_end - buffer_ptr;
521 memcpy(buffer_ptr, &data, partial_store_size);
528 state = state.
create(buffer, seed);
552 template <
typename T,
typename ...Ts>
554 const T &arg,
const Ts &...args) {
555 buffer_ptr = combine_data(length, buffer_ptr, buffer_end,
get_hashable_data(arg));
558 return combine(length, buffer_ptr, buffer_end, args...);
570 return hash_short(buffer, buffer_ptr - buffer, seed);
580 length += buffer_ptr - buffer;
619 const char *s =
reinterpret_cast<const char *
>(&value);
629 template <
typename T>
630 typename std::enable_if<is_integral_or_enum<T>::value,
hash_code>
::type 633 static_cast<uint64_t>(value));
640 reinterpret_cast<uintptr_t>(ptr));
645 template <
typename T,
typename U>
652 template <
typename T>
const_iterator end(StringRef path)
Get end iterator over path.
void swapByteOrder(T &Value)
Helper class to manage the recursive combining of hash_combine arguments.
This class represents lattice values for constants.
static const uint64_t k0
Some primes between 2^63 and 2^64 for various uses.
static const Metadata * get_hashable_data(const MDOperand &X)
Make MDOperand transparent for hashing.
uint64_t shift_mix(uint64_t val)
constexpr bool IsBigEndianHost
Trait to indicate whether a type's bits can be hashed directly.
uint64_t hash_17to32_bytes(const char *s, size_t len, uint64_t seed)
hash_code(size_t value)
Form a hash code directly from a numerical value.
uint64_t finalize(size_t length)
Compute the final 64-bit hash code value based on the current state and the length of bytes hashed...
uint64_t fetch64(const char *p)
static void mix_32_bytes(const char *s, uint64_t &a, uint64_t &b)
Mix 32-bytes from the input sequence into the 16-bytes of 'a' and 'b', including whatever is already ...
void set_fixed_execution_hash_seed(uint64_t fixed_value)
Override the execution seed with a fixed value.
uint64_t hash_1to3_bytes(const char *s, size_t len, uint64_t seed)
hash_code hash_value(const RegisterBankInfo::PartialMapping &PartMapping)
Hashing function for PartialMapping.
uint32_t fetch32(const char *p)
uint64_t hash_16_bytes(uint64_t low, uint64_t high)
hash_code combine(size_t length, char *buffer_ptr, char *buffer_end)
Base case for recursive, variadic combining.
friend bool operator==(const hash_code &lhs, const hash_code &rhs)
void mix(const char *s)
Mix in a 64-byte buffer of data.
static hash_state create(const char *s, uint64_t seed)
Create a new hash_state structure and initialize it based on the seed and the first 64-byte chunk...
uint64_t hash_4to8_bytes(const char *s, size_t len, uint64_t seed)
hash_code hash_integer_value(uint64_t value)
Helper to hash the value of a single integer.
hash_code()=default
Default construct a hash_code.
std::enable_if< is_hashable_data< ValueT >::value, hash_code >::type hash_combine_range_impl(ValueT *first, ValueT *last)
Implement the combining of integral values into a hash_code.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
uint64_t hash_9to16_bytes(const char *s, size_t len, uint64_t seed)
hash_combine_recursive_helper()
Construct a recursive hash combining helper.
uint64_t hash_short(const char *s, size_t length, uint64_t seed)
hash_code combine(size_t length, char *buffer_ptr, char *buffer_end, const T &arg, const Ts &...args)
Recursive, variadic combining method.
char * combine_data(size_t &length, char *buffer_ptr, char *buffer_end, T data)
Combine one chunk of data into the current in-flight hash.
uint64_t fixed_seed_override
A global, fixed seed-override variable.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
An opaque object representing a hash code.
uint64_t get_execution_seed()
bool store_and_advance(char *&buffer_ptr, char *buffer_end, const T &value, size_t offset=0)
Helper to store data from a value into a buffer and advance the pointer into that buffer...
The intermediate state used during hashing.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
friend size_t hash_value(const hash_code &code)
Allow a hash_code to be directly run through hash_value.
uint64_t hash_33to64_bytes(const char *s, size_t len, uint64_t seed)
friend bool operator!=(const hash_code &lhs, const hash_code &rhs)