LLVM  14.0.0git
StableHashing.h
Go to the documentation of this file.
1 //===- llvm/CodeGen/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, or compiler runs.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CODEGEN_STABLEHASHING_H
16 #define LLVM_CODEGEN_STABLEHASHING_H
17 
18 #include "llvm/ADT/StringRef.h"
19 
20 namespace llvm {
21 
22 /// An opaque object representing a stable hash code. It can be serialized,
23 /// deserialized, and is stable across processes and executions.
25 
26 // Implementation details
27 namespace hashing {
28 namespace detail {
29 
30 // Stable hashes are based on the 64-bit FNV-1 hash:
31 // https://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function
32 
33 const uint64_t FNV_PRIME_64 = 1099511628211u;
34 const uint64_t FNV_OFFSET_64 = 14695981039346656037u;
35 
36 inline void stable_hash_append(stable_hash &Hash, const char Value) {
37  Hash = Hash ^ (Value & 0xFF);
38  Hash = Hash * FNV_PRIME_64;
39 }
40 
42  for (unsigned I = 0; I < 8; ++I) {
43  stable_hash_append(Hash, static_cast<char>(Value));
44  Value >>= 8;
45  }
46 }
47 
48 } // namespace detail
49 } // namespace hashing
50 
55  return Hash;
56 }
57 
59  stable_hash C) {
64  return Hash;
65 }
66 
74  return Hash;
75 }
76 
77 /// Compute a stable_hash for a sequence of values.
78 ///
79 /// This hashes a sequence of values. It produces the same stable_hash as
80 /// 'stable_hash_combine(a, b, c, ...)', but can run over arbitrary sized
81 /// sequences and is significantly faster given pointers and types which
82 /// can be hashed as a sequence of bytes.
83 template <typename InputIteratorT>
85  InputIteratorT Last) {
87  for (auto I = First; I != Last; ++I)
89  return Hash;
90 }
91 
94  for (size_t I = 0; I < C; ++I)
96  return Hash;
97 }
98 
100  return stable_hash_combine_range(S.begin(), S.end());
101 }
102 
105  while (*C)
107  return Hash;
108 }
109 
110 } // namespace llvm
111 
112 #endif
llvm::stable_hash_combine_string
stable_hash stable_hash_combine_string(const StringRef &S)
Definition: StableHashing.h:99
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::stable_hash_combine_range
stable_hash stable_hash_combine_range(InputIteratorT First, InputIteratorT Last)
Compute a stable_hash for a sequence of values.
Definition: StableHashing.h:84
llvm::stable_hash_combine
stable_hash stable_hash_combine(stable_hash A, stable_hash B)
Definition: StableHashing.h:51
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::stable_hash_combine_array
stable_hash stable_hash_combine_array(const stable_hash *P, size_t C)
Definition: StableHashing.h:92
llvm::stable_hash
uint64_t stable_hash
An opaque object representing a stable hash code.
Definition: StableHashing.h:24
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
First
into llvm powi allowing the code generator to produce balanced multiplication trees First
Definition: README.txt:54
llvm::hashing::detail::FNV_OFFSET_64
const uint64_t FNV_OFFSET_64
Definition: StableHashing.h:34
uint64_t
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::hashing::detail::FNV_PRIME_64
const uint64_t FNV_PRIME_64
Definition: StableHashing.h:33
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::hashing::detail::stable_hash_append
void stable_hash_append(stable_hash &Hash, const char Value)
Definition: StableHashing.h:36
llvm::Value
LLVM Value Representation.
Definition: Value.h:75