diff options
| author | Dehao Chen <dehao@google.com> | 2017-03-10 19:45:16 +0000 |
|---|---|---|
| committer | Dehao Chen <dehao@google.com> | 2017-03-10 19:45:16 +0000 |
| commit | c2048155a0efbbc0a860da03f0d1f799016e73d6 (patch) | |
| tree | 703607eac397edb3e1e963f6fd612aae1f78b761 /llvm/lib/Analysis | |
| parent | ffdb00eda9e23389aca3be4bdc056efce35ad619 (diff) | |
| download | bcm5719-llvm-c2048155a0efbbc0a860da03f0d1f799016e73d6.tar.gz bcm5719-llvm-c2048155a0efbbc0a860da03f0d1f799016e73d6.zip | |
Refactor the PSI to extract getCallSiteCount and remove checks for profile type.
Summary: There is no need to check profile count as only CallInst will have metadata attached.
Reviewers: eraman
Reviewed By: eraman
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D30799
llvm-svn: 297500
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/ProfileSummaryInfo.cpp | 53 |
1 files changed, 21 insertions, 32 deletions
diff --git a/llvm/lib/Analysis/ProfileSummaryInfo.cpp b/llvm/lib/Analysis/ProfileSummaryInfo.cpp index 623c9fac52a..8f3092347b5 100644 --- a/llvm/lib/Analysis/ProfileSummaryInfo.cpp +++ b/llvm/lib/Analysis/ProfileSummaryInfo.cpp @@ -68,6 +68,23 @@ bool ProfileSummaryInfo::computeSummary() { return true; } +Optional<uint64_t> +ProfileSummaryInfo::getProfileCount(const Instruction *Inst, + BlockFrequencyInfo *BFI) { + if (!Inst) + return None; + assert((isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) && + "We can only get profile count for call/invoke instruction."); + // Check if there is a profile metadata on the instruction. If it is present, + // determine hotness solely based on that. + uint64_t TotalCount; + if (Inst->extractProfTotalWeight(TotalCount)) + return TotalCount; + if (BFI) + return BFI->getBlockProfileCount(Inst->getParent()); + return None; +} + /// 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). @@ -133,44 +150,16 @@ bool ProfileSummaryInfo::isColdBB(const BasicBlock *B, return Count && isColdCount(*Count); } -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) - return false; - - return (isa<CallInst>(I) || - (isa<TerminatorInst>(I) && !isa<ReturnInst>(I))) && - I->extractProfTotalWeight(TotalCount); -} - bool ProfileSummaryInfo::isHotCallSite(const CallSite &CS, BlockFrequencyInfo *BFI) { - auto *CallInst = CS.getInstruction(); - if (!CS) - return false; - // Check if there is a profile metadata on the instruction. If it is present, - // determine hotness solely based on that. - uint64_t TotalCount; - if (extractProfTotalWeight(CallInst, TotalCount)) - return isHotCount(TotalCount); - return BFI && isHotBB(CallInst->getParent(), BFI); + auto C = getProfileCount(CS.getInstruction(), BFI); + return C && isHotCount(*C); } bool ProfileSummaryInfo::isColdCallSite(const CallSite &CS, BlockFrequencyInfo *BFI) { - auto *CallInst = CS.getInstruction(); - if (!CS) - return false; - // Check if there is a profile metadata on the instruction. If it is present, - // and tells that the callsite is not cold, then return false; - uint64_t TotalCount; - if (extractProfTotalWeight(CallInst, TotalCount) && !isColdCount(TotalCount)) - return false; - return BFI && isColdBB(CallInst->getParent(), BFI); + auto C = getProfileCount(CS.getInstruction(), BFI); + return C && isColdCount(*C); } INITIALIZE_PASS(ProfileSummaryInfoWrapperPass, "profile-summary-info", |

