| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#ifndef LLVM_IR_PROFILESUMMARY_H |
| 14 |
#define LLVM_IR_PROFILESUMMARY_H |
| 15 |
|
| 16 |
#include <algorithm> |
| 17 |
#include <cassert> |
| 18 |
#include <cstdint> |
| 19 |
#include <vector> |
| 20 |
|
| 21 |
namespace llvm { |
| 22 |
|
| 23 |
class LLVMContext; |
| 24 |
class Metadata; |
| 25 |
class raw_ostream; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
struct ProfileSummaryEntry { |
| 34 |
const uint32_t Cutoff; |
| 35 |
const uint64_t MinCount; |
| 36 |
const uint64_t NumCounts; |
| 37 |
|
| 38 |
ProfileSummaryEntry(uint32_t TheCutoff, uint64_t TheMinCount, |
| 39 |
uint64_t TheNumCounts) |
| 40 |
: Cutoff(TheCutoff), MinCount(TheMinCount), NumCounts(TheNumCounts) {} |
| 41 |
}; |
| 42 |
|
| 43 |
using SummaryEntryVector = std::vector<ProfileSummaryEntry>; |
| 44 |
|
| 45 |
class ProfileSummary { |
| 46 |
public: |
| 47 |
enum Kind { PSK_Instr, PSK_CSInstr, PSK_Sample }; |
| 48 |
|
| 49 |
private: |
| 50 |
const Kind PSK; |
| 51 |
const SummaryEntryVector DetailedSummary; |
| 52 |
const uint64_t TotalCount, MaxCount, MaxInternalCount, MaxFunctionCount; |
| 53 |
const uint32_t NumCounts, NumFunctions; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
bool Partial = false; |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
double PartialProfileRatio = 0.0; |
| 65 |
|
| 66 |
Metadata *getDetailedSummaryMD(LLVMContext &Context); |
| 67 |
|
| 68 |
public: |
| 69 |
static const int Scale = 1000000; |
| 70 |
|
| 71 |
ProfileSummary(Kind K, const SummaryEntryVector &DetailedSummary, |
| 72 |
uint64_t TotalCount, uint64_t MaxCount, |
| 73 |
uint64_t MaxInternalCount, uint64_t MaxFunctionCount, |
| 74 |
uint32_t NumCounts, uint32_t NumFunctions, |
| 75 |
bool Partial = false, double PartialProfileRatio = 0) |
| 76 |
: PSK(K), DetailedSummary(std::move(DetailedSummary)), |
| 77 |
TotalCount(TotalCount), MaxCount(MaxCount), |
| 78 |
MaxInternalCount(MaxInternalCount), MaxFunctionCount(MaxFunctionCount), |
| 79 |
NumCounts(NumCounts), NumFunctions(NumFunctions), Partial(Partial), |
| 80 |
PartialProfileRatio(PartialProfileRatio) {} |
| 81 |
|
| 82 |
Kind getKind() const { return PSK; } |
| 83 |
|
| 84 |
Metadata *getMD(LLVMContext &Context, bool AddPartialField = true, |
| 85 |
bool AddPartialProfileRatioField = true); |
| 86 |
|
| 87 |
static ProfileSummary *getFromMD(Metadata *MD); |
| 88 |
const SummaryEntryVector &getDetailedSummary() { return DetailedSummary; } |
| 89 |
uint32_t getNumFunctions() const { return NumFunctions; } |
| 90 |
uint64_t getMaxFunctionCount() const { return MaxFunctionCount; } |
| 91 |
uint32_t getNumCounts() const { return NumCounts; } |
| 92 |
uint64_t getTotalCount() const { return TotalCount; } |
| 93 |
uint64_t getMaxCount() const { return MaxCount; } |
| 94 |
uint64_t getMaxInternalCount() const { return MaxInternalCount; } |
| 95 |
void setPartialProfile(bool PP) { Partial = PP; } |
| 96 |
bool isPartialProfile() const { return Partial; } |
| 97 |
double getPartialProfileRatio() const { return PartialProfileRatio; } |
| 98 |
void setPartialProfileRatio(double R) { |
| 99 |
assert(isPartialProfile() && "Unexpected when not partial profile"); |
| 100 |
PartialProfileRatio = R; |
| 101 |
} |
| 102 |
void printSummary(raw_ostream &OS) const; |
| 103 |
void printDetailedSummary(raw_ostream &OS) const; |
| 104 |
}; |
| 105 |
|
| 106 |
} |
| 107 |
|
| 108 |
#endif |