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
23// Upper bound on lifetime access density (accesses per byte per lifetime sec)
24// for marking an allocation cold.
26 "memprof-lifetime-access-density-cold-threshold", cl::init(0.05),
28 cl::desc("The threshold the lifetime access density (accesses per byte per "
29 "lifetime sec) must be under to consider an allocation cold"));
30
31// Lower bound on lifetime to mark an allocation cold (in addition to accesses
32// per byte per sec above). This is to avoid pessimizing short lived objects.
34 "memprof-ave-lifetime-cold-threshold", cl::init(200), cl::Hidden,
35 cl::desc("The average lifetime (s) for an allocation to be considered "
36 "cold"));
37
38// Lower bound on average lifetime accesses density (total life time access
39// density / alloc count) for marking an allocation hot.
41 "memprof-min-ave-lifetime-access-density-hot-threshold", cl::init(1000),
43 cl::desc("The minimum TotalLifetimeAccessDensity / AllocCount for an "
44 "allocation to be considered hot"));
45
47 MemProfUseHotHints("memprof-use-hot-hints", cl::init(false), cl::Hidden,
48 cl::desc("Enable use of hot hints (only supported for "
49 "unambigously hot allocations)"));
50
52 uint64_t AllocCount,
53 uint64_t TotalLifetime) {
54 // The access densities are multiplied by 100 to hold 2 decimal places of
55 // precision, so need to divide by 100.
56 if (((float)TotalLifetimeAccessDensity) / AllocCount / 100 <
58 // Lifetime is expected to be in ms, so convert the threshold to ms.
59 && ((float)TotalLifetime) / AllocCount >=
62
63 // The access densities are multiplied by 100 to hold 2 decimal places of
64 // precision, so need to divide by 100.
66 ((float)TotalLifetimeAccessDensity) / AllocCount / 100 >
69
71}
72
76 for (auto &F : CallStack)
77 HashBuilder.add(F.Function, F.LineOffset, F.Column);
79 uint64_t Id;
80 std::memcpy(&Id, Hash.data(), sizeof(Hash));
81 return Id;
82}
#define LLVM_ABI
Definition Compiler.h:213
#define F(x, y, z)
Definition MD5.cpp:55
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< 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"))
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)"))
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:66
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.
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