Address comments on last patch:
authorBill Wendling <isanbard@gmail.com>
Fri, 11 Dec 2009 03:14:18 +0000 (03:14 +0000)
committerBill Wendling <isanbard@gmail.com>
Fri, 11 Dec 2009 03:14:18 +0000 (03:14 +0000)
- 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

include/llvm/CodeGen/MachineBasicBlock.h
lib/CodeGen/MachineBasicBlock.cpp

index 023f9b6564e56a1af2ff12495efd47fb183a810d..7e3ce6bd7c96c97d3ae857fa975e35819ebb43b0 100644 (file)
@@ -327,9 +327,9 @@ public:
   /// 'Old', change the code and CFG so that it branches to 'New' instead.
   void ReplaceUsesOfBlockWith(MachineBasicBlock *Old, MachineBasicBlock *New);
 
-  /// BranchesToLandingPad - The basic block branches only to a landing pad or
-  /// to another basic block which branches only to a landing pad. No other
-  /// instructions are present other than the unconditional branch.
+  /// BranchesToLandingPad - The basic block is a landing pad or branches only
+  /// to a landing pad. No other instructions are present other than the
+  /// unconditional branch.
   bool BranchesToLandingPad(const MachineBasicBlock *MBB) const;
 
   /// CorrectExtraCFGEdges - Various pieces of code can cause excess edges in
index 684af344940cf59f9a04d1a57c2329deb2e7cc53..7ce723e019af2de5ac5ca1cc69e9a5dc33521193 100644 (file)
@@ -449,24 +449,19 @@ void MachineBasicBlock::ReplaceUsesOfBlockWith(MachineBasicBlock *Old,
   addSuccessor(New);
 }
 
-/// BranchesToLandingPad - The basic block branches only to a landing pad or to
-/// another basic block which branches only to a landing pad. No other
-/// instructions are present other than the unconditional branch.
+/// BranchesToLandingPad - The basic block is a landing pad or branches only to
+/// a landing pad. No other instructions are present other than the
+/// unconditional branch.
 bool
 MachineBasicBlock::BranchesToLandingPad(const MachineBasicBlock *MBB) const {
   SmallSet<const MachineBasicBlock*, 32> Visited;
   const MachineBasicBlock *CurMBB = MBB;
 
-  while (!Visited.count(CurMBB) && !CurMBB->isLandingPad()) {
-    if (CurMBB->size() != 1 || CurMBB->succ_empty() || CurMBB->succ_size() != 1)
+  while (!CurMBB->isLandingPad()) {
+    if (CurMBB->succ_size() != 1)
       break;
 
-    const TargetInstrInfo *TII =
-      CurMBB->getParent()->getTarget().getInstrInfo();
-    if (!TII->isUnpredicatedTerminator(CurMBB->begin()))
-      break;
-
-    Visited.insert(CurMBB);
+    if (!Visited.insert(CurMBB)) break;
     CurMBB = *CurMBB->succ_begin();
   }
 
@@ -516,8 +511,8 @@ bool MachineBasicBlock::CorrectExtraCFGEdges(MachineBasicBlock *DestA,
     } else if (MBB == DestB) {
       DestB = 0;
       ++SI;
-    } else if (BranchesToLandingPad(MBB) &&
-               MBB != OrigDestA && MBB != OrigDestB) {
+    } else if (MBB != OrigDestA && MBB != OrigDestB &&
+               BranchesToLandingPad(MBB)) {
       ++SI;
     } else {
       // Otherwise, this is a superfluous edge, remove it.