summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ProfileSummaryInfo.cpp
diff options
context:
space:
mode:
authorEaswaran Raman <eraman@google.com>2017-01-14 00:32:37 +0000
committerEaswaran Raman <eraman@google.com>2017-01-14 00:32:37 +0000
commita7bdb8a5130a4178f99e9235fd7739bbc4fd98ac (patch)
tree0f34f5921a3f7eb97bb65c4100b5ce88fc130d4d /llvm/lib/Analysis/ProfileSummaryInfo.cpp
parentb66164ca3478b37592f994771576a864e2060200 (diff)
downloadbcm5719-llvm-a7bdb8a5130a4178f99e9235fd7739bbc4fd98ac.tar.gz
bcm5719-llvm-a7bdb8a5130a4178f99e9235fd7739bbc4fd98ac.zip
Compute summary before calling extractProfTotalWeight
extractProfTotalWeight checks if the profile type is sample profile, but before that we have to ensure that summary is available. Also expanded the unittest to test the case where there is no summar Differential Revision: https://reviews.llvm.org/D28708 llvm-svn: 291982
Diffstat (limited to 'llvm/lib/Analysis/ProfileSummaryInfo.cpp')
-rw-r--r--llvm/lib/Analysis/ProfileSummaryInfo.cpp22
1 files changed, 11 insertions, 11 deletions
diff --git a/llvm/lib/Analysis/ProfileSummaryInfo.cpp b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
index d36464e7d47..5ca18303338 100644
--- a/llvm/lib/Analysis/ProfileSummaryInfo.cpp
+++ b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
@@ -56,22 +56,23 @@ static uint64_t getMinCountForPercentile(SummaryEntryVector &DS,
// The profile summary metadata may be attached either by the frontend or by
// any backend passes (IR level instrumentation, for example). This method
// checks if the Summary is null and if so checks if the summary metadata is now
-// available in the module and parses it to get the Summary object.
-void ProfileSummaryInfo::computeSummary() {
+// available in the module and parses it to get the Summary object. Returns true
+// if a valid Summary is available.
+bool ProfileSummaryInfo::computeSummary() {
if (Summary)
- return;
+ return true;
auto *SummaryMD = M.getProfileSummary();
if (!SummaryMD)
- return;
+ return false;
Summary.reset(ProfileSummary::getFromMD(SummaryMD));
+ return true;
}
/// Returns true if the function's entry is hot. If it returns false, it
/// either means it is not hot or it is unknown whether it is hot or not (for
/// example, no profile data is available).
bool ProfileSummaryInfo::isFunctionEntryHot(const Function *F) {
- computeSummary();
- if (!F || !Summary)
+ if (!F || !computeSummary())
return false;
auto FunctionCount = F->getEntryCount();
// FIXME: The heuristic used below for determining hotness is based on
@@ -84,13 +85,12 @@ bool ProfileSummaryInfo::isFunctionEntryHot(const Function *F) {
/// either means it is not cold or it is unknown whether it is cold or not (for
/// example, no profile data is available).
bool ProfileSummaryInfo::isFunctionEntryCold(const Function *F) {
- computeSummary();
if (!F)
return false;
if (F->hasFnAttribute(Attribute::Cold)) {
return true;
}
- if (!Summary)
+ if (!computeSummary())
return false;
auto FunctionCount = F->getEntryCount();
// FIXME: The heuristic used below for determining coldness is based on
@@ -101,9 +101,7 @@ bool ProfileSummaryInfo::isFunctionEntryCold(const Function *F) {
/// Compute the hot and cold thresholds.
void ProfileSummaryInfo::computeThresholds() {
- if (!Summary)
- computeSummary();
- if (!Summary)
+ if (!computeSummary())
return;
auto &DetailedSummary = Summary->getDetailedSummary();
HotCountThreshold =
@@ -148,6 +146,8 @@ bool ProfileSummaryInfo::isColdBB(const BasicBlock *B,
bool ProfileSummaryInfo::extractProfTotalWeight(const Instruction *I,
uint64_t &TotalCount) {
+ if (!computeSummary())
+ return false;
// Use profile weight on metadata only for sample profiling where block counts
// could differ from the count of an instruction within the block.
if (Summary.get()->getKind() != ProfileSummary::PSK_Sample)
OpenPOWER on IntegriCloud