diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-11-13 12:17:28 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-11-13 12:17:28 +0000 |
commit | 6527ecc9189058b762c699521462956995f59dd8 (patch) | |
tree | 12f24d1e098fa2f79877682923f71afb3c93b913 /lib/CodeGen | |
parent | f3fc0050abc1698504cbaede7766c4180c076928 (diff) |
Teach MBP to force-merge layout successors for blocks with unanalyzable
branches that also may involve fallthrough. In the case of blocks with
no fallthrough, we can still re-order the blocks profitably. For example
instruction decoding will in some cases continue past an indirect jump,
making laying out its most likely successor there profitable.
Note, no test case. I don't know how to write a test case that exercises
this logic, but it matches the described desired semantics in
discussions with Jakob and others. If anyone has a nice example of IR
that will trigger this, that would be lovely.
Also note, there are still assertion failures in real world code with
this. I'm digging into those next, now that I know this isn't the cause.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144499 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r-- | lib/CodeGen/MachineBlockPlacement.cpp | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/CodeGen/MachineBlockPlacement.cpp b/lib/CodeGen/MachineBlockPlacement.cpp index f934776731..d0b692681f 100644 --- a/lib/CodeGen/MachineBlockPlacement.cpp +++ b/lib/CodeGen/MachineBlockPlacement.cpp @@ -413,15 +413,32 @@ void MachineBlockPlacement::buildChain( assert(*Chain.begin() == BB); MachineBasicBlock *LoopHeaderBB = BB; markChainSuccessors(Chain, LoopHeaderBB, BlockWorkList, BlockFilter); + SmallVector<MachineOperand, 4> Cond; // For AnalyzeBranch. BB = *llvm::prior(Chain.end()); for (;;) { assert(BB); assert(BlockToChain[BB] == &Chain); assert(*llvm::prior(Chain.end()) == BB); + MachineBasicBlock *BestSucc = 0; + + // Check for unreasonable branches, and forcibly merge the existing layout + // successor for them. We can handle cases that AnalyzeBranch can't: jump + // tables etc are fine. The case we want to handle specially is when there + // is potential fallthrough, but the branch cannot be analyzed. This + // includes blocks without terminators as well as other cases. + Cond.clear(); + MachineBasicBlock *TBB = 0, *FBB = 0; // For AnalyzeBranch. + if (TII->AnalyzeBranch(*BB, TBB, FBB, Cond) && BB->canFallThrough()) { + MachineFunction::iterator I(BB); + assert(llvm::next(I) != BB->getParent()->end() && + "The final block in the function can fallthrough!"); + BestSucc = llvm::next(I); + } - // Look for the best viable successor if there is one to place immediately - // after this block. - MachineBasicBlock *BestSucc = selectBestSuccessor(BB, Chain, BlockFilter); + // Otherwise, look for the best viable successor if there is one to place + // immediately after this block. + if (!BestSucc) + 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 |