LLVM API Documentation
00001 //===-- llvm/CodeGen/LiveInterval.h - Interval representation ---*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file implements the LiveRange and LiveInterval classes. Given some 00011 // numbering of each the machine instructions an interval [i, j) is said to be a 00012 // live range for register v if there is no instruction with number j' >= j 00013 // such that v is live at j' and there is no instruction with number i' < i such 00014 // that v is live at i'. In this implementation ranges can have holes, 00015 // i.e. a range might look like [1,20), [50,65), [1000,1001). Each 00016 // individual segment is represented as an instance of LiveRange::Segment, 00017 // and the whole range is represented as an instance of LiveRange. 00018 // 00019 //===----------------------------------------------------------------------===// 00020 00021 #ifndef LLVM_CODEGEN_LIVEINTERVAL_H 00022 #define LLVM_CODEGEN_LIVEINTERVAL_H 00023 00024 #include "llvm/ADT/IntEqClasses.h" 00025 #include "llvm/CodeGen/SlotIndexes.h" 00026 #include "llvm/Support/AlignOf.h" 00027 #include "llvm/Support/Allocator.h" 00028 #include <cassert> 00029 #include <climits> 00030 00031 namespace llvm { 00032 class CoalescerPair; 00033 class LiveIntervals; 00034 class MachineInstr; 00035 class MachineRegisterInfo; 00036 class TargetRegisterInfo; 00037 class raw_ostream; 00038 template <typename T, unsigned Small> class SmallPtrSet; 00039 00040 /// VNInfo - Value Number Information. 00041 /// This class holds information about a machine level values, including 00042 /// definition and use points. 00043 /// 00044 class VNInfo { 00045 public: 00046 typedef BumpPtrAllocator Allocator; 00047 00048 /// The ID number of this value. 00049 unsigned id; 00050 00051 /// The index of the defining instruction. 00052 SlotIndex def; 00053 00054 /// VNInfo constructor. 00055 VNInfo(unsigned i, SlotIndex d) 00056 : id(i), def(d) 00057 { } 00058 00059 /// VNInfo construtor, copies values from orig, except for the value number. 00060 VNInfo(unsigned i, const VNInfo &orig) 00061 : id(i), def(orig.def) 00062 { } 00063 00064 /// Copy from the parameter into this VNInfo. 00065 void copyFrom(VNInfo &src) { 00066 def = src.def; 00067 } 00068 00069 /// Returns true if this value is defined by a PHI instruction (or was, 00070 /// PHI instructions may have been eliminated). 00071 /// PHI-defs begin at a block boundary, all other defs begin at register or 00072 /// EC slots. 00073 bool isPHIDef() const { return def.isBlock(); } 00074 00075 /// Returns true if this value is unused. 00076 bool isUnused() const { return !def.isValid(); } 00077 00078 /// Mark this value as unused. 00079 void markUnused() { def = SlotIndex(); } 00080 }; 00081 00082 /// Result of a LiveRange query. This class hides the implementation details 00083 /// of live ranges, and it should be used as the primary interface for 00084 /// examining live ranges around instructions. 00085 class LiveQueryResult { 00086 VNInfo *const EarlyVal; 00087 VNInfo *const LateVal; 00088 const SlotIndex EndPoint; 00089 const bool Kill; 00090 00091 public: 00092 LiveQueryResult(VNInfo *EarlyVal, VNInfo *LateVal, SlotIndex EndPoint, 00093 bool Kill) 00094 : EarlyVal(EarlyVal), LateVal(LateVal), EndPoint(EndPoint), Kill(Kill) 00095 {} 00096 00097 /// Return the value that is live-in to the instruction. This is the value 00098 /// that will be read by the instruction's use operands. Return NULL if no 00099 /// value is live-in. 00100 VNInfo *valueIn() const { 00101 return EarlyVal; 00102 } 00103 00104 /// Return true if the live-in value is killed by this instruction. This 00105 /// means that either the live range ends at the instruction, or it changes 00106 /// value. 00107 bool isKill() const { 00108 return Kill; 00109 } 00110 00111 /// Return true if this instruction has a dead def. 00112 bool isDeadDef() const { 00113 return EndPoint.isDead(); 00114 } 00115 00116 /// Return the value leaving the instruction, if any. This can be a 00117 /// live-through value, or a live def. A dead def returns NULL. 00118 VNInfo *valueOut() const { 00119 return isDeadDef() ? nullptr : LateVal; 00120 } 00121 00122 /// Return the value defined by this instruction, if any. This includes 00123 /// dead defs, it is the value created by the instruction's def operands. 00124 VNInfo *valueDefined() const { 00125 return EarlyVal == LateVal ? nullptr : LateVal; 00126 } 00127 00128 /// Return the end point of the last live range segment to interact with 00129 /// the instruction, if any. 00130 /// 00131 /// The end point is an invalid SlotIndex only if the live range doesn't 00132 /// intersect the instruction at all. 00133 /// 00134 /// The end point may be at or past the end of the instruction's basic 00135 /// block. That means the value was live out of the block. 00136 SlotIndex endPoint() const { 00137 return EndPoint; 00138 } 00139 }; 00140 00141 /// This class represents the liveness of a register, stack slot, etc. 00142 /// It manages an ordered list of Segment objects. 00143 /// The Segments are organized in a static single assignment form: At places 00144 /// where a new value is defined or different values reach a CFG join a new 00145 /// segment with a new value number is used. 00146 class LiveRange { 00147 public: 00148 00149 /// This represents a simple continuous liveness interval for a value. 00150 /// The start point is inclusive, the end point exclusive. These intervals 00151 /// are rendered as [start,end). 00152 struct Segment { 00153 SlotIndex start; // Start point of the interval (inclusive) 00154 SlotIndex end; // End point of the interval (exclusive) 00155 VNInfo *valno; // identifier for the value contained in this segment. 00156 00157 Segment() : valno(nullptr) {} 00158 00159 Segment(SlotIndex S, SlotIndex E, VNInfo *V) 00160 : start(S), end(E), valno(V) { 00161 assert(S < E && "Cannot create empty or backwards segment"); 00162 } 00163 00164 /// Return true if the index is covered by this segment. 00165 bool contains(SlotIndex I) const { 00166 return start <= I && I < end; 00167 } 00168 00169 /// Return true if the given interval, [S, E), is covered by this segment. 00170 bool containsInterval(SlotIndex S, SlotIndex E) const { 00171 assert((S < E) && "Backwards interval?"); 00172 return (start <= S && S < end) && (start < E && E <= end); 00173 } 00174 00175 bool operator<(const Segment &Other) const { 00176 return std::tie(start, end) < std::tie(Other.start, Other.end); 00177 } 00178 bool operator==(const Segment &Other) const { 00179 return start == Other.start && end == Other.end; 00180 } 00181 00182 void dump() const; 00183 }; 00184 00185 typedef SmallVector<Segment,4> Segments; 00186 typedef SmallVector<VNInfo*,4> VNInfoList; 00187 00188 Segments segments; // the liveness segments 00189 VNInfoList valnos; // value#'s 00190 00191 typedef Segments::iterator iterator; 00192 iterator begin() { return segments.begin(); } 00193 iterator end() { return segments.end(); } 00194 00195 typedef Segments::const_iterator const_iterator; 00196 const_iterator begin() const { return segments.begin(); } 00197 const_iterator end() const { return segments.end(); } 00198 00199 typedef VNInfoList::iterator vni_iterator; 00200 vni_iterator vni_begin() { return valnos.begin(); } 00201 vni_iterator vni_end() { return valnos.end(); } 00202 00203 typedef VNInfoList::const_iterator const_vni_iterator; 00204 const_vni_iterator vni_begin() const { return valnos.begin(); } 00205 const_vni_iterator vni_end() const { return valnos.end(); } 00206 00207 /// advanceTo - Advance the specified iterator to point to the Segment 00208 /// containing the specified position, or end() if the position is past the 00209 /// end of the range. If no Segment contains this position, but the 00210 /// position is in a hole, this method returns an iterator pointing to the 00211 /// Segment immediately after the hole. 00212 iterator advanceTo(iterator I, SlotIndex Pos) { 00213 assert(I != end()); 00214 if (Pos >= endIndex()) 00215 return end(); 00216 while (I->end <= Pos) ++I; 00217 return I; 00218 } 00219 00220 /// find - Return an iterator pointing to the first segment that ends after 00221 /// Pos, or end(). This is the same as advanceTo(begin(), Pos), but faster 00222 /// when searching large ranges. 00223 /// 00224 /// If Pos is contained in a Segment, that segment is returned. 00225 /// If Pos is in a hole, the following Segment is returned. 00226 /// If Pos is beyond endIndex, end() is returned. 00227 iterator find(SlotIndex Pos); 00228 00229 const_iterator find(SlotIndex Pos) const { 00230 return const_cast<LiveRange*>(this)->find(Pos); 00231 } 00232 00233 void clear() { 00234 valnos.clear(); 00235 segments.clear(); 00236 } 00237 00238 size_t size() const { 00239 return segments.size(); 00240 } 00241 00242 bool hasAtLeastOneValue() const { return !valnos.empty(); } 00243 00244 bool containsOneValue() const { return valnos.size() == 1; } 00245 00246 unsigned getNumValNums() const { return (unsigned)valnos.size(); } 00247 00248 /// getValNumInfo - Returns pointer to the specified val#. 00249 /// 00250 inline VNInfo *getValNumInfo(unsigned ValNo) { 00251 return valnos[ValNo]; 00252 } 00253 inline const VNInfo *getValNumInfo(unsigned ValNo) const { 00254 return valnos[ValNo]; 00255 } 00256 00257 /// containsValue - Returns true if VNI belongs to this range. 00258 bool containsValue(const VNInfo *VNI) const { 00259 return VNI && VNI->id < getNumValNums() && VNI == getValNumInfo(VNI->id); 00260 } 00261 00262 /// getNextValue - Create a new value number and return it. MIIdx specifies 00263 /// the instruction that defines the value number. 00264 VNInfo *getNextValue(SlotIndex def, VNInfo::Allocator &VNInfoAllocator) { 00265 VNInfo *VNI = 00266 new (VNInfoAllocator) VNInfo((unsigned)valnos.size(), def); 00267 valnos.push_back(VNI); 00268 return VNI; 00269 } 00270 00271 /// createDeadDef - Make sure the range has a value defined at Def. 00272 /// If one already exists, return it. Otherwise allocate a new value and 00273 /// add liveness for a dead def. 00274 VNInfo *createDeadDef(SlotIndex Def, VNInfo::Allocator &VNInfoAllocator); 00275 00276 /// Create a copy of the given value. The new value will be identical except 00277 /// for the Value number. 00278 VNInfo *createValueCopy(const VNInfo *orig, 00279 VNInfo::Allocator &VNInfoAllocator) { 00280 VNInfo *VNI = 00281 new (VNInfoAllocator) VNInfo((unsigned)valnos.size(), *orig); 00282 valnos.push_back(VNI); 00283 return VNI; 00284 } 00285 00286 /// RenumberValues - Renumber all values in order of appearance and remove 00287 /// unused values. 00288 void RenumberValues(); 00289 00290 /// MergeValueNumberInto - This method is called when two value numbers 00291 /// are found to be equivalent. This eliminates V1, replacing all 00292 /// segments with the V1 value number with the V2 value number. This can 00293 /// cause merging of V1/V2 values numbers and compaction of the value space. 00294 VNInfo* MergeValueNumberInto(VNInfo *V1, VNInfo *V2); 00295 00296 /// Merge all of the live segments of a specific val# in RHS into this live 00297 /// range as the specified value number. The segments in RHS are allowed 00298 /// to overlap with segments in the current range, it will replace the 00299 /// value numbers of the overlaped live segments with the specified value 00300 /// number. 00301 void MergeSegmentsInAsValue(const LiveRange &RHS, VNInfo *LHSValNo); 00302 00303 /// MergeValueInAsValue - Merge all of the segments of a specific val# 00304 /// in RHS into this live range as the specified value number. 00305 /// The segments in RHS are allowed to overlap with segments in the 00306 /// current range, but only if the overlapping segments have the 00307 /// specified value number. 00308 void MergeValueInAsValue(const LiveRange &RHS, 00309 const VNInfo *RHSValNo, VNInfo *LHSValNo); 00310 00311 bool empty() const { return segments.empty(); } 00312 00313 /// beginIndex - Return the lowest numbered slot covered. 00314 SlotIndex beginIndex() const { 00315 assert(!empty() && "Call to beginIndex() on empty range."); 00316 return segments.front().start; 00317 } 00318 00319 /// endNumber - return the maximum point of the range of the whole, 00320 /// exclusive. 00321 SlotIndex endIndex() const { 00322 assert(!empty() && "Call to endIndex() on empty range."); 00323 return segments.back().end; 00324 } 00325 00326 bool expiredAt(SlotIndex index) const { 00327 return index >= endIndex(); 00328 } 00329 00330 bool liveAt(SlotIndex index) const { 00331 const_iterator r = find(index); 00332 return r != end() && r->start <= index; 00333 } 00334 00335 /// Return the segment that contains the specified index, or null if there 00336 /// is none. 00337 const Segment *getSegmentContaining(SlotIndex Idx) const { 00338 const_iterator I = FindSegmentContaining(Idx); 00339 return I == end() ? nullptr : &*I; 00340 } 00341 00342 /// Return the live segment that contains the specified index, or null if 00343 /// there is none. 00344 Segment *getSegmentContaining(SlotIndex Idx) { 00345 iterator I = FindSegmentContaining(Idx); 00346 return I == end() ? nullptr : &*I; 00347 } 00348 00349 /// getVNInfoAt - Return the VNInfo that is live at Idx, or NULL. 00350 VNInfo *getVNInfoAt(SlotIndex Idx) const { 00351 const_iterator I = FindSegmentContaining(Idx); 00352 return I == end() ? nullptr : I->valno; 00353 } 00354 00355 /// getVNInfoBefore - Return the VNInfo that is live up to but not 00356 /// necessarilly including Idx, or NULL. Use this to find the reaching def 00357 /// used by an instruction at this SlotIndex position. 00358 VNInfo *getVNInfoBefore(SlotIndex Idx) const { 00359 const_iterator I = FindSegmentContaining(Idx.getPrevSlot()); 00360 return I == end() ? nullptr : I->valno; 00361 } 00362 00363 /// Return an iterator to the segment that contains the specified index, or 00364 /// end() if there is none. 00365 iterator FindSegmentContaining(SlotIndex Idx) { 00366 iterator I = find(Idx); 00367 return I != end() && I->start <= Idx ? I : end(); 00368 } 00369 00370 const_iterator FindSegmentContaining(SlotIndex Idx) const { 00371 const_iterator I = find(Idx); 00372 return I != end() && I->start <= Idx ? I : end(); 00373 } 00374 00375 /// overlaps - Return true if the intersection of the two live ranges is 00376 /// not empty. 00377 bool overlaps(const LiveRange &other) const { 00378 if (other.empty()) 00379 return false; 00380 return overlapsFrom(other, other.begin()); 00381 } 00382 00383 /// overlaps - Return true if the two ranges have overlapping segments 00384 /// that are not coalescable according to CP. 00385 /// 00386 /// Overlapping segments where one range is defined by a coalescable 00387 /// copy are allowed. 00388 bool overlaps(const LiveRange &Other, const CoalescerPair &CP, 00389 const SlotIndexes&) const; 00390 00391 /// overlaps - Return true if the live range overlaps an interval specified 00392 /// by [Start, End). 00393 bool overlaps(SlotIndex Start, SlotIndex End) const; 00394 00395 /// overlapsFrom - Return true if the intersection of the two live ranges 00396 /// is not empty. The specified iterator is a hint that we can begin 00397 /// scanning the Other range starting at I. 00398 bool overlapsFrom(const LiveRange &Other, const_iterator I) const; 00399 00400 /// Add the specified Segment to this range, merging segments as 00401 /// appropriate. This returns an iterator to the inserted segment (which 00402 /// may have grown since it was inserted). 00403 iterator addSegment(Segment S) { 00404 return addSegmentFrom(S, segments.begin()); 00405 } 00406 00407 /// extendInBlock - If this range is live before Kill in the basic block 00408 /// that starts at StartIdx, extend it to be live up to Kill, and return 00409 /// the value. If there is no segment before Kill, return NULL. 00410 VNInfo *extendInBlock(SlotIndex StartIdx, SlotIndex Kill); 00411 00412 /// join - Join two live ranges (this, and other) together. This applies 00413 /// mappings to the value numbers in the LHS/RHS ranges as specified. If 00414 /// the ranges are not joinable, this aborts. 00415 void join(LiveRange &Other, 00416 const int *ValNoAssignments, 00417 const int *RHSValNoAssignments, 00418 SmallVectorImpl<VNInfo *> &NewVNInfo); 00419 00420 /// True iff this segment is a single segment that lies between the 00421 /// specified boundaries, exclusively. Vregs live across a backedge are not 00422 /// considered local. The boundaries are expected to lie within an extended 00423 /// basic block, so vregs that are not live out should contain no holes. 00424 bool isLocal(SlotIndex Start, SlotIndex End) const { 00425 return beginIndex() > Start.getBaseIndex() && 00426 endIndex() < End.getBoundaryIndex(); 00427 } 00428 00429 /// Remove the specified segment from this range. Note that the segment 00430 /// must be a single Segment in its entirety. 00431 void removeSegment(SlotIndex Start, SlotIndex End, 00432 bool RemoveDeadValNo = false); 00433 00434 void removeSegment(Segment S, bool RemoveDeadValNo = false) { 00435 removeSegment(S.start, S.end, RemoveDeadValNo); 00436 } 00437 00438 /// Query Liveness at Idx. 00439 /// The sub-instruction slot of Idx doesn't matter, only the instruction 00440 /// it refers to is considered. 00441 LiveQueryResult Query(SlotIndex Idx) const { 00442 // Find the segment that enters the instruction. 00443 const_iterator I = find(Idx.getBaseIndex()); 00444 const_iterator E = end(); 00445 if (I == E) 00446 return LiveQueryResult(nullptr, nullptr, SlotIndex(), false); 00447 00448 // Is this an instruction live-in segment? 00449 // If Idx is the start index of a basic block, include live-in segments 00450 // that start at Idx.getBaseIndex(). 00451 VNInfo *EarlyVal = nullptr; 00452 VNInfo *LateVal = nullptr; 00453 SlotIndex EndPoint; 00454 bool Kill = false; 00455 if (I->start <= Idx.getBaseIndex()) { 00456 EarlyVal = I->valno; 00457 EndPoint = I->end; 00458 // Move to the potentially live-out segment. 00459 if (SlotIndex::isSameInstr(Idx, I->end)) { 00460 Kill = true; 00461 if (++I == E) 00462 return LiveQueryResult(EarlyVal, LateVal, EndPoint, Kill); 00463 } 00464 // Special case: A PHIDef value can have its def in the middle of a 00465 // segment if the value happens to be live out of the layout 00466 // predecessor. 00467 // Such a value is not live-in. 00468 if (EarlyVal->def == Idx.getBaseIndex()) 00469 EarlyVal = nullptr; 00470 } 00471 // I now points to the segment that may be live-through, or defined by 00472 // this instr. Ignore segments starting after the current instr. 00473 if (!SlotIndex::isEarlierInstr(Idx, I->start)) { 00474 LateVal = I->valno; 00475 EndPoint = I->end; 00476 } 00477 return LiveQueryResult(EarlyVal, LateVal, EndPoint, Kill); 00478 } 00479 00480 /// removeValNo - Remove all the segments defined by the specified value#. 00481 /// Also remove the value# from value# list. 00482 void removeValNo(VNInfo *ValNo); 00483 00484 /// Returns true if the live range is zero length, i.e. no live segments 00485 /// span instructions. It doesn't pay to spill such a range. 00486 bool isZeroLength(SlotIndexes *Indexes) const { 00487 for (const_iterator i = begin(), e = end(); i != e; ++i) 00488 if (Indexes->getNextNonNullIndex(i->start).getBaseIndex() < 00489 i->end.getBaseIndex()) 00490 return false; 00491 return true; 00492 } 00493 00494 bool operator<(const LiveRange& other) const { 00495 const SlotIndex &thisIndex = beginIndex(); 00496 const SlotIndex &otherIndex = other.beginIndex(); 00497 return thisIndex < otherIndex; 00498 } 00499 00500 void print(raw_ostream &OS) const; 00501 void dump() const; 00502 00503 /// \brief Walk the range and assert if any invariants fail to hold. 00504 /// 00505 /// Note that this is a no-op when asserts are disabled. 00506 #ifdef NDEBUG 00507 void verify() const {} 00508 #else 00509 void verify() const; 00510 #endif 00511 00512 private: 00513 00514 iterator addSegmentFrom(Segment S, iterator From); 00515 void extendSegmentEndTo(iterator I, SlotIndex NewEnd); 00516 iterator extendSegmentStartTo(iterator I, SlotIndex NewStr); 00517 void markValNoForDeletion(VNInfo *V); 00518 00519 }; 00520 00521 inline raw_ostream &operator<<(raw_ostream &OS, const LiveRange &LR) { 00522 LR.print(OS); 00523 return OS; 00524 } 00525 00526 /// LiveInterval - This class represents the liveness of a register, 00527 /// or stack slot. 00528 class LiveInterval : public LiveRange { 00529 public: 00530 typedef LiveRange super; 00531 00532 const unsigned reg; // the register or stack slot of this interval. 00533 float weight; // weight of this interval 00534 00535 LiveInterval(unsigned Reg, float Weight) 00536 : reg(Reg), weight(Weight) {} 00537 00538 /// getSize - Returns the sum of sizes of all the LiveRange's. 00539 /// 00540 unsigned getSize() const; 00541 00542 /// isSpillable - Can this interval be spilled? 00543 bool isSpillable() const { 00544 return weight != llvm::huge_valf; 00545 } 00546 00547 /// markNotSpillable - Mark interval as not spillable 00548 void markNotSpillable() { 00549 weight = llvm::huge_valf; 00550 } 00551 00552 bool operator<(const LiveInterval& other) const { 00553 const SlotIndex &thisIndex = beginIndex(); 00554 const SlotIndex &otherIndex = other.beginIndex(); 00555 return std::tie(thisIndex, reg) < std::tie(otherIndex, other.reg); 00556 } 00557 00558 void print(raw_ostream &OS) const; 00559 void dump() const; 00560 00561 private: 00562 LiveInterval& operator=(const LiveInterval& rhs) LLVM_DELETED_FUNCTION; 00563 00564 }; 00565 00566 inline raw_ostream &operator<<(raw_ostream &OS, const LiveInterval &LI) { 00567 LI.print(OS); 00568 return OS; 00569 } 00570 00571 raw_ostream &operator<<(raw_ostream &OS, const LiveRange::Segment &S); 00572 00573 inline bool operator<(SlotIndex V, const LiveRange::Segment &S) { 00574 return V < S.start; 00575 } 00576 00577 inline bool operator<(const LiveRange::Segment &S, SlotIndex V) { 00578 return S.start < V; 00579 } 00580 00581 /// Helper class for performant LiveRange bulk updates. 00582 /// 00583 /// Calling LiveRange::addSegment() repeatedly can be expensive on large 00584 /// live ranges because segments after the insertion point may need to be 00585 /// shifted. The LiveRangeUpdater class can defer the shifting when adding 00586 /// many segments in order. 00587 /// 00588 /// The LiveRange will be in an invalid state until flush() is called. 00589 class LiveRangeUpdater { 00590 LiveRange *LR; 00591 SlotIndex LastStart; 00592 LiveRange::iterator WriteI; 00593 LiveRange::iterator ReadI; 00594 SmallVector<LiveRange::Segment, 16> Spills; 00595 void mergeSpills(); 00596 00597 public: 00598 /// Create a LiveRangeUpdater for adding segments to LR. 00599 /// LR will temporarily be in an invalid state until flush() is called. 00600 LiveRangeUpdater(LiveRange *lr = nullptr) : LR(lr) {} 00601 00602 ~LiveRangeUpdater() { flush(); } 00603 00604 /// Add a segment to LR and coalesce when possible, just like 00605 /// LR.addSegment(). Segments should be added in increasing start order for 00606 /// best performance. 00607 void add(LiveRange::Segment); 00608 00609 void add(SlotIndex Start, SlotIndex End, VNInfo *VNI) { 00610 add(LiveRange::Segment(Start, End, VNI)); 00611 } 00612 00613 /// Return true if the LR is currently in an invalid state, and flush() 00614 /// needs to be called. 00615 bool isDirty() const { return LastStart.isValid(); } 00616 00617 /// Flush the updater state to LR so it is valid and contains all added 00618 /// segments. 00619 void flush(); 00620 00621 /// Select a different destination live range. 00622 void setDest(LiveRange *lr) { 00623 if (LR != lr && isDirty()) 00624 flush(); 00625 LR = lr; 00626 } 00627 00628 /// Get the current destination live range. 00629 LiveRange *getDest() const { return LR; } 00630 00631 void dump() const; 00632 void print(raw_ostream&) const; 00633 }; 00634 00635 inline raw_ostream &operator<<(raw_ostream &OS, const LiveRangeUpdater &X) { 00636 X.print(OS); 00637 return OS; 00638 } 00639 00640 /// ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a 00641 /// LiveInterval into equivalence clases of connected components. A 00642 /// LiveInterval that has multiple connected components can be broken into 00643 /// multiple LiveIntervals. 00644 /// 00645 /// Given a LiveInterval that may have multiple connected components, run: 00646 /// 00647 /// unsigned numComps = ConEQ.Classify(LI); 00648 /// if (numComps > 1) { 00649 /// // allocate numComps-1 new LiveIntervals into LIS[1..] 00650 /// ConEQ.Distribute(LIS); 00651 /// } 00652 00653 class ConnectedVNInfoEqClasses { 00654 LiveIntervals &LIS; 00655 IntEqClasses EqClass; 00656 00657 // Note that values a and b are connected. 00658 void Connect(unsigned a, unsigned b); 00659 00660 unsigned Renumber(); 00661 00662 public: 00663 explicit ConnectedVNInfoEqClasses(LiveIntervals &lis) : LIS(lis) {} 00664 00665 /// Classify - Classify the values in LI into connected components. 00666 /// Return the number of connected components. 00667 unsigned Classify(const LiveInterval *LI); 00668 00669 /// getEqClass - Classify creates equivalence classes numbered 0..N. Return 00670 /// the equivalence class assigned the VNI. 00671 unsigned getEqClass(const VNInfo *VNI) const { return EqClass[VNI->id]; } 00672 00673 /// Distribute - Distribute values in LIV[0] into a separate LiveInterval 00674 /// for each connected component. LIV must have a LiveInterval for each 00675 /// connected component. The LiveIntervals in Liv[1..] must be empty. 00676 /// Instructions using LIV[0] are rewritten. 00677 void Distribute(LiveInterval *LIV[], MachineRegisterInfo &MRI); 00678 00679 }; 00680 00681 } 00682 #endif