File indexing completed on 2026-05-10 08:44:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_IR_PROFILESUMMARY_H
0014 #define LLVM_IR_PROFILESUMMARY_H
0015
0016 #include <algorithm>
0017 #include <cassert>
0018 #include <cstdint>
0019 #include <vector>
0020
0021 namespace llvm {
0022
0023 class LLVMContext;
0024 class Metadata;
0025 class raw_ostream;
0026
0027
0028
0029
0030
0031
0032
0033 struct ProfileSummaryEntry {
0034 const uint32_t Cutoff;
0035 const uint64_t MinCount;
0036 const uint64_t NumCounts;
0037
0038 ProfileSummaryEntry(uint32_t TheCutoff, uint64_t TheMinCount,
0039 uint64_t TheNumCounts)
0040 : Cutoff(TheCutoff), MinCount(TheMinCount), NumCounts(TheNumCounts) {}
0041 };
0042
0043 using SummaryEntryVector = std::vector<ProfileSummaryEntry>;
0044
0045 class ProfileSummary {
0046 public:
0047 enum Kind { PSK_Instr, PSK_CSInstr, PSK_Sample };
0048
0049 private:
0050 const Kind PSK;
0051 const SummaryEntryVector DetailedSummary;
0052 const uint64_t TotalCount, MaxCount, MaxInternalCount, MaxFunctionCount;
0053 const uint32_t NumCounts, NumFunctions;
0054
0055
0056
0057
0058
0059 bool Partial = false;
0060
0061
0062
0063
0064 double PartialProfileRatio = 0.0;
0065
0066 Metadata *getDetailedSummaryMD(LLVMContext &Context);
0067
0068 public:
0069 static const int Scale = 1000000;
0070
0071 ProfileSummary(Kind K, const SummaryEntryVector &DetailedSummary,
0072 uint64_t TotalCount, uint64_t MaxCount,
0073 uint64_t MaxInternalCount, uint64_t MaxFunctionCount,
0074 uint32_t NumCounts, uint32_t NumFunctions,
0075 bool Partial = false, double PartialProfileRatio = 0)
0076 : PSK(K), DetailedSummary(DetailedSummary), TotalCount(TotalCount),
0077 MaxCount(MaxCount), MaxInternalCount(MaxInternalCount),
0078 MaxFunctionCount(MaxFunctionCount), NumCounts(NumCounts),
0079 NumFunctions(NumFunctions), Partial(Partial),
0080 PartialProfileRatio(PartialProfileRatio) {}
0081
0082 Kind getKind() const { return PSK; }
0083
0084 Metadata *getMD(LLVMContext &Context, bool AddPartialField = true,
0085 bool AddPartialProfileRatioField = true);
0086
0087 static ProfileSummary *getFromMD(Metadata *MD);
0088 const SummaryEntryVector &getDetailedSummary() { return DetailedSummary; }
0089 uint32_t getNumFunctions() const { return NumFunctions; }
0090 uint64_t getMaxFunctionCount() const { return MaxFunctionCount; }
0091 uint32_t getNumCounts() const { return NumCounts; }
0092 uint64_t getTotalCount() const { return TotalCount; }
0093 uint64_t getMaxCount() const { return MaxCount; }
0094 uint64_t getMaxInternalCount() const { return MaxInternalCount; }
0095 void setPartialProfile(bool PP) { Partial = PP; }
0096 bool isPartialProfile() const { return Partial; }
0097 double getPartialProfileRatio() const { return PartialProfileRatio; }
0098 void setPartialProfileRatio(double R) {
0099 assert(isPartialProfile() && "Unexpected when not partial profile");
0100 PartialProfileRatio = R;
0101 }
0102 void printSummary(raw_ostream &OS) const;
0103 void printDetailedSummary(raw_ostream &OS) const;
0104 };
0105
0106 }
0107
0108 #endif