LLVM 20.0.0git
StableHashing.h
Go to the documentation of this file.
1//===- llvm/ADT/StableHashing.h - Utilities for stable hashing * C++ *-----===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file provides types and functions for computing and combining stable
10// hashes. Stable hashes can be useful for hashing across different modules,
11// processes, machines, or compiler runs for a specific compiler version. It
12// currently employs the xxh3_64bits hashing algorithm. Be aware that this
13// implementation may be adjusted or updated as improvements to the compiler are
14// made.
15//
16//===----------------------------------------------------------------------===//
17
18#ifndef LLVM_ADT_STABLEHASHING_H
19#define LLVM_ADT_STABLEHASHING_H
20
21#include "llvm/ADT/StringRef.h"
22#include "llvm/Support/xxhash.h"
23
24namespace llvm {
25
26/// An opaque object representing a stable hash code. It can be serialized,
27/// deserialized, and is stable across processes and executions.
29
31 const uint8_t *Ptr = reinterpret_cast<const uint8_t *>(Buffer.data());
32 size_t Size = Buffer.size() * sizeof(stable_hash);
34}
35
37 stable_hash Hashes[2] = {A, B};
38 return stable_hash_combine(Hashes);
39}
40
42 stable_hash C) {
43 stable_hash Hashes[3] = {A, B, C};
44 return stable_hash_combine(Hashes);
45}
46
49 stable_hash Hashes[4] = {A, B, C, D};
50 return stable_hash_combine(Hashes);
51}
52
53// Removes suffixes introduced by LLVM from the name to enhance stability and
54// maintain closeness to the original name across different builds.
56 // Return the part after ".content." that represents contents.
57 auto [P0, S0] = Name.rsplit(".content.");
58 if (!S0.empty())
59 return S0;
60
61 // Ignore these suffixes.
62 auto [P1, S1] = Name.rsplit(".llvm.");
63 auto [P2, S2] = P1.rsplit(".__uniq.");
64 return P2;
65}
66
67// Generates a consistent hash value for a given input name across different
68// program executions and environments. This function first converts the input
69// name into a stable form using the `get_stable_name` function, and then
70// computes a hash of this stable name. For instance, `foo.llvm.1234` would have
71// the same hash as `foo.llvm.5678.
74}
75
76} // namespace llvm
77
78#endif
static const LLT S1
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
std::string Name
uint64_t Size
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:168
const T * data() const
Definition: ArrayRef.h:165
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Definition: xxhash.cpp:553
StringRef get_stable_name(StringRef Name)
Definition: StableHashing.h:55
stable_hash stable_hash_name(StringRef Name)
Definition: StableHashing.h:72
stable_hash stable_hash_combine(ArrayRef< stable_hash > Buffer)
Definition: StableHashing.h:30
uint64_t stable_hash
An opaque object representing a stable hash code.
Definition: StableHashing.h:28