From fe95ac0d356074fc1ff325d42212d567fb7de048 Mon Sep 17 00:00:00 2001 From: Dale Johannesen Date: Fri, 7 Aug 2009 17:41:29 +0000 Subject: [PATCH] Rewrite previous patch to follow Chris' stylistic preference; no functional change. llvm-svn: 78391 --- llvm/lib/CodeGen/BranchFolding.cpp | 36 ++++++++++++++++++------------ 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/llvm/lib/CodeGen/BranchFolding.cpp b/llvm/lib/CodeGen/BranchFolding.cpp index d25152b1e436..1ab3df28572b 100644 --- a/llvm/lib/CodeGen/BranchFolding.cpp +++ b/llvm/lib/CodeGen/BranchFolding.cpp @@ -850,6 +850,27 @@ bool BranchFolder::CanFallThrough(MachineBasicBlock *CurBB) { 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 @@ void BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) { // 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.