LLVM 22.0.0git
MemProfCommon.cpp
Go to the documentation of this file.
1//=-- MemProfCommon.cpp - MemProf common utilities ---------------=//
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 contains MemProf common utilities.
10//
11//===----------------------------------------------------------------------===//
12
15#include "llvm/Support/BLAKE3.h"
19
20using namespace llvm;
21using namespace llvm::memprof;
22
23namespace llvm {
24
25// Upper bound on lifetime access density (accesses per byte per lifetime sec)
26// for marking an allocation cold.
28 "memprof-lifetime-access-density-cold-threshold", cl::init(0.05),
30 cl::desc("The threshold the lifetime access density (accesses per byte per "
31 "lifetime sec) must be under to consider an allocation cold"));
32
33// Lower bound on lifetime to mark an allocation cold (in addition to accesses
34// per byte per sec above). This is to avoid pessimizing short lived objects.
36 "memprof-ave-lifetime-cold-threshold", cl::init(200), cl::Hidden,
37 cl::desc("The average lifetime (s) for an allocation to be considered "
38 "cold"));
39
40// Lower bound on average lifetime accesses density (total life time access
41// density / alloc count) for marking an allocation hot.
43 "memprof-min-ave-lifetime-access-density-hot-threshold", cl::init(1000),
45 cl::desc("The minimum TotalLifetimeAccessDensity / AllocCount for an "
46 "allocation to be considered hot"));
47
49 MemProfUseHotHints("memprof-use-hot-hints", cl::init(false), cl::Hidden,
50 cl::desc("Enable use of hot hints (only supported for "
51 "unambigously hot allocations)"));
52
53} // end namespace llvm
54
56 uint64_t AllocCount,
57 uint64_t TotalLifetime) {
58 // The access densities are multiplied by 100 to hold 2 decimal places of
59 // precision, so need to divide by 100.
60 if (((float)TotalLifetimeAccessDensity) / AllocCount / 100 <
62 // Lifetime is expected to be in ms, so convert the threshold to ms.
63 && ((float)TotalLifetime) / AllocCount >=
66
67 // The access densities are multiplied by 100 to hold 2 decimal places of
68 // precision, so need to divide by 100.
70 ((float)TotalLifetimeAccessDensity) / AllocCount / 100 >
73
75}
76
80 for (auto &F : CallStack)
81 HashBuilder.add(F.Function, F.LineOffset, F.Column);
83 uint64_t Id;
84 std::memcpy(&Id, Hash.data(), sizeof(Hash));
85 return Id;
86}
#define LLVM_ABI
Definition Compiler.h:213
#define F(x, y, z)
Definition MD5.cpp:55
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
HashResultTy< HasherT_ > final()
Forward to HasherT::final() if available.
Definition HashBuilder.h:64
Interface to help hash various types through a hasher type.
std::enable_if_t< hashbuilder_detail::IsHashableData< T >::value, HashBuilder & > add(T Value)
Implement hashing for hashable data types, e.g. integral or enum values.
Helper class to iterate through stack ids in both metadata (memprof MIB and callsite) and the corresp...
initializer< Ty > init(const Ty &Val)
LLVM_ABI AllocationType getAllocType(uint64_t TotalLifetimeAccessDensity, uint64_t AllocCount, uint64_t TotalLifetime)
Return the allocation type for a given set of memory profile values.
LLVM_ABI uint64_t computeFullStackId(ArrayRef< Frame > CallStack)
Helper to generate a single hash id for a given callstack, used for emitting matching statistics and ...
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI cl::opt< float > MemProfLifetimeAccessDensityColdThreshold("memprof-lifetime-access-density-cold-threshold", cl::init(0.05), cl::Hidden, cl::desc("The threshold the lifetime access density (accesses per byte per " "lifetime sec) must be under to consider an allocation cold"))
std::array< uint8_t, NumBytes > BLAKE3Result
The constant LLVM_BLAKE3_OUT_LEN provides the default output length, 32 bytes, which is recommended f...
Definition BLAKE3.h:35
LLVM_ABI cl::opt< unsigned > MemProfAveLifetimeColdThreshold("memprof-ave-lifetime-cold-threshold", cl::init(200), cl::Hidden, cl::desc("The average lifetime (s) for an allocation to be considered " "cold"))
LLVM_ABI cl::opt< unsigned > MemProfMinAveLifetimeAccessDensityHotThreshold("memprof-min-ave-lifetime-access-density-hot-threshold", cl::init(1000), cl::Hidden, cl::desc("The minimum TotalLifetimeAccessDensity / AllocCount for an " "allocation to be considered hot"))
LLVM_ABI cl::opt< bool > MemProfUseHotHints("memprof-use-hot-hints", cl::init(false), cl::Hidden, cl::desc("Enable use of hot hints (only supported for " "unambigously hot allocations)"))