- for (std::map<unsigned, unsigned>::iterator SI = I->second.begin(),
- SE = I->second.end(); SI != SE; ++SI) {
- mergeLiveIntervals(I->first, SI->first, SI->second);
- Fn.getRegInfo().replaceRegWith(SI->first, I->first);
+ while (I->second.size()) {
+ std::map<unsigned, MachineBasicBlock*>::iterator SI = I->second.begin();
+
+ DOUT << "Renaming: " << SI->first << " -> " << I->first << "\n";
+
+ if (SI->first != I->first) {
+ if (mergeLiveIntervals(I->first, SI->first)) {
+ Fn.getRegInfo().replaceRegWith(SI->first, I->first);
+
+ if (RenameSets.count(SI->first)) {
+ I->second.insert(RenameSets[SI->first].begin(),
+ RenameSets[SI->first].end());
+ RenameSets.erase(SI->first);
+ }
+ } else {
+ // Insert a last-minute copy if a conflict was detected.
+ const TargetInstrInfo *TII = Fn.getTarget().getInstrInfo();
+ const TargetRegisterClass *RC = Fn.getRegInfo().getRegClass(I->first);
+ TII->copyRegToReg(*SI->second, SI->second->getFirstTerminator(),
+ I->first, SI->first, RC, RC);
+
+ LI.computeNumbering();
+
+ LiveInterval& Int = LI.getOrCreateInterval(I->first);
+ unsigned instrIdx =
+ LI.getInstructionIndex(--SI->second->getFirstTerminator());
+ if (Int.liveAt(LiveIntervals::getDefIndex(instrIdx)))
+ Int.removeRange(LiveIntervals::getDefIndex(instrIdx),
+ LI.getMBBEndIdx(SI->second)+1, true);
+
+ LiveRange R = LI.addLiveRangeToEndOfBlock(I->first,
+ --SI->second->getFirstTerminator());
+ R.valno->copy = --SI->second->getFirstTerminator();
+ R.valno->def = LiveIntervals::getDefIndex(instrIdx);
+
+ DOUT << "Renaming failed: " << SI->first << " -> "
+ << I->first << "\n";
+ }
+ }
+
+ LiveInterval& Int = LI.getOrCreateInterval(I->first);
+ const LiveRange* LR =
+ Int.getLiveRangeContaining(LI.getMBBEndIdx(SI->second));
+ LR->valno->hasPHIKill = true;
+
+ I->second.erase(SI->first);