+/// ShortenDeadCopyLiveRange - Shorten a live range as it's artificially
+/// extended by a dead copy. Mark the last use (if any) of the val# as kill
+/// as ends the live range there. If there isn't another use, then this
+/// live range is dead.
+void SimpleRegisterCoalescing::ShortenDeadCopyLiveRange(LiveInterval &li,
+ MachineInstr *CopyMI) {
+ unsigned CopyIdx = li_->getInstructionIndex(CopyMI);
+ LiveInterval::iterator MLR =
+ li.FindLiveRangeContaining(li_->getDefIndex(CopyIdx));
+ unsigned RemoveStart = MLR->start;
+ unsigned RemoveEnd = MLR->end;
+ unsigned LastUseIdx;
+ MachineOperand *LastUse = lastRegisterUse(RemoveStart, CopyIdx, li.reg,
+ LastUseIdx);
+ if (LastUse) {
+ // Shorten the liveinterval to the end of last use.
+ LastUse->setIsKill();
+ RemoveStart = li_->getDefIndex(LastUseIdx);
+ }
+ li.removeRange(RemoveStart, RemoveEnd, true);
+ if (li.empty())
+ li_->removeInterval(li.reg);
+}
+