1 //===-- LiveInterval.cpp - Live Interval Representation -------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the LiveRange and LiveInterval classes. Given some
11 // numbering of each the machine instructions an interval [i, j) is said to be a
12 // live interval for register v if there is no instruction with number j' > j
13 // such that v is live at j' and there is no instruction with number i' < i such
14 // that v is live at i'. In this implementation intervals can have holes,
15 // i.e. an interval might look like [1,20), [50,65), [1000,1001). Each
16 // individual range is represented as an instance of LiveRange, and the whole
17 // interval is represented as an instance of LiveInterval.
19 //===----------------------------------------------------------------------===//
21 #include "llvm/CodeGen/LiveInterval.h"
22 #include "llvm/CodeGen/LiveIntervalAnalysis.h"
23 #include "llvm/CodeGen/MachineRegisterInfo.h"
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/SmallSet.h"
26 #include "llvm/ADT/STLExtras.h"
27 #include "llvm/Support/Debug.h"
28 #include "llvm/Support/raw_ostream.h"
29 #include "llvm/Target/TargetRegisterInfo.h"
33 // An example for liveAt():
35 // this = [1,4), liveAt(0) will return false. The instruction defining this
36 // spans slots [0,3]. The interval belongs to an spilled definition of the
37 // variable it represents. This is because slot 1 is used (def slot) and spans
38 // up to slot 3 (store slot).
40 bool LiveInterval::liveAt(SlotIndex I) const {
41 Ranges::const_iterator r = std::upper_bound(ranges.begin(), ranges.end(), I);
43 if (r == ranges.begin())
47 return r->contains(I);
50 // liveBeforeAndAt - Check if the interval is live at the index and the index
51 // just before it. If index is liveAt, check if it starts a new live range.
52 // If it does, then check if the previous live range ends at index-1.
53 bool LiveInterval::liveBeforeAndAt(SlotIndex I) const {
54 Ranges::const_iterator r = std::upper_bound(ranges.begin(), ranges.end(), I);
56 if (r == ranges.begin())
64 // I is the start of a live range. Check if the previous live range ends
66 if (r == ranges.begin())
71 /// killedAt - Return true if a live range ends at index. Note that the kill
72 /// point is not contained in the half-open live range. It is usually the
73 /// getDefIndex() slot following its last use.
74 bool LiveInterval::killedAt(SlotIndex I) const {
75 Ranges::const_iterator r = std::lower_bound(ranges.begin(), ranges.end(), I);
77 // Now r points to the first interval with start >= I, or ranges.end().
78 if (r == ranges.begin())
82 // Now r points to the last interval with end <= I.
83 // r->end is the kill point.
87 /// killedInRange - Return true if the interval has kills in [Start,End).
88 bool LiveInterval::killedInRange(SlotIndex Start, SlotIndex End) const {
89 Ranges::const_iterator r =
90 std::lower_bound(ranges.begin(), ranges.end(), End);
92 // Now r points to the first interval with start >= End, or ranges.end().
93 if (r == ranges.begin())
97 // Now r points to the last interval with end <= End.
98 // r->end is the kill point.
99 return r->end >= Start && r->end < End;
102 // overlaps - Return true if the intersection of the two live intervals is
105 // An example for overlaps():
109 // 8: C = A + B ;; last use of A
111 // The live intervals should look like:
117 // A->overlaps(C) should return false since we want to be able to join
120 bool LiveInterval::overlapsFrom(const LiveInterval& other,
121 const_iterator StartPos) const {
122 const_iterator i = begin();
123 const_iterator ie = end();
124 const_iterator j = StartPos;
125 const_iterator je = other.end();
127 assert((StartPos->start <= i->start || StartPos == other.begin()) &&
128 StartPos != other.end() && "Bogus start position hint!");
130 if (i->start < j->start) {
131 i = std::upper_bound(i, ie, j->start);
132 if (i != ranges.begin()) --i;
133 } else if (j->start < i->start) {
135 if (StartPos != other.end() && StartPos->start <= i->start) {
136 assert(StartPos < other.end() && i < end());
137 j = std::upper_bound(j, je, i->start);
138 if (j != other.ranges.begin()) --j;
144 if (j == je) return false;
147 if (i->start > j->start) {
152 if (i->end > j->start)
160 /// overlaps - Return true if the live interval overlaps a range specified
162 bool LiveInterval::overlaps(SlotIndex Start, SlotIndex End) const {
163 assert(Start < End && "Invalid range");
164 const_iterator I = begin();
165 const_iterator E = end();
166 const_iterator si = std::upper_bound(I, E, Start);
167 const_iterator ei = std::upper_bound(I, E, End);
173 return si->contains(Start);
176 /// extendIntervalEndTo - This method is used when we want to extend the range
177 /// specified by I to end at the specified endpoint. To do this, we should
178 /// merge and eliminate all ranges that this will overlap with. The iterator is
180 void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) {
181 assert(I != ranges.end() && "Not a valid interval!");
182 VNInfo *ValNo = I->valno;
184 // Search for the first interval that we can't merge with.
185 Ranges::iterator MergeTo = next(I);
186 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
187 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
190 // If NewEnd was in the middle of an interval, make sure to get its endpoint.
191 I->end = std::max(NewEnd, prior(MergeTo)->end);
193 // Erase any dead ranges.
194 ranges.erase(next(I), MergeTo);
196 // If the newly formed range now touches the range after it and if they have
197 // the same value number, merge the two ranges into one range.
198 Ranges::iterator Next = next(I);
199 if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) {
206 /// extendIntervalStartTo - This method is used when we want to extend the range
207 /// specified by I to start at the specified endpoint. To do this, we should
208 /// merge and eliminate all ranges that this will overlap with.
209 LiveInterval::Ranges::iterator
210 LiveInterval::extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStart) {
211 assert(I != ranges.end() && "Not a valid interval!");
212 VNInfo *ValNo = I->valno;
214 // Search for the first interval that we can't merge with.
215 Ranges::iterator MergeTo = I;
217 if (MergeTo == ranges.begin()) {
219 ranges.erase(MergeTo, I);
222 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
224 } while (NewStart <= MergeTo->start);
226 // If we start in the middle of another interval, just delete a range and
227 // extend that interval.
228 if (MergeTo->end >= NewStart && MergeTo->valno == ValNo) {
229 MergeTo->end = I->end;
231 // Otherwise, extend the interval right after.
233 MergeTo->start = NewStart;
234 MergeTo->end = I->end;
237 ranges.erase(next(MergeTo), next(I));
241 LiveInterval::iterator
242 LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
243 SlotIndex Start = LR.start, End = LR.end;
244 iterator it = std::upper_bound(From, ranges.end(), Start);
246 // If the inserted interval starts in the middle or right at the end of
247 // another interval, just extend that interval to contain the range of LR.
248 if (it != ranges.begin()) {
249 iterator B = prior(it);
250 if (LR.valno == B->valno) {
251 if (B->start <= Start && B->end >= Start) {
252 extendIntervalEndTo(B, End);
256 // Check to make sure that we are not overlapping two live ranges with
257 // different valno's.
258 assert(B->end <= Start &&
259 "Cannot overlap two LiveRanges with differing ValID's"
260 " (did you def the same reg twice in a MachineInstr?)");
264 // Otherwise, if this range ends in the middle of, or right next to, another
265 // interval, merge it into that interval.
266 if (it != ranges.end()) {
267 if (LR.valno == it->valno) {
268 if (it->start <= End) {
269 it = extendIntervalStartTo(it, Start);
271 // If LR is a complete superset of an interval, we may need to grow its
274 extendIntervalEndTo(it, End);
278 // Check to make sure that we are not overlapping two live ranges with
279 // different valno's.
280 assert(it->start >= End &&
281 "Cannot overlap two LiveRanges with differing ValID's");
285 // Otherwise, this is just a new range that doesn't interact with anything.
287 return ranges.insert(it, LR);
290 /// isInOneLiveRange - Return true if the range specified is entirely in
291 /// a single LiveRange of the live interval.
292 bool LiveInterval::isInOneLiveRange(SlotIndex Start, SlotIndex End) {
293 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
294 if (I == ranges.begin())
297 return I->containsRange(Start, End);
301 /// removeRange - Remove the specified range from this interval. Note that
302 /// the range must be in a single LiveRange in its entirety.
303 void LiveInterval::removeRange(SlotIndex Start, SlotIndex End,
304 bool RemoveDeadValNo) {
305 // Find the LiveRange containing this span.
306 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
307 assert(I != ranges.begin() && "Range is not in interval!");
309 assert(I->containsRange(Start, End) && "Range is not entirely in interval!");
311 // If the span we are removing is at the start of the LiveRange, adjust it.
312 VNInfo *ValNo = I->valno;
313 if (I->start == Start) {
315 if (RemoveDeadValNo) {
316 // Check if val# is dead.
318 for (const_iterator II = begin(), EE = end(); II != EE; ++II)
319 if (II != I && II->valno == ValNo) {
324 // Now that ValNo is dead, remove it. If it is the largest value
325 // number, just nuke it (and any other deleted values neighboring it),
326 // otherwise mark it as ~1U so it can be nuked later.
327 if (ValNo->id == getNumValNums()-1) {
330 } while (!valnos.empty() && valnos.back()->isUnused());
332 ValNo->setIsUnused(true);
337 ranges.erase(I); // Removed the whole LiveRange.
343 // Otherwise if the span we are removing is at the end of the LiveRange,
344 // adjust the other way.
350 // Otherwise, we are splitting the LiveRange into two pieces.
351 SlotIndex OldEnd = I->end;
352 I->end = Start; // Trim the old interval.
354 // Insert the new one.
355 ranges.insert(next(I), LiveRange(End, OldEnd, ValNo));
358 /// removeValNo - Remove all the ranges defined by the specified value#.
359 /// Also remove the value# from value# list.
360 void LiveInterval::removeValNo(VNInfo *ValNo) {
362 Ranges::iterator I = ranges.end();
363 Ranges::iterator E = ranges.begin();
366 if (I->valno == ValNo)
369 // Now that ValNo is dead, remove it. If it is the largest value
370 // number, just nuke it (and any other deleted values neighboring it),
371 // otherwise mark it as ~1U so it can be nuked later.
372 if (ValNo->id == getNumValNums()-1) {
375 } while (!valnos.empty() && valnos.back()->isUnused());
377 ValNo->setIsUnused(true);
381 /// getLiveRangeContaining - Return the live range that contains the
382 /// specified index, or null if there is none.
383 LiveInterval::const_iterator
384 LiveInterval::FindLiveRangeContaining(SlotIndex Idx) const {
385 const_iterator It = std::upper_bound(begin(), end(), Idx);
386 if (It != ranges.begin()) {
388 if (It->contains(Idx))
395 LiveInterval::iterator
396 LiveInterval::FindLiveRangeContaining(SlotIndex Idx) {
397 iterator It = std::upper_bound(begin(), end(), Idx);
400 if (It->contains(Idx))
407 /// findDefinedVNInfo - Find the VNInfo defined by the specified
408 /// index (register interval).
409 VNInfo *LiveInterval::findDefinedVNInfoForRegInt(SlotIndex Idx) const {
410 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
412 if ((*i)->def == Idx)
419 /// findDefinedVNInfo - Find the VNInfo defined by the specified
420 /// register (stack inteval).
421 VNInfo *LiveInterval::findDefinedVNInfoForStackInt(unsigned reg) const {
422 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
424 if ((*i)->getReg() == reg)
430 /// join - Join two live intervals (this, and other) together. This applies
431 /// mappings to the value numbers in the LHS/RHS intervals as specified. If
432 /// the intervals are not joinable, this aborts.
433 void LiveInterval::join(LiveInterval &Other,
434 const int *LHSValNoAssignments,
435 const int *RHSValNoAssignments,
436 SmallVector<VNInfo*, 16> &NewVNInfo,
437 MachineRegisterInfo *MRI) {
438 // Determine if any of our live range values are mapped. This is uncommon, so
439 // we want to avoid the interval scan if not.
440 bool MustMapCurValNos = false;
441 unsigned NumVals = getNumValNums();
442 unsigned NumNewVals = NewVNInfo.size();
443 for (unsigned i = 0; i != NumVals; ++i) {
444 unsigned LHSValID = LHSValNoAssignments[i];
446 (NewVNInfo[LHSValID] && NewVNInfo[LHSValID] != getValNumInfo(i)))
447 MustMapCurValNos = true;
450 // If we have to apply a mapping to our base interval assignment, rewrite it
452 if (MustMapCurValNos) {
453 // Map the first live range.
454 iterator OutIt = begin();
455 OutIt->valno = NewVNInfo[LHSValNoAssignments[OutIt->valno->id]];
457 for (iterator I = OutIt, E = end(); I != E; ++I) {
458 OutIt->valno = NewVNInfo[LHSValNoAssignments[I->valno->id]];
460 // If this live range has the same value # as its immediate predecessor,
461 // and if they are neighbors, remove one LiveRange. This happens when we
462 // have [0,3:0)[4,7:1) and map 0/1 onto the same value #.
463 if (OutIt->valno == (OutIt-1)->valno && (OutIt-1)->end == OutIt->start) {
464 (OutIt-1)->end = OutIt->end;
467 OutIt->start = I->start;
471 // Didn't merge, on to the next one.
476 // If we merge some live ranges, chop off the end.
477 ranges.erase(OutIt, end());
480 // Remember assignements because val# ids are changing.
481 SmallVector<unsigned, 16> OtherAssignments;
482 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
483 OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]);
485 // Update val# info. Renumber them and make sure they all belong to this
486 // LiveInterval now. Also remove dead val#'s.
487 unsigned NumValNos = 0;
488 for (unsigned i = 0; i < NumNewVals; ++i) {
489 VNInfo *VNI = NewVNInfo[i];
491 if (NumValNos >= NumVals)
492 valnos.push_back(VNI);
494 valnos[NumValNos] = VNI;
495 VNI->id = NumValNos++; // Renumber val#.
498 if (NumNewVals < NumVals)
499 valnos.resize(NumNewVals); // shrinkify
501 // Okay, now insert the RHS live ranges into the LHS.
502 iterator InsertPos = begin();
503 unsigned RangeNo = 0;
504 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I, ++RangeNo) {
505 // Map the valno in the other live range to the current live range.
506 I->valno = NewVNInfo[OtherAssignments[RangeNo]];
507 assert(I->valno && "Adding a dead range?");
508 InsertPos = addRangeFrom(*I, InsertPos);
511 ComputeJoinedWeight(Other);
513 // Update regalloc hint if currently there isn't one.
514 if (TargetRegisterInfo::isVirtualRegister(reg) &&
515 TargetRegisterInfo::isVirtualRegister(Other.reg)) {
516 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(reg);
517 if (Hint.first == 0 && Hint.second == 0) {
518 std::pair<unsigned, unsigned> OtherHint =
519 MRI->getRegAllocationHint(Other.reg);
520 if (OtherHint.first || OtherHint.second)
521 MRI->setRegAllocationHint(reg, OtherHint.first, OtherHint.second);
526 /// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
527 /// interval as the specified value number. The LiveRanges in RHS are
528 /// allowed to overlap with LiveRanges in the current interval, but only if
529 /// the overlapping LiveRanges have the specified value number.
530 void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS,
532 // TODO: Make this more efficient.
533 iterator InsertPos = begin();
534 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
535 // Map the valno in the other live range to the current live range.
537 Tmp.valno = LHSValNo;
538 InsertPos = addRangeFrom(Tmp, InsertPos);
543 /// MergeValueInAsValue - Merge all of the live ranges of a specific val#
544 /// in RHS into this live interval as the specified value number.
545 /// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
546 /// current interval, it will replace the value numbers of the overlaped
547 /// live ranges with the specified value number.
548 void LiveInterval::MergeValueInAsValue(
549 const LiveInterval &RHS,
550 const VNInfo *RHSValNo, VNInfo *LHSValNo) {
551 SmallVector<VNInfo*, 4> ReplacedValNos;
552 iterator IP = begin();
553 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
554 assert(I->valno == RHS.getValNumInfo(I->valno->id) && "Bad VNInfo");
555 if (I->valno != RHSValNo)
557 SlotIndex Start = I->start, End = I->end;
558 IP = std::upper_bound(IP, end(), Start);
559 // If the start of this range overlaps with an existing liverange, trim it.
560 if (IP != begin() && IP[-1].end > Start) {
561 if (IP[-1].valno != LHSValNo) {
562 ReplacedValNos.push_back(IP[-1].valno);
563 IP[-1].valno = LHSValNo; // Update val#.
566 // Trimmed away the whole range?
567 if (Start >= End) continue;
569 // If the end of this range overlaps with an existing liverange, trim it.
570 if (IP != end() && End > IP->start) {
571 if (IP->valno != LHSValNo) {
572 ReplacedValNos.push_back(IP->valno);
573 IP->valno = LHSValNo; // Update val#.
576 // If this trimmed away the whole range, ignore it.
577 if (Start == End) continue;
580 // Map the valno in the other live range to the current live range.
581 IP = addRangeFrom(LiveRange(Start, End, LHSValNo), IP);
585 SmallSet<VNInfo*, 4> Seen;
586 for (unsigned i = 0, e = ReplacedValNos.size(); i != e; ++i) {
587 VNInfo *V1 = ReplacedValNos[i];
588 if (Seen.insert(V1)) {
590 for (const_iterator I = begin(), E = end(); I != E; ++I)
591 if (I->valno == V1) {
596 // Now that V1 is dead, remove it. If it is the largest value number,
597 // just nuke it (and any other deleted values neighboring it), otherwise
598 // mark it as ~1U so it can be nuked later.
599 if (V1->id == getNumValNums()-1) {
602 } while (!valnos.empty() && valnos.back()->isUnused());
604 V1->setIsUnused(true);
612 /// MergeInClobberRanges - For any live ranges that are not defined in the
613 /// current interval, but are defined in the Clobbers interval, mark them
614 /// used with an unknown definition value.
615 void LiveInterval::MergeInClobberRanges(LiveIntervals &li_,
616 const LiveInterval &Clobbers,
617 VNInfo::Allocator &VNInfoAllocator) {
618 if (Clobbers.empty()) return;
620 DenseMap<VNInfo*, VNInfo*> ValNoMaps;
621 VNInfo *UnusedValNo = 0;
622 iterator IP = begin();
623 for (const_iterator I = Clobbers.begin(), E = Clobbers.end(); I != E; ++I) {
624 // For every val# in the Clobbers interval, create a new "unknown" val#.
625 VNInfo *ClobberValNo = 0;
626 DenseMap<VNInfo*, VNInfo*>::iterator VI = ValNoMaps.find(I->valno);
627 if (VI != ValNoMaps.end())
628 ClobberValNo = VI->second;
629 else if (UnusedValNo)
630 ClobberValNo = UnusedValNo;
632 UnusedValNo = ClobberValNo =
633 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
634 ValNoMaps.insert(std::make_pair(I->valno, ClobberValNo));
638 SlotIndex Start = I->start, End = I->end;
639 // If a clobber range starts before an existing range and ends after
640 // it, the clobber range will need to be split into multiple ranges.
641 // Loop until the entire clobber range is handled.
644 IP = std::upper_bound(IP, end(), Start);
645 SlotIndex SubRangeStart = Start;
646 SlotIndex SubRangeEnd = End;
648 // If the start of this range overlaps with an existing liverange, trim it.
649 if (IP != begin() && IP[-1].end > SubRangeStart) {
650 SubRangeStart = IP[-1].end;
651 // Trimmed away the whole range?
652 if (SubRangeStart >= SubRangeEnd) continue;
654 // If the end of this range overlaps with an existing liverange, trim it.
655 if (IP != end() && SubRangeEnd > IP->start) {
656 // If the clobber live range extends beyond the existing live range,
657 // it'll need at least another live range, so set the flag to keep
659 if (SubRangeEnd > IP->end) {
663 SubRangeEnd = IP->start;
664 // If this trimmed away the whole range, ignore it.
665 if (SubRangeStart == SubRangeEnd) continue;
668 // Insert the clobber interval.
669 IP = addRangeFrom(LiveRange(SubRangeStart, SubRangeEnd, ClobberValNo),
676 // Delete the last unused val#.
681 void LiveInterval::MergeInClobberRange(LiveIntervals &li_,
684 VNInfo::Allocator &VNInfoAllocator) {
685 // Find a value # to use for the clobber ranges. If there is already a value#
686 // for unknown values, use it.
687 VNInfo *ClobberValNo =
688 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
690 iterator IP = begin();
691 IP = std::upper_bound(IP, end(), Start);
693 // If the start of this range overlaps with an existing liverange, trim it.
694 if (IP != begin() && IP[-1].end > Start) {
696 // Trimmed away the whole range?
697 if (Start >= End) return;
699 // If the end of this range overlaps with an existing liverange, trim it.
700 if (IP != end() && End > IP->start) {
702 // If this trimmed away the whole range, ignore it.
703 if (Start == End) return;
706 // Insert the clobber interval.
707 addRangeFrom(LiveRange(Start, End, ClobberValNo), IP);
710 /// MergeValueNumberInto - This method is called when two value nubmers
711 /// are found to be equivalent. This eliminates V1, replacing all
712 /// LiveRanges with the V1 value number with the V2 value number. This can
713 /// cause merging of V1/V2 values numbers and compaction of the value space.
714 VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
715 assert(V1 != V2 && "Identical value#'s are always equivalent!");
717 // This code actually merges the (numerically) larger value number into the
718 // smaller value number, which is likely to allow us to compactify the value
719 // space. The only thing we have to be careful of is to preserve the
720 // instruction that defines the result value.
722 // Make sure V2 is smaller than V1.
723 if (V1->id < V2->id) {
728 // Merge V1 live ranges into V2.
729 for (iterator I = begin(); I != end(); ) {
731 if (LR->valno != V1) continue; // Not a V1 LiveRange.
733 // Okay, we found a V1 live range. If it had a previous, touching, V2 live
736 iterator Prev = LR-1;
737 if (Prev->valno == V2 && Prev->end == LR->start) {
740 // Erase this live-range.
747 // Okay, now we have a V1 or V2 live range that is maximally merged forward.
748 // Ensure that it is a V2 live-range.
751 // If we can merge it into later V2 live ranges, do so now. We ignore any
752 // following V1 live ranges, as they will be merged in subsequent iterations
755 if (I->start == LR->end && I->valno == V2) {
763 // Now that V1 is dead, remove it. If it is the largest value number, just
764 // nuke it (and any other deleted values neighboring it), otherwise mark it as
765 // ~1U so it can be nuked later.
766 if (V1->id == getNumValNums()-1) {
769 } while (valnos.back()->isUnused());
771 V1->setIsUnused(true);
777 void LiveInterval::Copy(const LiveInterval &RHS,
778 MachineRegisterInfo *MRI,
779 VNInfo::Allocator &VNInfoAllocator) {
782 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(RHS.reg);
783 MRI->setRegAllocationHint(reg, Hint.first, Hint.second);
786 for (unsigned i = 0, e = RHS.getNumValNums(); i != e; ++i) {
787 const VNInfo *VNI = RHS.getValNumInfo(i);
788 createValueCopy(VNI, VNInfoAllocator);
790 for (unsigned i = 0, e = RHS.ranges.size(); i != e; ++i) {
791 const LiveRange &LR = RHS.ranges[i];
792 addRange(LiveRange(LR.start, LR.end, getValNumInfo(LR.valno->id)));
796 unsigned LiveInterval::getSize() const {
798 for (const_iterator I = begin(), E = end(); I != E; ++I)
799 Sum += I->start.distance(I->end);
803 /// ComputeJoinedWeight - Set the weight of a live interval Joined
804 /// after Other has been merged into it.
805 void LiveInterval::ComputeJoinedWeight(const LiveInterval &Other) {
806 // If either of these intervals was spilled, the weight is the
807 // weight of the non-spilled interval. This can only happen with
808 // iterative coalescers.
810 if (Other.weight != HUGE_VALF) {
811 weight += Other.weight;
813 else if (weight == HUGE_VALF &&
814 !TargetRegisterInfo::isPhysicalRegister(reg)) {
815 // Remove this assert if you have an iterative coalescer
816 assert(0 && "Joining to spilled interval");
817 weight = Other.weight;
820 // Otherwise the weight stays the same
821 // Remove this assert if you have an iterative coalescer
822 assert(0 && "Joining from spilled interval");
826 raw_ostream& llvm::operator<<(raw_ostream& os, const LiveRange &LR) {
827 return os << '[' << LR.start << ',' << LR.end << ':' << LR.valno->id << ")";
830 void LiveRange::dump() const {
831 dbgs() << *this << "\n";
834 void LiveInterval::print(raw_ostream &OS, const TargetRegisterInfo *TRI) const {
836 OS << "SS#" << getStackSlotIndex();
837 else if (TRI && TargetRegisterInfo::isPhysicalRegister(reg))
838 OS << TRI->getName(reg);
848 for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
849 E = ranges.end(); I != E; ++I) {
851 assert(I->valno == getValNumInfo(I->valno->id) && "Bad VNInfo");
855 // Print value number info.
856 if (getNumValNums()) {
859 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
861 const VNInfo *vni = *i;
864 if (vni->isUnused()) {
867 if (!vni->isDefAccurate() && !vni->isPHIDef())
876 void LiveInterval::dump() const {
877 dbgs() << *this << "\n";
881 void LiveRange::print(raw_ostream &os) const {