1195534Sscottl//===- ProfileSummary.h - Profile summary data structure. -------*- C++ -*-===// 2195534Sscottl// 3195534Sscottl// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4195534Sscottl// See https://llvm.org/LICENSE.txt for license information. 5195534Sscottl// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6195534Sscottl// 7195534Sscottl//===----------------------------------------------------------------------===// 8195534Sscottl// 9195534Sscottl// This file defines the profile summary data structure. 10195534Sscottl// 11195534Sscottl//===----------------------------------------------------------------------===// 12195534Sscottl 13195534Sscottl#ifndef LLVM_IR_PROFILESUMMARY_H 14195534Sscottl#define LLVM_IR_PROFILESUMMARY_H 15195534Sscottl 16195534Sscottl#include <algorithm> 17195534Sscottl#include <cstdint> 18195534Sscottl#include <vector> 19195534Sscottl 20195534Sscottlnamespace llvm { 21195534Sscottl 22195534Sscottlclass LLVMContext; 23195534Sscottlclass Metadata; 24195534Sscottl 25195534Sscottl// The profile summary is one or more (Cutoff, MinCount, NumCounts) triplets. 26195534Sscottl// The semantics of counts depend on the type of profile. For instrumentation 27195534Sscottl// profile, counts are block counts and for sample profile, counts are 28195534Sscottl// per-line samples. Given a target counts percentile, we compute the minimum 29195534Sscottl// number of counts needed to reach this target and the minimum among these 30195534Sscottl// counts. 31195534Sscottlstruct ProfileSummaryEntry { 32195534Sscottl uint32_t Cutoff; ///< The required percentile of counts. 33195534Sscottl uint64_t MinCount; ///< The minimum count for this percentile. 34195534Sscottl uint64_t NumCounts; ///< Number of counts >= the minimum count. 35195534Sscottl 36195534Sscottl ProfileSummaryEntry(uint32_t TheCutoff, uint64_t TheMinCount, 37195534Sscottl uint64_t TheNumCounts) 38195534Sscottl : Cutoff(TheCutoff), MinCount(TheMinCount), NumCounts(TheNumCounts) {} 39195534Sscottl}; 40195534Sscottl 41195534Sscottlusing SummaryEntryVector = std::vector<ProfileSummaryEntry>; 42195534Sscottl 43195534Sscottlclass ProfileSummary { 44195534Sscottlpublic: 45195534Sscottl enum Kind { PSK_Instr, PSK_CSInstr, PSK_Sample }; 46195534Sscottl 47195534Sscottlprivate: 48195534Sscottl const Kind PSK; 49195534Sscottl SummaryEntryVector DetailedSummary; 50195534Sscottl uint64_t TotalCount, MaxCount, MaxInternalCount, MaxFunctionCount; 51195534Sscottl uint32_t NumCounts, NumFunctions; 52195534Sscottl /// Return detailed summary as metadata. 53195534Sscottl Metadata *getDetailedSummaryMD(LLVMContext &Context); 54195534Sscottl 55195534Sscottlpublic: 56195534Sscottl static const int Scale = 1000000; 57195534Sscottl 58195534Sscottl ProfileSummary(Kind K, SummaryEntryVector DetailedSummary, 59195534Sscottl uint64_t TotalCount, uint64_t MaxCount, 60195534Sscottl uint64_t MaxInternalCount, uint64_t MaxFunctionCount, 61195534Sscottl uint32_t NumCounts, uint32_t NumFunctions) 62195534Sscottl : PSK(K), DetailedSummary(std::move(DetailedSummary)), 63195534Sscottl TotalCount(TotalCount), MaxCount(MaxCount), 64195534Sscottl MaxInternalCount(MaxInternalCount), MaxFunctionCount(MaxFunctionCount), 65196656Smav NumCounts(NumCounts), NumFunctions(NumFunctions) {} 66195534Sscottl 67195534Sscottl Kind getKind() const { return PSK; } 68195534Sscottl /// Return summary information as metadata. 69195534Sscottl Metadata *getMD(LLVMContext &Context); 70195534Sscottl /// Construct profile summary from metdata. 71195534Sscottl static ProfileSummary *getFromMD(Metadata *MD); 72195534Sscottl SummaryEntryVector &getDetailedSummary() { return DetailedSummary; } 73195534Sscottl uint32_t getNumFunctions() { return NumFunctions; } 74199821Smav uint64_t getMaxFunctionCount() { return MaxFunctionCount; } 75195534Sscottl uint32_t getNumCounts() { return NumCounts; } 76195534Sscottl uint64_t getTotalCount() { return TotalCount; } 77195534Sscottl uint64_t getMaxCount() { return MaxCount; } 78195534Sscottl uint64_t getMaxInternalCount() { return MaxInternalCount; } 79195534Sscottl}; 80195534Sscottl 81203123Smav} // end namespace llvm 82195534Sscottl 83195534Sscottl#endif // LLVM_IR_PROFILESUMMARY_H 84195534Sscottl