LLVM 24.0.0git
AllocToken.h
Go to the documentation of this file.
1//===- llvm/Support/AllocToken.h - Allocation Token Calculation -----*- 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// Definition of AllocToken modes and shared calculation of stateless token IDs.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_SUPPORT_ALLOCTOKEN_H
14#define LLVM_SUPPORT_ALLOCTOKEN_H
15
17#include "llvm/ADT/StringRef.h"
18#include <cstdint>
19#include <optional>
20
21namespace llvm {
22
23/// Modes for generating allocation token IDs.
24enum class AllocTokenMode {
25 /// Incrementally increasing token ID.
27
28 /// Simple mode that returns a statically-assigned random token ID.
30
31 /// Token ID based on allocated type hash.
33
34 /// Token ID based on allocated type hash, where the top half ID-space is
35 /// reserved for types that contain pointers and the bottom half for types
36 /// that do not contain pointers.
38
39 /// Token ID based on allocated type hash and containing function name hash.
40 /// Uses k bits if MaxTokens is 2^k-1 (e.g. SIZE_MAX), or
41 /// floor(log2(MaxTokens)) bits otherwise.
43
44 /// Like TypeFuncHash, but for MaxTokens > 1 the most significant bit of the
45 /// ID space is set for types that contain pointers.
47};
48
49/// The default allocation token mode.
52
53/// Returns the AllocTokenMode from its canonical string name; if an invalid
54/// name was provided returns nullopt.
55LLVM_ABI std::optional<AllocTokenMode>
57
58/// Returns the canonical string name for the given AllocTokenMode.
60
61/// Metadata about an allocation used to generate a token ID.
65 /// Name of the function containing the allocation (TypeFuncHash modes).
66 std::optional<SmallString<64>> FunctionName = std::nullopt;
67};
68
69/// Calculates stable allocation token ID. Returns std::nullopt for stateful
70/// modes that are only available in the AllocToken pass, and for TypeFuncHash
71/// modes if FunctionName is not set.
72///
73/// \param Mode The token generation mode.
74/// \param Metadata The metadata about the allocation.
75/// \param MaxTokens The maximum number of tokens (must not be 0)
76/// \return The calculated allocation token ID, or std::nullopt.
77LLVM_ABI std::optional<uint64_t>
79 uint64_t MaxTokens);
80
81} // end namespace llvm
82
83#endif // LLVM_SUPPORT_ALLOCTOKEN_H
unsigned uint64_t
#define LLVM_ABI
Definition Compiler.h:215
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
This file defines the SmallString class.
Root of the metadata hierarchy.
Definition Metadata.h:64
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:26
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::optional< uint64_t > getAllocToken(AllocTokenMode Mode, const AllocTokenMetadata &Metadata, uint64_t MaxTokens)
Calculates stable allocation token ID.
constexpr AllocTokenMode DefaultAllocTokenMode
The default allocation token mode.
Definition AllocToken.h:50
AllocTokenMode
Modes for generating allocation token IDs.
Definition AllocToken.h:24
@ TypeFuncHashPointerSplit
Like TypeFuncHash, but for MaxTokens > 1 the most significant bit of the ID space is set for types th...
Definition AllocToken.h:46
@ TypeHash
Token ID based on allocated type hash.
Definition AllocToken.h:32
@ Random
Simple mode that returns a statically-assigned random token ID.
Definition AllocToken.h:29
@ Increment
Incrementally increasing token ID.
Definition AllocToken.h:26
@ TypeFuncHash
Token ID based on allocated type hash and containing function name hash.
Definition AllocToken.h:42
@ TypeHashPointerSplit
Token ID based on allocated type hash, where the top half ID-space is reserved for types that contain...
Definition AllocToken.h:37
LLVM_ABI std::optional< AllocTokenMode > getAllocTokenModeFromString(StringRef Name)
Returns the AllocTokenMode from its canonical string name; if an invalid name was provided returns nu...
LLVM_ABI StringRef getAllocTokenModeAsString(AllocTokenMode Mode)
Returns the canonical string name for the given AllocTokenMode.
Metadata about an allocation used to generate a token ID.
Definition AllocToken.h:62
SmallString< 64 > TypeName
Definition AllocToken.h:63
std::optional< SmallString< 64 > > FunctionName
Name of the function containing the allocation (TypeFuncHash modes).
Definition AllocToken.h:66