-//
-// Consider coalescing adjacent segments to save space, even though it makes
-// extraction more complicated.
-void LiveIntervalUnion::unify(LiveInterval &lvr) {
- // Add this live virtual register to the union
- LiveVirtRegs::iterator pos = std::upper_bound(lvrs_.begin(), lvrs_.end(),
- &lvr, less_ptr<LiveInterval>());
- assert((pos == lvrs_.end() || *pos != &lvr) && "duplicate LVR insertion");
- lvrs_.insert(pos, &lvr);
- // Insert each of the virtual register's live segments into the map
- SegmentIter segPos = segments_.begin();
- for (LiveInterval::iterator lvrI = lvr.begin(), lvrEnd = lvr.end();
- lvrI != lvrEnd; ++lvrI ) {
- LiveSegment segment(lvrI->start, lvrI->end, lvr);
- segPos = segments_.insert(segPos, segment);
- assert(*segPos == segment && "need equal val for equal key");
-#ifndef NDEBUG
- // check for overlap (inductively)
- if (segPos != segments_.begin()) {
- SegmentIter prevPos = segPos;
- --prevPos;
- assert(prevPos->end <= segment.start && "overlapping segments" );
- }
- SegmentIter nextPos = segPos;
- ++nextPos;
- if (nextPos != segments_.end())
- assert(segment.end <= nextPos->start && "overlapping segments" );
-#endif // NDEBUG
+void LiveIntervalUnion::unify(LiveInterval &VirtReg, const LiveRange &Range) {
+ if (Range.empty())
+ return;
+ ++Tag;
+
+ // Insert each of the virtual register's live segments into the map.
+ LiveRange::const_iterator RegPos = Range.begin();
+ LiveRange::const_iterator RegEnd = Range.end();
+ SegmentIter SegPos = Segments.find(RegPos->start);
+
+ while (SegPos.valid()) {
+ SegPos.insert(RegPos->start, RegPos->end, &VirtReg);
+ if (++RegPos == RegEnd)
+ return;
+ SegPos.advanceTo(RegPos->start);