LLVM 22.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"
14#include "llvm/Support/xxhash.h"
15
16using namespace llvm;
17
19 if (Name == "FNV-1a")
21 // Default to xxHash64 for backward compatibility
23}
24
26 switch (Algorithm) {
28 return "xxHash64";
30 return "FNV-1a";
31 }
32 llvm_unreachable("Unknown KCFI hash algorithm");
33}
34
36 KCFIHashAlgorithm Algorithm) {
37 switch (Algorithm) {
39 // Use lower 32 bits of xxHash64
40 return static_cast<uint32_t>(xxHash64(MangledTypeName));
42 // FNV-1a hash (32-bit)
43 uint32_t Hash = 2166136261u; // FNV offset basis
44 for (unsigned char C : MangledTypeName) {
45 Hash ^= C;
46 Hash *= 16777619u; // FNV prime
47 }
48 return Hash;
49 }
50 llvm_unreachable("Unknown KCFI hash algorithm");
51}
StringRef - 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.
KCFIHashAlgorithm parseKCFIHashAlgorithm(StringRef Name)
Parse a KCFI hash algorithm name.
Definition Hash.cpp:18
KCFIHashAlgorithm
Definition Hash.h:21
StringRef stringifyKCFIHashAlgorithm(KCFIHashAlgorithm Algorithm)
Convert a KCFI hash algorithm enum to its string representation.
Definition Hash.cpp:25
uint32_t getKCFITypeID(StringRef MangledTypeName, KCFIHashAlgorithm Algorithm)
Compute KCFI type ID from mangled type name.
Definition Hash.cpp:35