LLVM  4.0.0
ProfileSummary.h
Go to the documentation of this file.
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.
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.
40  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 
48 public:
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;
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) {}
70  Kind getKind() const { return PSK; }
71  /// \brief Return summary information as metadata.
73  /// \brief Construct profile summary from metdata.
74  static ProfileSummary *getFromMD(Metadata *MD);
75  SummaryEntryVector &getDetailedSummary() { return DetailedSummary; }
76  uint32_t getNumFunctions() { return NumFunctions; }
77  uint64_t getMaxFunctionCount() { return MaxFunctionCount; }
78  uint32_t getNumCounts() { return NumCounts; }
79  uint64_t getTotalCount() { return TotalCount; }
80  uint64_t getMaxCount() { return MaxCount; }
81  uint64_t getMaxInternalCount() { return MaxInternalCount; }
82 };
83 
84 } // end namespace llvm
85 #endif
Kind getKind() const
LLVMContext & Context
uint32_t Cutoff
The required percentile of counts.
uint64_t getMaxInternalCount()
Metadata * getMD(LLVMContext &Context)
Return summary information as metadata.
ProfileSummary(Kind K, SummaryEntryVector DetailedSummary, uint64_t TotalCount, uint64_t MaxCount, uint64_t MaxInternalCount, uint64_t MaxFunctionCount, uint32_t NumCounts, uint32_t NumFunctions)
static const int Scale
uint64_t getMaxFunctionCount()
SummaryEntryVector & getDetailedSummary()
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:48
uint64_t getTotalCount()
ProfileSummaryEntry(uint32_t TheCutoff, uint64_t TheMinCount, uint64_t TheNumCounts)
static ProfileSummary * getFromMD(Metadata *MD)
Construct profile summary from metdata.
uint32_t getNumFunctions()
uint64_t MinCount
The minimum count for this percentile.
uint64_t NumCounts
Number of counts >= the minimum count.
Root of the metadata hierarchy.
Definition: Metadata.h:55
std::vector< ProfileSummaryEntry > SummaryEntryVector