- li_->updateSpilledInterval(*cur, slot);
-
- // if we didn't eliminate the interval find where to add it
- // back to unhandled. We need to scan since unhandled are
- // sorted on earliest start point and we may have changed our
- // start point.
- if (!cur->empty()) {
- IntervalPtrs::iterator it = unhandled_.begin();
- while (it != unhandled_.end() && (*it)->start() < cur->start())
- ++it;
- unhandled_.insert(it, cur);
+ std::vector<LiveInterval*> added =
+ li_->addIntervalsForSpills(*cur, *vrm_, slot);
+ if (added.empty())
+ return; // Early exit if all spills were folded.
+#ifndef NDEBUG
+ int OldStart = -1;
+#endif
+
+ // Merge added with unhandled. Note that we know that
+ // addIntervalsForSpills returns intervals sorted by their starting
+ // point.
+ std::vector<LiveInterval*>::iterator addedIt = added.begin();
+ std::vector<LiveInterval*>::iterator addedItEnd = added.end();
+ for (IntervalPtrs::iterator i = unhandled_.begin(), e =unhandled_.end();
+ i != e && addedIt != addedItEnd; ++i) {
+ while (addedIt != addedItEnd &&
+ (*i)->start() > (*addedIt)->start()) {
+#ifndef NDEBUG
+ // This code only works if addIntervalsForSpills retursn a
+ // sorted interval list. Assert this is the case now.
+ assert(OldStart <= (int)(*addedIt)->start() &&
+ "addIntervalsForSpills didn't return sorted interval list!");
+ OldStart = (*addedIt)->start();
+#endif
+ i = unhandled_.insert(i, *(addedIt++));
+ }
+ }
+
+ while (addedIt != addedItEnd) {
+#ifndef NDEBUG
+ // This code only works if addIntervalsForSpills retursn a
+ // sorted interval list. Assert this is the case now.
+ assert(OldStart <= (int)(*addedIt)->start() &&
+ "addIntervalsForSpills didn't return sorted interval list!");
+ OldStart = (*addedIt)->start();
+#endif
+ unhandled_.push_back(*(addedIt++));