summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDehao Chen <dehao@google.com>2016-11-09 23:36:02 +0000
committerDehao Chen <dehao@google.com>2016-11-09 23:36:02 +0000
commit38a666d6e545537674d8cb58bacea0f66b0d624a (patch)
tree56fd0e1d48dd43e97b558c5db6b3873e7d3434be
parente08e78df6dda162f8dba15d6f17905607edd3620 (diff)
downloadbcm5719-llvm-38a666d6e545537674d8cb58bacea0f66b0d624a.tar.gz
bcm5719-llvm-38a666d6e545537674d8cb58bacea0f66b0d624a.zip
Add isHotBB helper function to ProfileSummaryInfo
Summary: This will unify all BB hotness checks. Reviewers: eraman, davidxl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D26353 llvm-svn: 286415
-rw-r--r--llvm/include/llvm/Analysis/ProfileSummaryInfo.h4
-rw-r--r--llvm/lib/Analysis/ProfileSummaryInfo.cpp20
2 files changed, 24 insertions, 0 deletions
diff --git a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
index ce5583cbb70..60e52357a84 100644
--- a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
+++ b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
@@ -27,6 +27,8 @@
#include <memory>
namespace llvm {
+class BasicBlock;
+class BlockFrequencyInfo;
class ProfileSummary;
/// \brief Analysis providing profile information.
///
@@ -59,6 +61,8 @@ public:
bool isHotCount(uint64_t C);
/// \brief Returns true if count \p C is considered cold.
bool isColdCount(uint64_t C);
+ /// \brief Returns true if BasicBlock \p B is considered hot.
+ bool isHotBB(const BasicBlock *B, BlockFrequencyInfo *BFI);
};
/// An analysis pass based on legacy pass manager to deliver ProfileSummaryInfo.
diff --git a/llvm/lib/Analysis/ProfileSummaryInfo.cpp b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
index af16fe63884..c414b8314a7 100644
--- a/llvm/lib/Analysis/ProfileSummaryInfo.cpp
+++ b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
@@ -12,7 +12,9 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/ProfileSummaryInfo.h"
+#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/ProfileSummary.h"
@@ -121,6 +123,24 @@ bool ProfileSummaryInfo::isColdCount(uint64_t C) {
return ColdCountThreshold && C <= ColdCountThreshold.getValue();
}
+bool ProfileSummaryInfo::isHotBB(const BasicBlock *B, BlockFrequencyInfo *BFI) {
+ auto Count = BFI->getBlockProfileCount(B);
+ if (Count && isHotCount(*Count))
+ return true;
+ // Use extractProfTotalWeight to get BB count.
+ // For Sample PGO, BFI may not provide accurate BB count due to errors
+ // magnified during sample count propagation. This serves as a backup plan
+ // to ensure all hot BB will not be missed.
+ // The query currently has false positives as branch instruction cloning does
+ // 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;
+}
+
INITIALIZE_PASS(ProfileSummaryInfoWrapperPass, "profile-summary-info",
"Profile summary info", false, true)
OpenPOWER on IntegriCloud