[llvm] r272749 - [MBP] add comments and bug fix
Xinliang David Li via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 14 20:03:30 PDT 2016
Author: davidxl
Date: Tue Jun 14 22:03:30 2016
New Revision: 272749
URL: http://llvm.org/viewvc/llvm-project?rev=272749&view=rev
Log:
[MBP] add comments and bug fix
Document the new parameter and threshod computation
model. Also fix a bug when the threshold parameter
is set to be different from the default.
Modified:
llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp
llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp
Modified: llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp?rev=272749&r1=272748&r2=272749&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBlockPlacement.cpp Tue Jun 14 22:03:30 2016
@@ -530,9 +530,19 @@ static BranchProbability getLayoutSucces
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);
+ if (Succ1->isSuccessor(Succ2) || Succ2->isSuccessor(Succ1)) {
+ /* See case 1 below for the cost analysis. For BB->Succ to
+ * be taken with smaller cost, the following needs to hold:
+ * Prob(BB->Succ) > 2* Prob(BB->Pred)
+ * So the threshold T
+ * T = 2 * (1-Prob(BB->Pred). Since T + Prob(BB->Pred) == 1,
+ * We have T + T/2 = 1, i.e. T = 2/3. Also adding user specified
+ * branch bias, we have
+ * T = (2/3)*(ProfileLikelyProb/50)
+ * = (2*ProfileLikelyProb)/150)
+ */
+ return BranchProbability(2 * ProfileLikelyProb, 150);
+ }
}
return BranchProbability(ProfileLikelyProb, 100);
}
Modified: llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp?rev=272749&r1=272748&r2=272749&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineBranchProbabilityInfo.cpp Tue Jun 14 22:03:30 2016
@@ -24,15 +24,16 @@ INITIALIZE_PASS_BEGIN(MachineBranchProba
INITIALIZE_PASS_END(MachineBranchProbabilityInfo, "machine-branch-prob",
"Machine Branch Probability Analysis", false, true)
-cl::opt<unsigned> StaticLikelyProb(
- "static-likely-prob",
- cl::desc("branch probability threshold to be considered very likely"),
- cl::init(80), cl::Hidden);
+cl::opt<unsigned>
+ StaticLikelyProb("static-likely-prob",
+ cl::desc("branch probability threshold in percentage"
+ "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::desc("branch probability threshold in percentage to be considered"
+ " very likely when profile is available"),
cl::init(51), cl::Hidden);
char MachineBranchProbabilityInfo::ID = 0;
More information about the llvm-commits
mailing list