44#ifndef LLVM_ADT_HASHING_H
45#define LLVM_ADT_HASHING_H
48#include "llvm/Config/abi-breaking.h"
62template <
typename T,
typename Enable>
struct DenseMapInfo;
88 operator size_t()
const {
return value; }
91 return lhs.value == rhs.value;
94 return lhs.value != rhs.value;
109std::enable_if_t<is_integral_or_enum<T>::value, hash_code>
hash_value(
T value);
114template <
typename T> hash_code
hash_value(
const T *ptr);
117template <
typename T,
typename U>
118hash_code
hash_value(
const std::pair<T, U> &arg);
121template <
typename... Ts>
122hash_code
hash_value(
const std::tuple<Ts...> &arg);
126hash_code
hash_value(
const std::basic_string<T> &arg);
129template <
typename T> hash_code
hash_value(
const std::optional<T> &arg);
139 std::memcpy(&result, p,
sizeof(result));
147 std::memcpy(&result, p,
sizeof(result));
164 return shift == 0 ? val : ((val >> shift) | (val << (64 - shift)));
168 return val ^ (val >> 47);
173 const uint64_t kMul = 0x9ddfea08eb382d69ULL;
208 llvm::rotr<uint64_t>(c ^ seed, 30) + d,
209 a + llvm::rotr<uint64_t>(b ^
k3, 20) - c + len + seed);
215 uint64_t b = llvm::rotr<uint64_t>(a + z, 52);
216 uint64_t c = llvm::rotr<uint64_t>(a, 37);
218 c += llvm::rotr<uint64_t>(a, 7);
221 uint64_t vs = b + llvm::rotr<uint64_t>(a, 31) + c;
224 b = llvm::rotr<uint64_t>(a + z, 52);
225 c = llvm::rotr<uint64_t>(a, 37);
227 c += llvm::rotr<uint64_t>(a, 7);
230 uint64_t ws = b + llvm::rotr<uint64_t>(a, 31) + c;
236 if (length >= 4 && length <= 8)
238 if (length > 8 && length <= 16)
240 if (length > 16 && length <= 32)
263 llvm::rotr<uint64_t>(seed ^
k1, 49),
277 b = llvm::rotr<uint64_t>(b + a + c, 21);
280 b += llvm::rotr<uint64_t>(a, 44) + d;
292 h2 = llvm::rotr<uint64_t>(
h2 +
h5, 33) *
k1;
315#if LLVM_ENABLE_ABI_BREAKING_CHECKS
319 return 0xff51afd7ed558ccdULL;
337 : std::integral_constant<bool, ((is_integral_or_enum<T>::value ||
338 std::is_pointer<T>::value) &&
339 64 % sizeof(T) == 0)> {};
346 : std::integral_constant<bool, (is_hashable_data<T>::value &&
347 is_hashable_data<U>::value &&
348 (sizeof(T) + sizeof(U)) ==
349 sizeof(std::pair<T, U>))> {};
354std::enable_if_t<is_hashable_data<T>::value,
T>
362std::enable_if_t<!is_hashable_data<T>::value,
size_t>
364 using ::llvm::hash_value;
378 size_t store_size =
sizeof(
value) - offset;
379 if (buffer_ptr + store_size > buffer_end)
381 const char *value_data =
reinterpret_cast<const char *
>(&
value);
382 std::memcpy(buffer_ptr, value_data + offset, store_size);
383 buffer_ptr += store_size;
392template <
typename InputIteratorT>
395 char buffer[64], *buffer_ptr = buffer;
396 char *
const buffer_end = std::end(buffer);
401 return hash_short(buffer, buffer_ptr - buffer, seed);
402 assert(buffer_ptr == buffer_end);
406 while (first != last) {
417 std::rotate(buffer, buffer_ptr, buffer_end);
421 length += buffer_ptr - buffer;
435template <
typename ValueT>
436std::enable_if_t<is_hashable_data<ValueT>::value,
hash_code>
439 const char *s_begin =
reinterpret_cast<const char *
>(first);
440 const char *s_end =
reinterpret_cast<const char *
>(last);
441 const size_t length = std::distance(s_begin, s_end);
445 const char *s_aligned_end = s_begin + (length & ~63);
448 while (s_begin != s_aligned_end) {
453 state.mix(s_end - 64);
455 return state.finalize(length);
468template <
typename InputIteratorT>
470 return ::llvm::hashing::detail::hash_combine_range_impl(first, last);
508 template <
typename T>
515 size_t partial_store_size = buffer_end - buffer_ptr;
516 std::memcpy(buffer_ptr, &
data, partial_store_size);
547 template <
typename T,
typename ...Ts>
549 const T &arg,
const Ts &...
args) {
553 return combine(length, buffer_ptr, buffer_end,
args...);
571 std::rotate(
buffer, buffer_ptr, buffer_end);
575 length += buffer_ptr -
buffer;
614 const char *s =
reinterpret_cast<const char *
>(&
value);
626 return ::llvm::hashing::detail::hash_integer_value(
633 return ::llvm::hashing::detail::hash_integer_value(
634 reinterpret_cast<uintptr_t
>(ptr));
639template <
typename T,
typename U>
645 return std::apply([](
const auto &...xs) {
return hash_combine(xs...); }, arg);
663 return static_cast<unsigned>(size_t(val));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Given that RA is a live value
An opaque object representing a hash code.
friend size_t hash_value(const hash_code &code)
Allow a hash_code to be directly run through hash_value.
friend bool operator==(const hash_code &lhs, const hash_code &rhs)
friend bool operator!=(const hash_code &lhs, const hash_code &rhs)
hash_code(size_t value)
Form a hash code directly from a numerical value.
hash_code()=default
Default construct a hash_code.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
uint64_t hash_1to3_bytes(const char *s, size_t len, uint64_t 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.
uint64_t hash_9to16_bytes(const char *s, size_t len, uint64_t seed)
uint64_t hash_4to8_bytes(const char *s, size_t len, uint64_t seed)
hash_code hash_combine_range_impl(InputIteratorT first, InputIteratorT last)
Implement the combining of integral values into a hash_code.
std::enable_if_t< is_hashable_data< T >::value, T > get_hashable_data(const T &value)
Helper to get the hashable data representation for a type.
hash_code hash_integer_value(uint64_t value)
Helper to hash the value of a single integer.
uint64_t rotate(uint64_t val, size_t shift)
Bitwise right rotate.
static constexpr uint64_t k2
uint64_t fetch64(const char *p)
uint64_t hash_17to32_bytes(const char *s, size_t len, uint64_t seed)
static constexpr uint64_t k1
uint64_t get_execution_seed()
In LLVM_ENABLE_ABI_BREAKING_CHECKS builds, the seed is non-deterministic per process (address of a fu...
uint32_t fetch32(const char *p)
static constexpr uint64_t k3
uint64_t hash_short(const char *s, size_t length, uint64_t seed)
static constexpr uint64_t k0
Some primes between 2^63 and 2^64 for various uses.
uint64_t shift_mix(uint64_t val)
uint64_t hash_33to64_bytes(const char *s, size_t len, uint64_t seed)
uint64_t hash_16_bytes(uint64_t low, uint64_t high)
constexpr bool IsBigEndianHost
void swapByteOrder(T &Value)
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...
LLVM_ABI void install_fatal_error_handler(fatal_error_handler_t handler, void *user_data=nullptr)
install_fatal_error_handler - Installs a new error handler to be used whenever a serious (non-recover...
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...
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.
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static bool isEqual(hash_code LHS, hash_code RHS)
static hash_code getEmptyKey()
static unsigned getHashValue(hash_code val)
static hash_code getTombstoneKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...
Helper class to manage the recursive combining of hash_combine arguments.
hash_code combine(size_t length, char *buffer_ptr, char *buffer_end)
Base case for recursive, variadic combining.
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.
hash_code combine(size_t length, char *buffer_ptr, char *buffer_end, const T &arg, const Ts &...args)
Recursive, variadic combining method.
hash_combine_recursive_helper()
Construct a recursive hash combining helper.
The intermediate state used during hashing.
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 finalize(size_t length)
Compute the final 64-bit hash code value based on the current state and the length of bytes hashed.
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 mix(const char *s)
Mix in a 64-byte buffer of data.
Trait to indicate whether a type's bits can be hashed directly.
size_t operator()(llvm::hash_code const &Val) const