mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-27 17:31:33 +00:00
Move the utility function UpdateTerminator() from CodePlacementOpt() into
MachineBasicBlock so other passes can utilize it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86947 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
01dec0e545
commit
7707a0df5b
@ -226,6 +226,12 @@ public:
|
|||||||
void moveBefore(MachineBasicBlock *NewAfter);
|
void moveBefore(MachineBasicBlock *NewAfter);
|
||||||
void moveAfter(MachineBasicBlock *NewBefore);
|
void moveAfter(MachineBasicBlock *NewBefore);
|
||||||
|
|
||||||
|
/// updateTerminator - Update the terminator instructions in block 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 updateTerminator();
|
||||||
|
|
||||||
// Machine-CFG mutators
|
// Machine-CFG mutators
|
||||||
|
|
||||||
/// addSuccessor - Add succ as a successor of this MachineBasicBlock.
|
/// addSuccessor - Add succ as a successor of this MachineBasicBlock.
|
||||||
|
@ -56,7 +56,6 @@ namespace {
|
|||||||
MachineFunction::iterator InsertPt,
|
MachineFunction::iterator InsertPt,
|
||||||
MachineFunction::iterator Begin,
|
MachineFunction::iterator Begin,
|
||||||
MachineFunction::iterator End);
|
MachineFunction::iterator End);
|
||||||
void UpdateTerminator(MachineBasicBlock *MBB);
|
|
||||||
bool EliminateUnconditionalJumpsToTop(MachineFunction &MF,
|
bool EliminateUnconditionalJumpsToTop(MachineFunction &MF,
|
||||||
MachineLoop *L);
|
MachineLoop *L);
|
||||||
bool MoveDiscontiguousLoopBlocks(MachineFunction &MF,
|
bool MoveDiscontiguousLoopBlocks(MachineFunction &MF,
|
||||||
@ -141,66 +140,9 @@ void CodePlacementOpt::Splice(MachineFunction &MF,
|
|||||||
|
|
||||||
MF.splice(InsertPt, Begin, End);
|
MF.splice(InsertPt, Begin, End);
|
||||||
|
|
||||||
UpdateTerminator(prior(Begin));
|
prior(Begin)->updateTerminator();
|
||||||
UpdateTerminator(OldBeginPrior);
|
OldBeginPrior->updateTerminator();
|
||||||
UpdateTerminator(OldEndPrior);
|
OldEndPrior->updateTerminator();
|
||||||
}
|
|
||||||
|
|
||||||
/// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EliminateUnconditionalJumpsToTop - Move blocks which unconditionally jump
|
/// EliminateUnconditionalJumpsToTop - Move blocks which unconditionally jump
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "llvm/Target/TargetRegisterInfo.h"
|
#include "llvm/Target/TargetRegisterInfo.h"
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Target/TargetInstrDesc.h"
|
#include "llvm/Target/TargetInstrDesc.h"
|
||||||
|
#include "llvm/Target/TargetInstrInfo.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
#include "llvm/Support/LeakDetector.h"
|
#include "llvm/Support/LeakDetector.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
@ -242,6 +243,58 @@ void MachineBasicBlock::moveAfter(MachineBasicBlock *NewBefore) {
|
|||||||
getParent()->splice(++BBI, this);
|
getParent()->splice(++BBI, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MachineBasicBlock::updateTerminator() {
|
||||||
|
const TargetInstrInfo *TII = getParent()->getTarget().getInstrInfo();
|
||||||
|
// A block with no successors has no concerns with fall-through edges.
|
||||||
|
if (this->succ_empty()) return;
|
||||||
|
|
||||||
|
MachineBasicBlock *TBB = 0, *FBB = 0;
|
||||||
|
SmallVector<MachineOperand, 4> Cond;
|
||||||
|
bool B = TII->AnalyzeBranch(*this, 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 (isLayoutSuccessor(TBB))
|
||||||
|
TII->RemoveBranch(*this);
|
||||||
|
} else {
|
||||||
|
// The block has an unconditional fallthrough. If its successor is not
|
||||||
|
// its layout successor, insert a branch.
|
||||||
|
TBB = *succ_begin();
|
||||||
|
if (!isLayoutSuccessor(TBB))
|
||||||
|
TII->InsertBranch(*this, 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 (isLayoutSuccessor(TBB)) {
|
||||||
|
TII->RemoveBranch(*this);
|
||||||
|
TII->ReverseBranchCondition(Cond);
|
||||||
|
TII->InsertBranch(*this, FBB, 0, Cond);
|
||||||
|
} else if (isLayoutSuccessor(FBB)) {
|
||||||
|
TII->RemoveBranch(*this);
|
||||||
|
TII->InsertBranch(*this, TBB, 0, Cond);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// The block has a fallthrough conditional branch.
|
||||||
|
MachineBasicBlock *MBBA = *succ_begin();
|
||||||
|
MachineBasicBlock *MBBB = *next(succ_begin());
|
||||||
|
if (MBBA == TBB) std::swap(MBBB, MBBA);
|
||||||
|
if (isLayoutSuccessor(TBB)) {
|
||||||
|
TII->RemoveBranch(*this);
|
||||||
|
TII->ReverseBranchCondition(Cond);
|
||||||
|
TII->InsertBranch(*this, MBBA, 0, Cond);
|
||||||
|
} else if (!isLayoutSuccessor(MBBA)) {
|
||||||
|
TII->RemoveBranch(*this);
|
||||||
|
TII->InsertBranch(*this, TBB, MBBA, Cond);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MachineBasicBlock::addSuccessor(MachineBasicBlock *succ) {
|
void MachineBasicBlock::addSuccessor(MachineBasicBlock *succ) {
|
||||||
Successors.push_back(succ);
|
Successors.push_back(succ);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user