diff options
author | Xinliang David Li <davidxl@google.com> | 2016-01-14 22:10:49 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-01-14 22:10:49 +0000 |
commit | 565b30138032d23efb95887dfc2a49ceac4f2d9c (patch) | |
tree | becd255113b10ad03f994f82fa03b25db28d987b /llvm/tools/llvm-profdata/llvm-profdata.cpp | |
parent | e594268e3723c9ab9d103468b5ca9406459b9183 (diff) | |
download | bcm5719-llvm-565b30138032d23efb95887dfc2a49ceac4f2d9c.tar.gz bcm5719-llvm-565b30138032d23efb95887dfc2a49ceac4f2d9c.zip |
[PGO] Move profile summary interface/impl into InstrProf.[*] /NFC
llvm-svn: 257819
Diffstat (limited to 'llvm/tools/llvm-profdata/llvm-profdata.cpp')
-rw-r--r-- | llvm/tools/llvm-profdata/llvm-profdata.cpp | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp index a3995075aaf..cbe28a16250 100644 --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -36,105 +36,6 @@ using namespace llvm; 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 = "", StringRef Hint = "") { errs() << "error: "; |