- if (RenameSets.count(SI->first)) {
- I->second.insert(RenameSets[SI->first].begin(),
- RenameSets[SI->first].end());
- RenameSets.erase(SI->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";