blob: e38663770a13935cecc18f436a9eb2bf74bfabc9 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- 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
21namespace llvm {
22
23class LLVMContext;
24class 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.
32struct ProfileSummaryEntry {
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
42using SummaryEntryVector = std::vector<ProfileSummaryEntry>;
43
44class ProfileSummary {
45public:
46 enum Kind { PSK_Instr, PSK_Sample };
47
48private:
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;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010054 /// Return detailed summary as metadata.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010055 Metadata *getDetailedSummaryMD(LLVMContext &Context);
56
57public:
58 static const int Scale = 1000000;
59
60 ProfileSummary(Kind K, SummaryEntryVector DetailedSummary,
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; }
Andrew Scullcdfcccc2018-10-05 20:58:37 +010070 /// Return summary information as metadata.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010071 Metadata *getMD(LLVMContext &Context);
Andrew Scullcdfcccc2018-10-05 20:58:37 +010072 /// Construct profile summary from metdata.
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010073 static ProfileSummary *getFromMD(Metadata *MD);
74 SummaryEntryVector &getDetailedSummary() { return DetailedSummary; }
75 uint32_t getNumFunctions() { return NumFunctions; }
76 uint64_t getMaxFunctionCount() { return MaxFunctionCount; }
77 uint32_t getNumCounts() { return NumCounts; }
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