summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorDehao Chen <dehao@google.com>2016-06-14 22:27:17 +0000
committerDehao Chen <dehao@google.com>2016-06-14 22:27:17 +0000
commit9f2bdfb40fd1bd1f8f450db079e93ad86dad8b1d (patch)
tree61f8c04e16769f35629f9a3d27a7ef91b720c90a /llvm/lib
parent9f3e96115ce58f97b24a292c2ce64517a99722a6 (diff)
downloadbcm5719-llvm-9f2bdfb40fd1bd1f8f450db079e93ad86dad8b1d.tar.gz
bcm5719-llvm-9f2bdfb40fd1bd1f8f450db079e93ad86dad8b1d.zip
Set machine block placement hot prob threshold for both static and runtime profile.
Summary: With runtime profile, we have more confidence in branch probability, thus during basic block layout, we set a lower hot prob threshold so that blocks can be layouted optimally. Reviewers: djasper, davidxl Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D20991 llvm-svn: 272729
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/CodeGen/MachineBlockPlacement.cpp24
-rw-r--r--llvm/lib/CodeGen/MachineBranchProbabilityInfo.cpp6
2 files changed, 22 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
index 186daa1cb8e..7379a3099b1 100644
--- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -125,6 +125,7 @@ BranchFoldPlacement("branch-fold-placement",
cl::init(true), cl::Hidden);
extern cl::opt<unsigned> StaticLikelyProb;
+extern cl::opt<unsigned> ProfileLikelyProb;
namespace {
class BlockChain;
@@ -520,13 +521,20 @@ bool MachineBlockPlacement::shouldPredBlockBeOutlined(
return false;
}
-// FIXME (PGO handling)
-// For now this method just returns a fixed threshold. It needs to be enhanced
-// such that BB and Succ is passed in so that CFG shapes are examined such that
-// the threshold is computed with more precise cost model when PGO is on.
-static BranchProbability getLayoutSuccessorProbThreshold() {
- BranchProbability HotProb(StaticLikelyProb, 100);
- return HotProb;
+// When profile is not present, return the StaticLikelyProb.
+// When profile is available, we need to handle the triangle-shape CFG.
+static BranchProbability getLayoutSuccessorProbThreshold(
+ MachineBasicBlock *BB) {
+ if (!BB->getParent()->getFunction()->getEntryCount())
+ return BranchProbability(StaticLikelyProb, 100);
+ if (BB->succ_size() == 2) {
+ const MachineBasicBlock *Succ1 = *BB->succ_begin();
+ const MachineBasicBlock *Succ2 = *(BB->succ_begin() + 1);
+ if (Succ1->isSuccessor(Succ2) || Succ2->isSuccessor(Succ1))
+ return BranchProbability(
+ 200 - 2 * ProfileLikelyProb, 200 - ProfileLikelyProb);
+ }
+ return BranchProbability(ProfileLikelyProb, 100);
}
/// Checks to see if the layout candidate block \p Succ has a better layout
@@ -593,7 +601,7 @@ bool MachineBlockPlacement::hasBetterLayoutPredecessor(
// edge: Prob(Succ->BB) needs to >= HotProb in order to be selected (without
// profile data).
- BranchProbability HotProb = getLayoutSuccessorProbThreshold();
+ BranchProbability HotProb = getLayoutSuccessorProbThreshold(BB);
// Forward checking. For case 2, SuccProb will be 1.
if (SuccProb < HotProb) {
diff --git a/llvm/lib/CodeGen/MachineBranchProbabilityInfo.cpp b/llvm/lib/CodeGen/MachineBranchProbabilityInfo.cpp
index 3554e4efa5f..9e14cb621dd 100644
--- a/llvm/lib/CodeGen/MachineBranchProbabilityInfo.cpp
+++ b/llvm/lib/CodeGen/MachineBranchProbabilityInfo.cpp
@@ -29,6 +29,12 @@ cl::opt<unsigned> StaticLikelyProb(
cl::desc("branch probability threshold to be considered very likely"),
cl::init(80), cl::Hidden);
+cl::opt<unsigned> ProfileLikelyProb(
+ "profile-likely-prob",
+ cl::desc("branch probability threshold to be considered very likely "
+ "when profile is available"),
+ cl::init(51), cl::Hidden);
+
char MachineBranchProbabilityInfo::ID = 0;
void MachineBranchProbabilityInfo::anchor() {}
OpenPOWER on IntegriCloud