mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-04-13 13:00:24 +00:00
[PGO] Move profile summary interface/impl into InstrProf.[*] /NFC
llvm-svn: 257819
This commit is contained in:
parent
825d101c30
commit
6b68a0ee43
@ -27,6 +27,7 @@
|
|||||||
#include "llvm/Support/MD5.h"
|
#include "llvm/Support/MD5.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <map>
|
||||||
#include <system_error>
|
#include <system_error>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -553,6 +554,68 @@ ValueProfData *
|
|||||||
serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record,
|
serializeValueProfDataFromRT(const ValueProfRuntimeRecord *Record,
|
||||||
ValueProfData *Dst);
|
ValueProfData *Dst);
|
||||||
|
|
||||||
|
///// Profile summary computation ////
|
||||||
|
// The 'show' command displays richer summary of the profile data. The profile
|
||||||
|
// summary is one or more (Cutoff, MinBlockCount, NumBlocks) triplets. Given a
|
||||||
|
// target execution count percentile, we compute the minimum number of blocks
|
||||||
|
// needed to reach this target and the minimum execution count of these blocks.
|
||||||
|
struct ProfileSummaryEntry {
|
||||||
|
uint32_t Cutoff; ///< The required percentile of total execution count.
|
||||||
|
uint64_t MinBlockCount; ///< The minimum execution count for this percentile.
|
||||||
|
uint64_t NumBlocks; ///< Number of blocks >= the minumum execution count.
|
||||||
|
};
|
||||||
|
|
||||||
|
class ProfileSummary {
|
||||||
|
// We keep track of the number of times a count appears in the profile and
|
||||||
|
// keep the map sorted in the descending order of counts.
|
||||||
|
std::map<uint64_t, uint32_t, std::greater<uint64_t>> CountFrequencies;
|
||||||
|
std::vector<ProfileSummaryEntry> DetailedSummary;
|
||||||
|
std::vector<uint32_t> DetailedSummaryCutoffs;
|
||||||
|
// Sum of all counts.
|
||||||
|
uint64_t TotalCount;
|
||||||
|
uint64_t MaxBlockCount, MaxFunctionCount;
|
||||||
|
uint32_t NumBlocks, NumFunctions;
|
||||||
|
inline void addCount(uint64_t Count);
|
||||||
|
void computeDetailedSummary();
|
||||||
|
|
||||||
|
public:
|
||||||
|
static const int Scale = 1000000;
|
||||||
|
ProfileSummary(std::vector<uint32_t> Cutoffs)
|
||||||
|
: DetailedSummaryCutoffs(Cutoffs), TotalCount(0), MaxBlockCount(0),
|
||||||
|
MaxFunctionCount(0), NumBlocks(0), NumFunctions(0) {}
|
||||||
|
inline void addRecord(const InstrProfRecord &);
|
||||||
|
inline std::vector<ProfileSummaryEntry> &getDetailedSummary();
|
||||||
|
uint32_t getNumBlocks() { return NumBlocks; }
|
||||||
|
uint64_t getTotalCount() { return TotalCount; }
|
||||||
|
uint32_t getNumFunctions() { return NumFunctions; }
|
||||||
|
uint64_t getMaxFunctionCount() { return MaxFunctionCount; }
|
||||||
|
uint64_t getMaxBlockCount() { return MaxBlockCount; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// This is called when a count is seen in the profile.
|
||||||
|
void ProfileSummary::addCount(uint64_t Count) {
|
||||||
|
TotalCount += Count;
|
||||||
|
if (Count > MaxBlockCount)
|
||||||
|
MaxBlockCount = Count;
|
||||||
|
NumBlocks++;
|
||||||
|
CountFrequencies[Count]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProfileSummary::addRecord(const InstrProfRecord &R) {
|
||||||
|
NumFunctions++;
|
||||||
|
if (R.Counts[0] > MaxFunctionCount)
|
||||||
|
MaxFunctionCount = R.Counts[0];
|
||||||
|
|
||||||
|
for (size_t I = 1, E = R.Counts.size(); I < E; ++I)
|
||||||
|
addCount(R.Counts[I]);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ProfileSummaryEntry> &ProfileSummary::getDetailedSummary() {
|
||||||
|
if (!DetailedSummaryCutoffs.empty() && DetailedSummary.empty())
|
||||||
|
computeDetailedSummary();
|
||||||
|
return DetailedSummary;
|
||||||
|
}
|
||||||
|
|
||||||
namespace IndexedInstrProf {
|
namespace IndexedInstrProf {
|
||||||
|
|
||||||
enum class HashT : uint32_t {
|
enum class HashT : uint32_t {
|
||||||
|
@ -599,4 +599,39 @@ void ValueProfData::swapBytesFromHost(support::endianness Endianness) {
|
|||||||
sys::swapByteOrder<uint32_t>(NumValueKinds);
|
sys::swapByteOrder<uint32_t>(NumValueKinds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The argument to this method is a vector of cutoff percentages and the return
|
||||||
|
// value is a vector of (Cutoff, MinBlockCount, NumBlocks) triplets.
|
||||||
|
void ProfileSummary::computeDetailedSummary() {
|
||||||
|
if (DetailedSummaryCutoffs.empty())
|
||||||
|
return;
|
||||||
|
auto Iter = CountFrequencies.begin();
|
||||||
|
auto End = CountFrequencies.end();
|
||||||
|
std::sort(DetailedSummaryCutoffs.begin(), DetailedSummaryCutoffs.end());
|
||||||
|
|
||||||
|
uint32_t BlocksSeen = 0;
|
||||||
|
uint64_t CurrSum = 0, Count;
|
||||||
|
|
||||||
|
for (uint32_t Cutoff : DetailedSummaryCutoffs) {
|
||||||
|
assert(Cutoff <= 999999);
|
||||||
|
APInt Temp(128, TotalCount);
|
||||||
|
APInt N(128, Cutoff);
|
||||||
|
APInt D(128, ProfileSummary::Scale);
|
||||||
|
Temp *= N;
|
||||||
|
Temp = Temp.sdiv(D);
|
||||||
|
uint64_t DesiredCount = Temp.getZExtValue();
|
||||||
|
assert(DesiredCount <= TotalCount);
|
||||||
|
while (CurrSum < DesiredCount && Iter != End) {
|
||||||
|
Count = Iter->first;
|
||||||
|
uint32_t Freq = Iter->second;
|
||||||
|
CurrSum += (Count * Freq);
|
||||||
|
BlocksSeen += Freq;
|
||||||
|
Iter++;
|
||||||
|
}
|
||||||
|
assert(CurrSum >= DesiredCount);
|
||||||
|
ProfileSummaryEntry PSE = {Cutoff, Count, BlocksSeen};
|
||||||
|
DetailedSummary.push_back(PSE);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,105 +36,6 @@ using namespace llvm;
|
|||||||
|
|
||||||
enum ProfileFormat { PF_None = 0, PF_Text, PF_Binary, PF_GCC };
|
enum ProfileFormat { PF_None = 0, PF_Text, PF_Binary, PF_GCC };
|
||||||
|
|
||||||
///// Profile summary computation ////
|
|
||||||
// The 'show' command displays richer summary of the profile data. The profile
|
|
||||||
// summary is one or more (Cutoff, MinBlockCount, NumBlocks) triplets. Given a
|
|
||||||
// target execution count percentile, we compute the minimum number of blocks
|
|
||||||
// needed to reach this target and the minimum execution count of these blocks.
|
|
||||||
struct ProfileSummaryEntry {
|
|
||||||
uint32_t Cutoff; ///< The required percentile of total execution count.
|
|
||||||
uint64_t MinBlockCount; ///< The minimum execution count for this percentile.
|
|
||||||
uint64_t NumBlocks; ///< Number of blocks >= the minumum execution count.
|
|
||||||
};
|
|
||||||
|
|
||||||
class ProfileSummary {
|
|
||||||
// We keep track of the number of times a count appears in the profile and
|
|
||||||
// keep the map sorted in the descending order of counts.
|
|
||||||
std::map<uint64_t, uint32_t, std::greater<uint64_t>> CountFrequencies;
|
|
||||||
std::vector<ProfileSummaryEntry> DetailedSummary;
|
|
||||||
std::vector<uint32_t> DetailedSummaryCutoffs;
|
|
||||||
// Sum of all counts.
|
|
||||||
uint64_t TotalCount;
|
|
||||||
uint64_t MaxBlockCount, MaxFunctionCount;
|
|
||||||
uint32_t NumBlocks, NumFunctions;
|
|
||||||
void addCount(uint64_t Count);
|
|
||||||
void computeDetailedSummary();
|
|
||||||
|
|
||||||
public:
|
|
||||||
static const int Scale = 1000000;
|
|
||||||
ProfileSummary(std::vector<uint32_t> Cutoffs)
|
|
||||||
: DetailedSummaryCutoffs(Cutoffs), TotalCount(0), MaxBlockCount(0),
|
|
||||||
MaxFunctionCount(0), NumBlocks(0), NumFunctions(0) {}
|
|
||||||
void addRecord(const InstrProfRecord &);
|
|
||||||
std::vector<ProfileSummaryEntry> &getDetailedSummary();
|
|
||||||
uint32_t getNumBlocks() { return NumBlocks; }
|
|
||||||
uint64_t getTotalCount() { return TotalCount; }
|
|
||||||
uint32_t getNumFunctions() { return NumFunctions; }
|
|
||||||
uint64_t getMaxFunctionCount() { return MaxFunctionCount; }
|
|
||||||
uint64_t getMaxBlockCount() { return MaxBlockCount; }
|
|
||||||
};
|
|
||||||
|
|
||||||
// This is called when a count is seen in the profile.
|
|
||||||
void ProfileSummary::addCount(uint64_t Count) {
|
|
||||||
TotalCount += Count;
|
|
||||||
if (Count > MaxBlockCount)
|
|
||||||
MaxBlockCount = Count;
|
|
||||||
NumBlocks++;
|
|
||||||
CountFrequencies[Count]++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProfileSummary::addRecord(const InstrProfRecord &R) {
|
|
||||||
NumFunctions++;
|
|
||||||
if (R.Counts[0] > MaxFunctionCount)
|
|
||||||
MaxFunctionCount = R.Counts[0];
|
|
||||||
|
|
||||||
for (size_t I = 1, E = R.Counts.size(); I < E; ++I)
|
|
||||||
addCount(R.Counts[I]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The argument to this method is a vector of cutoff percentages and the return
|
|
||||||
// value is a vector of (Cutoff, MinBlockCount, NumBlocks) triplets.
|
|
||||||
void ProfileSummary::computeDetailedSummary() {
|
|
||||||
if (DetailedSummaryCutoffs.empty())
|
|
||||||
return;
|
|
||||||
auto Iter = CountFrequencies.begin();
|
|
||||||
auto End = CountFrequencies.end();
|
|
||||||
std::sort(DetailedSummaryCutoffs.begin(), DetailedSummaryCutoffs.end());
|
|
||||||
|
|
||||||
uint32_t BlocksSeen = 0;
|
|
||||||
uint64_t CurrSum = 0, Count;
|
|
||||||
|
|
||||||
for (uint32_t Cutoff : DetailedSummaryCutoffs) {
|
|
||||||
assert(Cutoff <= 999999);
|
|
||||||
APInt Temp(128, TotalCount);
|
|
||||||
APInt N(128, Cutoff);
|
|
||||||
APInt D(128, ProfileSummary::Scale);
|
|
||||||
Temp *= N;
|
|
||||||
Temp = Temp.sdiv(D);
|
|
||||||
uint64_t DesiredCount = Temp.getZExtValue();
|
|
||||||
dbgs() << "Cutoff = " << Cutoff << "\n";
|
|
||||||
dbgs() << "DesiredCount = " << DesiredCount << "\n";
|
|
||||||
assert(DesiredCount <= TotalCount);
|
|
||||||
while (CurrSum < DesiredCount && Iter != End) {
|
|
||||||
Count = Iter->first;
|
|
||||||
uint32_t Freq = Iter->second;
|
|
||||||
CurrSum += (Count * Freq);
|
|
||||||
BlocksSeen += Freq;
|
|
||||||
Iter++;
|
|
||||||
}
|
|
||||||
assert(CurrSum >= DesiredCount);
|
|
||||||
ProfileSummaryEntry PSE = {Cutoff, Count, BlocksSeen};
|
|
||||||
DetailedSummary.push_back(PSE);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ProfileSummaryEntry> &ProfileSummary::getDetailedSummary() {
|
|
||||||
if (!DetailedSummaryCutoffs.empty() && DetailedSummary.empty())
|
|
||||||
computeDetailedSummary();
|
|
||||||
return DetailedSummary;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void exitWithError(const Twine &Message, StringRef Whence = "",
|
static void exitWithError(const Twine &Message, StringRef Whence = "",
|
||||||
StringRef Hint = "") {
|
StringRef Hint = "") {
|
||||||
errs() << "error: ";
|
errs() << "error: ";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user