LiveInterval.cpp revision e0a73ec0a982a4213f3de9860545d9bf2814593d
1//===-- LiveInterval.cpp - Live Interval Representation -------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
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.
18//
19//===----------------------------------------------------------------------===//
20
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"
30#include <algorithm>
31using namespace llvm;
32
33// CompEnd - Compare LiveRange ends.
34namespace {
35struct CompEnd {
36  bool operator()(const LiveRange &A, const LiveRange &B) const {
37    return A.end < B.end;
38  }
39};
40}
41
42LiveInterval::iterator LiveInterval::find(SlotIndex Pos) {
43  return std::upper_bound(begin(), end(), LiveRange(SlotIndex(), Pos, 0),
44                          CompEnd());
45}
46
47/// killedInRange - Return true if the interval has kills in [Start,End).
48bool LiveInterval::killedInRange(SlotIndex Start, SlotIndex End) const {
49  Ranges::const_iterator r =
50    std::lower_bound(ranges.begin(), ranges.end(), End);
51
52  // Now r points to the first interval with start >= End, or ranges.end().
53  if (r == ranges.begin())
54    return false;
55
56  --r;
57  // Now r points to the last interval with end <= End.
58  // r->end is the kill point.
59  return r->end >= Start && r->end < End;
60}
61
62// overlaps - Return true if the intersection of the two live intervals is
63// not empty.
64//
65// An example for overlaps():
66//
67// 0: A = ...
68// 4: B = ...
69// 8: C = A + B ;; last use of A
70//
71// The live intervals should look like:
72//
73// A = [3, 11)
74// B = [7, x)
75// C = [11, y)
76//
77// A->overlaps(C) should return false since we want to be able to join
78// A and C.
79//
80bool LiveInterval::overlapsFrom(const LiveInterval& other,
81                                const_iterator StartPos) const {
82  assert(!empty() && "empty interval");
83  const_iterator i = begin();
84  const_iterator ie = end();
85  const_iterator j = StartPos;
86  const_iterator je = other.end();
87
88  assert((StartPos->start <= i->start || StartPos == other.begin()) &&
89         StartPos != other.end() && "Bogus start position hint!");
90
91  if (i->start < j->start) {
92    i = std::upper_bound(i, ie, j->start);
93    if (i != ranges.begin()) --i;
94  } else if (j->start < i->start) {
95    ++StartPos;
96    if (StartPos != other.end() && StartPos->start <= i->start) {
97      assert(StartPos < other.end() && i < end());
98      j = std::upper_bound(j, je, i->start);
99      if (j != other.ranges.begin()) --j;
100    }
101  } else {
102    return true;
103  }
104
105  if (j == je) return false;
106
107  while (i != ie) {
108    if (i->start > j->start) {
109      std::swap(i, j);
110      std::swap(ie, je);
111    }
112
113    if (i->end > j->start)
114      return true;
115    ++i;
116  }
117
118  return false;
119}
120
121/// overlaps - Return true if the live interval overlaps a range specified
122/// by [Start, End).
123bool LiveInterval::overlaps(SlotIndex Start, SlotIndex End) const {
124  assert(Start < End && "Invalid range");
125  const_iterator I = std::lower_bound(begin(), end(), End);
126  return I != begin() && (--I)->end > Start;
127}
128
129
130/// ValNo is dead, remove it.  If it is the largest value number, just nuke it
131/// (and any other deleted values neighboring it), otherwise mark it as ~1U so
132/// it can be nuked later.
133void LiveInterval::markValNoForDeletion(VNInfo *ValNo) {
134  if (ValNo->id == getNumValNums()-1) {
135    do {
136      valnos.pop_back();
137    } while (!valnos.empty() && valnos.back()->isUnused());
138  } else {
139    ValNo->setIsUnused(true);
140  }
141}
142
143/// RenumberValues - Renumber all values in order of appearance and delete the
144/// remaining unused values.
145void LiveInterval::RenumberValues(LiveIntervals &lis) {
146  SmallPtrSet<VNInfo*, 8> Seen;
147  bool seenPHIDef = false;
148  valnos.clear();
149  for (const_iterator I = begin(), E = end(); I != E; ++I) {
150    VNInfo *VNI = I->valno;
151    if (!Seen.insert(VNI))
152      continue;
153    assert(!VNI->isUnused() && "Unused valno used by live range");
154    VNI->id = (unsigned)valnos.size();
155    valnos.push_back(VNI);
156    VNI->setHasPHIKill(false);
157    if (VNI->isPHIDef())
158      seenPHIDef = true;
159  }
160
161  // Recompute phi kill flags.
162  if (!seenPHIDef)
163    return;
164  for (const_vni_iterator I = vni_begin(), E = vni_end(); I != E; ++I) {
165    VNInfo *VNI = *I;
166    if (!VNI->isPHIDef())
167      continue;
168    const MachineBasicBlock *PHIBB = lis.getMBBFromIndex(VNI->def);
169    assert(PHIBB && "No basic block for phi-def");
170    for (MachineBasicBlock::const_pred_iterator PI = PHIBB->pred_begin(),
171         PE = PHIBB->pred_end(); PI != PE; ++PI) {
172      VNInfo *KVNI = getVNInfoAt(lis.getMBBEndIdx(*PI).getPrevSlot());
173      if (KVNI)
174        KVNI->setHasPHIKill(true);
175    }
176  }
177}
178
179/// extendIntervalEndTo - This method is used when we want to extend the range
180/// specified by I to end at the specified endpoint.  To do this, we should
181/// merge and eliminate all ranges that this will overlap with.  The iterator is
182/// not invalidated.
183void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) {
184  assert(I != ranges.end() && "Not a valid interval!");
185  VNInfo *ValNo = I->valno;
186
187  // Search for the first interval that we can't merge with.
188  Ranges::iterator MergeTo = llvm::next(I);
189  for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
190    assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
191  }
192
193  // If NewEnd was in the middle of an interval, make sure to get its endpoint.
194  I->end = std::max(NewEnd, prior(MergeTo)->end);
195
196  // Erase any dead ranges.
197  ranges.erase(llvm::next(I), MergeTo);
198
199  // If the newly formed range now touches the range after it and if they have
200  // the same value number, merge the two ranges into one range.
201  Ranges::iterator Next = llvm::next(I);
202  if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) {
203    I->end = Next->end;
204    ranges.erase(Next);
205  }
206}
207
208
209/// extendIntervalStartTo - This method is used when we want to extend the range
210/// specified by I to start at the specified endpoint.  To do this, we should
211/// merge and eliminate all ranges that this will overlap with.
212LiveInterval::Ranges::iterator
213LiveInterval::extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStart) {
214  assert(I != ranges.end() && "Not a valid interval!");
215  VNInfo *ValNo = I->valno;
216
217  // Search for the first interval that we can't merge with.
218  Ranges::iterator MergeTo = I;
219  do {
220    if (MergeTo == ranges.begin()) {
221      I->start = NewStart;
222      ranges.erase(MergeTo, I);
223      return I;
224    }
225    assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
226    --MergeTo;
227  } while (NewStart <= MergeTo->start);
228
229  // If we start in the middle of another interval, just delete a range and
230  // extend that interval.
231  if (MergeTo->end >= NewStart && MergeTo->valno == ValNo) {
232    MergeTo->end = I->end;
233  } else {
234    // Otherwise, extend the interval right after.
235    ++MergeTo;
236    MergeTo->start = NewStart;
237    MergeTo->end = I->end;
238  }
239
240  ranges.erase(llvm::next(MergeTo), llvm::next(I));
241  return MergeTo;
242}
243
244LiveInterval::iterator
245LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
246  SlotIndex Start = LR.start, End = LR.end;
247  iterator it = std::upper_bound(From, ranges.end(), Start);
248
249  // If the inserted interval starts in the middle or right at the end of
250  // another interval, just extend that interval to contain the range of LR.
251  if (it != ranges.begin()) {
252    iterator B = prior(it);
253    if (LR.valno == B->valno) {
254      if (B->start <= Start && B->end >= Start) {
255        extendIntervalEndTo(B, End);
256        return B;
257      }
258    } else {
259      // Check to make sure that we are not overlapping two live ranges with
260      // different valno's.
261      assert(B->end <= Start &&
262             "Cannot overlap two LiveRanges with differing ValID's"
263             " (did you def the same reg twice in a MachineInstr?)");
264    }
265  }
266
267  // Otherwise, if this range ends in the middle of, or right next to, another
268  // interval, merge it into that interval.
269  if (it != ranges.end()) {
270    if (LR.valno == it->valno) {
271      if (it->start <= End) {
272        it = extendIntervalStartTo(it, Start);
273
274        // If LR is a complete superset of an interval, we may need to grow its
275        // endpoint as well.
276        if (End > it->end)
277          extendIntervalEndTo(it, End);
278        return it;
279      }
280    } else {
281      // Check to make sure that we are not overlapping two live ranges with
282      // different valno's.
283      assert(it->start >= End &&
284             "Cannot overlap two LiveRanges with differing ValID's");
285    }
286  }
287
288  // Otherwise, this is just a new range that doesn't interact with anything.
289  // Insert it.
290  return ranges.insert(it, LR);
291}
292
293
294/// removeRange - Remove the specified range from this interval.  Note that
295/// the range must be in a single LiveRange in its entirety.
296void LiveInterval::removeRange(SlotIndex Start, SlotIndex End,
297                               bool RemoveDeadValNo) {
298  // Find the LiveRange containing this span.
299  Ranges::iterator I = find(Start);
300  assert(I != ranges.end() && "Range is not in interval!");
301  assert(I->containsRange(Start, End) && "Range is not entirely in interval!");
302
303  // If the span we are removing is at the start of the LiveRange, adjust it.
304  VNInfo *ValNo = I->valno;
305  if (I->start == Start) {
306    if (I->end == End) {
307      if (RemoveDeadValNo) {
308        // Check if val# is dead.
309        bool isDead = true;
310        for (const_iterator II = begin(), EE = end(); II != EE; ++II)
311          if (II != I && II->valno == ValNo) {
312            isDead = false;
313            break;
314          }
315        if (isDead) {
316          // Now that ValNo is dead, remove it.
317          markValNoForDeletion(ValNo);
318        }
319      }
320
321      ranges.erase(I);  // Removed the whole LiveRange.
322    } else
323      I->start = End;
324    return;
325  }
326
327  // Otherwise if the span we are removing is at the end of the LiveRange,
328  // adjust the other way.
329  if (I->end == End) {
330    I->end = Start;
331    return;
332  }
333
334  // Otherwise, we are splitting the LiveRange into two pieces.
335  SlotIndex OldEnd = I->end;
336  I->end = Start;   // Trim the old interval.
337
338  // Insert the new one.
339  ranges.insert(llvm::next(I), LiveRange(End, OldEnd, ValNo));
340}
341
342/// removeValNo - Remove all the ranges defined by the specified value#.
343/// Also remove the value# from value# list.
344void LiveInterval::removeValNo(VNInfo *ValNo) {
345  if (empty()) return;
346  Ranges::iterator I = ranges.end();
347  Ranges::iterator E = ranges.begin();
348  do {
349    --I;
350    if (I->valno == ValNo)
351      ranges.erase(I);
352  } while (I != E);
353  // Now that ValNo is dead, remove it.
354  markValNoForDeletion(ValNo);
355}
356
357/// findDefinedVNInfo - Find the VNInfo defined by the specified
358/// index (register interval).
359VNInfo *LiveInterval::findDefinedVNInfoForRegInt(SlotIndex Idx) const {
360  for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
361       i != e; ++i) {
362    if ((*i)->def == Idx)
363      return *i;
364  }
365
366  return 0;
367}
368
369/// join - Join two live intervals (this, and other) together.  This applies
370/// mappings to the value numbers in the LHS/RHS intervals as specified.  If
371/// the intervals are not joinable, this aborts.
372void LiveInterval::join(LiveInterval &Other,
373                        const int *LHSValNoAssignments,
374                        const int *RHSValNoAssignments,
375                        SmallVector<VNInfo*, 16> &NewVNInfo,
376                        MachineRegisterInfo *MRI) {
377  // Determine if any of our live range values are mapped.  This is uncommon, so
378  // we want to avoid the interval scan if not.
379  bool MustMapCurValNos = false;
380  unsigned NumVals = getNumValNums();
381  unsigned NumNewVals = NewVNInfo.size();
382  for (unsigned i = 0; i != NumVals; ++i) {
383    unsigned LHSValID = LHSValNoAssignments[i];
384    if (i != LHSValID ||
385        (NewVNInfo[LHSValID] && NewVNInfo[LHSValID] != getValNumInfo(i)))
386      MustMapCurValNos = true;
387  }
388
389  // If we have to apply a mapping to our base interval assignment, rewrite it
390  // now.
391  if (MustMapCurValNos) {
392    // Map the first live range.
393    iterator OutIt = begin();
394    OutIt->valno = NewVNInfo[LHSValNoAssignments[OutIt->valno->id]];
395    ++OutIt;
396    for (iterator I = OutIt, E = end(); I != E; ++I) {
397      OutIt->valno = NewVNInfo[LHSValNoAssignments[I->valno->id]];
398
399      // If this live range has the same value # as its immediate predecessor,
400      // and if they are neighbors, remove one LiveRange.  This happens when we
401      // have [0,3:0)[4,7:1) and map 0/1 onto the same value #.
402      if (OutIt->valno == (OutIt-1)->valno && (OutIt-1)->end == OutIt->start) {
403        (OutIt-1)->end = OutIt->end;
404      } else {
405        if (I != OutIt) {
406          OutIt->start = I->start;
407          OutIt->end = I->end;
408        }
409
410        // Didn't merge, on to the next one.
411        ++OutIt;
412      }
413    }
414
415    // If we merge some live ranges, chop off the end.
416    ranges.erase(OutIt, end());
417  }
418
419  // Remember assignements because val# ids are changing.
420  SmallVector<unsigned, 16> OtherAssignments;
421  for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
422    OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]);
423
424  // Update val# info. Renumber them and make sure they all belong to this
425  // LiveInterval now. Also remove dead val#'s.
426  unsigned NumValNos = 0;
427  for (unsigned i = 0; i < NumNewVals; ++i) {
428    VNInfo *VNI = NewVNInfo[i];
429    if (VNI) {
430      if (NumValNos >= NumVals)
431        valnos.push_back(VNI);
432      else
433        valnos[NumValNos] = VNI;
434      VNI->id = NumValNos++;  // Renumber val#.
435    }
436  }
437  if (NumNewVals < NumVals)
438    valnos.resize(NumNewVals);  // shrinkify
439
440  // Okay, now insert the RHS live ranges into the LHS.
441  iterator InsertPos = begin();
442  unsigned RangeNo = 0;
443  for (iterator I = Other.begin(), E = Other.end(); I != E; ++I, ++RangeNo) {
444    // Map the valno in the other live range to the current live range.
445    I->valno = NewVNInfo[OtherAssignments[RangeNo]];
446    assert(I->valno && "Adding a dead range?");
447    InsertPos = addRangeFrom(*I, InsertPos);
448  }
449
450  ComputeJoinedWeight(Other);
451}
452
453/// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
454/// interval as the specified value number.  The LiveRanges in RHS are
455/// allowed to overlap with LiveRanges in the current interval, but only if
456/// the overlapping LiveRanges have the specified value number.
457void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS,
458                                        VNInfo *LHSValNo) {
459  // TODO: Make this more efficient.
460  iterator InsertPos = begin();
461  for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
462    // Map the valno in the other live range to the current live range.
463    LiveRange Tmp = *I;
464    Tmp.valno = LHSValNo;
465    InsertPos = addRangeFrom(Tmp, InsertPos);
466  }
467}
468
469
470/// MergeValueInAsValue - Merge all of the live ranges of a specific val#
471/// in RHS into this live interval as the specified value number.
472/// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
473/// current interval, it will replace the value numbers of the overlaped
474/// live ranges with the specified value number.
475void LiveInterval::MergeValueInAsValue(
476                                    const LiveInterval &RHS,
477                                    const VNInfo *RHSValNo, VNInfo *LHSValNo) {
478  SmallVector<VNInfo*, 4> ReplacedValNos;
479  iterator IP = begin();
480  for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
481    assert(I->valno == RHS.getValNumInfo(I->valno->id) && "Bad VNInfo");
482    if (I->valno != RHSValNo)
483      continue;
484    SlotIndex Start = I->start, End = I->end;
485    IP = std::upper_bound(IP, end(), Start);
486    // If the start of this range overlaps with an existing liverange, trim it.
487    if (IP != begin() && IP[-1].end > Start) {
488      if (IP[-1].valno != LHSValNo) {
489        ReplacedValNos.push_back(IP[-1].valno);
490        IP[-1].valno = LHSValNo; // Update val#.
491      }
492      Start = IP[-1].end;
493      // Trimmed away the whole range?
494      if (Start >= End) continue;
495    }
496    // If the end of this range overlaps with an existing liverange, trim it.
497    if (IP != end() && End > IP->start) {
498      if (IP->valno != LHSValNo) {
499        ReplacedValNos.push_back(IP->valno);
500        IP->valno = LHSValNo;  // Update val#.
501      }
502      End = IP->start;
503      // If this trimmed away the whole range, ignore it.
504      if (Start == End) continue;
505    }
506
507    // Map the valno in the other live range to the current live range.
508    IP = addRangeFrom(LiveRange(Start, End, LHSValNo), IP);
509  }
510
511
512  SmallSet<VNInfo*, 4> Seen;
513  for (unsigned i = 0, e = ReplacedValNos.size(); i != e; ++i) {
514    VNInfo *V1 = ReplacedValNos[i];
515    if (Seen.insert(V1)) {
516      bool isDead = true;
517      for (const_iterator I = begin(), E = end(); I != E; ++I)
518        if (I->valno == V1) {
519          isDead = false;
520          break;
521        }
522      if (isDead) {
523        // Now that V1 is dead, remove it.
524        markValNoForDeletion(V1);
525      }
526    }
527  }
528}
529
530
531
532/// MergeValueNumberInto - This method is called when two value nubmers
533/// are found to be equivalent.  This eliminates V1, replacing all
534/// LiveRanges with the V1 value number with the V2 value number.  This can
535/// cause merging of V1/V2 values numbers and compaction of the value space.
536VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
537  assert(V1 != V2 && "Identical value#'s are always equivalent!");
538
539  // This code actually merges the (numerically) larger value number into the
540  // smaller value number, which is likely to allow us to compactify the value
541  // space.  The only thing we have to be careful of is to preserve the
542  // instruction that defines the result value.
543
544  // Make sure V2 is smaller than V1.
545  if (V1->id < V2->id) {
546    V1->copyFrom(*V2);
547    std::swap(V1, V2);
548  }
549
550  // Merge V1 live ranges into V2.
551  for (iterator I = begin(); I != end(); ) {
552    iterator LR = I++;
553    if (LR->valno != V1) continue;  // Not a V1 LiveRange.
554
555    // Okay, we found a V1 live range.  If it had a previous, touching, V2 live
556    // range, extend it.
557    if (LR != begin()) {
558      iterator Prev = LR-1;
559      if (Prev->valno == V2 && Prev->end == LR->start) {
560        Prev->end = LR->end;
561
562        // Erase this live-range.
563        ranges.erase(LR);
564        I = Prev+1;
565        LR = Prev;
566      }
567    }
568
569    // Okay, now we have a V1 or V2 live range that is maximally merged forward.
570    // Ensure that it is a V2 live-range.
571    LR->valno = V2;
572
573    // If we can merge it into later V2 live ranges, do so now.  We ignore any
574    // following V1 live ranges, as they will be merged in subsequent iterations
575    // of the loop.
576    if (I != end()) {
577      if (I->start == LR->end && I->valno == V2) {
578        LR->end = I->end;
579        ranges.erase(I);
580        I = LR+1;
581      }
582    }
583  }
584
585  // Merge the relevant flags.
586  V2->mergeFlags(V1);
587
588  // Now that V1 is dead, remove it.
589  markValNoForDeletion(V1);
590
591  return V2;
592}
593
594void LiveInterval::Copy(const LiveInterval &RHS,
595                        MachineRegisterInfo *MRI,
596                        VNInfo::Allocator &VNInfoAllocator) {
597  ranges.clear();
598  valnos.clear();
599  std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(RHS.reg);
600  MRI->setRegAllocationHint(reg, Hint.first, Hint.second);
601
602  weight = RHS.weight;
603  for (unsigned i = 0, e = RHS.getNumValNums(); i != e; ++i) {
604    const VNInfo *VNI = RHS.getValNumInfo(i);
605    createValueCopy(VNI, VNInfoAllocator);
606  }
607  for (unsigned i = 0, e = RHS.ranges.size(); i != e; ++i) {
608    const LiveRange &LR = RHS.ranges[i];
609    addRange(LiveRange(LR.start, LR.end, getValNumInfo(LR.valno->id)));
610  }
611}
612
613unsigned LiveInterval::getSize() const {
614  unsigned Sum = 0;
615  for (const_iterator I = begin(), E = end(); I != E; ++I)
616    Sum += I->start.distance(I->end);
617  return Sum;
618}
619
620/// ComputeJoinedWeight - Set the weight of a live interval Joined
621/// after Other has been merged into it.
622void LiveInterval::ComputeJoinedWeight(const LiveInterval &Other) {
623  // If either of these intervals was spilled, the weight is the
624  // weight of the non-spilled interval.  This can only happen with
625  // iterative coalescers.
626
627  if (Other.weight != HUGE_VALF) {
628    weight += Other.weight;
629  }
630  else if (weight == HUGE_VALF &&
631      !TargetRegisterInfo::isPhysicalRegister(reg)) {
632    // Remove this assert if you have an iterative coalescer
633    assert(0 && "Joining to spilled interval");
634    weight = Other.weight;
635  }
636  else {
637    // Otherwise the weight stays the same
638    // Remove this assert if you have an iterative coalescer
639    assert(0 && "Joining from spilled interval");
640  }
641}
642
643raw_ostream& llvm::operator<<(raw_ostream& os, const LiveRange &LR) {
644  return os << '[' << LR.start << ',' << LR.end << ':' << LR.valno->id << ")";
645}
646
647void LiveRange::dump() const {
648  dbgs() << *this << "\n";
649}
650
651void LiveInterval::print(raw_ostream &OS, const TargetRegisterInfo *TRI) const {
652  if (isStackSlot())
653    OS << "SS#" << getStackSlotIndex();
654  else if (TRI && TargetRegisterInfo::isPhysicalRegister(reg))
655    OS << TRI->getName(reg);
656  else
657    OS << "%reg" << reg;
658
659  OS << ',' << weight;
660
661  if (empty())
662    OS << " EMPTY";
663  else {
664    OS << " = ";
665    for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
666           E = ranges.end(); I != E; ++I) {
667      OS << *I;
668      assert(I->valno == getValNumInfo(I->valno->id) && "Bad VNInfo");
669    }
670  }
671
672  // Print value number info.
673  if (getNumValNums()) {
674    OS << "  ";
675    unsigned vnum = 0;
676    for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
677         ++i, ++vnum) {
678      const VNInfo *vni = *i;
679      if (vnum) OS << " ";
680      OS << vnum << "@";
681      if (vni->isUnused()) {
682        OS << "x";
683      } else {
684        OS << vni->def;
685        if (vni->hasPHIKill())
686          OS << "-phikill";
687        if (vni->hasRedefByEC())
688          OS << "-ec";
689      }
690    }
691  }
692}
693
694void LiveInterval::dump() const {
695  dbgs() << *this << "\n";
696}
697
698
699void LiveRange::print(raw_ostream &os) const {
700  os << *this;
701}
702