LLVM 22.0.0git
MemProfSummary.h
Go to the documentation of this file.
1//===- MemProfSummary.h - MemProf summary support ---------------*- 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// This file contains MemProf summary support.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_PROFILEDATA_MEMPROFSUMMARY_H
14#define LLVM_PROFILEDATA_MEMPROFSUMMARY_H
15
19
20namespace llvm {
21namespace memprof {
22
24private:
25 /// The number of summary fields below, which is used to enable some forwards
26 /// and backwards compatibility for the summary when serialized in the indexed
27 /// MemProf format. As long as no existing summary fields are removed or
28 /// reordered, and new summary fields are added after existing summary fields,
29 /// the MemProf indexed profile version does not need to be bumped to
30 /// accommodate new summary fields.
31 static constexpr unsigned NumSummaryFields = 6;
32
33 const uint64_t NumContexts, NumColdContexts, NumHotContexts;
34 const uint64_t MaxColdTotalSize, MaxWarmTotalSize, MaxHotTotalSize;
35
36 // MemProf v3 and prior versions don't have data access profile,
37 // so record the data access profile state.
38 bool HasDataAccessProfile = false;
39 size_t NumHotSymbolsAndStringLiterals = 0;
40 size_t NumKnownColdSymbols = 0;
41 size_t NumKnownColdStringLiterals = 0;
42
43public:
44 MemProfSummary(uint64_t NumContexts, uint64_t NumColdContexts,
45 uint64_t NumHotContexts, uint64_t MaxColdTotalSize,
46 uint64_t MaxWarmTotalSize, uint64_t MaxHotTotalSize)
47 : NumContexts(NumContexts), NumColdContexts(NumColdContexts),
48 NumHotContexts(NumHotContexts), MaxColdTotalSize(MaxColdTotalSize),
49 MaxWarmTotalSize(MaxWarmTotalSize), MaxHotTotalSize(MaxHotTotalSize),
50 HasDataAccessProfile(false) {}
51
52 static constexpr unsigned getNumSummaryFields() { return NumSummaryFields; }
53 uint64_t getNumContexts() const { return NumContexts; }
54 uint64_t getNumColdContexts() const { return NumColdContexts; }
55 uint64_t getNumHotContexts() const { return NumHotContexts; }
56 uint64_t getMaxColdTotalSize() const { return MaxColdTotalSize; }
57 uint64_t getMaxWarmTotalSize() const { return MaxWarmTotalSize; }
58 uint64_t getMaxHotTotalSize() const { return MaxHotTotalSize; }
60 /// Write to indexed MemProf profile.
61 LLVM_ABI void write(ProfOStream &OS) const;
62 /// Read from indexed MemProf profile.
63 LLVM_ABI static std::unique_ptr<MemProfSummary>
64 deserialize(const unsigned char *&);
65 /// Build data access profile summary from \p DataAccessProfile.
66 /// The pointer is not owned.
67 /// TODO: Remove this function after the data access profile summary is
68 /// serialized.
69 LLVM_ABI void
70 buildDataAccessSummary(const DataAccessProfData &DataAccessProfile);
71};
72
73} // namespace memprof
74} // namespace llvm
75
76#endif // LLVM_PROFILEDATA_MEMPROFSUMMARY_H
#define LLVM_ABI
Definition Compiler.h:213
Encapsulates the data access profile data and the methods to operate on it.
uint64_t getMaxColdTotalSize() const
LLVM_ABI void printSummaryYaml(raw_ostream &OS) const
MemProfSummary(uint64_t NumContexts, uint64_t NumColdContexts, uint64_t NumHotContexts, uint64_t MaxColdTotalSize, uint64_t MaxWarmTotalSize, uint64_t MaxHotTotalSize)
uint64_t getNumHotContexts() const
LLVM_ABI void buildDataAccessSummary(const DataAccessProfData &DataAccessProfile)
Build data access profile summary from DataAccessProfile.
uint64_t getMaxHotTotalSize() const
uint64_t getNumColdContexts() const
uint64_t getMaxWarmTotalSize() const
LLVM_ABI void write(ProfOStream &OS) const
Write to indexed MemProf profile.
static LLVM_ABI std::unique_ptr< MemProfSummary > deserialize(const unsigned char *&)
Read from indexed MemProf profile.
static constexpr unsigned getNumSummaryFields()
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.