ProfileSummary.h revision de2d8694e25a814696358e95141f4b1aa4d8847e
1//===-- ProfileSummary.h - Profile summary data structure. ------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file defines the profile summary data structure. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_SUPPORT_PROFILE_SUMMARY_H 15#define LLVM_SUPPORT_PROFILE_SUMMARY_H 16 17#include <cstdint> 18#include <utility> 19#include <vector> 20 21#include "llvm/Support/Casting.h" 22 23namespace llvm { 24 25class LLVMContext; 26class Metadata; 27class MDTuple; 28class MDNode; 29 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 35// counts. 36struct 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) {} 43}; 44 45typedef std::vector<ProfileSummaryEntry> SummaryEntryVector; 46 47class ProfileSummary { 48public: 49 enum Kind { PSK_Instr, PSK_Sample }; 50 51private: 52 const Kind PSK; 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); 59 60public: 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; } 82}; 83 84} // end namespace llvm 85#endif 86