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' abd 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/raw_ostream.h"
28 #include "llvm/Target/TargetRegisterInfo.h"
32 // An example for liveAt():
34 // this = [1,4), liveAt(0) will return false. The instruction defining this
35 // spans slots [0,3]. The interval belongs to an spilled definition of the
36 // variable it represents. This is because slot 1 is used (def slot) and spans
37 // up to slot 3 (store slot).
39 bool LiveInterval::liveAt(SlotIndex I) const {
40 Ranges::const_iterator r = std::upper_bound(ranges.begin(), ranges.end(), I);
42 if (r == ranges.begin())
46 return r->contains(I);
49 // liveBeforeAndAt - Check if the interval is live at the index and the index
50 // just before it. If index is liveAt, check if it starts a new live range.
51 // If it does, then check if the previous live range ends at index-1.
52 bool LiveInterval::liveBeforeAndAt(SlotIndex I) const {
53 Ranges::const_iterator r = std::upper_bound(ranges.begin(), ranges.end(), I);
55 if (r == ranges.begin())
63 // I is the start of a live range. Check if the previous live range ends
65 if (r == ranges.begin())
70 // overlaps - Return true if the intersection of the two live intervals is
73 // An example for overlaps():
77 // 8: C = A + B ;; last use of A
79 // The live intervals should look like:
85 // A->overlaps(C) should return false since we want to be able to join
88 bool LiveInterval::overlapsFrom(const LiveInterval& other,
89 const_iterator StartPos) const {
90 const_iterator i = begin();
91 const_iterator ie = end();
92 const_iterator j = StartPos;
93 const_iterator je = other.end();
95 assert((StartPos->start <= i->start || StartPos == other.begin()) &&
96 StartPos != other.end() && "Bogus start position hint!");
98 if (i->start < j->start) {
99 i = std::upper_bound(i, ie, j->start);
100 if (i != ranges.begin()) --i;
101 } else if (j->start < i->start) {
103 if (StartPos != other.end() && StartPos->start <= i->start) {
104 assert(StartPos < other.end() && i < end());
105 j = std::upper_bound(j, je, i->start);
106 if (j != other.ranges.begin()) --j;
112 if (j == je) return false;
115 if (i->start > j->start) {
120 if (i->end > j->start)
128 /// overlaps - Return true if the live interval overlaps a range specified
130 bool LiveInterval::overlaps(SlotIndex Start, SlotIndex End) const {
131 assert(Start < End && "Invalid range");
132 const_iterator I = begin();
133 const_iterator E = end();
134 const_iterator si = std::upper_bound(I, E, Start);
135 const_iterator ei = std::upper_bound(I, E, End);
141 return si->contains(Start);
144 /// extendIntervalEndTo - This method is used when we want to extend the range
145 /// specified by I to end at the specified endpoint. To do this, we should
146 /// merge and eliminate all ranges that this will overlap with. The iterator is
148 void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) {
149 assert(I != ranges.end() && "Not a valid interval!");
150 VNInfo *ValNo = I->valno;
151 SlotIndex OldEnd = I->end;
153 // Search for the first interval that we can't merge with.
154 Ranges::iterator MergeTo = next(I);
155 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
156 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
159 // If NewEnd was in the middle of an interval, make sure to get its endpoint.
160 I->end = std::max(NewEnd, prior(MergeTo)->end);
162 // Erase any dead ranges.
163 ranges.erase(next(I), MergeTo);
166 ValNo->removeKills(OldEnd, I->end.getPrevSlot());
168 // If the newly formed range now touches the range after it and if they have
169 // the same value number, merge the two ranges into one range.
170 Ranges::iterator Next = next(I);
171 if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) {
178 /// extendIntervalStartTo - This method is used when we want to extend the range
179 /// specified by I to start at the specified endpoint. To do this, we should
180 /// merge and eliminate all ranges that this will overlap with.
181 LiveInterval::Ranges::iterator
182 LiveInterval::extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStart) {
183 assert(I != ranges.end() && "Not a valid interval!");
184 VNInfo *ValNo = I->valno;
186 // Search for the first interval that we can't merge with.
187 Ranges::iterator MergeTo = I;
189 if (MergeTo == ranges.begin()) {
191 ranges.erase(MergeTo, I);
194 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
196 } while (NewStart <= MergeTo->start);
198 // If we start in the middle of another interval, just delete a range and
199 // extend that interval.
200 if (MergeTo->end >= NewStart && MergeTo->valno == ValNo) {
201 MergeTo->end = I->end;
203 // Otherwise, extend the interval right after.
205 MergeTo->start = NewStart;
206 MergeTo->end = I->end;
209 ranges.erase(next(MergeTo), next(I));
213 LiveInterval::iterator
214 LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
215 SlotIndex Start = LR.start, End = LR.end;
216 iterator it = std::upper_bound(From, ranges.end(), Start);
218 // If the inserted interval starts in the middle or right at the end of
219 // another interval, just extend that interval to contain the range of LR.
220 if (it != ranges.begin()) {
221 iterator B = prior(it);
222 if (LR.valno == B->valno) {
223 if (B->start <= Start && B->end >= Start) {
224 extendIntervalEndTo(B, End);
228 // Check to make sure that we are not overlapping two live ranges with
229 // different valno's.
230 assert(B->end <= Start &&
231 "Cannot overlap two LiveRanges with differing ValID's"
232 " (did you def the same reg twice in a MachineInstr?)");
236 // Otherwise, if this range ends in the middle of, or right next to, another
237 // interval, merge it into that interval.
238 if (it != ranges.end()) {
239 if (LR.valno == it->valno) {
240 if (it->start <= End) {
241 it = extendIntervalStartTo(it, Start);
243 // If LR is a complete superset of an interval, we may need to grow its
246 extendIntervalEndTo(it, End);
247 else if (End < it->end)
248 // Overlapping intervals, there might have been a kill here.
249 it->valno->removeKill(End);
253 // Check to make sure that we are not overlapping two live ranges with
254 // different valno's.
255 assert(it->start >= End &&
256 "Cannot overlap two LiveRanges with differing ValID's");
260 // Otherwise, this is just a new range that doesn't interact with anything.
262 return ranges.insert(it, LR);
265 /// isInOneLiveRange - Return true if the range specified is entirely in
266 /// a single LiveRange of the live interval.
267 bool LiveInterval::isInOneLiveRange(SlotIndex Start, SlotIndex End) {
268 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
269 if (I == ranges.begin())
272 return I->containsRange(Start, End);
276 /// removeRange - Remove the specified range from this interval. Note that
277 /// the range must be in a single LiveRange in its entirety.
278 void LiveInterval::removeRange(SlotIndex Start, SlotIndex End,
279 bool RemoveDeadValNo) {
280 // Find the LiveRange containing this span.
281 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
282 assert(I != ranges.begin() && "Range is not in interval!");
284 assert(I->containsRange(Start, End) && "Range is not entirely in interval!");
286 // If the span we are removing is at the start of the LiveRange, adjust it.
287 VNInfo *ValNo = I->valno;
288 if (I->start == Start) {
290 ValNo->removeKills(Start, End);
291 if (RemoveDeadValNo) {
292 // Check if val# is dead.
294 for (const_iterator II = begin(), EE = end(); II != EE; ++II)
295 if (II != I && II->valno == ValNo) {
300 // Now that ValNo is dead, remove it. If it is the largest value
301 // number, just nuke it (and any other deleted values neighboring it),
302 // otherwise mark it as ~1U so it can be nuked later.
303 if (ValNo->id == getNumValNums()-1) {
305 VNInfo *VNI = valnos.back();
308 } while (!valnos.empty() && valnos.back()->isUnused());
310 ValNo->setIsUnused(true);
315 ranges.erase(I); // Removed the whole LiveRange.
321 // Otherwise if the span we are removing is at the end of the LiveRange,
322 // adjust the other way.
324 ValNo->removeKills(Start, End);
329 // Otherwise, we are splitting the LiveRange into two pieces.
330 SlotIndex OldEnd = I->end;
331 I->end = Start; // Trim the old interval.
333 // Insert the new one.
334 ranges.insert(next(I), LiveRange(End, OldEnd, ValNo));
337 /// removeValNo - Remove all the ranges defined by the specified value#.
338 /// Also remove the value# from value# list.
339 void LiveInterval::removeValNo(VNInfo *ValNo) {
341 Ranges::iterator I = ranges.end();
342 Ranges::iterator E = ranges.begin();
345 if (I->valno == ValNo)
348 // Now that ValNo is dead, remove it. If it is the largest value
349 // number, just nuke it (and any other deleted values neighboring it),
350 // otherwise mark it as ~1U so it can be nuked later.
351 if (ValNo->id == getNumValNums()-1) {
353 VNInfo *VNI = valnos.back();
356 } while (!valnos.empty() && valnos.back()->isUnused());
358 ValNo->setIsUnused(true);
362 /// getLiveRangeContaining - Return the live range that contains the
363 /// specified index, or null if there is none.
364 LiveInterval::const_iterator
365 LiveInterval::FindLiveRangeContaining(SlotIndex Idx) const {
366 const_iterator It = std::upper_bound(begin(), end(), Idx);
367 if (It != ranges.begin()) {
369 if (It->contains(Idx))
376 LiveInterval::iterator
377 LiveInterval::FindLiveRangeContaining(SlotIndex Idx) {
378 iterator It = std::upper_bound(begin(), end(), Idx);
381 if (It->contains(Idx))
388 /// findDefinedVNInfo - Find the VNInfo defined by the specified
389 /// index (register interval).
390 VNInfo *LiveInterval::findDefinedVNInfoForRegInt(SlotIndex Idx) const {
391 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
393 if ((*i)->def == Idx)
400 /// findDefinedVNInfo - Find the VNInfo defined by the specified
401 /// register (stack inteval).
402 VNInfo *LiveInterval::findDefinedVNInfoForStackInt(unsigned reg) const {
403 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
405 if ((*i)->getReg() == reg)
411 /// join - Join two live intervals (this, and other) together. This applies
412 /// mappings to the value numbers in the LHS/RHS intervals as specified. If
413 /// the intervals are not joinable, this aborts.
414 void LiveInterval::join(LiveInterval &Other,
415 const int *LHSValNoAssignments,
416 const int *RHSValNoAssignments,
417 SmallVector<VNInfo*, 16> &NewVNInfo,
418 MachineRegisterInfo *MRI) {
419 // Determine if any of our live range values are mapped. This is uncommon, so
420 // we want to avoid the interval scan if not.
421 bool MustMapCurValNos = false;
422 unsigned NumVals = getNumValNums();
423 unsigned NumNewVals = NewVNInfo.size();
424 for (unsigned i = 0; i != NumVals; ++i) {
425 unsigned LHSValID = LHSValNoAssignments[i];
427 (NewVNInfo[LHSValID] && NewVNInfo[LHSValID] != getValNumInfo(i)))
428 MustMapCurValNos = true;
431 // If we have to apply a mapping to our base interval assignment, rewrite it
433 if (MustMapCurValNos) {
434 // Map the first live range.
435 iterator OutIt = begin();
436 OutIt->valno = NewVNInfo[LHSValNoAssignments[OutIt->valno->id]];
438 for (iterator I = OutIt, E = end(); I != E; ++I) {
439 OutIt->valno = NewVNInfo[LHSValNoAssignments[I->valno->id]];
441 // If this live range has the same value # as its immediate predecessor,
442 // and if they are neighbors, remove one LiveRange. This happens when we
443 // have [0,3:0)[4,7:1) and map 0/1 onto the same value #.
444 if (OutIt->valno == (OutIt-1)->valno && (OutIt-1)->end == OutIt->start) {
445 (OutIt-1)->end = OutIt->end;
448 OutIt->start = I->start;
452 // Didn't merge, on to the next one.
457 // If we merge some live ranges, chop off the end.
458 ranges.erase(OutIt, end());
461 // Remember assignements because val# ids are changing.
462 SmallVector<unsigned, 16> OtherAssignments;
463 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
464 OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]);
466 // Update val# info. Renumber them and make sure they all belong to this
467 // LiveInterval now. Also remove dead val#'s.
468 unsigned NumValNos = 0;
469 for (unsigned i = 0; i < NumNewVals; ++i) {
470 VNInfo *VNI = NewVNInfo[i];
472 if (NumValNos >= NumVals)
473 valnos.push_back(VNI);
475 valnos[NumValNos] = VNI;
476 VNI->id = NumValNos++; // Renumber val#.
479 if (NumNewVals < NumVals)
480 valnos.resize(NumNewVals); // shrinkify
482 // Okay, now insert the RHS live ranges into the LHS.
483 iterator InsertPos = begin();
484 unsigned RangeNo = 0;
485 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I, ++RangeNo) {
486 // Map the valno in the other live range to the current live range.
487 I->valno = NewVNInfo[OtherAssignments[RangeNo]];
488 assert(I->valno && "Adding a dead range?");
489 InsertPos = addRangeFrom(*I, InsertPos);
492 ComputeJoinedWeight(Other);
494 // Update regalloc hint if currently there isn't one.
495 if (TargetRegisterInfo::isVirtualRegister(reg) &&
496 TargetRegisterInfo::isVirtualRegister(Other.reg)) {
497 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(reg);
498 if (Hint.first == 0 && Hint.second == 0) {
499 std::pair<unsigned, unsigned> OtherHint =
500 MRI->getRegAllocationHint(Other.reg);
501 if (OtherHint.first || OtherHint.second)
502 MRI->setRegAllocationHint(reg, OtherHint.first, OtherHint.second);
507 /// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
508 /// interval as the specified value number. The LiveRanges in RHS are
509 /// allowed to overlap with LiveRanges in the current interval, but only if
510 /// the overlapping LiveRanges have the specified value number.
511 void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS,
513 // TODO: Make this more efficient.
514 iterator InsertPos = begin();
515 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
516 // Map the valno in the other live range to the current live range.
518 Tmp.valno = LHSValNo;
519 InsertPos = addRangeFrom(Tmp, InsertPos);
524 /// MergeValueInAsValue - Merge all of the live ranges of a specific val#
525 /// in RHS into this live interval as the specified value number.
526 /// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
527 /// current interval, it will replace the value numbers of the overlaped
528 /// live ranges with the specified value number.
529 void LiveInterval::MergeValueInAsValue(
530 const LiveInterval &RHS,
531 const VNInfo *RHSValNo, VNInfo *LHSValNo) {
532 SmallVector<VNInfo*, 4> ReplacedValNos;
533 iterator IP = begin();
534 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
535 if (I->valno != RHSValNo)
537 SlotIndex Start = I->start, End = I->end;
538 IP = std::upper_bound(IP, end(), Start);
539 // If the start of this range overlaps with an existing liverange, trim it.
540 if (IP != begin() && IP[-1].end > Start) {
541 if (IP[-1].valno != LHSValNo) {
542 ReplacedValNos.push_back(IP[-1].valno);
543 IP[-1].valno = LHSValNo; // Update val#.
546 // Trimmed away the whole range?
547 if (Start >= End) continue;
549 // If the end of this range overlaps with an existing liverange, trim it.
550 if (IP != end() && End > IP->start) {
551 if (IP->valno != LHSValNo) {
552 ReplacedValNos.push_back(IP->valno);
553 IP->valno = LHSValNo; // Update val#.
556 // If this trimmed away the whole range, ignore it.
557 if (Start == End) continue;
560 // Map the valno in the other live range to the current live range.
561 IP = addRangeFrom(LiveRange(Start, End, LHSValNo), IP);
565 SmallSet<VNInfo*, 4> Seen;
566 for (unsigned i = 0, e = ReplacedValNos.size(); i != e; ++i) {
567 VNInfo *V1 = ReplacedValNos[i];
568 if (Seen.insert(V1)) {
570 for (const_iterator I = begin(), E = end(); I != E; ++I)
571 if (I->valno == V1) {
576 // Now that V1 is dead, remove it. If it is the largest value number,
577 // just nuke it (and any other deleted values neighboring it), otherwise
578 // mark it as ~1U so it can be nuked later.
579 if (V1->id == getNumValNums()-1) {
581 VNInfo *VNI = valnos.back();
584 } while (!valnos.empty() && valnos.back()->isUnused());
586 V1->setIsUnused(true);
594 /// MergeInClobberRanges - For any live ranges that are not defined in the
595 /// current interval, but are defined in the Clobbers interval, mark them
596 /// used with an unknown definition value.
597 void LiveInterval::MergeInClobberRanges(LiveIntervals &li_,
598 const LiveInterval &Clobbers,
599 BumpPtrAllocator &VNInfoAllocator) {
600 if (Clobbers.empty()) return;
602 DenseMap<VNInfo*, VNInfo*> ValNoMaps;
603 VNInfo *UnusedValNo = 0;
604 iterator IP = begin();
605 for (const_iterator I = Clobbers.begin(), E = Clobbers.end(); I != E; ++I) {
606 // For every val# in the Clobbers interval, create a new "unknown" val#.
607 VNInfo *ClobberValNo = 0;
608 DenseMap<VNInfo*, VNInfo*>::iterator VI = ValNoMaps.find(I->valno);
609 if (VI != ValNoMaps.end())
610 ClobberValNo = VI->second;
611 else if (UnusedValNo)
612 ClobberValNo = UnusedValNo;
614 UnusedValNo = ClobberValNo =
615 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
616 ValNoMaps.insert(std::make_pair(I->valno, ClobberValNo));
620 SlotIndex Start = I->start, End = I->end;
621 // If a clobber range starts before an existing range and ends after
622 // it, the clobber range will need to be split into multiple ranges.
623 // Loop until the entire clobber range is handled.
626 IP = std::upper_bound(IP, end(), Start);
627 SlotIndex SubRangeStart = Start;
628 SlotIndex SubRangeEnd = End;
630 // If the start of this range overlaps with an existing liverange, trim it.
631 if (IP != begin() && IP[-1].end > SubRangeStart) {
632 SubRangeStart = IP[-1].end;
633 // Trimmed away the whole range?
634 if (SubRangeStart >= SubRangeEnd) continue;
636 // If the end of this range overlaps with an existing liverange, trim it.
637 if (IP != end() && SubRangeEnd > IP->start) {
638 // If the clobber live range extends beyond the existing live range,
639 // it'll need at least another live range, so set the flag to keep
641 if (SubRangeEnd > IP->end) {
645 SubRangeEnd = IP->start;
646 // If this trimmed away the whole range, ignore it.
647 if (SubRangeStart == SubRangeEnd) continue;
650 // Insert the clobber interval.
651 IP = addRangeFrom(LiveRange(SubRangeStart, SubRangeEnd, ClobberValNo),
658 // Delete the last unused val#.
660 UnusedValNo->~VNInfo();
664 void LiveInterval::MergeInClobberRange(LiveIntervals &li_,
667 BumpPtrAllocator &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. If it is the largest value number, just
747 // nuke it (and any other deleted values neighboring it), otherwise mark it as
748 // ~1U so it can be nuked later.
749 if (V1->id == getNumValNums()-1) {
751 VNInfo *VNI = valnos.back();
754 } while (valnos.back()->isUnused());
756 V1->setIsUnused(true);
762 void LiveInterval::Copy(const LiveInterval &RHS,
763 MachineRegisterInfo *MRI,
764 BumpPtrAllocator &VNInfoAllocator) {
767 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(RHS.reg);
768 MRI->setRegAllocationHint(reg, Hint.first, Hint.second);
771 for (unsigned i = 0, e = RHS.getNumValNums(); i != e; ++i) {
772 const VNInfo *VNI = RHS.getValNumInfo(i);
773 createValueCopy(VNI, VNInfoAllocator);
775 for (unsigned i = 0, e = RHS.ranges.size(); i != e; ++i) {
776 const LiveRange &LR = RHS.ranges[i];
777 addRange(LiveRange(LR.start, LR.end, getValNumInfo(LR.valno->id)));
781 unsigned LiveInterval::getSize() const {
783 for (const_iterator I = begin(), E = end(); I != E; ++I)
784 Sum += I->start.distance(I->end);
788 /// ComputeJoinedWeight - Set the weight of a live interval Joined
789 /// after Other has been merged into it.
790 void LiveInterval::ComputeJoinedWeight(const LiveInterval &Other) {
791 // If either of these intervals was spilled, the weight is the
792 // weight of the non-spilled interval. This can only happen with
793 // iterative coalescers.
795 if (Other.weight != HUGE_VALF) {
796 weight += Other.weight;
798 else if (weight == HUGE_VALF &&
799 !TargetRegisterInfo::isPhysicalRegister(reg)) {
800 // Remove this assert if you have an iterative coalescer
801 assert(0 && "Joining to spilled interval");
802 weight = Other.weight;
805 // Otherwise the weight stays the same
806 // Remove this assert if you have an iterative coalescer
807 assert(0 && "Joining from spilled interval");
811 raw_ostream& llvm::operator<<(raw_ostream& os, const LiveRange &LR) {
812 return os << '[' << LR.start << ',' << LR.end << ':' << LR.valno->id << ")";
815 void LiveRange::dump() const {
816 errs() << *this << "\n";
819 void LiveInterval::print(raw_ostream &OS, const TargetRegisterInfo *TRI) const {
821 OS << "SS#" << getStackSlotIndex();
822 else if (TRI && TargetRegisterInfo::isPhysicalRegister(reg))
823 OS << TRI->getName(reg);
833 for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
834 E = ranges.end(); I != E; ++I)
838 // Print value number info.
839 if (getNumValNums()) {
842 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
844 const VNInfo *vni = *i;
847 if (vni->isUnused()) {
850 if (!vni->isDefAccurate() && !vni->isPHIDef())
854 unsigned ee = vni->kills.size();
855 if (ee || vni->hasPHIKill()) {
857 for (unsigned j = 0; j != ee; ++j) {
862 if (vni->hasPHIKill()) {
874 void LiveInterval::dump() const {
875 errs() << *this << "\n";
879 void LiveRange::print(raw_ostream &os) const {