LLVM 22.0.0git
MemProfSummaryBuilder.cpp
Go to the documentation of this file.
1//=-- MemProfSummaryBuilder.cpp - MemProf summary building ---------------=//
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 summary builder.
10//
11//===----------------------------------------------------------------------===//
12
15
16using namespace llvm;
17using namespace llvm::memprof;
18
19std::unique_ptr<MemProfSummary> MemProfSummaryBuilder::getSummary() {
20 return std::make_unique<MemProfSummary>(NumContexts, NumColdContexts,
21 NumHotContexts, MaxColdTotalSize,
22 MaxWarmTotalSize, MaxHotTotalSize);
23}
24
25void MemProfSummaryBuilder::addRecord(uint64_t CSId,
26 const PortableMemInfoBlock &Info) {
27 auto I = Contexts.insert(CSId);
28 if (!I.second)
29 return;
30 NumContexts++;
31 auto AllocType = getAllocType(Info.getTotalLifetimeAccessDensity(),
32 Info.getAllocCount(), Info.getTotalLifetime());
33 auto TotalSize = Info.getTotalSize();
34 switch (AllocType) {
36 NumColdContexts++;
37 if (TotalSize > MaxColdTotalSize)
38 MaxColdTotalSize = TotalSize;
39 break;
41 if (TotalSize > MaxWarmTotalSize)
42 MaxWarmTotalSize = TotalSize;
43 break;
45 NumHotContexts++;
46 if (TotalSize > MaxHotTotalSize)
47 MaxHotTotalSize = TotalSize;
48 break;
49 default:
50 assert(false);
51 }
52}
53
54void MemProfSummaryBuilder::addRecord(const IndexedMemProfRecord &Record) {
55 for (auto &Alloc : Record.AllocSites)
56 addRecord(Alloc.CSId, Alloc.Info);
57}
58
59void MemProfSummaryBuilder::addRecord(const MemProfRecord &Record) {
60 for (auto &Alloc : Record.AllocSites)
61 addRecord(computeFullStackId(Alloc.CallStack), Alloc.Info);
62}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
#define I(x, y, z)
Definition: MD5.cpp:58
AllocType
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:194
LLVM_ABI std::unique_ptr< MemProfSummary > getSummary()
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.
Definition: AddressRanges.h:18