summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MachineBlockPlacement.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/MachineBlockPlacement.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineBlockPlacement.cpp24
1 files changed, 16 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) {
OpenPOWER on IntegriCloud