mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-04 17:56:53 +00:00
[MBB] Early exit to reduce indentation, per coding guidelines. NFC.
llvm-svn: 270773
This commit is contained in:
parent
e4580bceba
commit
7ea3413fa0
@ -404,7 +404,8 @@ void MachineBasicBlock::moveAfter(MachineBasicBlock *NewBefore) {
|
||||
void MachineBasicBlock::updateTerminator() {
|
||||
const TargetInstrInfo *TII = getParent()->getSubtarget().getInstrInfo();
|
||||
// A block with no successors has no concerns with fall-through edges.
|
||||
if (this->succ_empty()) return;
|
||||
if (this->succ_empty())
|
||||
return;
|
||||
|
||||
MachineBasicBlock *TBB = nullptr, *FBB = nullptr;
|
||||
SmallVector<MachineOperand, 4> Cond;
|
||||
@ -414,14 +415,14 @@ void MachineBasicBlock::updateTerminator() {
|
||||
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.
|
||||
// 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. First we have to locate the
|
||||
// only non-landing-pad successor, as that is the fallthrough block.
|
||||
// The block has an unconditional fallthrough. If its successor is not its
|
||||
// layout successor, insert a branch. First we have to locate the only
|
||||
// non-landing-pad successor, as that is the fallthrough block.
|
||||
for (succ_iterator SI = succ_begin(), SE = succ_end(); SI != SE; ++SI) {
|
||||
if ((*SI)->isEHPad())
|
||||
continue;
|
||||
@ -429,8 +430,8 @@ void MachineBasicBlock::updateTerminator() {
|
||||
TBB = *SI;
|
||||
}
|
||||
|
||||
// If there is no non-landing-pad successor, the block has no
|
||||
// fall-through edges to be concerned with.
|
||||
// If there is no non-landing-pad successor, the block has no fall-through
|
||||
// edges to be concerned with.
|
||||
if (!TBB)
|
||||
return;
|
||||
|
||||
@ -439,61 +440,63 @@ void MachineBasicBlock::updateTerminator() {
|
||||
if (!isLayoutSuccessor(TBB))
|
||||
TII->InsertBranch(*this, TBB, nullptr, Cond, DL);
|
||||
}
|
||||
} 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)) {
|
||||
if (TII->ReverseBranchCondition(Cond))
|
||||
return;
|
||||
TII->RemoveBranch(*this);
|
||||
TII->InsertBranch(*this, FBB, nullptr, Cond, DL);
|
||||
} else if (isLayoutSuccessor(FBB)) {
|
||||
TII->RemoveBranch(*this);
|
||||
TII->InsertBranch(*this, TBB, nullptr, Cond, DL);
|
||||
}
|
||||
} else {
|
||||
// Walk through the successors and find the successor which is not
|
||||
// a landing pad and is not the conditional branch destination (in TBB)
|
||||
// as the fallthrough successor.
|
||||
MachineBasicBlock *FallthroughBB = nullptr;
|
||||
for (succ_iterator SI = succ_begin(), SE = succ_end(); SI != SE; ++SI) {
|
||||
if ((*SI)->isEHPad() || *SI == TBB)
|
||||
continue;
|
||||
assert(!FallthroughBB && "Found more than one fallthrough successor.");
|
||||
FallthroughBB = *SI;
|
||||
}
|
||||
if (!FallthroughBB && canFallThrough()) {
|
||||
// We fallthrough to the same basic block as the conditional jump
|
||||
// targets. Remove the conditional jump, leaving unconditional
|
||||
// fallthrough.
|
||||
// FIXME: This does not seem like a reasonable pattern to support, but
|
||||
// it has been seen in the wild coming out of degenerate ARM test cases.
|
||||
TII->RemoveBranch(*this);
|
||||
return;
|
||||
}
|
||||
|
||||
// Finally update the unconditional successor to be reached via a branch
|
||||
// if it would not be reached by fallthrough.
|
||||
if (!isLayoutSuccessor(TBB))
|
||||
TII->InsertBranch(*this, TBB, nullptr, Cond, DL);
|
||||
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)) {
|
||||
if (TII->ReverseBranchCondition(Cond))
|
||||
return;
|
||||
}
|
||||
|
||||
// The block has a fallthrough conditional branch.
|
||||
if (isLayoutSuccessor(TBB)) {
|
||||
if (TII->ReverseBranchCondition(Cond)) {
|
||||
// We can't reverse the condition, add an unconditional branch.
|
||||
Cond.clear();
|
||||
TII->InsertBranch(*this, FallthroughBB, nullptr, Cond, DL);
|
||||
return;
|
||||
}
|
||||
TII->RemoveBranch(*this);
|
||||
TII->InsertBranch(*this, FallthroughBB, nullptr, Cond, DL);
|
||||
} else if (!isLayoutSuccessor(FallthroughBB)) {
|
||||
TII->RemoveBranch(*this);
|
||||
TII->InsertBranch(*this, TBB, FallthroughBB, Cond, DL);
|
||||
}
|
||||
TII->RemoveBranch(*this);
|
||||
TII->InsertBranch(*this, FBB, nullptr, Cond, DL);
|
||||
} else if (isLayoutSuccessor(FBB)) {
|
||||
TII->RemoveBranch(*this);
|
||||
TII->InsertBranch(*this, TBB, nullptr, Cond, DL);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Walk through the successors and find the successor which is not a landing
|
||||
// pad and is not the conditional branch destination (in TBB) as the
|
||||
// fallthrough successor.
|
||||
MachineBasicBlock *FallthroughBB = nullptr;
|
||||
for (succ_iterator SI = succ_begin(), SE = succ_end(); SI != SE; ++SI) {
|
||||
if ((*SI)->isEHPad() || *SI == TBB)
|
||||
continue;
|
||||
assert(!FallthroughBB && "Found more than one fallthrough successor.");
|
||||
FallthroughBB = *SI;
|
||||
}
|
||||
|
||||
if (!FallthroughBB && canFallThrough()) {
|
||||
// We fallthrough to the same basic block as the conditional jump targets.
|
||||
// Remove the conditional jump, leaving unconditional fallthrough.
|
||||
// FIXME: This does not seem like a reasonable pattern to support, but it
|
||||
// has been seen in the wild coming out of degenerate ARM test cases.
|
||||
TII->RemoveBranch(*this);
|
||||
|
||||
// Finally update the unconditional successor to be reached via a branch if
|
||||
// it would not be reached by fallthrough.
|
||||
if (!isLayoutSuccessor(TBB))
|
||||
TII->InsertBranch(*this, TBB, nullptr, Cond, DL);
|
||||
return;
|
||||
}
|
||||
|
||||
// The block has a fallthrough conditional branch.
|
||||
if (isLayoutSuccessor(TBB)) {
|
||||
if (TII->ReverseBranchCondition(Cond)) {
|
||||
// We can't reverse the condition, add an unconditional branch.
|
||||
Cond.clear();
|
||||
TII->InsertBranch(*this, FallthroughBB, nullptr, Cond, DL);
|
||||
return;
|
||||
}
|
||||
TII->RemoveBranch(*this);
|
||||
TII->InsertBranch(*this, FallthroughBB, nullptr, Cond, DL);
|
||||
} else if (!isLayoutSuccessor(FallthroughBB)) {
|
||||
TII->RemoveBranch(*this);
|
||||
TII->InsertBranch(*this, TBB, FallthroughBB, Cond, DL);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user