1#ifndef PROTEUS_HASHING_H
2#define PROTEUS_HASHING_H
10#include <llvm/ADT/ArrayRef.h>
11#include <llvm/ADT/DenseMap.h>
12#include <llvm/ADT/SmallVector.h>
13#if LLVM_VERSION_MAJOR >= 18
14#include <llvm/ADT/StableHashing.h>
16#include <llvm/CodeGen/StableHashing.h>
32 inline HashT(
const stable_hash HashValue) { Value = HashValue; }
33 inline HashT(
const StringRef &S) { S.getAsInteger(0, Value); }
34 inline stable_hash
getValue()
const {
return Value; }
35 inline std::string
toString()
const {
return std::to_string(Value); }
39#if PROTEUS_ENABLE_CUDA
46 return Value == Other.Value;
50 return Value < Other.Value;
58#if LLVM_VERSION_MAJOR >= 20
59 ArrayRef<uint8_t> Bytes(
reinterpret_cast<const uint8_t *
>(S.data()),
61 return xxh3_64bits(Bytes);
63 return stable_hash_combine_string(S);
70inline std::enable_if_t<std::is_scalar<T>::value,
HashT>
hashValue(
const T &V) {
71 return hashValue(StringRef{
reinterpret_cast<const char *
>(&V),
sizeof(T)});
84 StringRef{
reinterpret_cast<const char *
>(RC.
ArrInfo.
Blob.get()),
96 StringRef{
reinterpret_cast<const char *
>(RC.
ObjInfo.
Blob.get()),
106 return hashRuntimeConstantArray<bool>(RC);
108 return hashRuntimeConstantArray<int8_t>(RC);
110 return hashRuntimeConstantArray<int32_t>(RC);
112 return hashRuntimeConstantArray<int64_t>(RC);
114 return hashRuntimeConstantArray<float>(RC);
116 return hashRuntimeConstantArray<double>(RC);
125 StringRef{
reinterpret_cast<const char *
>(&RC.
Value),
sizeof(RC.
Value)});
139 H = stable_hash_combine(H.
getValue(),
141 H = stable_hash_combine(
149 H = stable_hash_combine(H.
getValue(),
151 H = stable_hash_combine(
172 for (
int I = 1, E = Arr.size(); I < E; ++I)
173 HashValue = stable_hash_combine(HashValue.
getValue(),
184 for (
const auto &Elt : Arr)
190template <
typename T,
unsigned N>
195template <
typename Key,
typename Value>
196inline std::enable_if_t<
197 std::is_integral<Key>::value || std::is_enum<Key>::value,
HashT>
202 SmallVector<Key, 32> Keys;
203 Keys.reserve(Map.size());
204 for (
const auto &KV : Map)
205 Keys.push_back(KV.first);
207 std::sort(Keys.begin(), Keys.end());
211 auto It = Map.find(K);
223template <
typename Key,
typename Value>
225 return hashValue(
static_cast<const DenseMap<Key, Value> &
>(Map));
241 if (Plugin.Insertion) {
244 hashValue(
static_cast<int>(Plugin.Insertion->Position)));
267template <
typename FirstT,
typename... RestTs>
#define TIMESCOPE(...)
Definition TimeTracing.h:66
bool specializeArgs() const
Definition Config.h:289
bool specializeDimsRange() const
Definition Config.h:291
bool specializeLaunchBounds() const
Definition Config.h:292
std::optional< const std::string > optPipeline() const
Definition Config.h:295
bool specializeDims() const
Definition Config.h:290
char optLevel() const
Definition Config.h:293
CodegenOption codeGenOption() const
Definition Config.h:288
int codeGenOptLevel() const
Definition Config.h:294
std::string toString() const
Definition Hashing.h:35
bool operator==(const HashT &Other) const
Definition Hashing.h:45
stable_hash getValue() const
Definition Hashing.h:34
bool operator<(const HashT &Other) const
Definition Hashing.h:49
HashT(const stable_hash HashValue)
Definition Hashing.h:32
HashT(const StringRef &S)
Definition Hashing.h:33
std::string toMangledSuffix() const
Definition Hashing.h:38
Definition CompiledLibrary.h:8
Definition MemoryCache.h:27
HashT hashValue(const HashT &H)
Definition Hashing.h:54
std::vector< JITPassPluginConfig > getJITPassPluginConfigs()
Definition JITPassPluginRegistry.cpp:105
@ ARRAY
Definition CompilerInterfaceTypes.h:33
@ VECTOR
Definition CompilerInterfaceTypes.h:32
@ INT32
Definition CompilerInterfaceTypes.h:25
@ INT64
Definition CompilerInterfaceTypes.h:26
@ FLOAT
Definition CompilerInterfaceTypes.h:27
@ STATIC_ARRAY
Definition CompilerInterfaceTypes.h:31
@ INT8
Definition CompilerInterfaceTypes.h:24
@ BOOL
Definition CompilerInterfaceTypes.h:23
@ OBJECT
Definition CompilerInterfaceTypes.h:34
@ DOUBLE
Definition CompilerInterfaceTypes.h:28
HashT hash(FirstT &&First, RestTs &&...Rest)
Definition Hashing.h:268
T getValue(const RuntimeConstant &RC)
Definition RuntimeConstantTypeHelpers.h:95
void reportFatalError(const llvm::Twine &Reason, const char *FILE, unsigned Line)
Definition Error.cpp:14
HashT hashRuntimeSpecializationConfig(const CodeGenerationConfig &CGConfig)
Definition Hashing.h:252
HashT hashCodeGenConfig(const CodeGenerationConfig &CGConfig)
Definition Hashing.h:232
HashT hashArrayRefElement(const RuntimeConstant &RC)
Definition Hashing.h:100
HashT hashCombine(HashT A, HashT B)
Definition Hashing.h:228
std::string toString(CodegenOption Option)
Definition Config.h:31
HashT hashRuntimeConstantObject(const RuntimeConstant &RC)
Definition Hashing.h:88
bool isScalarRuntimeConstantType(RuntimeConstantType RCType)
Definition RuntimeConstantTypeHelpers.h:148
HashT hashRuntimeConstantArray(const RuntimeConstant &RC)
Definition Hashing.h:75
int32_t NumElts
Definition CompilerInterfaceTypes.h:42
RuntimeConstantType EltType
Definition CompilerInterfaceTypes.h:43
std::shared_ptr< unsigned char[]> Blob
Definition CompilerInterfaceTypes.h:44
std::shared_ptr< unsigned char[]> Blob
Definition CompilerInterfaceTypes.h:53
bool PassByValue
Definition CompilerInterfaceTypes.h:52
int32_t Size
Definition CompilerInterfaceTypes.h:51
Definition CompilerInterfaceTypes.h:72
ArrayInfo ArrInfo
Definition CompilerInterfaceTypes.h:78
RuntimeConstantValue Value
Definition CompilerInterfaceTypes.h:73
RuntimeConstantType Type
Definition CompilerInterfaceTypes.h:74
int32_t Offset
Definition CompilerInterfaceTypes.h:76
ObjectInfo ObjInfo
Definition CompilerInterfaceTypes.h:79
int32_t Pos
Definition CompilerInterfaceTypes.h:75
std::size_t operator()(const proteus::HashT &Key) const
Definition Hashing.h:286