+/// InsertCopies - insert copies into MBB and all of its successors
+void StrongPHIElimination::InsertCopies(MachineBasicBlock* MBB) {
+ std::set<unsigned> pushed;
+
+ // Rewrite register uses from Stacks
+ for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end();
+ I != E; ++I)
+ for (unsigned i = 0; i < I->getNumOperands(); ++i)
+ if (I->getOperand(i).isRegister() &&
+ Stacks[I->getOperand(i).getReg()].size()) {
+ I->getOperand(i).setReg(Stacks[I->getOperand(i).getReg()].back());
+ }
+
+ // Schedule the copies for this block
+ ScheduleCopies(MBB, pushed);
+
+ // Recur to our successors
+ for (GraphTraits<MachineBasicBlock*>::ChildIteratorType I =
+ GraphTraits<MachineBasicBlock*>::child_begin(MBB), E =
+ GraphTraits<MachineBasicBlock*>::child_end(MBB); I != E; ++I)
+ InsertCopies(*I);
+
+ // As we exit this block, pop the names we pushed while processing it
+ for (std::set<unsigned>::iterator I = pushed.begin(),
+ E = pushed.end(); I != E; ++I)
+ Stacks[*I].pop_back();
+}
+