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/MachineBasicBlock.cpp | |
parent | 26042420d642e810f5cdfb2da6156b74aaf80945 (diff) | |
download | external_llvm-0370fad74b48388412c52d1325512f2c218487fa.zip external_llvm-0370fad74b48388412c52d1325512f2c218487fa.tar.gz external_llvm-0370fad74b48388412c52d1325512f2c218487fa.tar.bz2 |
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/MachineBasicBlock.cpp')
-rw-r--r-- | lib/CodeGen/MachineBasicBlock.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/CodeGen/MachineBasicBlock.cpp b/lib/CodeGen/MachineBasicBlock.cpp index 44f7f90..af36764 100644 --- a/lib/CodeGen/MachineBasicBlock.cpp +++ b/lib/CodeGen/MachineBasicBlock.cpp @@ -198,3 +198,30 @@ bool MachineBasicBlock::isSuccessor(MachineBasicBlock *MBB) const { std::find(Successors.begin(), Successors.end(), MBB); return I != Successors.end(); } + +/// ReplaceUsesOfBlockWith - Given a machine basic block that branched to +/// 'Old', change the code and CFG so that it branches to 'New' instead. +void MachineBasicBlock::ReplaceUsesOfBlockWith(MachineBasicBlock *Old, + MachineBasicBlock *New) { + assert(Old != New && "Cannot replace self with self!"); + + MachineBasicBlock::iterator I = end(); + while (I != begin()) { + --I; + if (!(I->getInstrDescriptor()->Flags & M_TERMINATOR_FLAG)) 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. + removeSuccessor(Old); + if (!isSuccessor(New)) + addSuccessor(New); +} + |