[llvm-commits] [llvm] r78391 - /llvm/trunk/lib/CodeGen/BranchFolding.cpp

Dale Johannesen dalej at apple.com
Fri Aug 7 10:41:29 PDT 2009


Author: johannes
Date: Fri Aug  7 12:41:29 2009
New Revision: 78391

URL: http://llvm.org/viewvc/llvm-project?rev=78391&view=rev
Log:
Rewrite previous patch to follow Chris' stylistic
preference; no functional change.


Modified:
    llvm/trunk/lib/CodeGen/BranchFolding.cpp

Modified: llvm/trunk/lib/CodeGen/BranchFolding.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/BranchFolding.cpp?rev=78391&r1=78390&r2=78391&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/BranchFolding.cpp (original)
+++ llvm/trunk/lib/CodeGen/BranchFolding.cpp Fri Aug  7 12:41:29 2009
@@ -850,6 +850,27 @@
   return CanFallThrough(CurBB, CurUnAnalyzable, TBB, FBB, Cond);
 }
 
+/// RemoveDuplicateSuccessor - make sure block Pred has at most one
+/// successor edge leading to Succ.  This is only called in one place,
+/// but Chris prefers that it be a separate function.
+static void RemoveDuplicateSuccessor(MachineBasicBlock *Pred,
+                                     MachineBasicBlock *Succ) {
+  MachineBasicBlock::succ_iterator SI = Pred->succ_begin();
+  bool found = false;
+  while (SI != Pred->succ_end()) {
+    if (*SI == Succ) {
+      if (!found) {
+        found = true;
+        ++SI;
+      } else {
+        SI = Pred->removeSuccessor(SI);
+      }
+    } else {
+      ++SI;
+    }
+  }
+}
+
 /// IsBetterFallthrough - Return true if it would be clearly better to
 /// fall-through to MBB1 than to fall through into MBB2.  This has to return
 /// a strict ordering, returning true for both (MBB1,MBB2) and (MBB2,MBB1) will
@@ -896,20 +917,7 @@
         // If this resulted in a predecessor with true and false edges
         // both going to the fallthrough block, clean up; 
         // BranchFolding doesn't like this.
-        MachineBasicBlock::succ_iterator SI = Pred->succ_begin();
-        bool found = false;
-        while (SI != Pred->succ_end()) {
-          if (*SI == FallThrough) {
-            if (!found) {
-              found = true;
-              ++SI;
-            } else {
-              SI = Pred->removeSuccessor(SI);
-            }
-          } else {
-            ++SI;
-          }
-        }
+        RemoveDuplicateSuccessor(Pred, FallThrough);
       }
       // If MBB was the target of a jump table, update jump tables to go to the
       // fallthrough instead.





More information about the llvm-commits mailing list