Skip to content

Commit e296e9d

Browse files
committed
[NFC] Change getEntryForPercentile to be a static function in ProfileSummaryBuilder.
Change file static function getEntryForPercentile to be a static member function in ProfileSummaryBuilder so it can be used by other files. Differential Revision: https://reviews.llvm.org/D83439
1 parent 78fe6a3 commit e296e9d

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

llvm/include/llvm/ProfileData/ProfileCommon.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ class ProfileSummaryBuilder {
6262
public:
6363
/// A vector of useful cutoff values for detailed summary.
6464
static const ArrayRef<uint32_t> DefaultCutoffs;
65+
66+
/// Find the summary entry for a desired percentile of counts.
67+
static const ProfileSummaryEntry &
68+
getEntryForPercentile(SummaryEntryVector &DS, uint64_t Percentile);
6569
};
6670

6771
class InstrProfSummaryBuilder final : public ProfileSummaryBuilder {

llvm/lib/Analysis/ProfileSummaryInfo.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/IR/Module.h"
2020
#include "llvm/IR/ProfileSummary.h"
2121
#include "llvm/InitializePasses.h"
22+
#include "llvm/ProfileData/ProfileCommon.h"
2223
#include "llvm/Support/CommandLine.h"
2324
using namespace llvm;
2425

@@ -86,19 +87,6 @@ static cl::opt<double> PartialSampleProfileWorkingSetSizeScaleFactor(
8687
"and the factor to scale the working set size to use the same "
8788
"shared thresholds as PGO."));
8889

89-
// Find the summary entry for a desired percentile of counts.
90-
static const ProfileSummaryEntry &getEntryForPercentile(SummaryEntryVector &DS,
91-
uint64_t Percentile) {
92-
auto It = partition_point(DS, [=](const ProfileSummaryEntry &Entry) {
93-
return Entry.Cutoff < Percentile;
94-
});
95-
// The required percentile has to be <= one of the percentiles in the
96-
// detailed summary.
97-
if (It == DS.end())
98-
report_fatal_error("Desired percentile exceeds the maximum cutoff");
99-
return *It;
100-
}
101-
10290
// The profile summary metadata may be attached either by the frontend or by
10391
// any backend passes (IR level instrumentation, for example). This method
10492
// checks if the Summary is null and if so checks if the summary metadata is now
@@ -284,13 +272,13 @@ bool ProfileSummaryInfo::isFunctionEntryCold(const Function *F) const {
284272
/// Compute the hot and cold thresholds.
285273
void ProfileSummaryInfo::computeThresholds() {
286274
auto &DetailedSummary = Summary->getDetailedSummary();
287-
auto &HotEntry =
288-
getEntryForPercentile(DetailedSummary, ProfileSummaryCutoffHot);
275+
auto &HotEntry = ProfileSummaryBuilder::getEntryForPercentile(
276+
DetailedSummary, ProfileSummaryCutoffHot);
289277
HotCountThreshold = HotEntry.MinCount;
290278
if (ProfileSummaryHotCount.getNumOccurrences() > 0)
291279
HotCountThreshold = ProfileSummaryHotCount;
292-
auto &ColdEntry =
293-
getEntryForPercentile(DetailedSummary, ProfileSummaryCutoffCold);
280+
auto &ColdEntry = ProfileSummaryBuilder::getEntryForPercentile(
281+
DetailedSummary, ProfileSummaryCutoffCold);
294282
ColdCountThreshold = ColdEntry.MinCount;
295283
if (ProfileSummaryColdCount.getNumOccurrences() > 0)
296284
ColdCountThreshold = ProfileSummaryColdCount;
@@ -324,8 +312,8 @@ ProfileSummaryInfo::computeThreshold(int PercentileCutoff) const {
324312
return iter->second;
325313
}
326314
auto &DetailedSummary = Summary->getDetailedSummary();
327-
auto &Entry =
328-
getEntryForPercentile(DetailedSummary, PercentileCutoff);
315+
auto &Entry = ProfileSummaryBuilder::getEntryForPercentile(DetailedSummary,
316+
PercentileCutoff);
329317
uint64_t CountThreshold = Entry.MinCount;
330318
ThresholdCache[PercentileCutoff] = CountThreshold;
331319
return CountThreshold;

llvm/lib/ProfileData/ProfileSummaryBuilder.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ static const uint32_t DefaultCutoffsData[] = {
3131
const ArrayRef<uint32_t> ProfileSummaryBuilder::DefaultCutoffs =
3232
DefaultCutoffsData;
3333

34+
const ProfileSummaryEntry &
35+
ProfileSummaryBuilder::getEntryForPercentile(SummaryEntryVector &DS,
36+
uint64_t Percentile) {
37+
auto It = partition_point(DS, [=](const ProfileSummaryEntry &Entry) {
38+
return Entry.Cutoff < Percentile;
39+
});
40+
// The required percentile has to be <= one of the percentiles in the
41+
// detailed summary.
42+
if (It == DS.end())
43+
report_fatal_error("Desired percentile exceeds the maximum cutoff");
44+
return *It;
45+
}
46+
3447
void InstrProfSummaryBuilder::addRecord(const InstrProfRecord &R) {
3548
// The first counter is not necessarily an entry count for IR
3649
// instrumentation profiles.

0 commit comments

Comments
 (0)