- while (MBB.front()->getOpcode() == TargetInstrInfo::PHI) {
- MachineInstr *MI = MBB.front();
- // Unlink the PHI node from the basic block... but don't delete the PHI yet
- MBB.erase(MBB.begin());
+ // VRegPHIUseCount - Keep track of the number of times each virtual register
+ // is used by PHI nodes in successors of this block.
+ DenseMap<unsigned, VirtReg2IndexFunctor> VRegPHIUseCount;
+ VRegPHIUseCount.grow(MF.getSSARegMap()->getLastVirtReg());
+
+ unsigned BBIsSuccOfPreds = 0; // Number of times MBB is a succ of preds
+ for (MachineBasicBlock::pred_iterator PI = MBB.pred_begin(),
+ E = MBB.pred_end(); PI != E; ++PI)
+ for (MachineBasicBlock::succ_iterator SI = (*PI)->succ_begin(),
+ E = (*PI)->succ_end(); SI != E; ++SI) {
+ BBIsSuccOfPreds += *SI == &MBB;
+ for (MachineBasicBlock::iterator BBI = (*SI)->begin(); BBI !=(*SI)->end() &&
+ BBI->getOpcode() == TargetInstrInfo::PHI; ++BBI)
+ for (unsigned i = 1, e = BBI->getNumOperands(); i != e; i += 2)
+ VRegPHIUseCount[BBI->getOperand(i).getReg()]++;
+ }