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;
170 /// ValNo is dead, remove it. If it is the largest value number, just nuke it
171 /// (and any other deleted values neighboring it), otherwise mark it as ~1U so
172 /// it can be nuked later.
173 void LiveInterval::markValNoForDeletion(VNInfo *ValNo) {
174 if (ValNo->id == getNumValNums()-1) {
177 } while (!valnos.empty() && valnos.back()->isUnused());
179 ValNo->setIsUnused(true);
183 /// extendIntervalEndTo - This method is used when we want to extend the range
184 /// specified by I to end at the specified endpoint. To do this, we should
185 /// merge and eliminate all ranges that this will overlap with. The iterator is
187 void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) {
188 assert(I != ranges.end() && "Not a valid interval!");
189 VNInfo *ValNo = I->valno;
191 // Search for the first interval that we can't merge with.
192 Ranges::iterator MergeTo = llvm::next(I);
193 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
194 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
197 // If NewEnd was in the middle of an interval, make sure to get its endpoint.
198 I->end = std::max(NewEnd, prior(MergeTo)->end);
200 // Erase any dead ranges.
201 ranges.erase(llvm::next(I), MergeTo);
203 // If the newly formed range now touches the range after it and if they have
204 // the same value number, merge the two ranges into one range.
205 Ranges::iterator Next = llvm::next(I);
206 if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) {
213 /// extendIntervalStartTo - This method is used when we want to extend the range
214 /// specified by I to start at the specified endpoint. To do this, we should
215 /// merge and eliminate all ranges that this will overlap with.
216 LiveInterval::Ranges::iterator
217 LiveInterval::extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStart) {
218 assert(I != ranges.end() && "Not a valid interval!");
219 VNInfo *ValNo = I->valno;
221 // Search for the first interval that we can't merge with.
222 Ranges::iterator MergeTo = I;
224 if (MergeTo == ranges.begin()) {
226 ranges.erase(MergeTo, I);
229 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
231 } while (NewStart <= MergeTo->start);
233 // If we start in the middle of another interval, just delete a range and
234 // extend that interval.
235 if (MergeTo->end >= NewStart && MergeTo->valno == ValNo) {
236 MergeTo->end = I->end;
238 // Otherwise, extend the interval right after.
240 MergeTo->start = NewStart;
241 MergeTo->end = I->end;
244 ranges.erase(llvm::next(MergeTo), llvm::next(I));
248 LiveInterval::iterator
249 LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
250 SlotIndex Start = LR.start, End = LR.end;
251 iterator it = std::upper_bound(From, ranges.end(), Start);
253 // If the inserted interval starts in the middle or right at the end of
254 // another interval, just extend that interval to contain the range of LR.
255 if (it != ranges.begin()) {
256 iterator B = prior(it);
257 if (LR.valno == B->valno) {
258 if (B->start <= Start && B->end >= Start) {
259 extendIntervalEndTo(B, End);
263 // Check to make sure that we are not overlapping two live ranges with
264 // different valno's.
265 assert(B->end <= Start &&
266 "Cannot overlap two LiveRanges with differing ValID's"
267 " (did you def the same reg twice in a MachineInstr?)");
271 // Otherwise, if this range ends in the middle of, or right next to, another
272 // interval, merge it into that interval.
273 if (it != ranges.end()) {
274 if (LR.valno == it->valno) {
275 if (it->start <= End) {
276 it = extendIntervalStartTo(it, Start);
278 // If LR is a complete superset of an interval, we may need to grow its
281 extendIntervalEndTo(it, End);
285 // Check to make sure that we are not overlapping two live ranges with
286 // different valno's.
287 assert(it->start >= End &&
288 "Cannot overlap two LiveRanges with differing ValID's");
292 // Otherwise, this is just a new range that doesn't interact with anything.
294 return ranges.insert(it, LR);
297 /// isInOneLiveRange - Return true if the range specified is entirely in
298 /// a single LiveRange of the live interval.
299 bool LiveInterval::isInOneLiveRange(SlotIndex Start, SlotIndex End) {
300 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
301 if (I == ranges.begin())
304 return I->containsRange(Start, End);
308 /// removeRange - Remove the specified range from this interval. Note that
309 /// the range must be in a single LiveRange in its entirety.
310 void LiveInterval::removeRange(SlotIndex Start, SlotIndex End,
311 bool RemoveDeadValNo) {
312 // Find the LiveRange containing this span.
313 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
314 assert(I != ranges.begin() && "Range is not in interval!");
316 assert(I->containsRange(Start, End) && "Range is not entirely in interval!");
318 // If the span we are removing is at the start of the LiveRange, adjust it.
319 VNInfo *ValNo = I->valno;
320 if (I->start == Start) {
322 if (RemoveDeadValNo) {
323 // Check if val# is dead.
325 for (const_iterator II = begin(), EE = end(); II != EE; ++II)
326 if (II != I && II->valno == ValNo) {
331 // Now that ValNo is dead, remove it.
332 markValNoForDeletion(ValNo);
336 ranges.erase(I); // Removed the whole LiveRange.
342 // Otherwise if the span we are removing is at the end of the LiveRange,
343 // adjust the other way.
349 // Otherwise, we are splitting the LiveRange into two pieces.
350 SlotIndex OldEnd = I->end;
351 I->end = Start; // Trim the old interval.
353 // Insert the new one.
354 ranges.insert(llvm::next(I), LiveRange(End, OldEnd, ValNo));
357 /// removeValNo - Remove all the ranges defined by the specified value#.
358 /// Also remove the value# from value# list.
359 void LiveInterval::removeValNo(VNInfo *ValNo) {
361 Ranges::iterator I = ranges.end();
362 Ranges::iterator E = ranges.begin();
365 if (I->valno == ValNo)
368 // Now that ValNo is dead, remove it.
369 markValNoForDeletion(ValNo);
372 /// getLiveRangeContaining - Return the live range that contains the
373 /// specified index, or null if there is none.
374 LiveInterval::const_iterator
375 LiveInterval::FindLiveRangeContaining(SlotIndex Idx) const {
376 const_iterator It = std::upper_bound(begin(), end(), Idx);
377 if (It != ranges.begin()) {
379 if (It->contains(Idx))
386 LiveInterval::iterator
387 LiveInterval::FindLiveRangeContaining(SlotIndex Idx) {
388 iterator It = std::upper_bound(begin(), end(), Idx);
391 if (It->contains(Idx))
398 /// findDefinedVNInfo - Find the VNInfo defined by the specified
399 /// index (register interval).
400 VNInfo *LiveInterval::findDefinedVNInfoForRegInt(SlotIndex Idx) const {
401 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
403 if ((*i)->def == Idx)
410 /// findDefinedVNInfo - Find the VNInfo defined by the specified
411 /// register (stack inteval).
412 VNInfo *LiveInterval::findDefinedVNInfoForStackInt(unsigned reg) const {
413 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
415 if ((*i)->getReg() == reg)
421 /// join - Join two live intervals (this, and other) together. This applies
422 /// mappings to the value numbers in the LHS/RHS intervals as specified. If
423 /// the intervals are not joinable, this aborts.
424 void LiveInterval::join(LiveInterval &Other,
425 const int *LHSValNoAssignments,
426 const int *RHSValNoAssignments,
427 SmallVector<VNInfo*, 16> &NewVNInfo,
428 MachineRegisterInfo *MRI) {
429 // Determine if any of our live range values are mapped. This is uncommon, so
430 // we want to avoid the interval scan if not.
431 bool MustMapCurValNos = false;
432 unsigned NumVals = getNumValNums();
433 unsigned NumNewVals = NewVNInfo.size();
434 for (unsigned i = 0; i != NumVals; ++i) {
435 unsigned LHSValID = LHSValNoAssignments[i];
437 (NewVNInfo[LHSValID] && NewVNInfo[LHSValID] != getValNumInfo(i)))
438 MustMapCurValNos = true;
441 // If we have to apply a mapping to our base interval assignment, rewrite it
443 if (MustMapCurValNos) {
444 // Map the first live range.
445 iterator OutIt = begin();
446 OutIt->valno = NewVNInfo[LHSValNoAssignments[OutIt->valno->id]];
448 for (iterator I = OutIt, E = end(); I != E; ++I) {
449 OutIt->valno = NewVNInfo[LHSValNoAssignments[I->valno->id]];
451 // If this live range has the same value # as its immediate predecessor,
452 // and if they are neighbors, remove one LiveRange. This happens when we
453 // have [0,3:0)[4,7:1) and map 0/1 onto the same value #.
454 if (OutIt->valno == (OutIt-1)->valno && (OutIt-1)->end == OutIt->start) {
455 (OutIt-1)->end = OutIt->end;
458 OutIt->start = I->start;
462 // Didn't merge, on to the next one.
467 // If we merge some live ranges, chop off the end.
468 ranges.erase(OutIt, end());
471 // Remember assignements because val# ids are changing.
472 SmallVector<unsigned, 16> OtherAssignments;
473 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
474 OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]);
476 // Update val# info. Renumber them and make sure they all belong to this
477 // LiveInterval now. Also remove dead val#'s.
478 unsigned NumValNos = 0;
479 for (unsigned i = 0; i < NumNewVals; ++i) {
480 VNInfo *VNI = NewVNInfo[i];
482 if (NumValNos >= NumVals)
483 valnos.push_back(VNI);
485 valnos[NumValNos] = VNI;
486 VNI->id = NumValNos++; // Renumber val#.
489 if (NumNewVals < NumVals)
490 valnos.resize(NumNewVals); // shrinkify
492 // Okay, now insert the RHS live ranges into the LHS.
493 iterator InsertPos = begin();
494 unsigned RangeNo = 0;
495 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I, ++RangeNo) {
496 // Map the valno in the other live range to the current live range.
497 I->valno = NewVNInfo[OtherAssignments[RangeNo]];
498 assert(I->valno && "Adding a dead range?");
499 InsertPos = addRangeFrom(*I, InsertPos);
502 ComputeJoinedWeight(Other);
504 // Update regalloc hint if currently there isn't one.
505 if (TargetRegisterInfo::isVirtualRegister(reg) &&
506 TargetRegisterInfo::isVirtualRegister(Other.reg)) {
507 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(reg);
508 if (Hint.first == 0 && Hint.second == 0) {
509 std::pair<unsigned, unsigned> OtherHint =
510 MRI->getRegAllocationHint(Other.reg);
511 if (OtherHint.first || OtherHint.second)
512 MRI->setRegAllocationHint(reg, OtherHint.first, OtherHint.second);
517 /// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
518 /// interval as the specified value number. The LiveRanges in RHS are
519 /// allowed to overlap with LiveRanges in the current interval, but only if
520 /// the overlapping LiveRanges have the specified value number.
521 void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS,
523 // TODO: Make this more efficient.
524 iterator InsertPos = begin();
525 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
526 // Map the valno in the other live range to the current live range.
528 Tmp.valno = LHSValNo;
529 InsertPos = addRangeFrom(Tmp, InsertPos);
534 /// MergeValueInAsValue - Merge all of the live ranges of a specific val#
535 /// in RHS into this live interval as the specified value number.
536 /// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
537 /// current interval, it will replace the value numbers of the overlaped
538 /// live ranges with the specified value number.
539 void LiveInterval::MergeValueInAsValue(
540 const LiveInterval &RHS,
541 const VNInfo *RHSValNo, VNInfo *LHSValNo) {
542 SmallVector<VNInfo*, 4> ReplacedValNos;
543 iterator IP = begin();
544 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
545 assert(I->valno == RHS.getValNumInfo(I->valno->id) && "Bad VNInfo");
546 if (I->valno != RHSValNo)
548 SlotIndex Start = I->start, End = I->end;
549 IP = std::upper_bound(IP, end(), Start);
550 // If the start of this range overlaps with an existing liverange, trim it.
551 if (IP != begin() && IP[-1].end > Start) {
552 if (IP[-1].valno != LHSValNo) {
553 ReplacedValNos.push_back(IP[-1].valno);
554 IP[-1].valno = LHSValNo; // Update val#.
557 // Trimmed away the whole range?
558 if (Start >= End) continue;
560 // If the end of this range overlaps with an existing liverange, trim it.
561 if (IP != end() && End > IP->start) {
562 if (IP->valno != LHSValNo) {
563 ReplacedValNos.push_back(IP->valno);
564 IP->valno = LHSValNo; // Update val#.
567 // If this trimmed away the whole range, ignore it.
568 if (Start == End) continue;
571 // Map the valno in the other live range to the current live range.
572 IP = addRangeFrom(LiveRange(Start, End, LHSValNo), IP);
576 SmallSet<VNInfo*, 4> Seen;
577 for (unsigned i = 0, e = ReplacedValNos.size(); i != e; ++i) {
578 VNInfo *V1 = ReplacedValNos[i];
579 if (Seen.insert(V1)) {
581 for (const_iterator I = begin(), E = end(); I != E; ++I)
582 if (I->valno == V1) {
587 // Now that V1 is dead, remove it.
588 markValNoForDeletion(V1);
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 VNInfo::Allocator &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#.
664 void LiveInterval::MergeInClobberRange(LiveIntervals &li_,
667 VNInfo::Allocator &VNInfoAllocator) {
668 // Find a value # to use for the clobber ranges. If there is already a value#
669 // for unknown values, use it.
670 VNInfo *ClobberValNo =
671 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
673 iterator IP = begin();
674 IP = std::upper_bound(IP, end(), Start);
676 // If the start of this range overlaps with an existing liverange, trim it.
677 if (IP != begin() && IP[-1].end > Start) {
679 // Trimmed away the whole range?
680 if (Start >= End) return;
682 // If the end of this range overlaps with an existing liverange, trim it.
683 if (IP != end() && End > IP->start) {
685 // If this trimmed away the whole range, ignore it.
686 if (Start == End) return;
689 // Insert the clobber interval.
690 addRangeFrom(LiveRange(Start, End, ClobberValNo), IP);
693 /// MergeValueNumberInto - This method is called when two value nubmers
694 /// are found to be equivalent. This eliminates V1, replacing all
695 /// LiveRanges with the V1 value number with the V2 value number. This can
696 /// cause merging of V1/V2 values numbers and compaction of the value space.
697 VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
698 assert(V1 != V2 && "Identical value#'s are always equivalent!");
700 // This code actually merges the (numerically) larger value number into the
701 // smaller value number, which is likely to allow us to compactify the value
702 // space. The only thing we have to be careful of is to preserve the
703 // instruction that defines the result value.
705 // Make sure V2 is smaller than V1.
706 if (V1->id < V2->id) {
711 // Merge V1 live ranges into V2.
712 for (iterator I = begin(); I != end(); ) {
714 if (LR->valno != V1) continue; // Not a V1 LiveRange.
716 // Okay, we found a V1 live range. If it had a previous, touching, V2 live
719 iterator Prev = LR-1;
720 if (Prev->valno == V2 && Prev->end == LR->start) {
723 // Erase this live-range.
730 // Okay, now we have a V1 or V2 live range that is maximally merged forward.
731 // Ensure that it is a V2 live-range.
734 // If we can merge it into later V2 live ranges, do so now. We ignore any
735 // following V1 live ranges, as they will be merged in subsequent iterations
738 if (I->start == LR->end && I->valno == V2) {
746 // Now that V1 is dead, remove it.
747 markValNoForDeletion(V1);
752 void LiveInterval::Copy(const LiveInterval &RHS,
753 MachineRegisterInfo *MRI,
754 VNInfo::Allocator &VNInfoAllocator) {
757 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(RHS.reg);
758 MRI->setRegAllocationHint(reg, Hint.first, Hint.second);
761 for (unsigned i = 0, e = RHS.getNumValNums(); i != e; ++i) {
762 const VNInfo *VNI = RHS.getValNumInfo(i);
763 createValueCopy(VNI, VNInfoAllocator);
765 for (unsigned i = 0, e = RHS.ranges.size(); i != e; ++i) {
766 const LiveRange &LR = RHS.ranges[i];
767 addRange(LiveRange(LR.start, LR.end, getValNumInfo(LR.valno->id)));
771 unsigned LiveInterval::getSize() const {
773 for (const_iterator I = begin(), E = end(); I != E; ++I)
774 Sum += I->start.distance(I->end);
778 /// ComputeJoinedWeight - Set the weight of a live interval Joined
779 /// after Other has been merged into it.
780 void LiveInterval::ComputeJoinedWeight(const LiveInterval &Other) {
781 // If either of these intervals was spilled, the weight is the
782 // weight of the non-spilled interval. This can only happen with
783 // iterative coalescers.
785 if (Other.weight != HUGE_VALF) {
786 weight += Other.weight;
788 else if (weight == HUGE_VALF &&
789 !TargetRegisterInfo::isPhysicalRegister(reg)) {
790 // Remove this assert if you have an iterative coalescer
791 assert(0 && "Joining to spilled interval");
792 weight = Other.weight;
795 // Otherwise the weight stays the same
796 // Remove this assert if you have an iterative coalescer
797 assert(0 && "Joining from spilled interval");
801 raw_ostream& llvm::operator<<(raw_ostream& os, const LiveRange &LR) {
802 return os << '[' << LR.start << ',' << LR.end << ':' << LR.valno->id << ")";
805 void LiveRange::dump() const {
806 dbgs() << *this << "\n";
809 void LiveInterval::print(raw_ostream &OS, const TargetRegisterInfo *TRI) const {
811 OS << "SS#" << getStackSlotIndex();
812 else if (TRI && TargetRegisterInfo::isPhysicalRegister(reg))
813 OS << TRI->getName(reg);
823 for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
824 E = ranges.end(); I != E; ++I) {
826 assert(I->valno == getValNumInfo(I->valno->id) && "Bad VNInfo");
830 // Print value number info.
831 if (getNumValNums()) {
834 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
836 const VNInfo *vni = *i;
839 if (vni->isUnused()) {
842 if (!vni->isDefAccurate() && !vni->isPHIDef())
846 if (vni->hasPHIKill())
848 if (vni->hasRedefByEC())
855 void LiveInterval::dump() const {
856 dbgs() << *this << "\n";
860 void LiveRange::print(raw_ostream &os) const {