LLVM  8.0.1
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_IR_PROFILESUMMARY_H
15 #define LLVM_IR_PROFILESUMMARY_H
16 
17 #include <algorithm>
18 #include <cstdint>
19 #include <vector>
20 
21 namespace llvm {
22 
23 class LLVMContext;
24 class Metadata;
25 
26 // The profile summary is one or more (Cutoff, MinCount, NumCounts) triplets.
27 // The semantics of counts depend on the type of profile. For instrumentation
28 // profile, counts are block counts and for sample profile, counts are
29 // per-line samples. Given a target counts percentile, we compute the minimum
30 // number of counts needed to reach this target and the minimum among these
31 // counts.
33  uint32_t Cutoff; ///< The required percentile of counts.
34  uint64_t MinCount; ///< The minimum count for this percentile.
35  uint64_t NumCounts; ///< Number of counts >= the minimum count.
36 
37  ProfileSummaryEntry(uint32_t TheCutoff, uint64_t TheMinCount,
38  uint64_t TheNumCounts)
39  : Cutoff(TheCutoff), MinCount(TheMinCount), NumCounts(TheNumCounts) {}
40 };
41 
42 using SummaryEntryVector = std::vector<ProfileSummaryEntry>;
43 
45 public:
46  enum Kind { PSK_Instr, PSK_Sample };
47 
48 private:
49  const Kind PSK;
50  static const char *KindStr[2];
51  SummaryEntryVector DetailedSummary;
52  uint64_t TotalCount, MaxCount, MaxInternalCount, MaxFunctionCount;
53  uint32_t NumCounts, NumFunctions;
54  /// Return detailed summary as metadata.
55  Metadata *getDetailedSummaryMD(LLVMContext &Context);
56 
57 public:
58  static const int Scale = 1000000;
59 
61  uint64_t TotalCount, uint64_t MaxCount,
62  uint64_t MaxInternalCount, uint64_t MaxFunctionCount,
63  uint32_t NumCounts, uint32_t NumFunctions)
64  : PSK(K), DetailedSummary(std::move(DetailedSummary)),
65  TotalCount(TotalCount), MaxCount(MaxCount),
66  MaxInternalCount(MaxInternalCount), MaxFunctionCount(MaxFunctionCount),
67  NumCounts(NumCounts), NumFunctions(NumFunctions) {}
68 
69  Kind getKind() const { return PSK; }
70  /// Return summary information as metadata.
71  Metadata *getMD(LLVMContext &Context);
72  /// Construct profile summary from metdata.
73  static ProfileSummary *getFromMD(Metadata *MD);
74  SummaryEntryVector &getDetailedSummary() { return DetailedSummary; }
75  uint32_t getNumFunctions() { return NumFunctions; }
76  uint64_t getMaxFunctionCount() { return MaxFunctionCount; }
78  uint64_t getTotalCount() { return TotalCount; }
79  uint64_t getMaxCount() { return MaxCount; }
80  uint64_t getMaxInternalCount() { return MaxInternalCount; }
81 };
82 
83 } // end namespace llvm
84 
85 #endif // LLVM_IR_PROFILESUMMARY_H
LLVMContext & Context
uint32_t Cutoff
The required percentile of counts.
Kind getKind() const
This class represents lattice values for constants.
Definition: AllocatorList.h:24
uint64_t getMaxInternalCount()
ProfileSummary(Kind K, SummaryEntryVector DetailedSummary, uint64_t TotalCount, uint64_t MaxCount, uint64_t MaxInternalCount, uint64_t MaxFunctionCount, uint32_t NumCounts, uint32_t NumFunctions)
Definition: BitVector.h:938
uint64_t getMaxFunctionCount()
SummaryEntryVector & getDetailedSummary()
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:69
uint64_t getTotalCount()
ProfileSummaryEntry(uint32_t TheCutoff, uint64_t TheMinCount, uint64_t TheNumCounts)
uint32_t getNumFunctions()
uint64_t MinCount
The minimum count for this percentile.
uint64_t NumCounts
Number of counts >= the minimum count.
std::vector< ProfileSummaryEntry > SummaryEntryVector
Root of the metadata hierarchy.
Definition: Metadata.h:58
std::vector< uint32_t > Metadata
PAL metadata represented as a vector.