43#ifndef LLVM_ADT_HASHING_H
44#define LLVM_ADT_HASHING_H
47#include "llvm/Config/abi-breaking.h"
63template <
typename T,
typename Enable>
struct DenseMapInfo;
89 constexpr operator size_t()
const {
return value; }
92 return lhs.value == rhs.value;
95 return lhs.value != rhs.value;
112std::enable_if_t<is_integral_or_enum<T>::value, hash_code>
hash_value(
T value);
117template <
typename T> hash_code
hash_value(
const T *ptr);
120template <
typename T,
typename U>
121hash_code
hash_value(
const std::pair<T, U> &arg);
124template <
typename... Ts>
125hash_code
hash_value(
const std::tuple<Ts...> &arg);
129hash_code
hash_value(
const std::basic_string<T> &arg);
132template <
typename T> hash_code
hash_value(
const std::optional<T> &arg);
145#if LLVM_ENABLE_ABI_BREAKING_CHECKS
149 return 0xff51afd7ed558ccdULL;
179 std::is_pointer<T>::value) &&
180 64 % sizeof(T) == 0)> {};
186template <
typename T,
typename U>
188 : std::bool_constant<(is_hashable_data<T>::value &&
189 is_hashable_data<U>::value &&
190 (sizeof(T) + sizeof(U)) == sizeof(std::pair<T, U>))> {
202 return static_cast<size_t>(
hash_value(value));
217template <
typename InputIteratorT>
219 alignas(
uint64_t)
char stack_buf[256];
220 std::unique_ptr<char[]> heap_buf;
221 char *buf = stack_buf;
222 size_t cap =
sizeof(stack_buf);
224 for (; first != last; ++first) {
226 if (len +
sizeof(
data) > cap) {
227 size_t new_cap = cap * 2;
228 while (new_cap < len +
sizeof(
data))
233 std::unique_ptr<char[]> new_buf(
new char[new_cap]);
234 std::memcpy(new_buf.get(), buf, len);
235 heap_buf = std::move(new_buf);
236 buf = heap_buf.get();
239 std::memcpy(buf + len, &
data,
sizeof(
data));
253template <
typename ValueT>
254std::enable_if_t<is_hashable_data<ValueT>::value,
hash_code>
257 size_t(last - first) *
sizeof(ValueT));
262 return (
size_t(0) + ... +
270 std::memcpy(buf + off, &
data,
sizeof(
data));
284template <
typename InputIteratorT>
286 return ::llvm::hashing::detail::hash_combine_range_impl(first, last);
309 std::array<char, std::max<size_t>(1,
Total)> buf;
310 [[maybe_unused]]
size_t off = 0;
328 x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9ULL;
329 x = (x ^ (x >> 27)) * 0x94d049bb133111ebULL;
330 return x ^ (x >> 31);
340 return ::llvm::hashing::detail::hash_integer_value(
347 return ::llvm::hashing::detail::hash_integer_value(
348 reinterpret_cast<uintptr_t
>(ptr));
353template <
typename T,
typename U>
359 return std::apply([](
const auto &...xs) {
return hash_combine(xs...); }, arg);
375 return static_cast<unsigned>(
size_t(val));
An opaque object representing a hash code.
constexpr hash_code(size_t value)
Form a hash code directly from a numerical value.
friend constexpr size_t hash_value(const hash_code &code)
Allow a hash_code to be directly run through hash_value.
hash_code()=default
Default construct a hash_code.
friend constexpr bool operator==(const hash_code &lhs, const hash_code &rhs)
friend constexpr bool operator!=(const hash_code &lhs, const hash_code &rhs)
hash_code combine_bytes(const char *data, size_t len)
Hash a contiguous byte buffer to a hash_code.
constexpr size_t total_hashable_size()
Sum of sizeof(get_hashable_data(arg)) across a parameter pack.
hash_code hash_combine_range_impl(InputIteratorT first, InputIteratorT last)
Implement the combining of integral values into a hash_code.
hash_code hash_integer_value(uint64_t value)
Helper to hash the value of a single integer.
auto get_hashable_data(const T &value)
Helper to get the hashable data representation for a type.
uint64_t get_execution_seed()
In LLVM_ENABLE_ABI_BREAKING_CHECKS builds, the seed is non-deterministic per process (address of a fu...
void store_hashable_data(char *buf, size_t &off, const T &arg)
Copy get_hashable_data(arg) into buf at offset off, advancing off.
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...
uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Inline ArrayRef overloads of the xxhash entry points declared out-of-line in llvm/Support/xxhash....
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.
static constexpr bool isEqual(hash_code LHS, hash_code RHS)
static constexpr unsigned getHashValue(hash_code val)
An information struct used to provide DenseMap with the various necessary components for a given valu...
Trait to indicate whether a type's bits can be hashed directly.
constexpr size_t operator()(llvm::hash_code const &Val) const