LLVM 23.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/ArrayRef.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/Support/Endian.h"
24#include "llvm/Support/xxhash.h"
25
26namespace llvm {
27
28/// An opaque object representing a stable hash code. It can be serialized,
29/// deserialized, and is stable across processes and executions.
31
33 return xxh3_64bits(reinterpret_cast<const uint8_t *>(Buffer.data()),
34 Buffer.size() * sizeof(stable_hash));
35}
36
44
54
65
66// Removes suffixes introduced by LLVM from the name to enhance stability and
67// maintain closeness to the original name across different builds.
69 // Return the part after ".content." that represents contents.
70 StringRef S0 = Name.rsplit(".content.").second;
71 if (!S0.empty())
72 return S0;
73
74 // Ignore these suffixes.
75 StringRef P1 = Name.rsplit(".llvm.").first;
76 return P1.rsplit(".__uniq.").first;
77}
78
79// Generates a consistent hash value for a given input name across different
80// program executions and environments. This function first converts the input
81// name into a stable form using the `get_stable_name` function, and then
82// computes a hash of this stable name. For instance, `foo.llvm.1234` would have
83// the same hash as `foo.llvm.5678.
87
88} // namespace llvm
89
90#endif
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
Get the array size.
Definition ArrayRef.h:141
const T * data() const
Definition ArrayRef.h:138
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
constexpr bool empty() const
Check if the string is empty.
Definition StringRef.h:141
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
value_type byte_swap(value_type value, endianness endian)
Definition Endian.h:44
This is an optimization pass for GlobalISel generic memory operations.
uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Inline ArrayRef overloads of the xxhash entry points declared out-of-line in llvm/Support/xxhash....
Definition ArrayRef.h:558
uint64_t stable_hash
An opaque object representing a stable hash code.
StringRef get_stable_name(StringRef Name)
stable_hash stable_hash_name(StringRef Name)
stable_hash stable_hash_combine(ArrayRef< stable_hash > Buffer)