LiveInterval.cpp (208954) | LiveInterval.cpp (210299) |
---|---|
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//===----------------------------------------------------------------------===// --- 54 unchanged lines hidden (view full) --- 63 return true; 64 // I is the start of a live range. Check if the previous live range ends 65 // at I-1. 66 if (r == ranges.begin()) 67 return false; 68 return r->end == I; 69} 70 | 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//===----------------------------------------------------------------------===// --- 54 unchanged lines hidden (view full) --- 63 return true; 64 // I is the start of a live range. Check if the previous live range ends 65 // at I-1. 66 if (r == ranges.begin()) 67 return false; 68 return r->end == I; 69} 70 |
71/// killedAt - Return true if a live range ends at index. Note that the kill 72/// point is not contained in the half-open live range. It is usually the 73/// getDefIndex() slot following its last use. 74bool LiveInterval::killedAt(SlotIndex I) const { 75 Ranges::const_iterator r = std::lower_bound(ranges.begin(), ranges.end(), I); 76 77 // Now r points to the first interval with start >= I, or ranges.end(). 78 if (r == ranges.begin()) 79 return false; 80 81 --r; 82 // Now r points to the last interval with end <= I. 83 // r->end is the kill point. 84 return r->end == I; 85} 86 87/// killedInRange - Return true if the interval has kills in [Start,End). 88bool LiveInterval::killedInRange(SlotIndex Start, SlotIndex End) const { 89 Ranges::const_iterator r = 90 std::lower_bound(ranges.begin(), ranges.end(), End); 91 92 // Now r points to the first interval with start >= End, or ranges.end(). 93 if (r == ranges.begin()) 94 return false; 95 96 --r; 97 // Now r points to the last interval with end <= End. 98 // r->end is the kill point. 99 return r->end >= Start && r->end < End; 100} 101 |
|
71// overlaps - Return true if the intersection of the two live intervals is 72// not empty. 73// 74// An example for overlaps(): 75// 76// 0: A = ... 77// 4: B = ... 78// 8: C = A + B ;; last use of A --- 4 unchanged lines hidden (view full) --- 83// B = [7, x) 84// C = [11, y) 85// 86// A->overlaps(C) should return false since we want to be able to join 87// A and C. 88// 89bool LiveInterval::overlapsFrom(const LiveInterval& other, 90 const_iterator StartPos) const { | 102// overlaps - Return true if the intersection of the two live intervals is 103// not empty. 104// 105// An example for overlaps(): 106// 107// 0: A = ... 108// 4: B = ... 109// 8: C = A + B ;; last use of A --- 4 unchanged lines hidden (view full) --- 114// B = [7, x) 115// C = [11, y) 116// 117// A->overlaps(C) should return false since we want to be able to join 118// A and C. 119// 120bool LiveInterval::overlapsFrom(const LiveInterval& other, 121 const_iterator StartPos) const { |
122 assert(!empty() && "empty interval"); |
|
91 const_iterator i = begin(); 92 const_iterator ie = end(); 93 const_iterator j = StartPos; 94 const_iterator je = other.end(); 95 96 assert((StartPos->start <= i->start || StartPos == other.begin()) && 97 StartPos != other.end() && "Bogus start position hint!"); 98 --- 26 unchanged lines hidden (view full) --- 125 126 return false; 127} 128 129/// overlaps - Return true if the live interval overlaps a range specified 130/// by [Start, End). 131bool LiveInterval::overlaps(SlotIndex Start, SlotIndex End) const { 132 assert(Start < End && "Invalid range"); | 123 const_iterator i = begin(); 124 const_iterator ie = end(); 125 const_iterator j = StartPos; 126 const_iterator je = other.end(); 127 128 assert((StartPos->start <= i->start || StartPos == other.begin()) && 129 StartPos != other.end() && "Bogus start position hint!"); 130 --- 26 unchanged lines hidden (view full) --- 157 158 return false; 159} 160 161/// overlaps - Return true if the live interval overlaps a range specified 162/// by [Start, End). 163bool LiveInterval::overlaps(SlotIndex Start, SlotIndex End) const { 164 assert(Start < End && "Invalid range"); |
133 const_iterator I = begin(); 134 const_iterator E = end(); 135 const_iterator si = std::upper_bound(I, E, Start); 136 const_iterator ei = std::upper_bound(I, E, End); 137 if (si != ei) 138 return true; 139 if (si == I) 140 return false; 141 --si; 142 return si->contains(Start); | 165 const_iterator I = std::lower_bound(begin(), end(), End); 166 return I != begin() && (--I)->end > Start; |
143} 144 145/// extendIntervalEndTo - This method is used when we want to extend the range 146/// specified by I to end at the specified endpoint. To do this, we should 147/// merge and eliminate all ranges that this will overlap with. The iterator is 148/// not invalidated. 149void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) { 150 assert(I != ranges.end() && "Not a valid interval!"); 151 VNInfo *ValNo = I->valno; | 167} 168 169/// extendIntervalEndTo - This method is used when we want to extend the range 170/// specified by I to end at the specified endpoint. To do this, we should 171/// merge and eliminate all ranges that this will overlap with. The iterator is 172/// not invalidated. 173void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) { 174 assert(I != ranges.end() && "Not a valid interval!"); 175 VNInfo *ValNo = I->valno; |
152 SlotIndex OldEnd = I->end; | |
153 154 // Search for the first interval that we can't merge with. 155 Ranges::iterator MergeTo = next(I); 156 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) { 157 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!"); 158 } 159 160 // If NewEnd was in the middle of an interval, make sure to get its endpoint. 161 I->end = std::max(NewEnd, prior(MergeTo)->end); 162 163 // Erase any dead ranges. 164 ranges.erase(next(I), MergeTo); 165 | 176 177 // Search for the first interval that we can't merge with. 178 Ranges::iterator MergeTo = next(I); 179 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) { 180 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!"); 181 } 182 183 // If NewEnd was in the middle of an interval, make sure to get its endpoint. 184 I->end = std::max(NewEnd, prior(MergeTo)->end); 185 186 // Erase any dead ranges. 187 ranges.erase(next(I), MergeTo); 188 |
166 // Update kill info. 167 ValNo->removeKills(OldEnd, I->end.getPrevSlot()); 168 | |
169 // If the newly formed range now touches the range after it and if they have 170 // the same value number, merge the two ranges into one range. 171 Ranges::iterator Next = next(I); 172 if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) { 173 I->end = Next->end; 174 ranges.erase(Next); 175 } 176} --- 63 unchanged lines hidden (view full) --- 240 if (LR.valno == it->valno) { 241 if (it->start <= End) { 242 it = extendIntervalStartTo(it, Start); 243 244 // If LR is a complete superset of an interval, we may need to grow its 245 // endpoint as well. 246 if (End > it->end) 247 extendIntervalEndTo(it, End); | 189 // If the newly formed range now touches the range after it and if they have 190 // the same value number, merge the two ranges into one range. 191 Ranges::iterator Next = next(I); 192 if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) { 193 I->end = Next->end; 194 ranges.erase(Next); 195 } 196} --- 63 unchanged lines hidden (view full) --- 260 if (LR.valno == it->valno) { 261 if (it->start <= End) { 262 it = extendIntervalStartTo(it, Start); 263 264 // If LR is a complete superset of an interval, we may need to grow its 265 // endpoint as well. 266 if (End > it->end) 267 extendIntervalEndTo(it, End); |
248 else if (End < it->end) 249 // Overlapping intervals, there might have been a kill here. 250 it->valno->removeKill(End); | |
251 return it; 252 } 253 } else { 254 // Check to make sure that we are not overlapping two live ranges with 255 // different valno's. 256 assert(it->start >= End && 257 "Cannot overlap two LiveRanges with differing ValID's"); 258 } --- 24 unchanged lines hidden (view full) --- 283 assert(I != ranges.begin() && "Range is not in interval!"); 284 --I; 285 assert(I->containsRange(Start, End) && "Range is not entirely in interval!"); 286 287 // If the span we are removing is at the start of the LiveRange, adjust it. 288 VNInfo *ValNo = I->valno; 289 if (I->start == Start) { 290 if (I->end == End) { | 268 return it; 269 } 270 } else { 271 // Check to make sure that we are not overlapping two live ranges with 272 // different valno's. 273 assert(it->start >= End && 274 "Cannot overlap two LiveRanges with differing ValID's"); 275 } --- 24 unchanged lines hidden (view full) --- 300 assert(I != ranges.begin() && "Range is not in interval!"); 301 --I; 302 assert(I->containsRange(Start, End) && "Range is not entirely in interval!"); 303 304 // If the span we are removing is at the start of the LiveRange, adjust it. 305 VNInfo *ValNo = I->valno; 306 if (I->start == Start) { 307 if (I->end == End) { |
291 ValNo->removeKills(Start, End); | |
292 if (RemoveDeadValNo) { 293 // Check if val# is dead. 294 bool isDead = true; 295 for (const_iterator II = begin(), EE = end(); II != EE; ++II) 296 if (II != I && II->valno == ValNo) { 297 isDead = false; 298 break; | 308 if (RemoveDeadValNo) { 309 // Check if val# is dead. 310 bool isDead = true; 311 for (const_iterator II = begin(), EE = end(); II != EE; ++II) 312 if (II != I && II->valno == ValNo) { 313 isDead = false; 314 break; |
299 } | 315 } |
300 if (isDead) { 301 // Now that ValNo is dead, remove it. If it is the largest value 302 // number, just nuke it (and any other deleted values neighboring it), 303 // otherwise mark it as ~1U so it can be nuked later. 304 if (ValNo->id == getNumValNums()-1) { 305 do { 306 valnos.pop_back(); 307 } while (!valnos.empty() && valnos.back()->isUnused()); --- 7 unchanged lines hidden (view full) --- 315 } else 316 I->start = End; 317 return; 318 } 319 320 // Otherwise if the span we are removing is at the end of the LiveRange, 321 // adjust the other way. 322 if (I->end == End) { | 316 if (isDead) { 317 // Now that ValNo is dead, remove it. If it is the largest value 318 // number, just nuke it (and any other deleted values neighboring it), 319 // otherwise mark it as ~1U so it can be nuked later. 320 if (ValNo->id == getNumValNums()-1) { 321 do { 322 valnos.pop_back(); 323 } while (!valnos.empty() && valnos.back()->isUnused()); --- 7 unchanged lines hidden (view full) --- 331 } else 332 I->start = End; 333 return; 334 } 335 336 // Otherwise if the span we are removing is at the end of the LiveRange, 337 // adjust the other way. 338 if (I->end == End) { |
323 ValNo->removeKills(Start, End); | |
324 I->end = Start; 325 return; 326 } 327 328 // Otherwise, we are splitting the LiveRange into two pieces. 329 SlotIndex OldEnd = I->end; 330 I->end = Start; // Trim the old interval. 331 --- 192 unchanged lines hidden (view full) --- 524/// current interval, it will replace the value numbers of the overlaped 525/// live ranges with the specified value number. 526void LiveInterval::MergeValueInAsValue( 527 const LiveInterval &RHS, 528 const VNInfo *RHSValNo, VNInfo *LHSValNo) { 529 SmallVector<VNInfo*, 4> ReplacedValNos; 530 iterator IP = begin(); 531 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) { | 339 I->end = Start; 340 return; 341 } 342 343 // Otherwise, we are splitting the LiveRange into two pieces. 344 SlotIndex OldEnd = I->end; 345 I->end = Start; // Trim the old interval. 346 --- 192 unchanged lines hidden (view full) --- 539/// current interval, it will replace the value numbers of the overlaped 540/// live ranges with the specified value number. 541void LiveInterval::MergeValueInAsValue( 542 const LiveInterval &RHS, 543 const VNInfo *RHSValNo, VNInfo *LHSValNo) { 544 SmallVector<VNInfo*, 4> ReplacedValNos; 545 iterator IP = begin(); 546 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) { |
547 assert(I->valno == RHS.getValNumInfo(I->valno->id) && "Bad VNInfo"); |
|
532 if (I->valno != RHSValNo) 533 continue; 534 SlotIndex Start = I->start, End = I->end; 535 IP = std::upper_bound(IP, end(), Start); 536 // If the start of this range overlaps with an existing liverange, trim it. 537 if (IP != begin() && IP[-1].end > Start) { 538 if (IP[-1].valno != LHSValNo) { 539 ReplacedValNos.push_back(IP[-1].valno); --- 278 unchanged lines hidden (view full) --- 818 819 OS << ',' << weight; 820 821 if (empty()) 822 OS << " EMPTY"; 823 else { 824 OS << " = "; 825 for (LiveInterval::Ranges::const_iterator I = ranges.begin(), | 548 if (I->valno != RHSValNo) 549 continue; 550 SlotIndex Start = I->start, End = I->end; 551 IP = std::upper_bound(IP, end(), Start); 552 // If the start of this range overlaps with an existing liverange, trim it. 553 if (IP != begin() && IP[-1].end > Start) { 554 if (IP[-1].valno != LHSValNo) { 555 ReplacedValNos.push_back(IP[-1].valno); --- 278 unchanged lines hidden (view full) --- 834 835 OS << ',' << weight; 836 837 if (empty()) 838 OS << " EMPTY"; 839 else { 840 OS << " = "; 841 for (LiveInterval::Ranges::const_iterator I = ranges.begin(), |
826 E = ranges.end(); I != E; ++I) 827 OS << *I; | 842 E = ranges.end(); I != E; ++I) { 843 OS << *I; 844 assert(I->valno == getValNumInfo(I->valno->id) && "Bad VNInfo"); 845 } |
828 } | 846 } |
829 | 847 |
830 // Print value number info. 831 if (getNumValNums()) { 832 OS << " "; 833 unsigned vnum = 0; 834 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e; 835 ++i, ++vnum) { 836 const VNInfo *vni = *i; 837 if (vnum) OS << " "; 838 OS << vnum << "@"; 839 if (vni->isUnused()) { 840 OS << "x"; 841 } else { 842 if (!vni->isDefAccurate() && !vni->isPHIDef()) 843 OS << "?"; 844 else 845 OS << vni->def; | 848 // Print value number info. 849 if (getNumValNums()) { 850 OS << " "; 851 unsigned vnum = 0; 852 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e; 853 ++i, ++vnum) { 854 const VNInfo *vni = *i; 855 if (vnum) OS << " "; 856 OS << vnum << "@"; 857 if (vni->isUnused()) { 858 OS << "x"; 859 } else { 860 if (!vni->isDefAccurate() && !vni->isPHIDef()) 861 OS << "?"; 862 else 863 OS << vni->def; |
846 unsigned ee = vni->kills.size(); 847 if (ee || vni->hasPHIKill()) { 848 OS << "-("; 849 for (unsigned j = 0; j != ee; ++j) { 850 OS << vni->kills[j]; 851 if (j != ee-1) 852 OS << " "; 853 } 854 if (vni->hasPHIKill()) { 855 if (ee) 856 OS << " "; 857 OS << "phi"; 858 } 859 OS << ")"; 860 } | 864 if (vni->hasPHIKill()) 865 OS << "-phikill"; 866 if (vni->hasRedefByEC()) 867 OS << "-ec"; |
861 } 862 } 863 } 864} 865 866void LiveInterval::dump() const { 867 dbgs() << *this << "\n"; 868} 869 870 871void LiveRange::print(raw_ostream &os) const { 872 os << *this; 873} | 868 } 869 } 870 } 871} 872 873void LiveInterval::dump() const { 874 dbgs() << *this << "\n"; 875} 876 877 878void LiveRange::print(raw_ostream &os) const { 879 os << *this; 880} |