summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/CodePlacementOpt.cpp
diff options
context:
space:
mode:
authorJim Grosbach <grosbach@apple.com>2009-11-12 03:55:33 +0000
committerJim Grosbach <grosbach@apple.com>2009-11-12 03:55:33 +0000
commit801b33b17c0aa9c11ef3df6eeab22e3ce68fcdb9 (patch)
treeceeac7f3a184bf1b5d5e5cd37c2e0ca3a9d1eab8 /llvm/lib/CodeGen/CodePlacementOpt.cpp
parent6385ea7c4eef23fe999cf1ab460452c9a3380260 (diff)
downloadbcm5719-llvm-801b33b17c0aa9c11ef3df6eeab22e3ce68fcdb9.tar.gz
bcm5719-llvm-801b33b17c0aa9c11ef3df6eeab22e3ce68fcdb9.zip
Move the utility function UpdateTerminator() from CodePlacementOpt() into
MachineBasicBlock so other passes can utilize it. llvm-svn: 86947
Diffstat (limited to 'llvm/lib/CodeGen/CodePlacementOpt.cpp')
-rw-r--r--llvm/lib/CodeGen/CodePlacementOpt.cpp64
1 files changed, 3 insertions, 61 deletions
diff --git a/llvm/lib/CodeGen/CodePlacementOpt.cpp b/llvm/lib/CodeGen/CodePlacementOpt.cpp
index 6fff12c0b0d..e9844d84c17 100644
--- a/llvm/lib/CodeGen/CodePlacementOpt.cpp
+++ b/llvm/lib/CodeGen/CodePlacementOpt.cpp
@@ -56,7 +56,6 @@ namespace {
MachineFunction::iterator InsertPt,
MachineFunction::iterator Begin,
MachineFunction::iterator End);
- void UpdateTerminator(MachineBasicBlock *MBB);
bool EliminateUnconditionalJumpsToTop(MachineFunction &MF,
MachineLoop *L);
bool MoveDiscontiguousLoopBlocks(MachineFunction &MF,
@@ -141,66 +140,9 @@ void CodePlacementOpt::Splice(MachineFunction &MF,
MF.splice(InsertPt, Begin, End);
- UpdateTerminator(prior(Begin));
- UpdateTerminator(OldBeginPrior);
- UpdateTerminator(OldEndPrior);
-}
-
-/// UpdateTerminator - Update the terminator instructions in MBB to account
-/// for changes to the layout. If the block previously used a fallthrough,
-/// it may now need a branch, and if it previously used branching it may now
-/// be able to use a fallthrough.
-///
-void CodePlacementOpt::UpdateTerminator(MachineBasicBlock *MBB) {
- // A block with no successors has no concerns with fall-through edges.
- if (MBB->succ_empty()) return;
-
- MachineBasicBlock *TBB = 0, *FBB = 0;
- SmallVector<MachineOperand, 4> Cond;
- bool B = TII->AnalyzeBranch(*MBB, TBB, FBB, Cond);
- (void) B;
- assert(!B && "UpdateTerminators requires analyzable predecessors!");
- if (Cond.empty()) {
- if (TBB) {
- // The block has an unconditional branch. If its successor is now
- // its layout successor, delete the branch.
- if (MBB->isLayoutSuccessor(TBB))
- TII->RemoveBranch(*MBB);
- } else {
- // The block has an unconditional fallthrough. If its successor is not
- // its layout successor, insert a branch.
- TBB = *MBB->succ_begin();
- if (!MBB->isLayoutSuccessor(TBB))
- TII->InsertBranch(*MBB, TBB, 0, Cond);
- }
- } else {
- if (FBB) {
- // The block has a non-fallthrough conditional branch. If one of its
- // successors is its layout successor, rewrite it to a fallthrough
- // conditional branch.
- if (MBB->isLayoutSuccessor(TBB)) {
- TII->RemoveBranch(*MBB);
- TII->ReverseBranchCondition(Cond);
- TII->InsertBranch(*MBB, FBB, 0, Cond);
- } else if (MBB->isLayoutSuccessor(FBB)) {
- TII->RemoveBranch(*MBB);
- TII->InsertBranch(*MBB, TBB, 0, Cond);
- }
- } else {
- // The block has a fallthrough conditional branch.
- MachineBasicBlock *MBBA = *MBB->succ_begin();
- MachineBasicBlock *MBBB = *next(MBB->succ_begin());
- if (MBBA == TBB) std::swap(MBBB, MBBA);
- if (MBB->isLayoutSuccessor(TBB)) {
- TII->RemoveBranch(*MBB);
- TII->ReverseBranchCondition(Cond);
- TII->InsertBranch(*MBB, MBBA, 0, Cond);
- } else if (!MBB->isLayoutSuccessor(MBBA)) {
- TII->RemoveBranch(*MBB);
- TII->InsertBranch(*MBB, TBB, MBBA, Cond);
- }
- }
- }
+ prior(Begin)->updateTerminator();
+ OldBeginPrior->updateTerminator();
+ OldEndPrior->updateTerminator();
}
/// EliminateUnconditionalJumpsToTop - Move blocks which unconditionally jump
OpenPOWER on IntegriCloud