LLVM 23.0.0git
Hash.cpp
Go to the documentation of this file.
1//===- Hash.cpp - Hash functions ---------------------------------------===//
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 implements hash functions.
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/Support/Hash.h"
15#include "llvm/Support/xxhash.h"
16
17using namespace llvm;
18
20 if (Name == "FNV-1a")
22 // Default to xxHash64 for backward compatibility
24}
25
27 switch (Algorithm) {
29 return "xxHash64";
31 return "FNV-1a";
32 }
33 llvm_unreachable("Unknown KCFI hash algorithm");
34}
35
37 KCFIHashAlgorithm Algorithm) {
38 switch (Algorithm) {
40 // Use lower 32 bits of xxHash64
41 return static_cast<uint32_t>(xxHash64(MangledTypeName));
43 // FNV-1a hash (32-bit)
44 uint32_t Hash = 2166136261u; // FNV offset basis
45 for (unsigned char C : MangledTypeName) {
46 Hash ^= C;
47 Hash *= 16777619u; // FNV prime
48 }
49 return Hash;
50 }
51 llvm_unreachable("Unknown KCFI hash algorithm");
52}
Represent a constant reference to a string, i.e.
Definition StringRef.h:55
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI KCFIHashAlgorithm parseKCFIHashAlgorithm(StringRef Name)
Parse a KCFI hash algorithm name.
Definition Hash.cpp:19
KCFIHashAlgorithm
Definition Hash.h:21
LLVM_ABI StringRef stringifyKCFIHashAlgorithm(KCFIHashAlgorithm Algorithm)
Convert a KCFI hash algorithm enum to its string representation.
Definition Hash.cpp:26
LLVM_ABI uint32_t getKCFITypeID(StringRef MangledTypeName, KCFIHashAlgorithm Algorithm)
Compute KCFI type ID from mangled type name.
Definition Hash.cpp:36