#ifndef LLVM_CODEGEN_STABLEHASHING_H
#define LLVM_CODEGEN_STABLEHASHING_H
#include "llvm/ADT/StringRef.h"
namespace llvm {
using stable_hash = uint64_t;
namespace hashing {
namespace detail {
const uint64_t FNV_PRIME_64 = 1099511628211u;
const uint64_t FNV_OFFSET_64 = 14695981039346656037u;
inline void stable_hash_append(stable_hash &Hash, const char Value) {
Hash = Hash ^ (Value & 0xFF);
Hash = Hash * FNV_PRIME_64;
}
inline void stable_hash_append(stable_hash &Hash, stable_hash Value) {
for (unsigned I = 0; I < 8; ++I) {
stable_hash_append(Hash, static_cast<char>(Value));
Value >>= 8;
}
}
} }
inline stable_hash stable_hash_combine(stable_hash A, stable_hash B) {
stable_hash Hash = hashing::detail::FNV_OFFSET_64;
hashing::detail::stable_hash_append(Hash, A);
hashing::detail::stable_hash_append(Hash, B);
return Hash;
}
inline stable_hash stable_hash_combine(stable_hash A, stable_hash B,
stable_hash C) {
stable_hash Hash = hashing::detail::FNV_OFFSET_64;
hashing::detail::stable_hash_append(Hash, A);
hashing::detail::stable_hash_append(Hash, B);
hashing::detail::stable_hash_append(Hash, C);
return Hash;
}
inline stable_hash stable_hash_combine(stable_hash A, stable_hash B,
stable_hash C, stable_hash D) {
stable_hash Hash = hashing::detail::FNV_OFFSET_64;
hashing::detail::stable_hash_append(Hash, A);
hashing::detail::stable_hash_append(Hash, B);
hashing::detail::stable_hash_append(Hash, C);
hashing::detail::stable_hash_append(Hash, D);
return Hash;
}
template <typename InputIteratorT>
stable_hash stable_hash_combine_range(InputIteratorT First,
InputIteratorT Last) {
stable_hash Hash = hashing::detail::FNV_OFFSET_64;
for (auto I = First; I != Last; ++I)
hashing::detail::stable_hash_append(Hash, *I);
return Hash;
}
inline stable_hash stable_hash_combine_array(const stable_hash *P, size_t C) {
stable_hash Hash = hashing::detail::FNV_OFFSET_64;
for (size_t I = 0; I < C; ++I)
hashing::detail::stable_hash_append(Hash, P[I]);
return Hash;
}
inline stable_hash stable_hash_combine_string(const StringRef &S) {
return stable_hash_combine_range(S.begin(), S.end());
}
inline stable_hash stable_hash_combine_string(const char *C) {
stable_hash Hash = hashing::detail::FNV_OFFSET_64;
while (*C)
hashing::detail::stable_hash_append(Hash, *(C++));
return Hash;
}
}
#endif