LiveInterval: Add a 'covers' operation to LiveRange.
[oota-llvm.git] / include / llvm / CodeGen / LiveInterval.h
1 //===-- llvm/CodeGen/LiveInterval.h - Interval representation ---*- C++ -*-===//
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 range 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 ranges can have holes,
15 // i.e. a range might look like [1,20), [50,65), [1000,1001).  Each
16 // individual segment is represented as an instance of LiveRange::Segment,
17 // and the whole range is represented as an instance of LiveRange.
18 //
19 //===----------------------------------------------------------------------===//
20
21 #ifndef LLVM_CODEGEN_LIVEINTERVAL_H
22 #define LLVM_CODEGEN_LIVEINTERVAL_H
23
24 #include "llvm/ADT/IntEqClasses.h"
25 #include "llvm/CodeGen/SlotIndexes.h"
26 #include "llvm/Support/AlignOf.h"
27 #include "llvm/Support/Allocator.h"
28 #include <cassert>
29 #include <climits>
30
31 namespace llvm {
32   class CoalescerPair;
33   class LiveIntervals;
34   class MachineInstr;
35   class MachineRegisterInfo;
36   class TargetRegisterInfo;
37   class raw_ostream;
38   template <typename T, unsigned Small> class SmallPtrSet;
39
40   /// VNInfo - Value Number Information.
41   /// This class holds information about a machine level values, including
42   /// definition and use points.
43   ///
44   class VNInfo {
45   public:
46     typedef BumpPtrAllocator Allocator;
47
48     /// The ID number of this value.
49     unsigned id;
50
51     /// The index of the defining instruction.
52     SlotIndex def;
53
54     /// VNInfo constructor.
55     VNInfo(unsigned i, SlotIndex d)
56       : id(i), def(d)
57     { }
58
59     /// VNInfo construtor, copies values from orig, except for the value number.
60     VNInfo(unsigned i, const VNInfo &orig)
61       : id(i), def(orig.def)
62     { }
63
64     /// Copy from the parameter into this VNInfo.
65     void copyFrom(VNInfo &src) {
66       def = src.def;
67     }
68
69     /// Returns true if this value is defined by a PHI instruction (or was,
70     /// PHI instructions may have been eliminated).
71     /// PHI-defs begin at a block boundary, all other defs begin at register or
72     /// EC slots.
73     bool isPHIDef() const { return def.isBlock(); }
74
75     /// Returns true if this value is unused.
76     bool isUnused() const { return !def.isValid(); }
77
78     /// Mark this value as unused.
79     void markUnused() { def = SlotIndex(); }
80   };
81
82   /// Result of a LiveRange query. This class hides the implementation details
83   /// of live ranges, and it should be used as the primary interface for
84   /// examining live ranges around instructions.
85   class LiveQueryResult {
86     VNInfo *const EarlyVal;
87     VNInfo *const LateVal;
88     const SlotIndex EndPoint;
89     const bool Kill;
90
91   public:
92     LiveQueryResult(VNInfo *EarlyVal, VNInfo *LateVal, SlotIndex EndPoint,
93                     bool Kill)
94       : EarlyVal(EarlyVal), LateVal(LateVal), EndPoint(EndPoint), Kill(Kill)
95     {}
96
97     /// Return the value that is live-in to the instruction. This is the value
98     /// that will be read by the instruction's use operands. Return NULL if no
99     /// value is live-in.
100     VNInfo *valueIn() const {
101       return EarlyVal;
102     }
103
104     /// Return true if the live-in value is killed by this instruction. This
105     /// means that either the live range ends at the instruction, or it changes
106     /// value.
107     bool isKill() const {
108       return Kill;
109     }
110
111     /// Return true if this instruction has a dead def.
112     bool isDeadDef() const {
113       return EndPoint.isDead();
114     }
115
116     /// Return the value leaving the instruction, if any. This can be a
117     /// live-through value, or a live def. A dead def returns NULL.
118     VNInfo *valueOut() const {
119       return isDeadDef() ? nullptr : LateVal;
120     }
121
122     /// Return the value defined by this instruction, if any. This includes
123     /// dead defs, it is the value created by the instruction's def operands.
124     VNInfo *valueDefined() const {
125       return EarlyVal == LateVal ? nullptr : LateVal;
126     }
127
128     /// Return the end point of the last live range segment to interact with
129     /// the instruction, if any.
130     ///
131     /// The end point is an invalid SlotIndex only if the live range doesn't
132     /// intersect the instruction at all.
133     ///
134     /// The end point may be at or past the end of the instruction's basic
135     /// block. That means the value was live out of the block.
136     SlotIndex endPoint() const {
137       return EndPoint;
138     }
139   };
140
141   /// This class represents the liveness of a register, stack slot, etc.
142   /// It manages an ordered list of Segment objects.
143   /// The Segments are organized in a static single assignment form: At places
144   /// where a new value is defined or different values reach a CFG join a new
145   /// segment with a new value number is used.
146   class LiveRange {
147   public:
148
149     /// This represents a simple continuous liveness interval for a value.
150     /// The start point is inclusive, the end point exclusive. These intervals
151     /// are rendered as [start,end).
152     struct Segment {
153       SlotIndex start;  // Start point of the interval (inclusive)
154       SlotIndex end;    // End point of the interval (exclusive)
155       VNInfo *valno;    // identifier for the value contained in this segment.
156
157       Segment() : valno(nullptr) {}
158
159       Segment(SlotIndex S, SlotIndex E, VNInfo *V)
160         : start(S), end(E), valno(V) {
161         assert(S < E && "Cannot create empty or backwards segment");
162       }
163
164       /// Return true if the index is covered by this segment.
165       bool contains(SlotIndex I) const {
166         return start <= I && I < end;
167       }
168
169       /// Return true if the given interval, [S, E), is covered by this segment.
170       bool containsInterval(SlotIndex S, SlotIndex E) const {
171         assert((S < E) && "Backwards interval?");
172         return (start <= S && S < end) && (start < E && E <= end);
173       }
174
175       bool operator<(const Segment &Other) const {
176         return std::tie(start, end) < std::tie(Other.start, Other.end);
177       }
178       bool operator==(const Segment &Other) const {
179         return start == Other.start && end == Other.end;
180       }
181
182       void dump() const;
183     };
184
185     typedef SmallVector<Segment,4> Segments;
186     typedef SmallVector<VNInfo*,4> VNInfoList;
187
188     Segments segments;   // the liveness segments
189     VNInfoList valnos;   // value#'s
190
191     typedef Segments::iterator iterator;
192     iterator begin() { return segments.begin(); }
193     iterator end()   { return segments.end(); }
194
195     typedef Segments::const_iterator const_iterator;
196     const_iterator begin() const { return segments.begin(); }
197     const_iterator end() const  { return segments.end(); }
198
199     typedef VNInfoList::iterator vni_iterator;
200     vni_iterator vni_begin() { return valnos.begin(); }
201     vni_iterator vni_end()   { return valnos.end(); }
202
203     typedef VNInfoList::const_iterator const_vni_iterator;
204     const_vni_iterator vni_begin() const { return valnos.begin(); }
205     const_vni_iterator vni_end() const   { return valnos.end(); }
206
207     /// advanceTo - Advance the specified iterator to point to the Segment
208     /// containing the specified position, or end() if the position is past the
209     /// end of the range.  If no Segment contains this position, but the
210     /// position is in a hole, this method returns an iterator pointing to the
211     /// Segment immediately after the hole.
212     iterator advanceTo(iterator I, SlotIndex Pos) {
213       assert(I != end());
214       if (Pos >= endIndex())
215         return end();
216       while (I->end <= Pos) ++I;
217       return I;
218     }
219
220     const_iterator advanceTo(const_iterator I, SlotIndex Pos) const {
221       assert(I != end());
222       if (Pos >= endIndex())
223         return end();
224       while (I->end <= Pos) ++I;
225       return I;
226     }
227
228     /// find - Return an iterator pointing to the first segment that ends after
229     /// Pos, or end(). This is the same as advanceTo(begin(), Pos), but faster
230     /// when searching large ranges.
231     ///
232     /// If Pos is contained in a Segment, that segment is returned.
233     /// If Pos is in a hole, the following Segment is returned.
234     /// If Pos is beyond endIndex, end() is returned.
235     iterator find(SlotIndex Pos);
236
237     const_iterator find(SlotIndex Pos) const {
238       return const_cast<LiveRange*>(this)->find(Pos);
239     }
240
241     void clear() {
242       valnos.clear();
243       segments.clear();
244     }
245
246     size_t size() const {
247       return segments.size();
248     }
249
250     bool hasAtLeastOneValue() const { return !valnos.empty(); }
251
252     bool containsOneValue() const { return valnos.size() == 1; }
253
254     unsigned getNumValNums() const { return (unsigned)valnos.size(); }
255
256     /// getValNumInfo - Returns pointer to the specified val#.
257     ///
258     inline VNInfo *getValNumInfo(unsigned ValNo) {
259       return valnos[ValNo];
260     }
261     inline const VNInfo *getValNumInfo(unsigned ValNo) const {
262       return valnos[ValNo];
263     }
264
265     /// containsValue - Returns true if VNI belongs to this range.
266     bool containsValue(const VNInfo *VNI) const {
267       return VNI && VNI->id < getNumValNums() && VNI == getValNumInfo(VNI->id);
268     }
269
270     /// getNextValue - Create a new value number and return it.  MIIdx specifies
271     /// the instruction that defines the value number.
272     VNInfo *getNextValue(SlotIndex def, VNInfo::Allocator &VNInfoAllocator) {
273       VNInfo *VNI =
274         new (VNInfoAllocator) VNInfo((unsigned)valnos.size(), def);
275       valnos.push_back(VNI);
276       return VNI;
277     }
278
279     /// createDeadDef - Make sure the range has a value defined at Def.
280     /// If one already exists, return it. Otherwise allocate a new value and
281     /// add liveness for a dead def.
282     VNInfo *createDeadDef(SlotIndex Def, VNInfo::Allocator &VNInfoAllocator);
283
284     /// Create a copy of the given value. The new value will be identical except
285     /// for the Value number.
286     VNInfo *createValueCopy(const VNInfo *orig,
287                             VNInfo::Allocator &VNInfoAllocator) {
288       VNInfo *VNI =
289         new (VNInfoAllocator) VNInfo((unsigned)valnos.size(), *orig);
290       valnos.push_back(VNI);
291       return VNI;
292     }
293
294     /// RenumberValues - Renumber all values in order of appearance and remove
295     /// unused values.
296     void RenumberValues();
297
298     /// MergeValueNumberInto - This method is called when two value numbers
299     /// are found to be equivalent.  This eliminates V1, replacing all
300     /// segments with the V1 value number with the V2 value number.  This can
301     /// cause merging of V1/V2 values numbers and compaction of the value space.
302     VNInfo* MergeValueNumberInto(VNInfo *V1, VNInfo *V2);
303
304     /// Merge all of the live segments of a specific val# in RHS into this live
305     /// range as the specified value number. The segments in RHS are allowed
306     /// to overlap with segments in the current range, it will replace the
307     /// value numbers of the overlaped live segments with the specified value
308     /// number.
309     void MergeSegmentsInAsValue(const LiveRange &RHS, VNInfo *LHSValNo);
310
311     /// MergeValueInAsValue - Merge all of the segments of a specific val#
312     /// in RHS into this live range as the specified value number.
313     /// The segments in RHS are allowed to overlap with segments in the
314     /// current range, but only if the overlapping segments have the
315     /// specified value number.
316     void MergeValueInAsValue(const LiveRange &RHS,
317                              const VNInfo *RHSValNo, VNInfo *LHSValNo);
318
319     bool empty() const { return segments.empty(); }
320
321     /// beginIndex - Return the lowest numbered slot covered.
322     SlotIndex beginIndex() const {
323       assert(!empty() && "Call to beginIndex() on empty range.");
324       return segments.front().start;
325     }
326
327     /// endNumber - return the maximum point of the range of the whole,
328     /// exclusive.
329     SlotIndex endIndex() const {
330       assert(!empty() && "Call to endIndex() on empty range.");
331       return segments.back().end;
332     }
333
334     bool expiredAt(SlotIndex index) const {
335       return index >= endIndex();
336     }
337
338     bool liveAt(SlotIndex index) const {
339       const_iterator r = find(index);
340       return r != end() && r->start <= index;
341     }
342
343     /// Return the segment that contains the specified index, or null if there
344     /// is none.
345     const Segment *getSegmentContaining(SlotIndex Idx) const {
346       const_iterator I = FindSegmentContaining(Idx);
347       return I == end() ? nullptr : &*I;
348     }
349
350     /// Return the live segment that contains the specified index, or null if
351     /// there is none.
352     Segment *getSegmentContaining(SlotIndex Idx) {
353       iterator I = FindSegmentContaining(Idx);
354       return I == end() ? nullptr : &*I;
355     }
356
357     /// getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
358     VNInfo *getVNInfoAt(SlotIndex Idx) const {
359       const_iterator I = FindSegmentContaining(Idx);
360       return I == end() ? nullptr : I->valno;
361     }
362
363     /// getVNInfoBefore - Return the VNInfo that is live up to but not
364     /// necessarilly including Idx, or NULL. Use this to find the reaching def
365     /// used by an instruction at this SlotIndex position.
366     VNInfo *getVNInfoBefore(SlotIndex Idx) const {
367       const_iterator I = FindSegmentContaining(Idx.getPrevSlot());
368       return I == end() ? nullptr : I->valno;
369     }
370
371     /// Return an iterator to the segment that contains the specified index, or
372     /// end() if there is none.
373     iterator FindSegmentContaining(SlotIndex Idx) {
374       iterator I = find(Idx);
375       return I != end() && I->start <= Idx ? I : end();
376     }
377
378     const_iterator FindSegmentContaining(SlotIndex Idx) const {
379       const_iterator I = find(Idx);
380       return I != end() && I->start <= Idx ? I : end();
381     }
382
383     /// overlaps - Return true if the intersection of the two live ranges is
384     /// not empty.
385     bool overlaps(const LiveRange &other) const {
386       if (other.empty())
387         return false;
388       return overlapsFrom(other, other.begin());
389     }
390
391     /// overlaps - Return true if the two ranges have overlapping segments
392     /// that are not coalescable according to CP.
393     ///
394     /// Overlapping segments where one range is defined by a coalescable
395     /// copy are allowed.
396     bool overlaps(const LiveRange &Other, const CoalescerPair &CP,
397                   const SlotIndexes&) const;
398
399     /// overlaps - Return true if the live range overlaps an interval specified
400     /// by [Start, End).
401     bool overlaps(SlotIndex Start, SlotIndex End) const;
402
403     /// overlapsFrom - Return true if the intersection of the two live ranges
404     /// is not empty.  The specified iterator is a hint that we can begin
405     /// scanning the Other range starting at I.
406     bool overlapsFrom(const LiveRange &Other, const_iterator I) const;
407
408     /// Returns true if all segments of the @p Other live range are completely
409     /// covered by this live range.
410     /// Adjacent live ranges do not affect the covering:the liverange
411     /// [1,5](5,10] covers (3,7].
412     bool covers(const LiveRange &Other) const;
413
414     /// Add the specified Segment to this range, merging segments as
415     /// appropriate.  This returns an iterator to the inserted segment (which
416     /// may have grown since it was inserted).
417     iterator addSegment(Segment S) {
418       return addSegmentFrom(S, segments.begin());
419     }
420
421     /// extendInBlock - If this range is live before Kill in the basic block
422     /// that starts at StartIdx, extend it to be live up to Kill, and return
423     /// the value. If there is no segment before Kill, return NULL.
424     VNInfo *extendInBlock(SlotIndex StartIdx, SlotIndex Kill);
425
426     /// join - Join two live ranges (this, and other) together.  This applies
427     /// mappings to the value numbers in the LHS/RHS ranges as specified.  If
428     /// the ranges are not joinable, this aborts.
429     void join(LiveRange &Other,
430               const int *ValNoAssignments,
431               const int *RHSValNoAssignments,
432               SmallVectorImpl<VNInfo *> &NewVNInfo);
433
434     /// True iff this segment is a single segment that lies between the
435     /// specified boundaries, exclusively. Vregs live across a backedge are not
436     /// considered local. The boundaries are expected to lie within an extended
437     /// basic block, so vregs that are not live out should contain no holes.
438     bool isLocal(SlotIndex Start, SlotIndex End) const {
439       return beginIndex() > Start.getBaseIndex() &&
440         endIndex() < End.getBoundaryIndex();
441     }
442
443     /// Remove the specified segment from this range.  Note that the segment
444     /// must be a single Segment in its entirety.
445     void removeSegment(SlotIndex Start, SlotIndex End,
446                        bool RemoveDeadValNo = false);
447
448     void removeSegment(Segment S, bool RemoveDeadValNo = false) {
449       removeSegment(S.start, S.end, RemoveDeadValNo);
450     }
451
452     /// Query Liveness at Idx.
453     /// The sub-instruction slot of Idx doesn't matter, only the instruction
454     /// it refers to is considered.
455     LiveQueryResult Query(SlotIndex Idx) const {
456       // Find the segment that enters the instruction.
457       const_iterator I = find(Idx.getBaseIndex());
458       const_iterator E = end();
459       if (I == E)
460         return LiveQueryResult(nullptr, nullptr, SlotIndex(), false);
461
462       // Is this an instruction live-in segment?
463       // If Idx is the start index of a basic block, include live-in segments
464       // that start at Idx.getBaseIndex().
465       VNInfo *EarlyVal = nullptr;
466       VNInfo *LateVal  = nullptr;
467       SlotIndex EndPoint;
468       bool Kill = false;
469       if (I->start <= Idx.getBaseIndex()) {
470         EarlyVal = I->valno;
471         EndPoint = I->end;
472         // Move to the potentially live-out segment.
473         if (SlotIndex::isSameInstr(Idx, I->end)) {
474           Kill = true;
475           if (++I == E)
476             return LiveQueryResult(EarlyVal, LateVal, EndPoint, Kill);
477         }
478         // Special case: A PHIDef value can have its def in the middle of a
479         // segment if the value happens to be live out of the layout
480         // predecessor.
481         // Such a value is not live-in.
482         if (EarlyVal->def == Idx.getBaseIndex())
483           EarlyVal = nullptr;
484       }
485       // I now points to the segment that may be live-through, or defined by
486       // this instr. Ignore segments starting after the current instr.
487       if (!SlotIndex::isEarlierInstr(Idx, I->start)) {
488         LateVal = I->valno;
489         EndPoint = I->end;
490       }
491       return LiveQueryResult(EarlyVal, LateVal, EndPoint, Kill);
492     }
493
494     /// removeValNo - Remove all the segments defined by the specified value#.
495     /// Also remove the value# from value# list.
496     void removeValNo(VNInfo *ValNo);
497
498     /// Returns true if the live range is zero length, i.e. no live segments
499     /// span instructions. It doesn't pay to spill such a range.
500     bool isZeroLength(SlotIndexes *Indexes) const {
501       for (const_iterator i = begin(), e = end(); i != e; ++i)
502         if (Indexes->getNextNonNullIndex(i->start).getBaseIndex() <
503             i->end.getBaseIndex())
504           return false;
505       return true;
506     }
507
508     bool operator<(const LiveRange& other) const {
509       const SlotIndex &thisIndex = beginIndex();
510       const SlotIndex &otherIndex = other.beginIndex();
511       return thisIndex < otherIndex;
512     }
513
514     void print(raw_ostream &OS) const;
515     void dump() const;
516
517     /// \brief Walk the range and assert if any invariants fail to hold.
518     ///
519     /// Note that this is a no-op when asserts are disabled.
520 #ifdef NDEBUG
521     void verify() const {}
522 #else
523     void verify() const;
524 #endif
525
526   private:
527
528     iterator addSegmentFrom(Segment S, iterator From);
529     void extendSegmentEndTo(iterator I, SlotIndex NewEnd);
530     iterator extendSegmentStartTo(iterator I, SlotIndex NewStr);
531     void markValNoForDeletion(VNInfo *V);
532
533   };
534
535   inline raw_ostream &operator<<(raw_ostream &OS, const LiveRange &LR) {
536     LR.print(OS);
537     return OS;
538   }
539
540   /// LiveInterval - This class represents the liveness of a register,
541   /// or stack slot.
542   class LiveInterval : public LiveRange {
543   public:
544     typedef LiveRange super;
545
546     const unsigned reg;  // the register or stack slot of this interval.
547     float weight;        // weight of this interval
548
549     LiveInterval(unsigned Reg, float Weight)
550       : reg(Reg), weight(Weight) {}
551
552     /// getSize - Returns the sum of sizes of all the LiveRange's.
553     ///
554     unsigned getSize() const;
555
556     /// isSpillable - Can this interval be spilled?
557     bool isSpillable() const {
558       return weight != llvm::huge_valf;
559     }
560
561     /// markNotSpillable - Mark interval as not spillable
562     void markNotSpillable() {
563       weight = llvm::huge_valf;
564     }
565
566     bool operator<(const LiveInterval& other) const {
567       const SlotIndex &thisIndex = beginIndex();
568       const SlotIndex &otherIndex = other.beginIndex();
569       return std::tie(thisIndex, reg) < std::tie(otherIndex, other.reg);
570     }
571
572     void print(raw_ostream &OS) const;
573     void dump() const;
574
575   private:
576     LiveInterval& operator=(const LiveInterval& rhs) LLVM_DELETED_FUNCTION;
577
578   };
579
580   inline raw_ostream &operator<<(raw_ostream &OS, const LiveInterval &LI) {
581     LI.print(OS);
582     return OS;
583   }
584
585   raw_ostream &operator<<(raw_ostream &OS, const LiveRange::Segment &S);
586
587   inline bool operator<(SlotIndex V, const LiveRange::Segment &S) {
588     return V < S.start;
589   }
590
591   inline bool operator<(const LiveRange::Segment &S, SlotIndex V) {
592     return S.start < V;
593   }
594
595   /// Helper class for performant LiveRange bulk updates.
596   ///
597   /// Calling LiveRange::addSegment() repeatedly can be expensive on large
598   /// live ranges because segments after the insertion point may need to be
599   /// shifted. The LiveRangeUpdater class can defer the shifting when adding
600   /// many segments in order.
601   ///
602   /// The LiveRange will be in an invalid state until flush() is called.
603   class LiveRangeUpdater {
604     LiveRange *LR;
605     SlotIndex LastStart;
606     LiveRange::iterator WriteI;
607     LiveRange::iterator ReadI;
608     SmallVector<LiveRange::Segment, 16> Spills;
609     void mergeSpills();
610
611   public:
612     /// Create a LiveRangeUpdater for adding segments to LR.
613     /// LR will temporarily be in an invalid state until flush() is called.
614     LiveRangeUpdater(LiveRange *lr = nullptr) : LR(lr) {}
615
616     ~LiveRangeUpdater() { flush(); }
617
618     /// Add a segment to LR and coalesce when possible, just like
619     /// LR.addSegment(). Segments should be added in increasing start order for
620     /// best performance.
621     void add(LiveRange::Segment);
622
623     void add(SlotIndex Start, SlotIndex End, VNInfo *VNI) {
624       add(LiveRange::Segment(Start, End, VNI));
625     }
626
627     /// Return true if the LR is currently in an invalid state, and flush()
628     /// needs to be called.
629     bool isDirty() const { return LastStart.isValid(); }
630
631     /// Flush the updater state to LR so it is valid and contains all added
632     /// segments.
633     void flush();
634
635     /// Select a different destination live range.
636     void setDest(LiveRange *lr) {
637       if (LR != lr && isDirty())
638         flush();
639       LR = lr;
640     }
641
642     /// Get the current destination live range.
643     LiveRange *getDest() const { return LR; }
644
645     void dump() const;
646     void print(raw_ostream&) const;
647   };
648
649   inline raw_ostream &operator<<(raw_ostream &OS, const LiveRangeUpdater &X) {
650     X.print(OS);
651     return OS;
652   }
653
654   /// ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a
655   /// LiveInterval into equivalence clases of connected components. A
656   /// LiveInterval that has multiple connected components can be broken into
657   /// multiple LiveIntervals.
658   ///
659   /// Given a LiveInterval that may have multiple connected components, run:
660   ///
661   ///   unsigned numComps = ConEQ.Classify(LI);
662   ///   if (numComps > 1) {
663   ///     // allocate numComps-1 new LiveIntervals into LIS[1..]
664   ///     ConEQ.Distribute(LIS);
665   /// }
666
667   class ConnectedVNInfoEqClasses {
668     LiveIntervals &LIS;
669     IntEqClasses EqClass;
670
671     // Note that values a and b are connected.
672     void Connect(unsigned a, unsigned b);
673
674     unsigned Renumber();
675
676   public:
677     explicit ConnectedVNInfoEqClasses(LiveIntervals &lis) : LIS(lis) {}
678
679     /// Classify - Classify the values in LI into connected components.
680     /// Return the number of connected components.
681     unsigned Classify(const LiveInterval *LI);
682
683     /// getEqClass - Classify creates equivalence classes numbered 0..N. Return
684     /// the equivalence class assigned the VNI.
685     unsigned getEqClass(const VNInfo *VNI) const { return EqClass[VNI->id]; }
686
687     /// Distribute - Distribute values in LIV[0] into a separate LiveInterval
688     /// for each connected component. LIV must have a LiveInterval for each
689     /// connected component. The LiveIntervals in Liv[1..] must be empty.
690     /// Instructions using LIV[0] are rewritten.
691     void Distribute(LiveInterval *LIV[], MachineRegisterInfo &MRI);
692
693   };
694
695 }
696 #endif