diff options
| author | Lucas Ramirez <11032120+lucas-rami@users.noreply.github.com> | 2025-07-25 04:38:20 -0700 |
|---|---|---|
| committer | Amir Ayupov <aaupov@fb.com> | 2025-07-25 04:38:20 -0700 |
| commit | f45382b8900a58374b1395a7dd03d7f40085faf3 (patch) | |
| tree | eddff09d0f6bff927ae0866a4c817b6aef84707b /llvm/tools/llvm-profdata/llvm-profdata.cpp | |
| parent | 832d1b1c812acff0a2e01799a0a59d69ebcc7d25 (diff) | |
| parent | e38f98f535f6e2ce2b42ea0413919f87b1239964 (diff) | |
[𝘀𝗽𝗿] changes introduced through rebaseusers/aaupov/spr/main.bolt-require-cfg-in-bat-mode
Created using spr 1.3.4
[skip ci]
Diffstat (limited to 'llvm/tools/llvm-profdata/llvm-profdata.cpp')
| -rw-r--r-- | llvm/tools/llvm-profdata/llvm-profdata.cpp | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/llvm/tools/llvm-profdata/llvm-profdata.cpp b/llvm/tools/llvm-profdata/llvm-profdata.cpp index 45eac90aef93..207ae2ddd4cf 100644 --- a/llvm/tools/llvm-profdata/llvm-profdata.cpp +++ b/llvm/tools/llvm-profdata/llvm-profdata.cpp @@ -47,7 +47,6 @@ #include <algorithm> #include <cmath> #include <optional> -#include <queue> using namespace llvm; using ProfCorrelatorKind = InstrProfCorrelator::ProfCorrelatorKind; @@ -2849,9 +2848,8 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) { auto FS = vfs::getRealFileSystem(); auto ReaderOrErr = InstrProfReader::create(Filename, *FS); std::vector<uint32_t> Cutoffs = std::move(DetailedSummaryCutoffs); - if (ShowDetailedSummary && Cutoffs.empty()) { + if (Cutoffs.empty() && (ShowDetailedSummary || ShowHotFuncList)) Cutoffs = ProfileSummaryBuilder::DefaultCutoffs; - } InstrProfSummaryBuilder Builder(std::move(Cutoffs)); if (Error E = ReaderOrErr.takeError()) exitWithError(std::move(E), Filename); @@ -2863,15 +2861,7 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) { int NumVPKind = IPVK_Last - IPVK_First + 1; std::vector<ValueSitesStats> VPStats(NumVPKind); - auto MinCmp = [](const std::pair<std::string, uint64_t> &v1, - const std::pair<std::string, uint64_t> &v2) { - return v1.second > v2.second; - }; - - std::priority_queue<std::pair<std::string, uint64_t>, - std::vector<std::pair<std::string, uint64_t>>, - decltype(MinCmp)> - HottestFuncs(MinCmp); + std::vector<std::pair<StringRef, uint64_t>> NameAndMaxCount; if (!TextFormat && OnlyListBelow) { OS << "The list of functions with the maximum counter less than " @@ -2946,15 +2936,8 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) { } else if (OnlyListBelow) continue; - if (TopNFunctions) { - if (HottestFuncs.size() == TopNFunctions) { - if (HottestFuncs.top().second < FuncMax) { - HottestFuncs.pop(); - HottestFuncs.emplace(std::make_pair(std::string(Func.Name), FuncMax)); - } - } else - HottestFuncs.emplace(std::make_pair(std::string(Func.Name), FuncMax)); - } + if (TopNFunctions || ShowHotFuncList) + NameAndMaxCount.emplace_back(Func.Name, FuncMax); if (Show) { if (!ShownFunctions) @@ -3034,16 +3017,27 @@ static int showInstrProfile(ShowFormat SFormat, raw_fd_ostream &OS) { << "): " << PS->getNumFunctions() - BelowCutoffFunctions << "\n"; } + // Sort by MaxCount in decreasing order + llvm::stable_sort(NameAndMaxCount, [](const auto &L, const auto &R) { + return L.second > R.second; + }); if (TopNFunctions) { - std::vector<std::pair<std::string, uint64_t>> SortedHottestFuncs; - while (!HottestFuncs.empty()) { - SortedHottestFuncs.emplace_back(HottestFuncs.top()); - HottestFuncs.pop(); - } OS << "Top " << TopNFunctions << " functions with the largest internal block counts: \n"; - for (auto &hotfunc : llvm::reverse(SortedHottestFuncs)) - OS << " " << hotfunc.first << ", max count = " << hotfunc.second << "\n"; + auto TopFuncs = ArrayRef(NameAndMaxCount).take_front(TopNFunctions); + for (auto [Name, MaxCount] : TopFuncs) + OS << " " << Name << ", max count = " << MaxCount << "\n"; + } + + if (ShowHotFuncList) { + auto HotCountThreshold = + ProfileSummaryBuilder::getHotCountThreshold(PS->getDetailedSummary()); + OS << "# Hot count threshold: " << HotCountThreshold << "\n"; + for (auto [Name, MaxCount] : NameAndMaxCount) { + if (MaxCount < HotCountThreshold) + break; + OS << Name << "\n"; + } } if (ShownFunctions && ShowIndirectCallTargets) { |
