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 // overlaps - Return true if the intersection of the two live intervals is
74 // An example for overlaps():
78 // 8: C = A + B ;; last use of A
80 // The live intervals should look like:
86 // A->overlaps(C) should return false since we want to be able to join
89 bool LiveInterval::overlapsFrom(const LiveInterval& other,
90 const_iterator StartPos) const {
91 const_iterator i = begin();
92 const_iterator ie = end();
93 const_iterator j = StartPos;
94 const_iterator je = other.end();
96 assert((StartPos->start <= i->start || StartPos == other.begin()) &&
97 StartPos != other.end() && "Bogus start position hint!");
99 if (i->start < j->start) {
100 i = std::upper_bound(i, ie, j->start);
101 if (i != ranges.begin()) --i;
102 } else if (j->start < i->start) {
104 if (StartPos != other.end() && StartPos->start <= i->start) {
105 assert(StartPos < other.end() && i < end());
106 j = std::upper_bound(j, je, i->start);
107 if (j != other.ranges.begin()) --j;
113 if (j == je) return false;
116 if (i->start > j->start) {
121 if (i->end > j->start)
129 /// overlaps - Return true if the live interval overlaps a range specified
131 bool LiveInterval::overlaps(SlotIndex Start, SlotIndex End) const {
132 assert(Start < End && "Invalid range");
133 const_iterator I = begin();
134 const_iterator E = end();
135 const_iterator si = std::upper_bound(I, E, Start);
136 const_iterator ei = std::upper_bound(I, E, End);
142 return si->contains(Start);
145 /// extendIntervalEndTo - This method is used when we want to extend the range
146 /// specified by I to end at the specified endpoint. To do this, we should
147 /// merge and eliminate all ranges that this will overlap with. The iterator is
149 void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) {
150 assert(I != ranges.end() && "Not a valid interval!");
151 VNInfo *ValNo = I->valno;
152 SlotIndex OldEnd = I->end;
154 // Search for the first interval that we can't merge with.
155 Ranges::iterator MergeTo = next(I);
156 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
157 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
160 // If NewEnd was in the middle of an interval, make sure to get its endpoint.
161 I->end = std::max(NewEnd, prior(MergeTo)->end);
163 // Erase any dead ranges.
164 ranges.erase(next(I), MergeTo);
167 ValNo->removeKills(OldEnd, I->end.getPrevSlot());
169 // If the newly formed range now touches the range after it and if they have
170 // the same value number, merge the two ranges into one range.
171 Ranges::iterator Next = next(I);
172 if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) {
179 /// extendIntervalStartTo - This method is used when we want to extend the range
180 /// specified by I to start at the specified endpoint. To do this, we should
181 /// merge and eliminate all ranges that this will overlap with.
182 LiveInterval::Ranges::iterator
183 LiveInterval::extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStart) {
184 assert(I != ranges.end() && "Not a valid interval!");
185 VNInfo *ValNo = I->valno;
187 // Search for the first interval that we can't merge with.
188 Ranges::iterator MergeTo = I;
190 if (MergeTo == ranges.begin()) {
192 ranges.erase(MergeTo, I);
195 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
197 } while (NewStart <= MergeTo->start);
199 // If we start in the middle of another interval, just delete a range and
200 // extend that interval.
201 if (MergeTo->end >= NewStart && MergeTo->valno == ValNo) {
202 MergeTo->end = I->end;
204 // Otherwise, extend the interval right after.
206 MergeTo->start = NewStart;
207 MergeTo->end = I->end;
210 ranges.erase(next(MergeTo), next(I));
214 LiveInterval::iterator
215 LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
216 SlotIndex Start = LR.start, End = LR.end;
217 iterator it = std::upper_bound(From, ranges.end(), Start);
219 // If the inserted interval starts in the middle or right at the end of
220 // another interval, just extend that interval to contain the range of LR.
221 if (it != ranges.begin()) {
222 iterator B = prior(it);
223 if (LR.valno == B->valno) {
224 if (B->start <= Start && B->end >= Start) {
225 extendIntervalEndTo(B, End);
229 // Check to make sure that we are not overlapping two live ranges with
230 // different valno's.
231 assert(B->end <= Start &&
232 "Cannot overlap two LiveRanges with differing ValID's"
233 " (did you def the same reg twice in a MachineInstr?)");
237 // Otherwise, if this range ends in the middle of, or right next to, another
238 // interval, merge it into that interval.
239 if (it != ranges.end()) {
240 if (LR.valno == it->valno) {
241 if (it->start <= End) {
242 it = extendIntervalStartTo(it, Start);
244 // If LR is a complete superset of an interval, we may need to grow its
247 extendIntervalEndTo(it, End);
248 else if (End < it->end)
249 // Overlapping intervals, there might have been a kill here.
250 it->valno->removeKill(End);
254 // Check to make sure that we are not overlapping two live ranges with
255 // different valno's.
256 assert(it->start >= End &&
257 "Cannot overlap two LiveRanges with differing ValID's");
261 // Otherwise, this is just a new range that doesn't interact with anything.
263 return ranges.insert(it, LR);
266 /// isInOneLiveRange - Return true if the range specified is entirely in
267 /// a single LiveRange of the live interval.
268 bool LiveInterval::isInOneLiveRange(SlotIndex Start, SlotIndex End) {
269 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
270 if (I == ranges.begin())
273 return I->containsRange(Start, End);
277 /// removeRange - Remove the specified range from this interval. Note that
278 /// the range must be in a single LiveRange in its entirety.
279 void LiveInterval::removeRange(SlotIndex Start, SlotIndex End,
280 bool RemoveDeadValNo) {
281 // Find the LiveRange containing this span.
282 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
283 assert(I != ranges.begin() && "Range is not in interval!");
285 assert(I->containsRange(Start, End) && "Range is not entirely in interval!");
287 // If the span we are removing is at the start of the LiveRange, adjust it.
288 VNInfo *ValNo = I->valno;
289 if (I->start == Start) {
291 ValNo->removeKills(Start, End);
292 if (RemoveDeadValNo) {
293 // Check if val# is dead.
295 for (const_iterator II = begin(), EE = end(); II != EE; ++II)
296 if (II != I && II->valno == ValNo) {
301 // Now that ValNo is dead, remove it. If it is the largest value
302 // number, just nuke it (and any other deleted values neighboring it),
303 // otherwise mark it as ~1U so it can be nuked later.
304 if (ValNo->id == getNumValNums()-1) {
306 VNInfo *VNI = valnos.back();
309 } while (!valnos.empty() && valnos.back()->isUnused());
311 ValNo->setIsUnused(true);
316 ranges.erase(I); // Removed the whole LiveRange.
322 // Otherwise if the span we are removing is at the end of the LiveRange,
323 // adjust the other way.
325 ValNo->removeKills(Start, End);
330 // Otherwise, we are splitting the LiveRange into two pieces.
331 SlotIndex OldEnd = I->end;
332 I->end = Start; // Trim the old interval.
334 // Insert the new one.
335 ranges.insert(next(I), LiveRange(End, OldEnd, ValNo));
338 /// removeValNo - Remove all the ranges defined by the specified value#.
339 /// Also remove the value# from value# list.
340 void LiveInterval::removeValNo(VNInfo *ValNo) {
342 Ranges::iterator I = ranges.end();
343 Ranges::iterator E = ranges.begin();
346 if (I->valno == ValNo)
349 // Now that ValNo is dead, remove it. If it is the largest value
350 // number, just nuke it (and any other deleted values neighboring it),
351 // otherwise mark it as ~1U so it can be nuked later.
352 if (ValNo->id == getNumValNums()-1) {
354 VNInfo *VNI = valnos.back();
357 } while (!valnos.empty() && valnos.back()->isUnused());
359 ValNo->setIsUnused(true);
363 /// getLiveRangeContaining - Return the live range that contains the
364 /// specified index, or null if there is none.
365 LiveInterval::const_iterator
366 LiveInterval::FindLiveRangeContaining(SlotIndex Idx) const {
367 const_iterator It = std::upper_bound(begin(), end(), Idx);
368 if (It != ranges.begin()) {
370 if (It->contains(Idx))
377 LiveInterval::iterator
378 LiveInterval::FindLiveRangeContaining(SlotIndex Idx) {
379 iterator It = std::upper_bound(begin(), end(), Idx);
382 if (It->contains(Idx))
389 /// findDefinedVNInfo - Find the VNInfo defined by the specified
390 /// index (register interval).
391 VNInfo *LiveInterval::findDefinedVNInfoForRegInt(SlotIndex Idx) const {
392 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
394 if ((*i)->def == Idx)
401 /// findDefinedVNInfo - Find the VNInfo defined by the specified
402 /// register (stack inteval).
403 VNInfo *LiveInterval::findDefinedVNInfoForStackInt(unsigned reg) const {
404 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
406 if ((*i)->getReg() == reg)
412 /// join - Join two live intervals (this, and other) together. This applies
413 /// mappings to the value numbers in the LHS/RHS intervals as specified. If
414 /// the intervals are not joinable, this aborts.
415 void LiveInterval::join(LiveInterval &Other,
416 const int *LHSValNoAssignments,
417 const int *RHSValNoAssignments,
418 SmallVector<VNInfo*, 16> &NewVNInfo,
419 MachineRegisterInfo *MRI) {
420 // Determine if any of our live range values are mapped. This is uncommon, so
421 // we want to avoid the interval scan if not.
422 bool MustMapCurValNos = false;
423 unsigned NumVals = getNumValNums();
424 unsigned NumNewVals = NewVNInfo.size();
425 for (unsigned i = 0; i != NumVals; ++i) {
426 unsigned LHSValID = LHSValNoAssignments[i];
428 (NewVNInfo[LHSValID] && NewVNInfo[LHSValID] != getValNumInfo(i)))
429 MustMapCurValNos = true;
432 // If we have to apply a mapping to our base interval assignment, rewrite it
434 if (MustMapCurValNos) {
435 // Map the first live range.
436 iterator OutIt = begin();
437 OutIt->valno = NewVNInfo[LHSValNoAssignments[OutIt->valno->id]];
439 for (iterator I = OutIt, E = end(); I != E; ++I) {
440 OutIt->valno = NewVNInfo[LHSValNoAssignments[I->valno->id]];
442 // If this live range has the same value # as its immediate predecessor,
443 // and if they are neighbors, remove one LiveRange. This happens when we
444 // have [0,3:0)[4,7:1) and map 0/1 onto the same value #.
445 if (OutIt->valno == (OutIt-1)->valno && (OutIt-1)->end == OutIt->start) {
446 (OutIt-1)->end = OutIt->end;
449 OutIt->start = I->start;
453 // Didn't merge, on to the next one.
458 // If we merge some live ranges, chop off the end.
459 ranges.erase(OutIt, end());
462 // Remember assignements because val# ids are changing.
463 SmallVector<unsigned, 16> OtherAssignments;
464 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
465 OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]);
467 // Update val# info. Renumber them and make sure they all belong to this
468 // LiveInterval now. Also remove dead val#'s.
469 unsigned NumValNos = 0;
470 for (unsigned i = 0; i < NumNewVals; ++i) {
471 VNInfo *VNI = NewVNInfo[i];
473 if (NumValNos >= NumVals)
474 valnos.push_back(VNI);
476 valnos[NumValNos] = VNI;
477 VNI->id = NumValNos++; // Renumber val#.
480 if (NumNewVals < NumVals)
481 valnos.resize(NumNewVals); // shrinkify
483 // Okay, now insert the RHS live ranges into the LHS.
484 iterator InsertPos = begin();
485 unsigned RangeNo = 0;
486 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I, ++RangeNo) {
487 // Map the valno in the other live range to the current live range.
488 I->valno = NewVNInfo[OtherAssignments[RangeNo]];
489 assert(I->valno && "Adding a dead range?");
490 InsertPos = addRangeFrom(*I, InsertPos);
493 ComputeJoinedWeight(Other);
495 // Update regalloc hint if currently there isn't one.
496 if (TargetRegisterInfo::isVirtualRegister(reg) &&
497 TargetRegisterInfo::isVirtualRegister(Other.reg)) {
498 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(reg);
499 if (Hint.first == 0 && Hint.second == 0) {
500 std::pair<unsigned, unsigned> OtherHint =
501 MRI->getRegAllocationHint(Other.reg);
502 if (OtherHint.first || OtherHint.second)
503 MRI->setRegAllocationHint(reg, OtherHint.first, OtherHint.second);
508 /// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
509 /// interval as the specified value number. The LiveRanges in RHS are
510 /// allowed to overlap with LiveRanges in the current interval, but only if
511 /// the overlapping LiveRanges have the specified value number.
512 void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS,
514 // TODO: Make this more efficient.
515 iterator InsertPos = begin();
516 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
517 // Map the valno in the other live range to the current live range.
519 Tmp.valno = LHSValNo;
520 InsertPos = addRangeFrom(Tmp, InsertPos);
525 /// MergeValueInAsValue - Merge all of the live ranges of a specific val#
526 /// in RHS into this live interval as the specified value number.
527 /// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
528 /// current interval, it will replace the value numbers of the overlaped
529 /// live ranges with the specified value number.
530 void LiveInterval::MergeValueInAsValue(
531 const LiveInterval &RHS,
532 const VNInfo *RHSValNo, VNInfo *LHSValNo) {
533 SmallVector<VNInfo*, 4> ReplacedValNos;
534 iterator IP = begin();
535 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
536 if (I->valno != RHSValNo)
538 SlotIndex Start = I->start, End = I->end;
539 IP = std::upper_bound(IP, end(), Start);
540 // If the start of this range overlaps with an existing liverange, trim it.
541 if (IP != begin() && IP[-1].end > Start) {
542 if (IP[-1].valno != LHSValNo) {
543 ReplacedValNos.push_back(IP[-1].valno);
544 IP[-1].valno = LHSValNo; // Update val#.
547 // Trimmed away the whole range?
548 if (Start >= End) continue;
550 // If the end of this range overlaps with an existing liverange, trim it.
551 if (IP != end() && End > IP->start) {
552 if (IP->valno != LHSValNo) {
553 ReplacedValNos.push_back(IP->valno);
554 IP->valno = LHSValNo; // Update val#.
557 // If this trimmed away the whole range, ignore it.
558 if (Start == End) continue;
561 // Map the valno in the other live range to the current live range.
562 IP = addRangeFrom(LiveRange(Start, End, LHSValNo), IP);
566 SmallSet<VNInfo*, 4> Seen;
567 for (unsigned i = 0, e = ReplacedValNos.size(); i != e; ++i) {
568 VNInfo *V1 = ReplacedValNos[i];
569 if (Seen.insert(V1)) {
571 for (const_iterator I = begin(), E = end(); I != E; ++I)
572 if (I->valno == V1) {
577 // Now that V1 is dead, remove it. If it is the largest value number,
578 // just nuke it (and any other deleted values neighboring it), otherwise
579 // mark it as ~1U so it can be nuked later.
580 if (V1->id == getNumValNums()-1) {
582 VNInfo *VNI = valnos.back();
585 } while (!valnos.empty() && valnos.back()->isUnused());
587 V1->setIsUnused(true);
595 /// MergeInClobberRanges - For any live ranges that are not defined in the
596 /// current interval, but are defined in the Clobbers interval, mark them
597 /// used with an unknown definition value.
598 void LiveInterval::MergeInClobberRanges(LiveIntervals &li_,
599 const LiveInterval &Clobbers,
600 BumpPtrAllocator &VNInfoAllocator) {
601 if (Clobbers.empty()) return;
603 DenseMap<VNInfo*, VNInfo*> ValNoMaps;
604 VNInfo *UnusedValNo = 0;
605 iterator IP = begin();
606 for (const_iterator I = Clobbers.begin(), E = Clobbers.end(); I != E; ++I) {
607 // For every val# in the Clobbers interval, create a new "unknown" val#.
608 VNInfo *ClobberValNo = 0;
609 DenseMap<VNInfo*, VNInfo*>::iterator VI = ValNoMaps.find(I->valno);
610 if (VI != ValNoMaps.end())
611 ClobberValNo = VI->second;
612 else if (UnusedValNo)
613 ClobberValNo = UnusedValNo;
615 UnusedValNo = ClobberValNo =
616 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
617 ValNoMaps.insert(std::make_pair(I->valno, ClobberValNo));
621 SlotIndex Start = I->start, End = I->end;
622 // If a clobber range starts before an existing range and ends after
623 // it, the clobber range will need to be split into multiple ranges.
624 // Loop until the entire clobber range is handled.
627 IP = std::upper_bound(IP, end(), Start);
628 SlotIndex SubRangeStart = Start;
629 SlotIndex SubRangeEnd = End;
631 // If the start of this range overlaps with an existing liverange, trim it.
632 if (IP != begin() && IP[-1].end > SubRangeStart) {
633 SubRangeStart = IP[-1].end;
634 // Trimmed away the whole range?
635 if (SubRangeStart >= SubRangeEnd) continue;
637 // If the end of this range overlaps with an existing liverange, trim it.
638 if (IP != end() && SubRangeEnd > IP->start) {
639 // If the clobber live range extends beyond the existing live range,
640 // it'll need at least another live range, so set the flag to keep
642 if (SubRangeEnd > IP->end) {
646 SubRangeEnd = IP->start;
647 // If this trimmed away the whole range, ignore it.
648 if (SubRangeStart == SubRangeEnd) continue;
651 // Insert the clobber interval.
652 IP = addRangeFrom(LiveRange(SubRangeStart, SubRangeEnd, ClobberValNo),
659 // Delete the last unused val#.
661 UnusedValNo->~VNInfo();
665 void LiveInterval::MergeInClobberRange(LiveIntervals &li_,
668 BumpPtrAllocator &VNInfoAllocator) {
669 // Find a value # to use for the clobber ranges. If there is already a value#
670 // for unknown values, use it.
671 VNInfo *ClobberValNo =
672 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
674 iterator IP = begin();
675 IP = std::upper_bound(IP, end(), Start);
677 // If the start of this range overlaps with an existing liverange, trim it.
678 if (IP != begin() && IP[-1].end > Start) {
680 // Trimmed away the whole range?
681 if (Start >= End) return;
683 // If the end of this range overlaps with an existing liverange, trim it.
684 if (IP != end() && End > IP->start) {
686 // If this trimmed away the whole range, ignore it.
687 if (Start == End) return;
690 // Insert the clobber interval.
691 addRangeFrom(LiveRange(Start, End, ClobberValNo), IP);
694 /// MergeValueNumberInto - This method is called when two value nubmers
695 /// are found to be equivalent. This eliminates V1, replacing all
696 /// LiveRanges with the V1 value number with the V2 value number. This can
697 /// cause merging of V1/V2 values numbers and compaction of the value space.
698 VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
699 assert(V1 != V2 && "Identical value#'s are always equivalent!");
701 // This code actually merges the (numerically) larger value number into the
702 // smaller value number, which is likely to allow us to compactify the value
703 // space. The only thing we have to be careful of is to preserve the
704 // instruction that defines the result value.
706 // Make sure V2 is smaller than V1.
707 if (V1->id < V2->id) {
712 // Merge V1 live ranges into V2.
713 for (iterator I = begin(); I != end(); ) {
715 if (LR->valno != V1) continue; // Not a V1 LiveRange.
717 // Okay, we found a V1 live range. If it had a previous, touching, V2 live
720 iterator Prev = LR-1;
721 if (Prev->valno == V2 && Prev->end == LR->start) {
724 // Erase this live-range.
731 // Okay, now we have a V1 or V2 live range that is maximally merged forward.
732 // Ensure that it is a V2 live-range.
735 // If we can merge it into later V2 live ranges, do so now. We ignore any
736 // following V1 live ranges, as they will be merged in subsequent iterations
739 if (I->start == LR->end && I->valno == V2) {
747 // Now that V1 is dead, remove it. If it is the largest value number, just
748 // nuke it (and any other deleted values neighboring it), otherwise mark it as
749 // ~1U so it can be nuked later.
750 if (V1->id == getNumValNums()-1) {
752 VNInfo *VNI = valnos.back();
755 } while (valnos.back()->isUnused());
757 V1->setIsUnused(true);
763 void LiveInterval::Copy(const LiveInterval &RHS,
764 MachineRegisterInfo *MRI,
765 BumpPtrAllocator &VNInfoAllocator) {
768 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(RHS.reg);
769 MRI->setRegAllocationHint(reg, Hint.first, Hint.second);
772 for (unsigned i = 0, e = RHS.getNumValNums(); i != e; ++i) {
773 const VNInfo *VNI = RHS.getValNumInfo(i);
774 createValueCopy(VNI, VNInfoAllocator);
776 for (unsigned i = 0, e = RHS.ranges.size(); i != e; ++i) {
777 const LiveRange &LR = RHS.ranges[i];
778 addRange(LiveRange(LR.start, LR.end, getValNumInfo(LR.valno->id)));
782 unsigned LiveInterval::getSize() const {
784 for (const_iterator I = begin(), E = end(); I != E; ++I)
785 Sum += I->start.distance(I->end);
789 /// ComputeJoinedWeight - Set the weight of a live interval Joined
790 /// after Other has been merged into it.
791 void LiveInterval::ComputeJoinedWeight(const LiveInterval &Other) {
792 // If either of these intervals was spilled, the weight is the
793 // weight of the non-spilled interval. This can only happen with
794 // iterative coalescers.
796 if (Other.weight != HUGE_VALF) {
797 weight += Other.weight;
799 else if (weight == HUGE_VALF &&
800 !TargetRegisterInfo::isPhysicalRegister(reg)) {
801 // Remove this assert if you have an iterative coalescer
802 assert(0 && "Joining to spilled interval");
803 weight = Other.weight;
806 // Otherwise the weight stays the same
807 // Remove this assert if you have an iterative coalescer
808 assert(0 && "Joining from spilled interval");
812 raw_ostream& llvm::operator<<(raw_ostream& os, const LiveRange &LR) {
813 return os << '[' << LR.start << ',' << LR.end << ':' << LR.valno->id << ")";
816 void LiveRange::dump() const {
817 dbgs() << *this << "\n";
820 void LiveInterval::print(raw_ostream &OS, const TargetRegisterInfo *TRI) const {
822 OS << "SS#" << getStackSlotIndex();
823 else if (TRI && TargetRegisterInfo::isPhysicalRegister(reg))
824 OS << TRI->getName(reg);
834 for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
835 E = ranges.end(); I != E; ++I)
839 // Print value number info.
840 if (getNumValNums()) {
843 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
845 const VNInfo *vni = *i;
848 if (vni->isUnused()) {
851 if (!vni->isDefAccurate() && !vni->isPHIDef())
855 unsigned ee = vni->kills.size();
856 if (ee || vni->hasPHIKill()) {
858 for (unsigned j = 0; j != ee; ++j) {
863 if (vni->hasPHIKill()) {
875 void LiveInterval::dump() const {
876 dbgs() << *this << "\n";
880 void LiveRange::print(raw_ostream &os) const {