xref: /freebsd/contrib/llvm-project/llvm/include/llvm/ProfileData/MemProfSummary.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
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 
16 #include "llvm/ProfileData/InstrProf.h"
17 #include "llvm/Support/Compiler.h"
18 
19 namespace llvm {
20 namespace memprof {
21 
22 class MemProfSummary {
23 private:
24   /// The number of summary fields below, which is used to enable some forwards
25   /// and backwards compatibility for the summary when serialized in the indexed
26   /// MemProf format. As long as no existing summary fields are removed or
27   /// reordered, and new summary fields are added after existing summary fields,
28   /// the MemProf indexed profile version does not need to be bumped to
29   /// accommodate new summary fields.
30   static constexpr unsigned NumSummaryFields = 6;
31 
32   const uint64_t NumContexts, NumColdContexts, NumHotContexts;
33   const uint64_t MaxColdTotalSize, MaxWarmTotalSize, MaxHotTotalSize;
34 
35 public:
MemProfSummary(uint64_t NumContexts,uint64_t NumColdContexts,uint64_t NumHotContexts,uint64_t MaxColdTotalSize,uint64_t MaxWarmTotalSize,uint64_t MaxHotTotalSize)36   MemProfSummary(uint64_t NumContexts, uint64_t NumColdContexts,
37                  uint64_t NumHotContexts, uint64_t MaxColdTotalSize,
38                  uint64_t MaxWarmTotalSize, uint64_t MaxHotTotalSize)
39       : NumContexts(NumContexts), NumColdContexts(NumColdContexts),
40         NumHotContexts(NumHotContexts), MaxColdTotalSize(MaxColdTotalSize),
41         MaxWarmTotalSize(MaxWarmTotalSize), MaxHotTotalSize(MaxHotTotalSize) {}
42 
getNumSummaryFields()43   static constexpr unsigned getNumSummaryFields() { return NumSummaryFields; }
getNumContexts()44   uint64_t getNumContexts() const { return NumContexts; }
getNumColdContexts()45   uint64_t getNumColdContexts() const { return NumColdContexts; }
getNumHotContexts()46   uint64_t getNumHotContexts() const { return NumHotContexts; }
getMaxColdTotalSize()47   uint64_t getMaxColdTotalSize() const { return MaxColdTotalSize; }
getMaxWarmTotalSize()48   uint64_t getMaxWarmTotalSize() const { return MaxWarmTotalSize; }
getMaxHotTotalSize()49   uint64_t getMaxHotTotalSize() const { return MaxHotTotalSize; }
50   LLVM_ABI void printSummaryYaml(raw_ostream &OS) const;
51   /// Write to indexed MemProf profile.
52   LLVM_ABI void write(ProfOStream &OS) const;
53   /// Read from indexed MemProf profile.
54   LLVM_ABI static std::unique_ptr<MemProfSummary>
55   deserialize(const unsigned char *&);
56 };
57 
58 } // namespace memprof
59 } // namespace llvm
60 
61 #endif // LLVM_PROFILEDATA_MEMPROFSUMMARY_H
62