[llvm-commits] CVS: llvm/lib/CodeGen/BranchFolding.cpp MachineBasicBlock.cpp
Evan Cheng
evan.cheng at apple.com
Sun Jun 3 23:44:23 PDT 2007
Changes in directory llvm/lib/CodeGen:
BranchFolding.cpp updated: 1.63 -> 1.64
MachineBasicBlock.cpp updated: 1.45 -> 1.46
---
Log message:
Move ReplaceUsesOfBlockWith() out of BranchFolding into a MachineBasicBlock general facility.
---
Diffs of the changes: (+29 -40)
BranchFolding.cpp | 42 ++----------------------------------------
MachineBasicBlock.cpp | 27 +++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 40 deletions(-)
Index: llvm/lib/CodeGen/BranchFolding.cpp
diff -u llvm/lib/CodeGen/BranchFolding.cpp:1.63 llvm/lib/CodeGen/BranchFolding.cpp:1.64
--- llvm/lib/CodeGen/BranchFolding.cpp:1.63 Fri Jun 1 19:08:15 2007
+++ llvm/lib/CodeGen/BranchFolding.cpp Mon Jun 4 01:44:01 2007
@@ -733,44 +733,6 @@
}
-/// 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 @@
// 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 @@
HasBranchToSelf = true;
} else {
DidChange = true;
- ReplaceUsesOfBlockWith(*PI, MBB, CurTBB, TII);
+ (*PI)->ReplaceUsesOfBlockWith(MBB, CurTBB);
}
}
Index: llvm/lib/CodeGen/MachineBasicBlock.cpp
diff -u llvm/lib/CodeGen/MachineBasicBlock.cpp:1.45 llvm/lib/CodeGen/MachineBasicBlock.cpp:1.46
--- llvm/lib/CodeGen/MachineBasicBlock.cpp:1.45 Thu May 17 18:58:53 2007
+++ llvm/lib/CodeGen/MachineBasicBlock.cpp Mon Jun 4 01:44:01 2007
@@ -198,3 +198,30 @@
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);
+}
+
More information about the llvm-commits
mailing list