• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- ProfileSummary.h - Profile summary data structure. ------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the profile summary data structure.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_SUPPORT_PROFILE_SUMMARY_H
15 #define LLVM_SUPPORT_PROFILE_SUMMARY_H
16 
17 #include <cstdint>
18 #include <utility>
19 #include <vector>
20 
21 #include "llvm/Support/Casting.h"
22 
23 namespace llvm {
24 
25 class LLVMContext;
26 class Metadata;
27 class MDTuple;
28 class MDNode;
29 
30 // The profile summary is one or more (Cutoff, MinCount, NumCounts) triplets.
31 // The semantics of counts depend on the type of profile. For instrumentation
32 // profile, counts are block counts and for sample profile, counts are
33 // per-line samples. Given a target counts percentile, we compute the minimum
34 // number of counts needed to reach this target and the minimum among these
35 // counts.
36 struct ProfileSummaryEntry {
37   uint32_t Cutoff;    ///< The required percentile of counts.
38   uint64_t MinCount;  ///< The minimum count for this percentile.
39   uint64_t NumCounts; ///< Number of counts >= the minimum count.
ProfileSummaryEntryProfileSummaryEntry40   ProfileSummaryEntry(uint32_t TheCutoff, uint64_t TheMinCount,
41                       uint64_t TheNumCounts)
42       : Cutoff(TheCutoff), MinCount(TheMinCount), NumCounts(TheNumCounts) {}
43 };
44 
45 typedef std::vector<ProfileSummaryEntry> SummaryEntryVector;
46 
47 class ProfileSummary {
48 public:
49   enum Kind { PSK_Instr, PSK_Sample };
50 
51 private:
52   const Kind PSK;
53   static const char *KindStr[2];
54   SummaryEntryVector DetailedSummary;
55   uint64_t TotalCount, MaxCount, MaxInternalCount, MaxFunctionCount;
56   uint32_t NumCounts, NumFunctions;
57   /// \brief Return detailed summary as metadata.
58   Metadata *getDetailedSummaryMD(LLVMContext &Context);
59 
60 public:
61   static const int Scale = 1000000;
ProfileSummary(Kind K,SummaryEntryVector DetailedSummary,uint64_t TotalCount,uint64_t MaxCount,uint64_t MaxInternalCount,uint64_t MaxFunctionCount,uint32_t NumCounts,uint32_t NumFunctions)62   ProfileSummary(Kind K, SummaryEntryVector DetailedSummary,
63                  uint64_t TotalCount, uint64_t MaxCount,
64                  uint64_t MaxInternalCount, uint64_t MaxFunctionCount,
65                  uint32_t NumCounts, uint32_t NumFunctions)
66       : PSK(K), DetailedSummary(std::move(DetailedSummary)),
67         TotalCount(TotalCount), MaxCount(MaxCount),
68         MaxInternalCount(MaxInternalCount), MaxFunctionCount(MaxFunctionCount),
69         NumCounts(NumCounts), NumFunctions(NumFunctions) {}
getKind()70   Kind getKind() const { return PSK; }
71   /// \brief Return summary information as metadata.
72   Metadata *getMD(LLVMContext &Context);
73   /// \brief Construct profile summary from metdata.
74   static ProfileSummary *getFromMD(Metadata *MD);
getDetailedSummary()75   SummaryEntryVector &getDetailedSummary() { return DetailedSummary; }
getNumFunctions()76   uint32_t getNumFunctions() { return NumFunctions; }
getMaxFunctionCount()77   uint64_t getMaxFunctionCount() { return MaxFunctionCount; }
getNumCounts()78   uint32_t getNumCounts() { return NumCounts; }
getTotalCount()79   uint64_t getTotalCount() { return TotalCount; }
getMaxCount()80   uint64_t getMaxCount() { return MaxCount; }
getMaxInternalCount()81   uint64_t getMaxInternalCount() { return MaxInternalCount; }
82 };
83 
84 } // end namespace llvm
85 #endif
86