45 #ifndef LLVM_ADT_HASHING_H 46 #define LLVM_ADT_HASHING_H 84 operator size_t()
const {
return value; }
87 return lhs.value == rhs.value;
90 return lhs.value != rhs.value;
104 template <
typename T>
105 typename std::enable_if<is_integral_or_enum<T>::value,
hash_code>
::type 114 template <
typename T,
typename U>
118 template <
typename T>
147 memcpy(&result, p,
sizeof(result));
155 memcpy(&result, p,
sizeof(result));
162 static const uint64_t
k0 = 0xc3a5c85c97cb3127ULL;
163 static const uint64_t
k1 = 0xb492b66fbe98f273ULL;
164 static const uint64_t
k2 = 0x9ae16a3b2f90404fULL;
165 static const uint64_t
k3 = 0xc949d7c7509e6557ULL;
170 inline uint64_t
rotate(uint64_t val,
size_t shift) {
172 return shift == 0 ? val : ((val >> shift) | (val << (64 - shift)));
176 return val ^ (val >> 47);
181 const uint64_t kMul = 0x9ddfea08eb382d69ULL;
182 uint64_t a = (low ^ high) * kMul;
184 uint64_t b = (high ^ a) * kMul;
192 uint8_t b = s[len >> 1];
193 uint8_t c = s[len - 1];
206 uint64_t b =
fetch64(s + len - 8);
216 a +
rotate(b ^ k3, 20) - c + len + seed);
222 uint64_t b =
rotate(a + z, 52);
223 uint64_t c =
rotate(a, 37);
228 uint64_t vs = b +
rotate(a, 31) + c;
237 uint64_t ws = b +
rotate(a, 31) + c;
238 uint64_t r =
shift_mix((vf + ws) * k2 + (wf + vs) * k0);
242 inline uint64_t
hash_short(
const char *s,
size_t length, uint64_t seed) {
243 if (length >= 4 && length <= 8)
245 if (length > 8 && length <= 16)
247 if (length > 16 && length <= 32)
261 uint64_t h0, h1, h2, h3, h4, h5,
h6;
280 b =
rotate(b + a + c, 21);
298 mix_32_bytes(s, h3, h4);
301 mix_32_bytes(s + 32, h5, h6);
328 const uint64_t seed_prime = 0xff51afd7ed558ccdULL;
347 : std::integral_constant<bool, ((is_integral_or_enum<T>::value ||
348 std::is_pointer<T>::value) &&
349 64 % sizeof(T) == 0)> {};
356 : std::integral_constant<bool, (is_hashable_data<T>::value &&
357 is_hashable_data<U>::value &&
358 (sizeof(T) + sizeof(U)) ==
359 sizeof(std::pair<T, U>))> {};
363 template <
typename T>
364 typename std::enable_if<is_hashable_data<T>::value,
T>
::type 371 template <
typename T>
372 typename std::enable_if<!is_hashable_data<T>::value,
size_t>
::type 385 template <
typename T>
388 size_t store_size =
sizeof(value) - offset;
389 if (buffer_ptr + store_size > buffer_end)
391 const char *value_data =
reinterpret_cast<const char *
>(&value);
392 memcpy(buffer_ptr, value_data + offset, store_size);
393 buffer_ptr += store_size;
402 template <
typename InputIteratorT>
405 char buffer[64], *buffer_ptr = buffer;
406 char *
const buffer_end =
std::end(buffer);
411 return hash_short(buffer, buffer_ptr - buffer, seed);
412 assert(buffer_ptr == buffer_end);
416 while (first != last) {
431 length += buffer_ptr - buffer;
445 template <
typename ValueT>
446 typename std::enable_if<is_hashable_data<ValueT>::value,
hash_code>
::type 449 const char *s_begin =
reinterpret_cast<const char *
>(
first);
450 const char *s_end =
reinterpret_cast<const char *
>(last);
451 const size_t length = std::distance(s_begin, s_end);
455 const char *s_aligned_end = s_begin + (length & ~63);
458 while (s_begin != s_aligned_end) {
463 state.mix(s_end - 64);
465 return state.finalize(length);
478 template <
typename InputIteratorT>
514 template <
typename T>
515 char *
combine_data(
size_t &length,
char *buffer_ptr,
char *buffer_end,
T data) {
521 size_t partial_store_size = buffer_end - buffer_ptr;
522 memcpy(buffer_ptr, &data, partial_store_size);
529 state = state.
create(buffer, seed);
553 template <
typename T,
typename ...Ts>
555 const T &arg,
const Ts &...args) {
556 buffer_ptr = combine_data(length, buffer_ptr, buffer_end,
get_hashable_data(arg));
559 return combine(length, buffer_ptr, buffer_end, args...);
571 return hash_short(buffer, buffer_ptr - buffer, seed);
581 length += buffer_ptr - buffer;
620 const char *s =
reinterpret_cast<const char *
>(&value);
630 template <
typename T>
631 typename std::enable_if<is_integral_or_enum<T>::value,
hash_code>
::type 634 static_cast<uint64_t>(value));
641 reinterpret_cast<uintptr_t>(ptr));
646 template <
typename T,
typename U>
653 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.
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)