Address comments on last patch:

- Loosen the restrictions when checking of it branches to a landing pad.
- Make the loop more efficient by checking the '.insert' return value.
- Do cheaper checks first.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91101 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling 2009-12-11 03:14:18 +00:00
parent 4bde1ab82d
commit 64bdde2093
2 changed files with 11 additions and 16 deletions

View File

@ -327,9 +327,9 @@ public:
/// 'Old', change the code and CFG so that it branches to 'New' instead. /// 'Old', change the code and CFG so that it branches to 'New' instead.
void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New); void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New);
/// BranchesToLandingPad - The basic block branches only to a landing pad or /// BranchesToLandingPad - The basic block is a landing pad or branches only
/// to another basic block which branches only to a landing pad. No other /// to a landing pad. No other instructions are present other than the
/// instructions are present other than the unconditional branch. /// unconditional branch.
bool BranchesToLandingPad(const MachineBasicBlock *MBB) const; bool BranchesToLandingPad(const MachineBasicBlock *MBB) const;
/// CorrectExtraCFGEdges - Various pieces of code can cause excess edges in /// CorrectExtraCFGEdges - Various pieces of code can cause excess edges in

View File

@ -449,24 +449,19 @@ void MachineBasicBlock::ReplaceUsesOfBlockWith(MachineBasicBlock *Old,
addSuccessor(New); addSuccessor(New);
} }
/// BranchesToLandingPad - The basic block branches only to a landing pad or to /// BranchesToLandingPad - The basic block is a landing pad or branches only to
/// another basic block which branches only to a landing pad. No other /// a landing pad. No other instructions are present other than the
/// instructions are present other than the unconditional branch. /// unconditional branch.
bool bool
MachineBasicBlock::BranchesToLandingPad(const MachineBasicBlock *MBB) const { MachineBasicBlock::BranchesToLandingPad(const MachineBasicBlock *MBB) const {
SmallSet<const MachineBasicBlock*, 32> Visited; SmallSet<const MachineBasicBlock*, 32> Visited;
const MachineBasicBlock *CurMBB = MBB; const MachineBasicBlock *CurMBB = MBB;
while (!Visited.count(CurMBB) && !CurMBB->isLandingPad()) { while (!CurMBB->isLandingPad()) {
if (CurMBB->size() != 1 || CurMBB->succ_empty() || CurMBB->succ_size() != 1) if (CurMBB->succ_size() != 1)
break; break;
const TargetInstrInfo *TII = if (!Visited.insert(CurMBB)) break;
CurMBB->getParent()->getTarget().getInstrInfo();
if (!TII->isUnpredicatedTerminator(CurMBB->begin()))
break;
Visited.insert(CurMBB);
CurMBB = *CurMBB->succ_begin(); CurMBB = *CurMBB->succ_begin();
} }
@ -516,8 +511,8 @@ bool MachineBasicBlock::CorrectExtraCFGEdges(MachineBasicBlock *DestA,
} else if (MBB == DestB) { } else if (MBB == DestB) {
DestB = 0; DestB = 0;
++SI; ++SI;
} else if (BranchesToLandingPad(MBB) && } else if (MBB != OrigDestA && MBB != OrigDestB &&
MBB != OrigDestA && MBB != OrigDestB) { BranchesToLandingPad(MBB)) {
++SI; ++SI;
} else { } else {
// Otherwise, this is a superfluous edge, remove it. // Otherwise, this is a superfluous edge, remove it.