diff options
author | Dale Johannesen <dalej@apple.com> | 2009-08-07 17:41:29 +0000 |
---|---|---|
committer | Dale Johannesen <dalej@apple.com> | 2009-08-07 17:41:29 +0000 |
commit | 1c5a28706d0b2e712f4c825d638b46bbe6eb67d6 (patch) | |
tree | 95060482b277c886775f6ea572e2403480b5c58f /lib/CodeGen/BranchFolding.cpp | |
parent | b7f40c1a2a74fe9bd98cfab3d0ff139a8510fdfe (diff) |
Rewrite previous patch to follow Chris' stylistic
preference; no functional change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78391 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/BranchFolding.cpp')
-rw-r--r-- | lib/CodeGen/BranchFolding.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp index d25152b1e4..1ab3df2857 100644 --- a/lib/CodeGen/BranchFolding.cpp +++ b/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. |