1 //===- ProfileSummary.h - Profile summary data structure. -------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines the profile summary data structure.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_IR_PROFILESUMMARY_H
14 #define LLVM_IR_PROFILESUMMARY_H
25 // The profile summary is one or more (Cutoff, MinCount, NumCounts) triplets.
26 // The semantics of counts depend on the type of profile. For instrumentation
27 // profile, counts are block counts and for sample profile, counts are
28 // per-line samples. Given a target counts percentile, we compute the minimum
29 // number of counts needed to reach this target and the minimum among these
31 struct ProfileSummaryEntry
{
32 uint32_t Cutoff
; ///< The required percentile of counts.
33 uint64_t MinCount
; ///< The minimum count for this percentile.
34 uint64_t NumCounts
; ///< Number of counts >= the minimum count.
36 ProfileSummaryEntry(uint32_t TheCutoff
, uint64_t TheMinCount
,
37 uint64_t TheNumCounts
)
38 : Cutoff(TheCutoff
), MinCount(TheMinCount
), NumCounts(TheNumCounts
) {}
41 using SummaryEntryVector
= std::vector
<ProfileSummaryEntry
>;
43 class ProfileSummary
{
45 enum Kind
{ PSK_Instr
, PSK_Sample
};
49 static const char *KindStr
[2];
50 SummaryEntryVector DetailedSummary
;
51 uint64_t TotalCount
, MaxCount
, MaxInternalCount
, MaxFunctionCount
;
52 uint32_t NumCounts
, NumFunctions
;
53 /// Return detailed summary as metadata.
54 Metadata
*getDetailedSummaryMD(LLVMContext
&Context
);
57 static const int Scale
= 1000000;
59 ProfileSummary(Kind K
, SummaryEntryVector DetailedSummary
,
60 uint64_t TotalCount
, uint64_t MaxCount
,
61 uint64_t MaxInternalCount
, uint64_t MaxFunctionCount
,
62 uint32_t NumCounts
, uint32_t NumFunctions
)
63 : PSK(K
), DetailedSummary(std::move(DetailedSummary
)),
64 TotalCount(TotalCount
), MaxCount(MaxCount
),
65 MaxInternalCount(MaxInternalCount
), MaxFunctionCount(MaxFunctionCount
),
66 NumCounts(NumCounts
), NumFunctions(NumFunctions
) {}
68 Kind
getKind() const { return PSK
; }
69 /// Return summary information as metadata.
70 Metadata
*getMD(LLVMContext
&Context
);
71 /// Construct profile summary from metdata.
72 static ProfileSummary
*getFromMD(Metadata
*MD
);
73 SummaryEntryVector
&getDetailedSummary() { return DetailedSummary
; }
74 uint32_t getNumFunctions() { return NumFunctions
; }
75 uint64_t getMaxFunctionCount() { return MaxFunctionCount
; }
76 uint32_t getNumCounts() { return NumCounts
; }
77 uint64_t getTotalCount() { return TotalCount
; }
78 uint64_t getMaxCount() { return MaxCount
; }
79 uint64_t getMaxInternalCount() { return MaxInternalCount
; }
82 } // end namespace llvm
84 #endif // LLVM_IR_PROFILESUMMARY_H