[llvm] r286415 - Add isHotBB helper function to ProfileSummaryInfo
Dehao Chen via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 9 15:36:03 PST 2016
Author: dehao
Date: Wed Nov 9 17:36:02 2016
New Revision: 286415
URL: http://llvm.org/viewvc/llvm-project?rev=286415&view=rev
Log:
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
Modified:
llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h
llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp
Modified: llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h?rev=286415&r1=286414&r2=286415&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/ProfileSummaryInfo.h Wed Nov 9 17:36:02 2016
@@ -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.
Modified: llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp?rev=286415&r1=286414&r2=286415&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/ProfileSummaryInfo.cpp Wed Nov 9 17:36:02 2016
@@ -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(uin
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)
More information about the llvm-commits
mailing list