1 //===- ProfileSummary.h - Profile summary data structure. -------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the profile summary data structure.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_IR_PROFILESUMMARY_H
15 #define LLVM_IR_PROFILESUMMARY_H
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
32 struct 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.
37 ProfileSummaryEntry(uint32_t TheCutoff, uint64_t TheMinCount,
38 uint64_t TheNumCounts)
39 : Cutoff(TheCutoff), MinCount(TheMinCount), NumCounts(TheNumCounts) {}
42 using SummaryEntryVector = std::vector<ProfileSummaryEntry>;
44 class ProfileSummary {
46 enum Kind { PSK_Instr, PSK_Sample };
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);
58 static const int Scale = 1000000;
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) {}
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; }
77 uint32_t getNumCounts() { return NumCounts; }
78 uint64_t getTotalCount() { return TotalCount; }
79 uint64_t getMaxCount() { return MaxCount; }
80 uint64_t getMaxInternalCount() { return MaxInternalCount; }
83 } // end namespace llvm
85 #endif // LLVM_IR_PROFILESUMMARY_H