43#ifndef LLVM_ADT_HASHING_H
44#define LLVM_ADT_HASHING_H
47#include "llvm/Config/abi-breaking.h"
64template <
typename T,
typename Enable>
struct DenseMapInfo;
90 constexpr operator size_t()
const {
return value; }
93 return lhs.value == rhs.value;
96 return lhs.value != rhs.value;
113std::enable_if_t<is_integral_or_enum<T>::value, hash_code>
hash_value(
T value);
118template <
typename T> hash_code
hash_value(
const T *ptr);
121template <
typename T,
typename U>
122hash_code
hash_value(
const std::pair<T, U> &arg);
125template <
typename... Ts>
126hash_code
hash_value(
const std::tuple<Ts...> &arg);
130hash_code
hash_value(
const std::basic_string<T> &arg);
133template <
typename T> hash_code
hash_value(
const std::optional<T> &arg);
143 std::memcpy(&result, p,
sizeof(result));
151 const uint64_t kMul = 0x9ddfea08eb382d69ULL;
165#if LLVM_ENABLE_ABI_BREAKING_CHECKS
169 return 0xff51afd7ed558ccdULL;
199 std::is_pointer<T>::value) &&
200 64 % sizeof(T) == 0)> {};
206template <
typename T,
typename U>
208 : std::bool_constant<(is_hashable_data<T>::value &&
209 is_hashable_data<U>::value &&
210 (sizeof(T) + sizeof(U)) == sizeof(std::pair<T, U>))> {
222 return static_cast<size_t>(
hash_value(value));
237template <
typename InputIteratorT>
239 alignas(
uint64_t)
char stack_buf[256];
240 std::unique_ptr<char[]> heap_buf;
241 char *buf = stack_buf;
242 size_t cap =
sizeof(stack_buf);
244 for (; first != last; ++first) {
246 if (len +
sizeof(
data) > cap) {
247 size_t new_cap = cap * 2;
248 while (new_cap < len +
sizeof(
data))
253 std::unique_ptr<char[]> new_buf(
new char[new_cap]);
254 std::memcpy(new_buf.get(), buf, len);
255 heap_buf = std::move(new_buf);
256 buf = heap_buf.get();
259 std::memcpy(buf + len, &
data,
sizeof(
data));
273template <
typename ValueT>
274std::enable_if_t<is_hashable_data<ValueT>::value,
hash_code>
277 size_t(last - first) *
sizeof(ValueT));
282 return (
size_t(0) + ... +
290 std::memcpy(buf + off, &
data,
sizeof(
data));
304template <
typename InputIteratorT>
306 return ::llvm::hashing::detail::hash_combine_range_impl(first, last);
329 std::array<char, std::max<size_t>(1,
Total)> buf;
348 const char *s =
reinterpret_cast<const char *
>(&value);
360 return ::llvm::hashing::detail::hash_integer_value(
367 return ::llvm::hashing::detail::hash_integer_value(
368 reinterpret_cast<uintptr_t
>(ptr));
373template <
typename T,
typename U>
379 return std::apply([](
const auto &...xs) {
return hash_combine(xs...); }, arg);
397 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 uint64_t hash_16_bytes(uint64_t low, uint64_t high)
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...
uint32_t fetch32(const char *p)
void store_hashable_data(char *buf, size_t &off, const T &arg)
Copy get_hashable_data(arg) into buf at offset off, advancing off.
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...
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 hash_code getEmptyKey()
static constexpr unsigned getHashValue(hash_code val)
static constexpr hash_code getTombstoneKey()
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