diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2015-01-14 20:19:29 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2015-01-14 20:19:29 +0000 |
commit | 8af8091ef5a6cd3f79ab73d47ee07d91c9a5437f (patch) | |
tree | 74364a5312ee793c1b0d58a4161702873b131046 /lib/CodeGen | |
parent | 11abe69e9857390a035470c20534b8e5ac4d479e (diff) |
[MBP] Add flags to disable the BadCFGConflict check in MachineBlockPlacement.
Some benchmarks have shown that this could lead to a potential
performance benefit, and so adding some flags to try to help measure the
difference.
A possible explanation. In diamond-shaped CFGs (A followed by either
B or C both followed by D), putting B and C both in between A and
D leads to the code being less dense than it could be. Always either
B or C have to be skipped increasing the chance of cache misses etc.
Moving either B or C to after D might be beneficial on average.
In the long run, but we should probably do a better job of analyzing the
basic block and branch probabilities to move the correct one of B or
C to after D. But even if we don't use this in the long run, it is
a good baseline for benchmarking.
Original patch authored by Daniel Jasper with test tweaks and a second
flag added by me.
Differential Revision: http://reviews.llvm.org/D6969
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226034 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/MachineBlockPlacement.cpp | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/lib/CodeGen/MachineBlockPlacement.cpp b/lib/CodeGen/MachineBlockPlacement.cpp index aaa7d915697..779b84e99b8 100644 --- a/lib/CodeGen/MachineBlockPlacement.cpp +++ b/lib/CodeGen/MachineBlockPlacement.cpp @@ -60,6 +60,17 @@ static cl::opt<unsigned> AlignAllBlock("align-all-blocks", "blocks in the function."), cl::init(0), cl::Hidden); +static cl::opt<bool> OnlyHotBadCFGConflictCheck( + "only-hot-bad-cfg-conflict-check", + cl::desc("Only check that a hot successor doesn't have a hot predecessor."), + cl::init(false), cl::Hidden); + +static cl::opt<bool> NoBadCFGConflictCheck( + "no-bad-cfg-conflict-check", + cl::desc("Don't check whether a hot successor has a more important " + "predecessor."), + cl::init(false), cl::Hidden); + // FIXME: Find a good default for this flag and remove the flag. static cl::opt<unsigned> ExitBlockBias("block-placement-exit-block-bias", @@ -374,29 +385,33 @@ MachineBasicBlock *MachineBlockPlacement::selectBestSuccessor( continue; } - // Make sure that a hot successor doesn't have a globally more important - // predecessor. - BlockFrequency CandidateEdgeFreq - = MBFI->getBlockFreq(BB) * SuccProb * HotProb.getCompl(); - bool BadCFGConflict = false; - for (MachineBasicBlock::pred_iterator PI = (*SI)->pred_begin(), - PE = (*SI)->pred_end(); - PI != PE; ++PI) { - if (*PI == *SI || (BlockFilter && !BlockFilter->count(*PI)) || - BlockToChain[*PI] == &Chain) + if (!NoBadCFGConflictCheck) { + // Make sure that a hot successor doesn't have a globally more + // important predecessor. + BlockFrequency CandidateEdgeFreq = + OnlyHotBadCFGConflictCheck + ? MBFI->getBlockFreq(BB) * SuccProb + : MBFI->getBlockFreq(BB) * SuccProb * HotProb.getCompl(); + bool BadCFGConflict = false; + for (MachineBasicBlock::pred_iterator PI = (*SI)->pred_begin(), + PE = (*SI)->pred_end(); + PI != PE; ++PI) { + if (*PI == *SI || (BlockFilter && !BlockFilter->count(*PI)) || + BlockToChain[*PI] == &Chain) + continue; + BlockFrequency PredEdgeFreq = + MBFI->getBlockFreq(*PI) * MBPI->getEdgeProbability(*PI, *SI); + if (PredEdgeFreq >= CandidateEdgeFreq) { + BadCFGConflict = true; + break; + } + } + if (BadCFGConflict) { + DEBUG(dbgs() << " " << getBlockName(*SI) << " -> " << SuccProb + << " (prob) (non-cold CFG conflict)\n"); continue; - BlockFrequency PredEdgeFreq - = MBFI->getBlockFreq(*PI) * MBPI->getEdgeProbability(*PI, *SI); - if (PredEdgeFreq >= CandidateEdgeFreq) { - BadCFGConflict = true; - break; } } - if (BadCFGConflict) { - DEBUG(dbgs() << " " << getBlockName(*SI) << " -> " << SuccProb - << " (prob) (non-cold CFG conflict)\n"); - continue; - } } DEBUG(dbgs() << " " << getBlockName(*SI) << " -> " << SuccProb |