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 assert(!empty() && "empty interval");
123 const_iterator i = begin();
124 const_iterator ie = end();
125 const_iterator j = StartPos;
126 const_iterator je = other.end();
128 assert((StartPos->start <= i->start || StartPos == other.begin()) &&
129 StartPos != other.end() && "Bogus start position hint!");
131 if (i->start < j->start) {
132 i = std::upper_bound(i, ie, j->start);
133 if (i != ranges.begin()) --i;
134 } else if (j->start < i->start) {
136 if (StartPos != other.end() && StartPos->start <= i->start) {
137 assert(StartPos < other.end() && i < end());
138 j = std::upper_bound(j, je, i->start);
139 if (j != other.ranges.begin()) --j;
145 if (j == je) return false;
148 if (i->start > j->start) {
153 if (i->end > j->start)
161 /// overlaps - Return true if the live interval overlaps a range specified
163 bool LiveInterval::overlaps(SlotIndex Start, SlotIndex End) const {
164 assert(Start < End && "Invalid range");
165 const_iterator I = std::lower_bound(begin(), end(), End);
166 return I != begin() && (--I)->end > Start;
169 /// extendIntervalEndTo - This method is used when we want to extend the range
170 /// specified by I to end at the specified endpoint. To do this, we should
171 /// merge and eliminate all ranges that this will overlap with. The iterator is
173 void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) {
174 assert(I != ranges.end() && "Not a valid interval!");
175 VNInfo *ValNo = I->valno;
177 // Search for the first interval that we can't merge with.
178 Ranges::iterator MergeTo = next(I);
179 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
180 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
183 // If NewEnd was in the middle of an interval, make sure to get its endpoint.
184 I->end = std::max(NewEnd, prior(MergeTo)->end);
186 // Erase any dead ranges.
187 ranges.erase(next(I), MergeTo);
189 // If the newly formed range now touches the range after it and if they have
190 // the same value number, merge the two ranges into one range.
191 Ranges::iterator Next = next(I);
192 if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) {
199 /// extendIntervalStartTo - This method is used when we want to extend the range
200 /// specified by I to start at the specified endpoint. To do this, we should
201 /// merge and eliminate all ranges that this will overlap with.
202 LiveInterval::Ranges::iterator
203 LiveInterval::extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStart) {
204 assert(I != ranges.end() && "Not a valid interval!");
205 VNInfo *ValNo = I->valno;
207 // Search for the first interval that we can't merge with.
208 Ranges::iterator MergeTo = I;
210 if (MergeTo == ranges.begin()) {
212 ranges.erase(MergeTo, I);
215 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
217 } while (NewStart <= MergeTo->start);
219 // If we start in the middle of another interval, just delete a range and
220 // extend that interval.
221 if (MergeTo->end >= NewStart && MergeTo->valno == ValNo) {
222 MergeTo->end = I->end;
224 // Otherwise, extend the interval right after.
226 MergeTo->start = NewStart;
227 MergeTo->end = I->end;
230 ranges.erase(next(MergeTo), next(I));
234 LiveInterval::iterator
235 LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
236 SlotIndex Start = LR.start, End = LR.end;
237 iterator it = std::upper_bound(From, ranges.end(), Start);
239 // If the inserted interval starts in the middle or right at the end of
240 // another interval, just extend that interval to contain the range of LR.
241 if (it != ranges.begin()) {
242 iterator B = prior(it);
243 if (LR.valno == B->valno) {
244 if (B->start <= Start && B->end >= Start) {
245 extendIntervalEndTo(B, End);
249 // Check to make sure that we are not overlapping two live ranges with
250 // different valno's.
251 assert(B->end <= Start &&
252 "Cannot overlap two LiveRanges with differing ValID's"
253 " (did you def the same reg twice in a MachineInstr?)");
257 // Otherwise, if this range ends in the middle of, or right next to, another
258 // interval, merge it into that interval.
259 if (it != ranges.end()) {
260 if (LR.valno == it->valno) {
261 if (it->start <= End) {
262 it = extendIntervalStartTo(it, Start);
264 // If LR is a complete superset of an interval, we may need to grow its
267 extendIntervalEndTo(it, End);
271 // Check to make sure that we are not overlapping two live ranges with
272 // different valno's.
273 assert(it->start >= End &&
274 "Cannot overlap two LiveRanges with differing ValID's");
278 // Otherwise, this is just a new range that doesn't interact with anything.
280 return ranges.insert(it, LR);
283 /// isInOneLiveRange - Return true if the range specified is entirely in
284 /// a single LiveRange of the live interval.
285 bool LiveInterval::isInOneLiveRange(SlotIndex Start, SlotIndex End) {
286 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
287 if (I == ranges.begin())
290 return I->containsRange(Start, End);
294 /// removeRange - Remove the specified range from this interval. Note that
295 /// the range must be in a single LiveRange in its entirety.
296 void LiveInterval::removeRange(SlotIndex Start, SlotIndex End,
297 bool RemoveDeadValNo) {
298 // Find the LiveRange containing this span.
299 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
300 assert(I != ranges.begin() && "Range is not in interval!");
302 assert(I->containsRange(Start, End) && "Range is not entirely in interval!");
304 // If the span we are removing is at the start of the LiveRange, adjust it.
305 VNInfo *ValNo = I->valno;
306 if (I->start == Start) {
308 if (RemoveDeadValNo) {
309 // Check if val# is dead.
311 for (const_iterator II = begin(), EE = end(); II != EE; ++II)
312 if (II != I && II->valno == ValNo) {
317 // Now that ValNo is dead, remove it. If it is the largest value
318 // number, just nuke it (and any other deleted values neighboring it),
319 // otherwise mark it as ~1U so it can be nuked later.
320 if (ValNo->id == getNumValNums()-1) {
323 } while (!valnos.empty() && valnos.back()->isUnused());
325 ValNo->setIsUnused(true);
330 ranges.erase(I); // Removed the whole LiveRange.
336 // Otherwise if the span we are removing is at the end of the LiveRange,
337 // adjust the other way.
343 // Otherwise, we are splitting the LiveRange into two pieces.
344 SlotIndex OldEnd = I->end;
345 I->end = Start; // Trim the old interval.
347 // Insert the new one.
348 ranges.insert(next(I), LiveRange(End, OldEnd, ValNo));
351 /// removeValNo - Remove all the ranges defined by the specified value#.
352 /// Also remove the value# from value# list.
353 void LiveInterval::removeValNo(VNInfo *ValNo) {
355 Ranges::iterator I = ranges.end();
356 Ranges::iterator E = ranges.begin();
359 if (I->valno == ValNo)
362 // Now that ValNo is dead, remove it. If it is the largest value
363 // number, just nuke it (and any other deleted values neighboring it),
364 // otherwise mark it as ~1U so it can be nuked later.
365 if (ValNo->id == getNumValNums()-1) {
368 } while (!valnos.empty() && valnos.back()->isUnused());
370 ValNo->setIsUnused(true);
374 /// getLiveRangeContaining - Return the live range that contains the
375 /// specified index, or null if there is none.
376 LiveInterval::const_iterator
377 LiveInterval::FindLiveRangeContaining(SlotIndex Idx) const {
378 const_iterator It = std::upper_bound(begin(), end(), Idx);
379 if (It != ranges.begin()) {
381 if (It->contains(Idx))
388 LiveInterval::iterator
389 LiveInterval::FindLiveRangeContaining(SlotIndex Idx) {
390 iterator It = std::upper_bound(begin(), end(), Idx);
393 if (It->contains(Idx))
400 /// findDefinedVNInfo - Find the VNInfo defined by the specified
401 /// index (register interval).
402 VNInfo *LiveInterval::findDefinedVNInfoForRegInt(SlotIndex Idx) const {
403 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
405 if ((*i)->def == Idx)
412 /// findDefinedVNInfo - Find the VNInfo defined by the specified
413 /// register (stack inteval).
414 VNInfo *LiveInterval::findDefinedVNInfoForStackInt(unsigned reg) const {
415 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
417 if ((*i)->getReg() == reg)
423 /// join - Join two live intervals (this, and other) together. This applies
424 /// mappings to the value numbers in the LHS/RHS intervals as specified. If
425 /// the intervals are not joinable, this aborts.
426 void LiveInterval::join(LiveInterval &Other,
427 const int *LHSValNoAssignments,
428 const int *RHSValNoAssignments,
429 SmallVector<VNInfo*, 16> &NewVNInfo,
430 MachineRegisterInfo *MRI) {
431 // Determine if any of our live range values are mapped. This is uncommon, so
432 // we want to avoid the interval scan if not.
433 bool MustMapCurValNos = false;
434 unsigned NumVals = getNumValNums();
435 unsigned NumNewVals = NewVNInfo.size();
436 for (unsigned i = 0; i != NumVals; ++i) {
437 unsigned LHSValID = LHSValNoAssignments[i];
439 (NewVNInfo[LHSValID] && NewVNInfo[LHSValID] != getValNumInfo(i)))
440 MustMapCurValNos = true;
443 // If we have to apply a mapping to our base interval assignment, rewrite it
445 if (MustMapCurValNos) {
446 // Map the first live range.
447 iterator OutIt = begin();
448 OutIt->valno = NewVNInfo[LHSValNoAssignments[OutIt->valno->id]];
450 for (iterator I = OutIt, E = end(); I != E; ++I) {
451 OutIt->valno = NewVNInfo[LHSValNoAssignments[I->valno->id]];
453 // If this live range has the same value # as its immediate predecessor,
454 // and if they are neighbors, remove one LiveRange. This happens when we
455 // have [0,3:0)[4,7:1) and map 0/1 onto the same value #.
456 if (OutIt->valno == (OutIt-1)->valno && (OutIt-1)->end == OutIt->start) {
457 (OutIt-1)->end = OutIt->end;
460 OutIt->start = I->start;
464 // Didn't merge, on to the next one.
469 // If we merge some live ranges, chop off the end.
470 ranges.erase(OutIt, end());
473 // Remember assignements because val# ids are changing.
474 SmallVector<unsigned, 16> OtherAssignments;
475 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
476 OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]);
478 // Update val# info. Renumber them and make sure they all belong to this
479 // LiveInterval now. Also remove dead val#'s.
480 unsigned NumValNos = 0;
481 for (unsigned i = 0; i < NumNewVals; ++i) {
482 VNInfo *VNI = NewVNInfo[i];
484 if (NumValNos >= NumVals)
485 valnos.push_back(VNI);
487 valnos[NumValNos] = VNI;
488 VNI->id = NumValNos++; // Renumber val#.
491 if (NumNewVals < NumVals)
492 valnos.resize(NumNewVals); // shrinkify
494 // Okay, now insert the RHS live ranges into the LHS.
495 iterator InsertPos = begin();
496 unsigned RangeNo = 0;
497 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I, ++RangeNo) {
498 // Map the valno in the other live range to the current live range.
499 I->valno = NewVNInfo[OtherAssignments[RangeNo]];
500 assert(I->valno && "Adding a dead range?");
501 InsertPos = addRangeFrom(*I, InsertPos);
504 ComputeJoinedWeight(Other);
506 // Update regalloc hint if currently there isn't one.
507 if (TargetRegisterInfo::isVirtualRegister(reg) &&
508 TargetRegisterInfo::isVirtualRegister(Other.reg)) {
509 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(reg);
510 if (Hint.first == 0 && Hint.second == 0) {
511 std::pair<unsigned, unsigned> OtherHint =
512 MRI->getRegAllocationHint(Other.reg);
513 if (OtherHint.first || OtherHint.second)
514 MRI->setRegAllocationHint(reg, OtherHint.first, OtherHint.second);
519 /// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
520 /// interval as the specified value number. The LiveRanges in RHS are
521 /// allowed to overlap with LiveRanges in the current interval, but only if
522 /// the overlapping LiveRanges have the specified value number.
523 void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS,
525 // TODO: Make this more efficient.
526 iterator InsertPos = begin();
527 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
528 // Map the valno in the other live range to the current live range.
530 Tmp.valno = LHSValNo;
531 InsertPos = addRangeFrom(Tmp, InsertPos);
536 /// MergeValueInAsValue - Merge all of the live ranges of a specific val#
537 /// in RHS into this live interval as the specified value number.
538 /// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
539 /// current interval, it will replace the value numbers of the overlaped
540 /// live ranges with the specified value number.
541 void LiveInterval::MergeValueInAsValue(
542 const LiveInterval &RHS,
543 const VNInfo *RHSValNo, VNInfo *LHSValNo) {
544 SmallVector<VNInfo*, 4> ReplacedValNos;
545 iterator IP = begin();
546 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
547 assert(I->valno == RHS.getValNumInfo(I->valno->id) && "Bad VNInfo");
548 if (I->valno != RHSValNo)
550 SlotIndex Start = I->start, End = I->end;
551 IP = std::upper_bound(IP, end(), Start);
552 // If the start of this range overlaps with an existing liverange, trim it.
553 if (IP != begin() && IP[-1].end > Start) {
554 if (IP[-1].valno != LHSValNo) {
555 ReplacedValNos.push_back(IP[-1].valno);
556 IP[-1].valno = LHSValNo; // Update val#.
559 // Trimmed away the whole range?
560 if (Start >= End) continue;
562 // If the end of this range overlaps with an existing liverange, trim it.
563 if (IP != end() && End > IP->start) {
564 if (IP->valno != LHSValNo) {
565 ReplacedValNos.push_back(IP->valno);
566 IP->valno = LHSValNo; // Update val#.
569 // If this trimmed away the whole range, ignore it.
570 if (Start == End) continue;
573 // Map the valno in the other live range to the current live range.
574 IP = addRangeFrom(LiveRange(Start, End, LHSValNo), IP);
578 SmallSet<VNInfo*, 4> Seen;
579 for (unsigned i = 0, e = ReplacedValNos.size(); i != e; ++i) {
580 VNInfo *V1 = ReplacedValNos[i];
581 if (Seen.insert(V1)) {
583 for (const_iterator I = begin(), E = end(); I != E; ++I)
584 if (I->valno == V1) {
589 // Now that V1 is dead, remove it. If it is the largest value number,
590 // just nuke it (and any other deleted values neighboring it), otherwise
591 // mark it as ~1U so it can be nuked later.
592 if (V1->id == getNumValNums()-1) {
595 } while (!valnos.empty() && valnos.back()->isUnused());
597 V1->setIsUnused(true);
605 /// MergeInClobberRanges - For any live ranges that are not defined in the
606 /// current interval, but are defined in the Clobbers interval, mark them
607 /// used with an unknown definition value.
608 void LiveInterval::MergeInClobberRanges(LiveIntervals &li_,
609 const LiveInterval &Clobbers,
610 VNInfo::Allocator &VNInfoAllocator) {
611 if (Clobbers.empty()) return;
613 DenseMap<VNInfo*, VNInfo*> ValNoMaps;
614 VNInfo *UnusedValNo = 0;
615 iterator IP = begin();
616 for (const_iterator I = Clobbers.begin(), E = Clobbers.end(); I != E; ++I) {
617 // For every val# in the Clobbers interval, create a new "unknown" val#.
618 VNInfo *ClobberValNo = 0;
619 DenseMap<VNInfo*, VNInfo*>::iterator VI = ValNoMaps.find(I->valno);
620 if (VI != ValNoMaps.end())
621 ClobberValNo = VI->second;
622 else if (UnusedValNo)
623 ClobberValNo = UnusedValNo;
625 UnusedValNo = ClobberValNo =
626 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
627 ValNoMaps.insert(std::make_pair(I->valno, ClobberValNo));
631 SlotIndex Start = I->start, End = I->end;
632 // If a clobber range starts before an existing range and ends after
633 // it, the clobber range will need to be split into multiple ranges.
634 // Loop until the entire clobber range is handled.
637 IP = std::upper_bound(IP, end(), Start);
638 SlotIndex SubRangeStart = Start;
639 SlotIndex SubRangeEnd = End;
641 // If the start of this range overlaps with an existing liverange, trim it.
642 if (IP != begin() && IP[-1].end > SubRangeStart) {
643 SubRangeStart = IP[-1].end;
644 // Trimmed away the whole range?
645 if (SubRangeStart >= SubRangeEnd) continue;
647 // If the end of this range overlaps with an existing liverange, trim it.
648 if (IP != end() && SubRangeEnd > IP->start) {
649 // If the clobber live range extends beyond the existing live range,
650 // it'll need at least another live range, so set the flag to keep
652 if (SubRangeEnd > IP->end) {
656 SubRangeEnd = IP->start;
657 // If this trimmed away the whole range, ignore it.
658 if (SubRangeStart == SubRangeEnd) continue;
661 // Insert the clobber interval.
662 IP = addRangeFrom(LiveRange(SubRangeStart, SubRangeEnd, ClobberValNo),
669 // Delete the last unused val#.
674 void LiveInterval::MergeInClobberRange(LiveIntervals &li_,
677 VNInfo::Allocator &VNInfoAllocator) {
678 // Find a value # to use for the clobber ranges. If there is already a value#
679 // for unknown values, use it.
680 VNInfo *ClobberValNo =
681 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
683 iterator IP = begin();
684 IP = std::upper_bound(IP, end(), Start);
686 // If the start of this range overlaps with an existing liverange, trim it.
687 if (IP != begin() && IP[-1].end > Start) {
689 // Trimmed away the whole range?
690 if (Start >= End) return;
692 // If the end of this range overlaps with an existing liverange, trim it.
693 if (IP != end() && End > IP->start) {
695 // If this trimmed away the whole range, ignore it.
696 if (Start == End) return;
699 // Insert the clobber interval.
700 addRangeFrom(LiveRange(Start, End, ClobberValNo), IP);
703 /// MergeValueNumberInto - This method is called when two value nubmers
704 /// are found to be equivalent. This eliminates V1, replacing all
705 /// LiveRanges with the V1 value number with the V2 value number. This can
706 /// cause merging of V1/V2 values numbers and compaction of the value space.
707 VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
708 assert(V1 != V2 && "Identical value#'s are always equivalent!");
710 // This code actually merges the (numerically) larger value number into the
711 // smaller value number, which is likely to allow us to compactify the value
712 // space. The only thing we have to be careful of is to preserve the
713 // instruction that defines the result value.
715 // Make sure V2 is smaller than V1.
716 if (V1->id < V2->id) {
721 // Merge V1 live ranges into V2.
722 for (iterator I = begin(); I != end(); ) {
724 if (LR->valno != V1) continue; // Not a V1 LiveRange.
726 // Okay, we found a V1 live range. If it had a previous, touching, V2 live
729 iterator Prev = LR-1;
730 if (Prev->valno == V2 && Prev->end == LR->start) {
733 // Erase this live-range.
740 // Okay, now we have a V1 or V2 live range that is maximally merged forward.
741 // Ensure that it is a V2 live-range.
744 // If we can merge it into later V2 live ranges, do so now. We ignore any
745 // following V1 live ranges, as they will be merged in subsequent iterations
748 if (I->start == LR->end && I->valno == V2) {
756 // Now that V1 is dead, remove it. If it is the largest value number, just
757 // nuke it (and any other deleted values neighboring it), otherwise mark it as
758 // ~1U so it can be nuked later.
759 if (V1->id == getNumValNums()-1) {
762 } while (valnos.back()->isUnused());
764 V1->setIsUnused(true);
770 void LiveInterval::Copy(const LiveInterval &RHS,
771 MachineRegisterInfo *MRI,
772 VNInfo::Allocator &VNInfoAllocator) {
775 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(RHS.reg);
776 MRI->setRegAllocationHint(reg, Hint.first, Hint.second);
779 for (unsigned i = 0, e = RHS.getNumValNums(); i != e; ++i) {
780 const VNInfo *VNI = RHS.getValNumInfo(i);
781 createValueCopy(VNI, VNInfoAllocator);
783 for (unsigned i = 0, e = RHS.ranges.size(); i != e; ++i) {
784 const LiveRange &LR = RHS.ranges[i];
785 addRange(LiveRange(LR.start, LR.end, getValNumInfo(LR.valno->id)));
789 unsigned LiveInterval::getSize() const {
791 for (const_iterator I = begin(), E = end(); I != E; ++I)
792 Sum += I->start.distance(I->end);
796 /// ComputeJoinedWeight - Set the weight of a live interval Joined
797 /// after Other has been merged into it.
798 void LiveInterval::ComputeJoinedWeight(const LiveInterval &Other) {
799 // If either of these intervals was spilled, the weight is the
800 // weight of the non-spilled interval. This can only happen with
801 // iterative coalescers.
803 if (Other.weight != HUGE_VALF) {
804 weight += Other.weight;
806 else if (weight == HUGE_VALF &&
807 !TargetRegisterInfo::isPhysicalRegister(reg)) {
808 // Remove this assert if you have an iterative coalescer
809 assert(0 && "Joining to spilled interval");
810 weight = Other.weight;
813 // Otherwise the weight stays the same
814 // Remove this assert if you have an iterative coalescer
815 assert(0 && "Joining from spilled interval");
819 raw_ostream& llvm::operator<<(raw_ostream& os, const LiveRange &LR) {
820 return os << '[' << LR.start << ',' << LR.end << ':' << LR.valno->id << ")";
823 void LiveRange::dump() const {
824 dbgs() << *this << "\n";
827 void LiveInterval::print(raw_ostream &OS, const TargetRegisterInfo *TRI) const {
829 OS << "SS#" << getStackSlotIndex();
830 else if (TRI && TargetRegisterInfo::isPhysicalRegister(reg))
831 OS << TRI->getName(reg);
841 for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
842 E = ranges.end(); I != E; ++I) {
844 assert(I->valno == getValNumInfo(I->valno->id) && "Bad VNInfo");
848 // Print value number info.
849 if (getNumValNums()) {
852 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
854 const VNInfo *vni = *i;
857 if (vni->isUnused()) {
860 if (!vni->isDefAccurate() && !vni->isPHIDef())
864 if (vni->hasPHIKill())
866 if (vni->hasRedefByEC())
873 void LiveInterval::dump() const {
874 dbgs() << *this << "\n";
878 void LiveRange::print(raw_ostream &os) const {