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 const uint8_t *Ptr = reinterpret_cast<const uint8_t *>(Buffer.data());
34 size_t Size = Buffer.size() * sizeof(stable_hash);
36}
37
45
55
66
67// Removes suffixes introduced by LLVM from the name to enhance stability and
68// maintain closeness to the original name across different builds.
70 // Return the part after ".content." that represents contents.
71 StringRef S0 = Name.rsplit(".content.").second;
72 if (!S0.empty())
73 return S0;
74
75 // Ignore these suffixes.
76 StringRef P1 = Name.rsplit(".llvm.").first;
77 return P1.rsplit(".__uniq.").first;
78}
79
80// Generates a consistent hash value for a given input name across different
81// program executions and environments. This function first converts the input
82// name into a stable form using the `get_stable_name` function, and then
83// computes a hash of this stable name. For instance, `foo.llvm.1234` would have
84// the same hash as `foo.llvm.5678.
88
89} // namespace llvm
90
91#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")
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
size_t size() const
size - Get the array size.
Definition ArrayRef.h:142
const T * data() const
Definition ArrayRef.h:139
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition StringRef.h:140
@ 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.
LLVM_ABI uint64_t xxh3_64bits(ArrayRef< uint8_t > data)
Definition xxhash.cpp:553
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)