Minor code simplification.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86853 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman 2009-11-11 18:18:34 +00:00
parent 641c6f983e
commit d194498d26

View File

@ -875,6 +875,7 @@ static bool IsBetterFallthrough(MachineBasicBlock *MBB1,
/// block. This is never called on the entry block. /// block. This is never called on the entry block.
bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) { bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
bool MadeChange = false; bool MadeChange = false;
MachineFunction &MF = *MBB->getParent();
MachineFunction::iterator FallThrough = MBB; MachineFunction::iterator FallThrough = MBB;
++FallThrough; ++FallThrough;
@ -887,7 +888,7 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
// Dead block? Leave for cleanup later. // Dead block? Leave for cleanup later.
if (MBB->pred_empty()) return MadeChange; if (MBB->pred_empty()) return MadeChange;
if (FallThrough == MBB->getParent()->end()) { if (FallThrough == MF.end()) {
// TODO: Simplify preds to not branch here if possible! // TODO: Simplify preds to not branch here if possible!
} else { } else {
// Rewrite all predecessors of the old block to go to the fallthrough // Rewrite all predecessors of the old block to go to the fallthrough
@ -898,8 +899,7 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
} }
// If MBB was the target of a jump table, update jump tables to go to the // If MBB was the target of a jump table, update jump tables to go to the
// fallthrough instead. // fallthrough instead.
MBB->getParent()->getJumpTableInfo()-> MF.getJumpTableInfo()->ReplaceMBBInJumpTables(MBB, FallThrough);
ReplaceMBBInJumpTables(MBB, FallThrough);
MadeChange = true; MadeChange = true;
} }
return MadeChange; return MadeChange;
@ -982,7 +982,7 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
// last block in the function, we'd just keep swapping the two blocks for // last block in the function, we'd just keep swapping the two blocks for
// last. Only do the swap if one is clearly better to fall through than // last. Only do the swap if one is clearly better to fall through than
// the other. // the other.
if (FallThrough == --MBB->getParent()->end() && if (FallThrough == --MF.end() &&
!IsBetterFallthrough(PriorTBB, MBB)) !IsBetterFallthrough(PriorTBB, MBB))
DoTransform = false; DoTransform = false;
@ -1013,7 +1013,7 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
TII->InsertBranch(PrevBB, MBB, 0, NewPriorCond); TII->InsertBranch(PrevBB, MBB, 0, NewPriorCond);
// Move this block to the end of the function. // Move this block to the end of the function.
MBB->moveAfter(--MBB->getParent()->end()); MBB->moveAfter(--MF.end());
MadeChange = true; MadeChange = true;
++NumBranchOpts; ++NumBranchOpts;
return MadeChange; return MadeChange;
@ -1114,8 +1114,7 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
} }
// Change any jumptables to go to the new MBB. // Change any jumptables to go to the new MBB.
MBB->getParent()->getJumpTableInfo()-> MF.getJumpTableInfo()->ReplaceMBBInJumpTables(MBB, CurTBB);
ReplaceMBBInJumpTables(MBB, CurTBB);
if (DidChange) { if (DidChange) {
++NumBranchOpts; ++NumBranchOpts;
MadeChange = true; MadeChange = true;
@ -1195,9 +1194,9 @@ bool BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) {
// Okay, there is no really great place to put this block. If, however, // Okay, there is no really great place to put this block. If, however,
// the block before this one would be a fall-through if this block were // the block before this one would be a fall-through if this block were
// removed, move this block to the end of the function. // removed, move this block to the end of the function.
if (FallThrough != MBB->getParent()->end() && if (FallThrough != MF.end() &&
PrevBB.isSuccessor(FallThrough)) { PrevBB.isSuccessor(FallThrough)) {
MBB->moveAfter(--MBB->getParent()->end()); MBB->moveAfter(--MF.end());
MadeChange = true; MadeChange = true;
return MadeChange; return MadeChange;
} }