summaryrefslogtreecommitdiff
path: root/lib/CodeGen/MachineBlockPlacement.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-11-13 11:34:53 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-11-13 11:34:53 +0000
commit9fd4e056e433b286f0e6576046ef2242365bfc38 (patch)
tree241f5460ef949777b27a604c34f6f3b8cd24335d /lib/CodeGen/MachineBlockPlacement.cpp
parentdf234353fb396e84e7a3a1cdd94f73681e65bd88 (diff)
downloadllvm-9fd4e056e433b286f0e6576046ef2242365bfc38.tar.gz
llvm-9fd4e056e433b286f0e6576046ef2242365bfc38.tar.bz2
llvm-9fd4e056e433b286f0e6576046ef2242365bfc38.tar.xz
Hoist a nested loop into its own method.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144496 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/MachineBlockPlacement.cpp')
-rw-r--r--lib/CodeGen/MachineBlockPlacement.cpp86
1 files changed, 53 insertions, 33 deletions
diff --git a/lib/CodeGen/MachineBlockPlacement.cpp b/lib/CodeGen/MachineBlockPlacement.cpp
index 6aa4268f42..3eb2998116 100644
--- a/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/lib/CodeGen/MachineBlockPlacement.cpp
@@ -208,6 +208,9 @@ class MachineBlockPlacement : public MachineFunctionPass {
MachineBasicBlock *LoopHeaderBB,
SmallVectorImpl<MachineBasicBlock *> &Blocks,
const BlockFilterSet *BlockFilter = 0);
+ MachineBasicBlock *selectBestSuccessor(MachineBasicBlock *BB,
+ BlockChain &Chain,
+ const BlockFilterSet *BlockFilter);
void buildChain(MachineBasicBlock *BB, BlockChain &Chain,
SmallVectorImpl<MachineBasicBlock *> &Blocks,
const BlockFilterSet *BlockFilter = 0);
@@ -303,12 +306,60 @@ void MachineBlockPlacement::markChainSuccessors(
}
}
+/// \brief Select the best successor for a block.
+///
+/// This looks across all successors of a particular block and attempts to
+/// select the "best" one to be the layout successor. It only considers direct
+/// successors which also pass the block filter. It will attempt to avoid
+/// breaking CFG structure, but cave and break such structures in the case of
+/// very hot successor edges.
+///
+/// \returns The best successor block found, or null if none are viable.
+MachineBasicBlock *MachineBlockPlacement::selectBestSuccessor(
+ MachineBasicBlock *BB, BlockChain &Chain,
+ const BlockFilterSet *BlockFilter) {
+ const BranchProbability HotProb(4, 5); // 80%
+
+ MachineBasicBlock *BestSucc = 0;
+ BranchProbability BestProb = BranchProbability::getZero();
+ DEBUG(dbgs() << "Attempting merge from: " << getBlockName(BB) << "\n");
+ for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
+ SE = BB->succ_end();
+ SI != SE; ++SI) {
+ if (BlockFilter && !BlockFilter->count(*SI))
+ continue;
+ BlockChain &SuccChain = *BlockToChain[*SI];
+ if (&SuccChain == &Chain) {
+ DEBUG(dbgs() << " " << getBlockName(*SI) << " -> Already merged!\n");
+ continue;
+ }
+
+ BranchProbability SuccProb = MBPI->getEdgeProbability(BB, *SI);
+
+ // Only consider successors which are either "hot", or wouldn't violate
+ // any CFG constraints.
+ if (SuccChain.LoopPredecessors != 0 && SuccProb < HotProb) {
+ DEBUG(dbgs() << " " << getBlockName(*SI) << " -> CFG conflict\n");
+ continue;
+ }
+
+ DEBUG(dbgs() << " " << getBlockName(*SI) << " -> " << SuccProb
+ << " (prob)"
+ << (SuccChain.LoopPredecessors != 0 ? " (CFG break)" : "")
+ << "\n");
+ if (BestSucc && BestProb >= SuccProb)
+ continue;
+ BestSucc = *SI;
+ BestProb = SuccProb;
+ }
+ return BestSucc;
+}
+
void MachineBlockPlacement::buildChain(
MachineBasicBlock *BB,
BlockChain &Chain,
SmallVectorImpl<MachineBasicBlock *> &BlockWorkList,
const BlockFilterSet *BlockFilter) {
- const BranchProbability HotProb(4, 5); // 80%
assert(BB);
assert(BlockToChain[BB] == &Chain);
assert(*Chain.begin() == BB);
@@ -322,38 +373,7 @@ void MachineBlockPlacement::buildChain(
// Look for the best viable successor if there is one to place immediately
// after this block.
- MachineBasicBlock *BestSucc = 0;
- BranchProbability BestProb = BranchProbability::getZero();
- DEBUG(dbgs() << "Attempting merge from: " << getBlockName(BB) << "\n");
- for (MachineBasicBlock::succ_iterator SI = BB->succ_begin(),
- SE = BB->succ_end();
- SI != SE; ++SI) {
- if (BlockFilter && !BlockFilter->count(*SI))
- continue;
- BlockChain &SuccChain = *BlockToChain[*SI];
- if (&SuccChain == &Chain) {
- DEBUG(dbgs() << " " << getBlockName(*SI) << " -> Already merged!\n");
- continue;
- }
-
- BranchProbability SuccProb = MBPI->getEdgeProbability(BB, *SI);
-
- // Only consider successors which are either "hot", or wouldn't violate
- // any CFG constraints.
- if (SuccChain.LoopPredecessors != 0 && SuccProb < HotProb) {
- DEBUG(dbgs() << " " << getBlockName(*SI) << " -> CFG conflict\n");
- continue;
- }
-
- DEBUG(dbgs() << " " << getBlockName(*SI) << " -> " << SuccProb
- << " (prob)"
- << (SuccChain.LoopPredecessors != 0 ? " (CFG break)" : "")
- << "\n");
- if (BestSucc && BestProb >= SuccProb)
- continue;
- BestSucc = *SI;
- BestProb = SuccProb;
- }
+ MachineBasicBlock *BestSucc = selectBestSuccessor(BB, Chain, BlockFilter);
// If an immediate successor isn't available, look for the best viable
// block among those we've identified as not violating the loop's CFG at