summaryrefslogtreecommitdiff
path: root/lib/Analysis/ProfileSummaryInfo.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-12-18 20:10:56 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-12-18 20:10:56 +0000
commit044eb2f6afba375a914ac9d8024f8f5142bb912e (patch)
tree1475247dc9f9fe5be155ebd4c9069c75aadf8c20 /lib/Analysis/ProfileSummaryInfo.cpp
parenteb70dddbd77e120e5d490bd8fbe7ff3f8fa81c6b (diff)
Notes
Diffstat (limited to 'lib/Analysis/ProfileSummaryInfo.cpp')
-rw-r--r--lib/Analysis/ProfileSummaryInfo.cpp55
1 files changed, 44 insertions, 11 deletions
diff --git a/lib/Analysis/ProfileSummaryInfo.cpp b/lib/Analysis/ProfileSummaryInfo.cpp
index 12b86daa602b..671744f93fb8 100644
--- a/lib/Analysis/ProfileSummaryInfo.cpp
+++ b/lib/Analysis/ProfileSummaryInfo.cpp
@@ -30,7 +30,7 @@ using namespace llvm;
// considered cold).
static cl::opt<int> ProfileSummaryCutoffHot(
- "profile-summary-cutoff-hot", cl::Hidden, cl::init(999000), cl::ZeroOrMore,
+ "profile-summary-cutoff-hot", cl::Hidden, cl::init(990000), cl::ZeroOrMore,
cl::desc("A count is hot if it exceeds the minimum count to"
" reach this percentile of total counts."));
@@ -39,9 +39,21 @@ static cl::opt<int> ProfileSummaryCutoffCold(
cl::desc("A count is cold if it is below the minimum count"
" to reach this percentile of total counts."));
-// Find the minimum count to reach a desired percentile of counts.
-static uint64_t getMinCountForPercentile(SummaryEntryVector &DS,
- uint64_t Percentile) {
+static cl::opt<bool> ProfileSampleAccurate(
+ "profile-sample-accurate", cl::Hidden, cl::init(false),
+ cl::desc("If the sample profile is accurate, we will mark all un-sampled "
+ "callsite as cold. Otherwise, treat un-sampled callsites as if "
+ "we have no profile."));
+static cl::opt<unsigned> ProfileSummaryHugeWorkingSetSizeThreshold(
+ "profile-summary-huge-working-set-size-threshold", cl::Hidden,
+ cl::init(15000), cl::ZeroOrMore,
+ cl::desc("The code working set size is considered huge if the number of"
+ " blocks required to reach the -profile-summary-cutoff-hot"
+ " percentile exceeds this count."));
+
+// Find the summary entry for a desired percentile of counts.
+static const ProfileSummaryEntry &getEntryForPercentile(SummaryEntryVector &DS,
+ uint64_t Percentile) {
auto Compare = [](const ProfileSummaryEntry &Entry, uint64_t Percentile) {
return Entry.Cutoff < Percentile;
};
@@ -50,7 +62,7 @@ static uint64_t getMinCountForPercentile(SummaryEntryVector &DS,
// detailed summary.
if (It == DS.end())
report_fatal_error("Desired percentile exceeds the maximum cutoff");
- return It->MinCount;
+ return *It;
}
// The profile summary metadata may be attached either by the frontend or by
@@ -78,10 +90,12 @@ ProfileSummaryInfo::getProfileCount(const Instruction *Inst,
if (hasSampleProfile()) {
// In sample PGO mode, check if there is a profile metadata on the
// instruction. If it is present, determine hotness solely based on that,
- // since the sampled entry count may not be accurate.
+ // since the sampled entry count may not be accurate. If there is no
+ // annotated on the instruction, return None.
uint64_t TotalCount;
if (Inst->extractProfTotalWeight(TotalCount))
return TotalCount;
+ return None;
}
if (BFI)
return BFI->getBlockProfileCount(Inst->getParent());
@@ -161,10 +175,20 @@ void ProfileSummaryInfo::computeThresholds() {
if (!computeSummary())
return;
auto &DetailedSummary = Summary->getDetailedSummary();
- HotCountThreshold =
- getMinCountForPercentile(DetailedSummary, ProfileSummaryCutoffHot);
- ColdCountThreshold =
- getMinCountForPercentile(DetailedSummary, ProfileSummaryCutoffCold);
+ auto &HotEntry =
+ getEntryForPercentile(DetailedSummary, ProfileSummaryCutoffHot);
+ HotCountThreshold = HotEntry.MinCount;
+ auto &ColdEntry =
+ getEntryForPercentile(DetailedSummary, ProfileSummaryCutoffCold);
+ ColdCountThreshold = ColdEntry.MinCount;
+ HasHugeWorkingSetSize =
+ HotEntry.NumCounts > ProfileSummaryHugeWorkingSetSizeThreshold;
+}
+
+bool ProfileSummaryInfo::hasHugeWorkingSetSize() {
+ if (!HasHugeWorkingSetSize)
+ computeThresholds();
+ return HasHugeWorkingSetSize && HasHugeWorkingSetSize.getValue();
}
bool ProfileSummaryInfo::isHotCount(uint64_t C) {
@@ -199,7 +223,16 @@ bool ProfileSummaryInfo::isHotCallSite(const CallSite &CS,
bool ProfileSummaryInfo::isColdCallSite(const CallSite &CS,
BlockFrequencyInfo *BFI) {
auto C = getProfileCount(CS.getInstruction(), BFI);
- return C && isColdCount(*C);
+ if (C)
+ return isColdCount(*C);
+
+ // In SamplePGO, if the caller has been sampled, and there is no profile
+ // annotatedon the callsite, we consider the callsite as cold.
+ // If there is no profile for the caller, and we know the profile is
+ // accurate, we consider the callsite as cold.
+ return (hasSampleProfile() &&
+ (CS.getCaller()->getEntryCount() || ProfileSampleAccurate ||
+ CS.getCaller()->hasFnAttribute("profile-sample-accurate")));
}
INITIALIZE_PASS(ProfileSummaryInfoWrapperPass, "profile-summary-info",