diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/Analysis/ProfileSummaryInfo.cpp | 20 | ||||
| -rw-r--r-- | llvm/lib/Transforms/IPO/SampleProfile.cpp | 22 |
2 files changed, 20 insertions, 22 deletions
diff --git a/llvm/lib/Analysis/ProfileSummaryInfo.cpp b/llvm/lib/Analysis/ProfileSummaryInfo.cpp index 4326e53b43b..1d70c75f2e1 100644 --- a/llvm/lib/Analysis/ProfileSummaryInfo.cpp +++ b/llvm/lib/Analysis/ProfileSummaryInfo.cpp @@ -39,11 +39,6 @@ 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.")); -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, @@ -261,14 +256,7 @@ bool ProfileSummaryInfo::isHotBlock(const BasicBlock *BB, BlockFrequencyInfo *BF bool ProfileSummaryInfo::isColdBlock(const BasicBlock *BB, BlockFrequencyInfo *BFI) { auto Count = BFI->getBlockProfileCount(BB); - if (Count) - return isColdCount(*Count); - if (!hasSampleProfile()) - return false; - - const Function *F = BB->getParent(); - return ProfileSampleAccurate || - (F && F->hasFnAttribute("profile-sample-accurate")); + return Count && isColdCount(*Count); } bool ProfileSummaryInfo::isHotCallSite(const CallSite &CS, @@ -285,11 +273,7 @@ bool ProfileSummaryInfo::isColdCallSite(const CallSite &CS, // In SamplePGO, if the caller has been sampled, and there is no profile // annotated on 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()->hasProfileData() || ProfileSampleAccurate || - CS.getCaller()->hasFnAttribute("profile-sample-accurate"))); + return hasSampleProfile() && CS.getCaller()->hasProfileData(); } INITIALIZE_PASS(ProfileSummaryInfoWrapperPass, "profile-summary-info", diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp index 37f1ea4a807..06a1ce89827 100644 --- a/llvm/lib/Transforms/IPO/SampleProfile.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp @@ -123,6 +123,12 @@ static cl::opt<bool> NoWarnSampleUnused( cl::desc("Use this option to turn off/on warnings about function with " "samples but without debug information to use those samples. ")); +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 and function as having 0 samples. Otherwise, treat " + "un-sampled callsites and functions conservatively as unknown. ")); + namespace { using BlockWeightMap = DenseMap<const BasicBlock *, uint64_t>; @@ -1604,10 +1610,18 @@ bool SampleProfileLoaderLegacyPass::runOnModule(Module &M) { } bool SampleProfileLoader::runOnFunction(Function &F, ModuleAnalysisManager *AM) { - // Initialize the entry count to -1, which will be treated conservatively - // by getEntryCount as the same as unknown (None). If we have samples this - // will be overwritten in emitAnnotations. - F.setEntryCount(ProfileCount(-1, Function::PCT_Real)); + // By default the entry count is initialized to -1, which will be treated + // conservatively by getEntryCount as the same as unknown (None). This is + // to avoid newly added code to be treated as cold. If we have samples + // this will be overwritten in emitAnnotations. + // If ProfileSampleAccurate is true or F has profile-sample-accurate + // attribute, initialize the entry count to 0 so callsites or functions + // unsampled will be treated as cold. + uint64_t initialEntryCount = + (ProfileSampleAccurate || F.hasFnAttribute("profile-sample-accurate")) + ? 0 + : -1; + F.setEntryCount(ProfileCount(initialEntryCount, Function::PCT_Real)); std::unique_ptr<OptimizationRemarkEmitter> OwnedORE; if (AM) { auto &FAM = |

