[llvm-commits] CVS: llvm/lib/CodeGen/BranchFolding.cpp
Jim Laskey
jlaskey at apple.com
Wed Feb 21 14:42:37 PST 2007
Changes in directory llvm/lib/CodeGen:
BranchFolding.cpp updated: 1.42 -> 1.43
---
Log message:
Make branch folding behave in the presence of landing pads.
---
Diffs of the changes: (+30 -25)
BranchFolding.cpp | 55 +++++++++++++++++++++++++++++-------------------------
1 files changed, 30 insertions(+), 25 deletions(-)
Index: llvm/lib/CodeGen/BranchFolding.cpp
diff -u llvm/lib/CodeGen/BranchFolding.cpp:1.42 llvm/lib/CodeGen/BranchFolding.cpp:1.43
--- llvm/lib/CodeGen/BranchFolding.cpp:1.42 Fri Feb 16 18:44:34 2007
+++ llvm/lib/CodeGen/BranchFolding.cpp Wed Feb 21 16:42:20 2007
@@ -67,7 +67,8 @@
/// RemoveDeadBlock - Remove the specified dead machine basic block from the
/// function, updating the CFG.
void BranchFolder::RemoveDeadBlock(MachineBasicBlock *MBB) {
- assert(MBB->pred_empty() && "MBB must be dead!");
+ assert(!MBB->isAccessable() && "MBB must be dead!");
+ DOUT << "\nRemoving MBB: " << *MBB;
MachineFunction *MF = MBB->getParent();
// drop all successors.
@@ -439,7 +440,7 @@
OptimizeBlock(MBB);
// If it is dead, remove it.
- if (MBB->pred_empty()) {
+ if (!MBB->isAccessable()) {
RemoveDeadBlock(MBB);
MadeChange = true;
++NumDeadBlocks;
@@ -485,6 +486,8 @@
} else if (*SI == DestB) {
DestB = 0;
++SI;
+ } else if ((*SI)->isLandingPad()) {
+ ++SI;
} else {
// Otherwise, this is a superfluous edge, remove it.
MBB.removeSuccessor(SI);
@@ -615,14 +618,14 @@
// explicitly.
if (MBB->empty()) {
// Dead block? Leave for cleanup later.
- if (MBB->pred_empty()) return;
+ if (!MBB->isAccessable()) return;
if (FallThrough == MBB->getParent()->end()) {
// TODO: Simplify preds to not branch here if possible!
} else {
// Rewrite all predecessors of the old block to go to the fallthrough
// instead.
- while (!MBB->pred_empty()) {
+ while (MBB->isAccessable()) {
MachineBasicBlock *Pred = *(MBB->pred_end()-1);
ReplaceUsesOfBlockWith(Pred, MBB, FallThrough, TII);
}
@@ -855,28 +858,30 @@
bool CurFallsThru = CanFallThrough(MBB, CurUnAnalyzable, CurTBB, CurFBB,
CurCond);
- // Check all the predecessors of this block. If one of them has no fall
- // throughs, move this block right after it.
- for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(),
- E = MBB->pred_end(); PI != E; ++PI) {
- // Analyze the branch at the end of the pred.
- MachineBasicBlock *PredBB = *PI;
- MachineFunction::iterator PredFallthrough = PredBB; ++PredFallthrough;
- if (PredBB != MBB && !CanFallThrough(PredBB)
- && (!CurFallsThru || MBB->getNumber() >= PredBB->getNumber())) {
- // If the current block doesn't fall through, just move it.
- // If the current block can fall through and does not end with a
- // conditional branch, we need to append an unconditional jump to
- // the (current) next block. To avoid a possible compile-time
- // infinite loop, move blocks only backward in this case.
- if (CurFallsThru) {
- MachineBasicBlock *NextBB = next(MachineFunction::iterator(MBB));
- CurCond.clear();
- TII->InsertBranch(*MBB, NextBB, 0, CurCond);
+ if (!MBB->isLandingPad()) {
+ // Check all the predecessors of this block. If one of them has no fall
+ // throughs, move this block right after it.
+ for (MachineBasicBlock::pred_iterator PI = MBB->pred_begin(),
+ E = MBB->pred_end(); PI != E; ++PI) {
+ // Analyze the branch at the end of the pred.
+ MachineBasicBlock *PredBB = *PI;
+ MachineFunction::iterator PredFallthrough = PredBB; ++PredFallthrough;
+ if (PredBB != MBB && !CanFallThrough(PredBB)
+ && (!CurFallsThru || MBB->getNumber() >= PredBB->getNumber())) {
+ // If the current block doesn't fall through, just move it.
+ // If the current block can fall through and does not end with a
+ // conditional branch, we need to append an unconditional jump to
+ // the (current) next block. To avoid a possible compile-time
+ // infinite loop, move blocks only backward in this case.
+ if (CurFallsThru) {
+ MachineBasicBlock *NextBB = next(MachineFunction::iterator(MBB));
+ CurCond.clear();
+ TII->InsertBranch(*MBB, NextBB, 0, CurCond);
+ }
+ MBB->moveAfter(PredBB);
+ MadeChange = true;
+ return OptimizeBlock(MBB);
}
- MBB->moveAfter(PredBB);
- MadeChange = true;
- return OptimizeBlock(MBB);
}
}
More information about the llvm-commits
mailing list