diff options
author | Easwaran Raman <eraman@google.com> | 2017-01-13 01:34:00 +0000 |
---|---|---|
committer | Easwaran Raman <eraman@google.com> | 2017-01-13 01:34:00 +0000 |
commit | b035f914e42c83955054ff0b09ca910a958db604 (patch) | |
tree | 2c48048a078373a1d61fc94572c23f8de8573862 /llvm/lib/Analysis/ProfileSummaryInfo.cpp | |
parent | 5adfb5a814768b76855a6ed90becae4331e09285 (diff) | |
download | bcm5719-llvm-b035f914e42c83955054ff0b09ca910a958db604.tar.gz bcm5719-llvm-b035f914e42c83955054ff0b09ca910a958db604.zip |
ProfileSummaryInfo improvements.
* Add is{Hot|Cold}CallSite methods
* Fix a bug in isHotBB where it was looking for MD_prof on a return instruction
* Use MD_prof data only if sample profiling was used to collect profiles.
* Add an unit test to ProfileSummaryInfo
Differential Revision: https://reviews.llvm.org/D28584
llvm-svn: 291878
Diffstat (limited to 'llvm/lib/Analysis/ProfileSummaryInfo.cpp')
-rw-r--r-- | llvm/lib/Analysis/ProfileSummaryInfo.cpp | 53 |
1 files changed, 48 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ProfileSummaryInfo.cpp b/llvm/lib/Analysis/ProfileSummaryInfo.cpp index 16d3614c14c..d36464e7d47 100644 --- a/llvm/lib/Analysis/ProfileSummaryInfo.cpp +++ b/llvm/lib/Analysis/ProfileSummaryInfo.cpp @@ -12,9 +12,10 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Analysis/BlockFrequencyInfo.h" #include "llvm/Analysis/ProfileSummaryInfo.h" +#include "llvm/Analysis/BlockFrequencyInfo.h" #include "llvm/IR/BasicBlock.h" +#include "llvm/IR/CallSite.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/IR/ProfileSummary.h" @@ -135,10 +136,52 @@ bool ProfileSummaryInfo::isHotBB(const BasicBlock *B, BlockFrequencyInfo *BFI) { // not update/scale branch weights. Unlike false negatives, this will not cause // performance problem. uint64_t TotalCount; - if (B->getTerminator()->extractProfTotalWeight(TotalCount) && - isHotCount(TotalCount)) - return true; - return false; + auto *TI = B->getTerminator(); + return extractProfTotalWeight(TI, TotalCount) && isHotCount(TotalCount); +} + +bool ProfileSummaryInfo::isColdBB(const BasicBlock *B, + BlockFrequencyInfo *BFI) { + auto Count = BFI->getBlockProfileCount(B); + return Count && isColdCount(*Count); +} + +bool ProfileSummaryInfo::extractProfTotalWeight(const Instruction *I, + uint64_t &TotalCount) { + // 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); +} + +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); } INITIALIZE_PASS(ProfileSummaryInfoWrapperPass, "profile-summary-info", |