diff options
author | Evan Cheng <evan.cheng@apple.com> | 2007-06-04 06:44:01 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2007-06-04 06:44:01 +0000 |
commit | 0370fad74b48388412c52d1325512f2c218487fa (patch) | |
tree | 719b56402f4e3d3d2072bec9dc55d461d93eeb53 /lib/CodeGen/BranchFolding.cpp | |
parent | 26042420d642e810f5cdfb2da6156b74aaf80945 (diff) |
Move ReplaceUsesOfBlockWith() out of BranchFolding into a MachineBasicBlock general facility.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@37408 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/BranchFolding.cpp')
-rw-r--r-- | lib/CodeGen/BranchFolding.cpp | 42 |
1 files changed, 2 insertions, 40 deletions
diff --git a/lib/CodeGen/BranchFolding.cpp b/lib/CodeGen/BranchFolding.cpp index 53cf0aabb9..2f25800cd0 100644 --- a/lib/CodeGen/BranchFolding.cpp +++ b/lib/CodeGen/BranchFolding.cpp @@ -733,44 +733,6 @@ static bool CorrectExtraCFGEdges(MachineBasicBlock &MBB, } -/// ReplaceUsesOfBlockWith - Given a machine basic block 'BB' that branched to -/// 'Old', change the code and CFG so that it branches to 'New' instead. -static void ReplaceUsesOfBlockWith(MachineBasicBlock *BB, - MachineBasicBlock *Old, - MachineBasicBlock *New, - const TargetInstrInfo *TII) { - assert(Old != New && "Cannot replace self with self!"); - - MachineBasicBlock::iterator I = BB->end(); - while (I != BB->begin()) { - --I; - if (!TII->isTerminatorInstr(I->getOpcode())) break; - - // Scan the operands of this machine instruction, replacing any uses of Old - // with New. - for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) - if (I->getOperand(i).isMachineBasicBlock() && - I->getOperand(i).getMachineBasicBlock() == Old) - I->getOperand(i).setMachineBasicBlock(New); - } - - // Update the successor information. If New was already a successor, just - // remove the link to Old instead of creating another one. PR 1444. - bool HadSuccessorNew = false; - std::vector<MachineBasicBlock*> Succs(BB->succ_begin(), BB->succ_end()); - for (int i = Succs.size()-1; i >= 0; --i) - if (Succs[i] == New) { - HadSuccessorNew = true; - break; - } - for (int i = Succs.size()-1; i >= 0; --i) - if (Succs[i] == Old) { - BB->removeSuccessor(Old); - if (!HadSuccessorNew) - BB->addSuccessor(New); - } -} - /// CanFallThrough - Return true if the specified block (with the specified /// branch condition) can implicitly transfer control to the block after it by /// falling off the end of it. This should return false if it can reach the @@ -865,7 +827,7 @@ void BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) { // instead. while (!MBB->pred_empty()) { MachineBasicBlock *Pred = *(MBB->pred_end()-1); - ReplaceUsesOfBlockWith(Pred, MBB, FallThrough, TII); + Pred->ReplaceUsesOfBlockWith(MBB, FallThrough); } // If MBB was the target of a jump table, update jump tables to go to the @@ -1066,7 +1028,7 @@ void BranchFolder::OptimizeBlock(MachineBasicBlock *MBB) { HasBranchToSelf = true; } else { DidChange = true; - ReplaceUsesOfBlockWith(*PI, MBB, CurTBB, TII); + (*PI)->ReplaceUsesOfBlockWith(MBB, CurTBB); } } |