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_SUPPORT_PROFILE_SUMMARY_H
15 #define LLVM_SUPPORT_PROFILE_SUMMARY_H
21 #include "llvm/Support/Casting.h"
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
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.
40 ProfileSummaryEntry(uint32_t TheCutoff, uint64_t TheMinCount,
41 uint64_t TheNumCounts)
42 : Cutoff(TheCutoff), MinCount(TheMinCount), NumCounts(TheNumCounts) {}
45 typedef std::vector<ProfileSummaryEntry> SummaryEntryVector;
47 class ProfileSummary {
49 enum Kind { PSK_Instr, PSK_Sample };
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);
61 static const int Scale = 1000000;
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) {}
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);
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; }
84 } // end namespace llvm