Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 1 | //===-- LiveInterval.cpp - Live Interval Representation -------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 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 |
Bob Wilson | 86af655 | 2010-01-12 22:18:56 +0000 | [diff] [blame] | 13 | // such that v is live at j' and there is no instruction with number i' < i such |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 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 | |
Bill Wendling | d9fd2ac | 2006-11-28 02:08:17 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/LiveInterval.h" |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/LiveIntervalAnalysis.h" |
Evan Cheng | 90f95f8 | 2009-06-14 20:22:55 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Evan Cheng | 0adb527 | 2009-04-25 09:25:19 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/DenseMap.h" |
Evan Cheng | 3c1f4a4 | 2007-10-17 02:13:29 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SmallSet.h" |
Bill Wendling | 38b0e7b | 2006-11-28 03:31:29 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/STLExtras.h" |
David Greene | 5242154 | 2010-01-04 22:41:43 +0000 | [diff] [blame] | 27 | #include "llvm/Support/Debug.h" |
Daniel Dunbar | a717b7b | 2009-07-24 10:47:20 +0000 | [diff] [blame] | 28 | #include "llvm/Support/raw_ostream.h" |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 29 | #include "llvm/Target/TargetRegisterInfo.h" |
Alkis Evlogimenos | c4d3b91 | 2004-09-28 02:38:58 +0000 | [diff] [blame] | 30 | #include <algorithm> |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 31 | using namespace llvm; |
| 32 | |
John Wiegley | 6fd2472 | 2011-03-11 08:54:34 +0000 | [diff] [blame^] | 33 | // SlotIndexIterator - adapt an iterator over LiveRanges to look |
| 34 | // like an iterator over SlotIndexes by accessing the .end member. |
Jakob Stoklund Olesen | 89bfef0 | 2010-09-21 18:34:17 +0000 | [diff] [blame] | 35 | namespace { |
John Wiegley | 6fd2472 | 2011-03-11 08:54:34 +0000 | [diff] [blame^] | 36 | struct SlotIndexIterator |
| 37 | : std::iterator<std::random_access_iterator_tag, SlotIndex> { |
| 38 | |
| 39 | SlotIndexIterator() { |
Jakob Stoklund Olesen | b64f669 | 2011-03-03 04:23:52 +0000 | [diff] [blame] | 40 | } |
John Wiegley | 6fd2472 | 2011-03-11 08:54:34 +0000 | [diff] [blame^] | 41 | |
| 42 | explicit SlotIndexIterator(LiveInterval::iterator it) |
| 43 | : it(it) { |
Jakob Stoklund Olesen | 2de0e80 | 2010-09-21 18:24:30 +0000 | [diff] [blame] | 44 | } |
John Wiegley | 6fd2472 | 2011-03-11 08:54:34 +0000 | [diff] [blame^] | 45 | |
| 46 | SlotIndexIterator(const SlotIndexIterator & that) |
| 47 | : it(that.it) { |
Jakob Stoklund Olesen | 5bf76cd | 2011-03-08 19:37:54 +0000 | [diff] [blame] | 48 | } |
John Wiegley | 6fd2472 | 2011-03-11 08:54:34 +0000 | [diff] [blame^] | 49 | |
| 50 | SlotIndexIterator & operator=(const SlotIndexIterator & that) { |
| 51 | it = that.it; |
| 52 | return *this; |
| 53 | } |
| 54 | |
| 55 | SlotIndexIterator & operator++() { |
| 56 | ++it; |
| 57 | return *this; |
| 58 | } |
| 59 | |
| 60 | SlotIndexIterator operator++(int) { |
| 61 | SlotIndexIterator that(*this); |
| 62 | ++*this; |
| 63 | return that; |
| 64 | } |
| 65 | |
| 66 | SlotIndexIterator & operator--() { |
| 67 | --it; |
| 68 | return *this; |
| 69 | } |
| 70 | |
| 71 | SlotIndexIterator operator--(int) { |
| 72 | SlotIndexIterator that(*this); |
| 73 | --*this; |
| 74 | return that; |
| 75 | } |
| 76 | |
| 77 | SlotIndexIterator & operator+=(std::ptrdiff_t n) { |
| 78 | it += n; |
| 79 | return *this; |
| 80 | } |
| 81 | |
| 82 | SlotIndexIterator & operator-=(std::ptrdiff_t n) { |
| 83 | it -= n; |
| 84 | return *this; |
| 85 | } |
| 86 | |
| 87 | friend bool operator==(SlotIndexIterator lhs, SlotIndexIterator rhs) { |
| 88 | return lhs.it == rhs.it; |
| 89 | } |
| 90 | |
| 91 | friend bool operator!=(SlotIndexIterator lhs, SlotIndexIterator rhs) { |
| 92 | return lhs.it != rhs.it; |
| 93 | } |
| 94 | |
| 95 | friend bool operator<(SlotIndexIterator lhs, SlotIndexIterator rhs) { |
| 96 | return lhs.it < rhs.it; |
| 97 | } |
| 98 | |
| 99 | friend bool operator<=(SlotIndexIterator lhs, SlotIndexIterator rhs) { |
| 100 | return lhs.it <= rhs.it; |
| 101 | } |
| 102 | |
| 103 | friend bool operator>(SlotIndexIterator lhs, SlotIndexIterator rhs) { |
| 104 | return lhs.it > rhs.it; |
| 105 | } |
| 106 | |
| 107 | friend bool operator>=(SlotIndexIterator lhs, SlotIndexIterator rhs) { |
| 108 | return lhs.it >= rhs.it; |
| 109 | } |
| 110 | |
| 111 | friend SlotIndexIterator operator+(SlotIndexIterator that, std::ptrdiff_t n) { |
| 112 | return SlotIndexIterator(that.it + n); |
| 113 | } |
| 114 | |
| 115 | friend SlotIndexIterator operator+(std::ptrdiff_t n, SlotIndexIterator that) { |
| 116 | return SlotIndexIterator(n + that.it); |
| 117 | } |
| 118 | |
| 119 | friend SlotIndexIterator operator-(SlotIndexIterator that, std::ptrdiff_t n) { |
| 120 | return SlotIndexIterator(that.it - n); |
| 121 | } |
| 122 | |
| 123 | friend std::ptrdiff_t operator-(SlotIndexIterator lhs, SlotIndexIterator rhs) { |
| 124 | return lhs.it - rhs.it; |
| 125 | } |
| 126 | |
| 127 | reference operator*() const { |
| 128 | return it->end; |
| 129 | } |
| 130 | |
| 131 | reference operator[](std::ptrdiff_t n) const { |
| 132 | return it[n].end; |
| 133 | } |
| 134 | |
| 135 | pointer operator->() const { |
| 136 | return &it->end; |
| 137 | } |
| 138 | |
| 139 | LiveInterval::iterator base() const { |
| 140 | return it; |
| 141 | } |
| 142 | |
| 143 | private: |
| 144 | LiveInterval::iterator it; |
Jakob Stoklund Olesen | 2de0e80 | 2010-09-21 18:24:30 +0000 | [diff] [blame] | 145 | }; |
Jakob Stoklund Olesen | 89bfef0 | 2010-09-21 18:34:17 +0000 | [diff] [blame] | 146 | } |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 147 | |
Jakob Stoklund Olesen | f568b27 | 2010-09-21 17:12:18 +0000 | [diff] [blame] | 148 | LiveInterval::iterator LiveInterval::find(SlotIndex Pos) { |
Jakob Stoklund Olesen | 201ecfc | 2010-10-05 18:48:55 +0000 | [diff] [blame] | 149 | assert(Pos.isValid() && "Cannot search for an invalid index"); |
John Wiegley | 6fd2472 | 2011-03-11 08:54:34 +0000 | [diff] [blame^] | 150 | return std::upper_bound( |
| 151 | SlotIndexIterator(begin()), |
| 152 | SlotIndexIterator(end()), Pos).base(); |
Jakob Stoklund Olesen | 15a5714 | 2010-06-25 22:53:05 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /// killedInRange - Return true if the interval has kills in [Start,End). |
| 156 | bool LiveInterval::killedInRange(SlotIndex Start, SlotIndex End) const { |
| 157 | Ranges::const_iterator r = |
| 158 | std::lower_bound(ranges.begin(), ranges.end(), End); |
| 159 | |
| 160 | // Now r points to the first interval with start >= End, or ranges.end(). |
| 161 | if (r == ranges.begin()) |
| 162 | return false; |
| 163 | |
| 164 | --r; |
| 165 | // Now r points to the last interval with end <= End. |
| 166 | // r->end is the kill point. |
| 167 | return r->end >= Start && r->end < End; |
| 168 | } |
| 169 | |
Chris Lattner | bae74d9 | 2004-11-18 03:47:34 +0000 | [diff] [blame] | 170 | // overlaps - Return true if the intersection of the two live intervals is |
| 171 | // not empty. |
| 172 | // |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 173 | // An example for overlaps(): |
| 174 | // |
| 175 | // 0: A = ... |
| 176 | // 4: B = ... |
| 177 | // 8: C = A + B ;; last use of A |
| 178 | // |
| 179 | // The live intervals should look like: |
| 180 | // |
| 181 | // A = [3, 11) |
| 182 | // B = [7, x) |
| 183 | // C = [11, y) |
| 184 | // |
| 185 | // A->overlaps(C) should return false since we want to be able to join |
| 186 | // A and C. |
Chris Lattner | bae74d9 | 2004-11-18 03:47:34 +0000 | [diff] [blame] | 187 | // |
| 188 | bool LiveInterval::overlapsFrom(const LiveInterval& other, |
| 189 | const_iterator StartPos) const { |
Jakob Stoklund Olesen | 6382d2c | 2010-07-13 19:56:28 +0000 | [diff] [blame] | 190 | assert(!empty() && "empty interval"); |
Chris Lattner | bae74d9 | 2004-11-18 03:47:34 +0000 | [diff] [blame] | 191 | const_iterator i = begin(); |
| 192 | const_iterator ie = end(); |
| 193 | const_iterator j = StartPos; |
| 194 | const_iterator je = other.end(); |
| 195 | |
| 196 | assert((StartPos->start <= i->start || StartPos == other.begin()) && |
Chris Lattner | 8c68b6a | 2004-11-18 04:02:11 +0000 | [diff] [blame] | 197 | StartPos != other.end() && "Bogus start position hint!"); |
Chris Lattner | f542649 | 2004-07-25 07:11:19 +0000 | [diff] [blame] | 198 | |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 199 | if (i->start < j->start) { |
Chris Lattner | aa14147 | 2004-07-23 18:40:00 +0000 | [diff] [blame] | 200 | i = std::upper_bound(i, ie, j->start); |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 201 | if (i != ranges.begin()) --i; |
Chris Lattner | aa14147 | 2004-07-23 18:40:00 +0000 | [diff] [blame] | 202 | } else if (j->start < i->start) { |
Chris Lattner | ead1b3f | 2004-12-04 01:22:09 +0000 | [diff] [blame] | 203 | ++StartPos; |
| 204 | if (StartPos != other.end() && StartPos->start <= i->start) { |
| 205 | assert(StartPos < other.end() && i < end()); |
Chris Lattner | 8c68b6a | 2004-11-18 04:02:11 +0000 | [diff] [blame] | 206 | j = std::upper_bound(j, je, i->start); |
| 207 | if (j != other.ranges.begin()) --j; |
| 208 | } |
Chris Lattner | aa14147 | 2004-07-23 18:40:00 +0000 | [diff] [blame] | 209 | } else { |
| 210 | return true; |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 211 | } |
| 212 | |
Chris Lattner | 9fddc12 | 2004-11-18 05:28:21 +0000 | [diff] [blame] | 213 | if (j == je) return false; |
| 214 | |
| 215 | while (i != ie) { |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 216 | if (i->start > j->start) { |
Alkis Evlogimenos | a1613db | 2004-07-24 11:44:15 +0000 | [diff] [blame] | 217 | std::swap(i, j); |
| 218 | std::swap(ie, je); |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 219 | } |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 220 | |
| 221 | if (i->end > j->start) |
| 222 | return true; |
| 223 | ++i; |
| 224 | } |
| 225 | |
| 226 | return false; |
| 227 | } |
| 228 | |
Evan Cheng | cccdb2b | 2009-04-18 08:52:15 +0000 | [diff] [blame] | 229 | /// overlaps - Return true if the live interval overlaps a range specified |
| 230 | /// by [Start, End). |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 231 | bool LiveInterval::overlaps(SlotIndex Start, SlotIndex End) const { |
Evan Cheng | cccdb2b | 2009-04-18 08:52:15 +0000 | [diff] [blame] | 232 | assert(Start < End && "Invalid range"); |
Jakob Stoklund Olesen | 186eb73 | 2010-07-13 19:42:20 +0000 | [diff] [blame] | 233 | const_iterator I = std::lower_bound(begin(), end(), End); |
| 234 | return I != begin() && (--I)->end > Start; |
Evan Cheng | cccdb2b | 2009-04-18 08:52:15 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Lang Hames | 6f4e4df | 2010-07-26 01:49:41 +0000 | [diff] [blame] | 237 | |
| 238 | /// ValNo is dead, remove it. If it is the largest value number, just nuke it |
| 239 | /// (and any other deleted values neighboring it), otherwise mark it as ~1U so |
| 240 | /// it can be nuked later. |
| 241 | void LiveInterval::markValNoForDeletion(VNInfo *ValNo) { |
| 242 | if (ValNo->id == getNumValNums()-1) { |
| 243 | do { |
| 244 | valnos.pop_back(); |
| 245 | } while (!valnos.empty() && valnos.back()->isUnused()); |
| 246 | } else { |
| 247 | ValNo->setIsUnused(true); |
| 248 | } |
| 249 | } |
| 250 | |
Jakob Stoklund Olesen | 2343659 | 2010-08-06 18:46:59 +0000 | [diff] [blame] | 251 | /// RenumberValues - Renumber all values in order of appearance and delete the |
| 252 | /// remaining unused values. |
Jakob Stoklund Olesen | fff2c47 | 2010-08-12 20:38:03 +0000 | [diff] [blame] | 253 | void LiveInterval::RenumberValues(LiveIntervals &lis) { |
Jakob Stoklund Olesen | 2343659 | 2010-08-06 18:46:59 +0000 | [diff] [blame] | 254 | SmallPtrSet<VNInfo*, 8> Seen; |
Jakob Stoklund Olesen | fff2c47 | 2010-08-12 20:38:03 +0000 | [diff] [blame] | 255 | bool seenPHIDef = false; |
Jakob Stoklund Olesen | 2343659 | 2010-08-06 18:46:59 +0000 | [diff] [blame] | 256 | valnos.clear(); |
| 257 | for (const_iterator I = begin(), E = end(); I != E; ++I) { |
| 258 | VNInfo *VNI = I->valno; |
| 259 | if (!Seen.insert(VNI)) |
| 260 | continue; |
| 261 | assert(!VNI->isUnused() && "Unused valno used by live range"); |
| 262 | VNI->id = (unsigned)valnos.size(); |
| 263 | valnos.push_back(VNI); |
Jakob Stoklund Olesen | fff2c47 | 2010-08-12 20:38:03 +0000 | [diff] [blame] | 264 | VNI->setHasPHIKill(false); |
| 265 | if (VNI->isPHIDef()) |
| 266 | seenPHIDef = true; |
| 267 | } |
| 268 | |
| 269 | // Recompute phi kill flags. |
| 270 | if (!seenPHIDef) |
| 271 | return; |
| 272 | for (const_vni_iterator I = vni_begin(), E = vni_end(); I != E; ++I) { |
| 273 | VNInfo *VNI = *I; |
| 274 | if (!VNI->isPHIDef()) |
| 275 | continue; |
| 276 | const MachineBasicBlock *PHIBB = lis.getMBBFromIndex(VNI->def); |
| 277 | assert(PHIBB && "No basic block for phi-def"); |
| 278 | for (MachineBasicBlock::const_pred_iterator PI = PHIBB->pred_begin(), |
| 279 | PE = PHIBB->pred_end(); PI != PE; ++PI) { |
| 280 | VNInfo *KVNI = getVNInfoAt(lis.getMBBEndIdx(*PI).getPrevSlot()); |
| 281 | if (KVNI) |
| 282 | KVNI->setHasPHIKill(true); |
| 283 | } |
Jakob Stoklund Olesen | 2343659 | 2010-08-06 18:46:59 +0000 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 287 | /// extendIntervalEndTo - This method is used when we want to extend the range |
| 288 | /// specified by I to end at the specified endpoint. To do this, we should |
| 289 | /// merge and eliminate all ranges that this will overlap with. The iterator is |
| 290 | /// not invalidated. |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 291 | void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) { |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 292 | assert(I != ranges.end() && "Not a valid interval!"); |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 293 | VNInfo *ValNo = I->valno; |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 294 | |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 295 | // Search for the first interval that we can't merge with. |
Oscar Fuentes | ee56c42 | 2010-08-02 06:00:15 +0000 | [diff] [blame] | 296 | Ranges::iterator MergeTo = llvm::next(I); |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 297 | for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) { |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 298 | assert(MergeTo->valno == ValNo && "Cannot merge with differing values!"); |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 299 | } |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 300 | |
| 301 | // If NewEnd was in the middle of an interval, make sure to get its endpoint. |
| 302 | I->end = std::max(NewEnd, prior(MergeTo)->end); |
| 303 | |
Chris Lattner | b0fa11c | 2005-10-20 07:39:25 +0000 | [diff] [blame] | 304 | // Erase any dead ranges. |
Oscar Fuentes | ee56c42 | 2010-08-02 06:00:15 +0000 | [diff] [blame] | 305 | ranges.erase(llvm::next(I), MergeTo); |
Evan Cheng | 4f8ff16 | 2007-08-11 00:59:19 +0000 | [diff] [blame] | 306 | |
Chris Lattner | b0fa11c | 2005-10-20 07:39:25 +0000 | [diff] [blame] | 307 | // If the newly formed range now touches the range after it and if they have |
| 308 | // the same value number, merge the two ranges into one range. |
Oscar Fuentes | ee56c42 | 2010-08-02 06:00:15 +0000 | [diff] [blame] | 309 | Ranges::iterator Next = llvm::next(I); |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 310 | if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) { |
Chris Lattner | cef6010 | 2005-10-20 22:50:10 +0000 | [diff] [blame] | 311 | I->end = Next->end; |
| 312 | ranges.erase(Next); |
Chris Lattner | b0fa11c | 2005-10-20 07:39:25 +0000 | [diff] [blame] | 313 | } |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | |
| 317 | /// extendIntervalStartTo - This method is used when we want to extend the range |
| 318 | /// specified by I to start at the specified endpoint. To do this, we should |
| 319 | /// merge and eliminate all ranges that this will overlap with. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 320 | LiveInterval::Ranges::iterator |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 321 | LiveInterval::extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStart) { |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 322 | assert(I != ranges.end() && "Not a valid interval!"); |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 323 | VNInfo *ValNo = I->valno; |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 324 | |
| 325 | // Search for the first interval that we can't merge with. |
| 326 | Ranges::iterator MergeTo = I; |
| 327 | do { |
| 328 | if (MergeTo == ranges.begin()) { |
| 329 | I->start = NewStart; |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 330 | ranges.erase(MergeTo, I); |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 331 | return I; |
| 332 | } |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 333 | assert(MergeTo->valno == ValNo && "Cannot merge with differing values!"); |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 334 | --MergeTo; |
| 335 | } while (NewStart <= MergeTo->start); |
| 336 | |
| 337 | // If we start in the middle of another interval, just delete a range and |
| 338 | // extend that interval. |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 339 | if (MergeTo->end >= NewStart && MergeTo->valno == ValNo) { |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 340 | MergeTo->end = I->end; |
| 341 | } else { |
| 342 | // Otherwise, extend the interval right after. |
| 343 | ++MergeTo; |
| 344 | MergeTo->start = NewStart; |
| 345 | MergeTo->end = I->end; |
| 346 | } |
| 347 | |
Oscar Fuentes | ee56c42 | 2010-08-02 06:00:15 +0000 | [diff] [blame] | 348 | ranges.erase(llvm::next(MergeTo), llvm::next(I)); |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 349 | return MergeTo; |
| 350 | } |
| 351 | |
Chris Lattner | c114b2c | 2006-08-25 23:41:24 +0000 | [diff] [blame] | 352 | LiveInterval::iterator |
| 353 | LiveInterval::addRangeFrom(LiveRange LR, iterator From) { |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 354 | SlotIndex Start = LR.start, End = LR.end; |
Chris Lattner | c114b2c | 2006-08-25 23:41:24 +0000 | [diff] [blame] | 355 | iterator it = std::upper_bound(From, ranges.end(), Start); |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 356 | |
| 357 | // If the inserted interval starts in the middle or right at the end of |
| 358 | // another interval, just extend that interval to contain the range of LR. |
| 359 | if (it != ranges.begin()) { |
Chris Lattner | c114b2c | 2006-08-25 23:41:24 +0000 | [diff] [blame] | 360 | iterator B = prior(it); |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 361 | if (LR.valno == B->valno) { |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 362 | if (B->start <= Start && B->end >= Start) { |
| 363 | extendIntervalEndTo(B, End); |
| 364 | return B; |
| 365 | } |
| 366 | } else { |
| 367 | // Check to make sure that we are not overlapping two live ranges with |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 368 | // different valno's. |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 369 | assert(B->end <= Start && |
Brian Gaeke | 8311bef | 2004-11-16 06:52:35 +0000 | [diff] [blame] | 370 | "Cannot overlap two LiveRanges with differing ValID's" |
| 371 | " (did you def the same reg twice in a MachineInstr?)"); |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | |
| 375 | // Otherwise, if this range ends in the middle of, or right next to, another |
| 376 | // interval, merge it into that interval. |
Anton Korobeynikov | 4c71dfe | 2008-02-20 11:10:28 +0000 | [diff] [blame] | 377 | if (it != ranges.end()) { |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 378 | if (LR.valno == it->valno) { |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 379 | if (it->start <= End) { |
| 380 | it = extendIntervalStartTo(it, Start); |
| 381 | |
| 382 | // If LR is a complete superset of an interval, we may need to grow its |
| 383 | // endpoint as well. |
| 384 | if (End > it->end) |
| 385 | extendIntervalEndTo(it, End); |
| 386 | return it; |
| 387 | } |
| 388 | } else { |
| 389 | // Check to make sure that we are not overlapping two live ranges with |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 390 | // different valno's. |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 391 | assert(it->start >= End && |
| 392 | "Cannot overlap two LiveRanges with differing ValID's"); |
| 393 | } |
Anton Korobeynikov | 4c71dfe | 2008-02-20 11:10:28 +0000 | [diff] [blame] | 394 | } |
Chris Lattner | b26c215 | 2004-07-23 19:38:44 +0000 | [diff] [blame] | 395 | |
| 396 | // Otherwise, this is just a new range that doesn't interact with anything. |
| 397 | // Insert it. |
| 398 | return ranges.insert(it, LR); |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Jakob Stoklund Olesen | 9763e2b | 2011-03-02 00:06:15 +0000 | [diff] [blame] | 401 | /// extendInBlock - If this interval is live before UseIdx in the basic |
| 402 | /// block that starts at StartIdx, extend it to be live at UseIdx and return |
| 403 | /// the value. If there is no live range before UseIdx, return NULL. |
| 404 | VNInfo *LiveInterval::extendInBlock(SlotIndex StartIdx, SlotIndex UseIdx) { |
| 405 | if (empty()) |
| 406 | return 0; |
| 407 | iterator I = std::upper_bound(begin(), end(), UseIdx); |
| 408 | if (I == begin()) |
| 409 | return 0; |
| 410 | --I; |
| 411 | if (I->end <= StartIdx) |
| 412 | return 0; |
| 413 | if (I->end <= UseIdx) |
| 414 | extendIntervalEndTo(I, UseIdx.getNextSlot()); |
| 415 | return I->valno; |
| 416 | } |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 417 | |
| 418 | /// removeRange - Remove the specified range from this interval. Note that |
Evan Cheng | 42cc6e3 | 2009-01-29 00:06:09 +0000 | [diff] [blame] | 419 | /// the range must be in a single LiveRange in its entirety. |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 420 | void LiveInterval::removeRange(SlotIndex Start, SlotIndex End, |
Evan Cheng | d2b8d7b | 2008-02-13 02:48:26 +0000 | [diff] [blame] | 421 | bool RemoveDeadValNo) { |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 422 | // Find the LiveRange containing this span. |
Jakob Stoklund Olesen | f568b27 | 2010-09-21 17:12:18 +0000 | [diff] [blame] | 423 | Ranges::iterator I = find(Start); |
| 424 | assert(I != ranges.end() && "Range is not in interval!"); |
Lang Hames | 8651125 | 2009-09-04 20:41:11 +0000 | [diff] [blame] | 425 | assert(I->containsRange(Start, End) && "Range is not entirely in interval!"); |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 426 | |
| 427 | // If the span we are removing is at the start of the LiveRange, adjust it. |
Evan Cheng | d2b8d7b | 2008-02-13 02:48:26 +0000 | [diff] [blame] | 428 | VNInfo *ValNo = I->valno; |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 429 | if (I->start == Start) { |
Evan Cheng | 4f8ff16 | 2007-08-11 00:59:19 +0000 | [diff] [blame] | 430 | if (I->end == End) { |
Evan Cheng | d2b8d7b | 2008-02-13 02:48:26 +0000 | [diff] [blame] | 431 | if (RemoveDeadValNo) { |
| 432 | // Check if val# is dead. |
| 433 | bool isDead = true; |
| 434 | for (const_iterator II = begin(), EE = end(); II != EE; ++II) |
| 435 | if (II != I && II->valno == ValNo) { |
| 436 | isDead = false; |
| 437 | break; |
Jakob Stoklund Olesen | 15a5714 | 2010-06-25 22:53:05 +0000 | [diff] [blame] | 438 | } |
Evan Cheng | d2b8d7b | 2008-02-13 02:48:26 +0000 | [diff] [blame] | 439 | if (isDead) { |
Lang Hames | 6f4e4df | 2010-07-26 01:49:41 +0000 | [diff] [blame] | 440 | // Now that ValNo is dead, remove it. |
| 441 | markValNoForDeletion(ValNo); |
Evan Cheng | d2b8d7b | 2008-02-13 02:48:26 +0000 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 445 | ranges.erase(I); // Removed the whole LiveRange. |
Evan Cheng | 4f8ff16 | 2007-08-11 00:59:19 +0000 | [diff] [blame] | 446 | } else |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 447 | I->start = End; |
| 448 | return; |
| 449 | } |
| 450 | |
| 451 | // Otherwise if the span we are removing is at the end of the LiveRange, |
| 452 | // adjust the other way. |
| 453 | if (I->end == End) { |
Chris Lattner | 6925a9f | 2004-07-25 05:43:53 +0000 | [diff] [blame] | 454 | I->end = Start; |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 455 | return; |
| 456 | } |
| 457 | |
| 458 | // Otherwise, we are splitting the LiveRange into two pieces. |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 459 | SlotIndex OldEnd = I->end; |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 460 | I->end = Start; // Trim the old interval. |
| 461 | |
| 462 | // Insert the new one. |
Oscar Fuentes | ee56c42 | 2010-08-02 06:00:15 +0000 | [diff] [blame] | 463 | ranges.insert(llvm::next(I), LiveRange(End, OldEnd, ValNo)); |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Evan Cheng | d2b8d7b | 2008-02-13 02:48:26 +0000 | [diff] [blame] | 466 | /// removeValNo - Remove all the ranges defined by the specified value#. |
| 467 | /// Also remove the value# from value# list. |
| 468 | void LiveInterval::removeValNo(VNInfo *ValNo) { |
| 469 | if (empty()) return; |
| 470 | Ranges::iterator I = ranges.end(); |
| 471 | Ranges::iterator E = ranges.begin(); |
| 472 | do { |
| 473 | --I; |
| 474 | if (I->valno == ValNo) |
| 475 | ranges.erase(I); |
| 476 | } while (I != E); |
Lang Hames | 6f4e4df | 2010-07-26 01:49:41 +0000 | [diff] [blame] | 477 | // Now that ValNo is dead, remove it. |
| 478 | markValNoForDeletion(ValNo); |
Evan Cheng | d2b8d7b | 2008-02-13 02:48:26 +0000 | [diff] [blame] | 479 | } |
Lang Hames | 8651125 | 2009-09-04 20:41:11 +0000 | [diff] [blame] | 480 | |
Lang Hames | 8651125 | 2009-09-04 20:41:11 +0000 | [diff] [blame] | 481 | /// findDefinedVNInfo - Find the VNInfo defined by the specified |
| 482 | /// index (register interval). |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 483 | VNInfo *LiveInterval::findDefinedVNInfoForRegInt(SlotIndex Idx) const { |
Evan Cheng | 3f32d65 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 484 | for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end(); |
Lang Hames | 8651125 | 2009-09-04 20:41:11 +0000 | [diff] [blame] | 485 | i != e; ++i) { |
| 486 | if ((*i)->def == Idx) |
| 487 | return *i; |
| 488 | } |
| 489 | |
| 490 | return 0; |
| 491 | } |
| 492 | |
Chris Lattner | 6d8fbef | 2006-08-29 23:18:15 +0000 | [diff] [blame] | 493 | /// join - Join two live intervals (this, and other) together. This applies |
| 494 | /// mappings to the value numbers in the LHS/RHS intervals as specified. If |
| 495 | /// the intervals are not joinable, this aborts. |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 496 | void LiveInterval::join(LiveInterval &Other, |
| 497 | const int *LHSValNoAssignments, |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 498 | const int *RHSValNoAssignments, |
Evan Cheng | 90f95f8 | 2009-06-14 20:22:55 +0000 | [diff] [blame] | 499 | SmallVector<VNInfo*, 16> &NewVNInfo, |
| 500 | MachineRegisterInfo *MRI) { |
Chris Lattner | 6d8fbef | 2006-08-29 23:18:15 +0000 | [diff] [blame] | 501 | // Determine if any of our live range values are mapped. This is uncommon, so |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 502 | // we want to avoid the interval scan if not. |
Chris Lattner | 6d8fbef | 2006-08-29 23:18:15 +0000 | [diff] [blame] | 503 | bool MustMapCurValNos = false; |
Evan Cheng | 3430135 | 2007-09-01 02:03:17 +0000 | [diff] [blame] | 504 | unsigned NumVals = getNumValNums(); |
| 505 | unsigned NumNewVals = NewVNInfo.size(); |
| 506 | for (unsigned i = 0; i != NumVals; ++i) { |
| 507 | unsigned LHSValID = LHSValNoAssignments[i]; |
| 508 | if (i != LHSValID || |
Evan Cheng | f3bb2e6 | 2007-09-05 21:46:51 +0000 | [diff] [blame] | 509 | (NewVNInfo[LHSValID] && NewVNInfo[LHSValID] != getValNumInfo(i))) |
Chris Lattner | 6d8fbef | 2006-08-29 23:18:15 +0000 | [diff] [blame] | 510 | MustMapCurValNos = true; |
Chris Lattner | deb9971 | 2004-07-24 03:41:50 +0000 | [diff] [blame] | 511 | } |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 512 | |
Chris Lattner | 6d8fbef | 2006-08-29 23:18:15 +0000 | [diff] [blame] | 513 | // If we have to apply a mapping to our base interval assignment, rewrite it |
| 514 | // now. |
| 515 | if (MustMapCurValNos) { |
| 516 | // Map the first live range. |
| 517 | iterator OutIt = begin(); |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 518 | OutIt->valno = NewVNInfo[LHSValNoAssignments[OutIt->valno->id]]; |
Chris Lattner | 6d8fbef | 2006-08-29 23:18:15 +0000 | [diff] [blame] | 519 | ++OutIt; |
| 520 | for (iterator I = OutIt, E = end(); I != E; ++I) { |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 521 | OutIt->valno = NewVNInfo[LHSValNoAssignments[I->valno->id]]; |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 522 | |
Chris Lattner | 6d8fbef | 2006-08-29 23:18:15 +0000 | [diff] [blame] | 523 | // If this live range has the same value # as its immediate predecessor, |
| 524 | // and if they are neighbors, remove one LiveRange. This happens when we |
| 525 | // have [0,3:0)[4,7:1) and map 0/1 onto the same value #. |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 526 | if (OutIt->valno == (OutIt-1)->valno && (OutIt-1)->end == OutIt->start) { |
Chris Lattner | 6d8fbef | 2006-08-29 23:18:15 +0000 | [diff] [blame] | 527 | (OutIt-1)->end = OutIt->end; |
| 528 | } else { |
| 529 | if (I != OutIt) { |
| 530 | OutIt->start = I->start; |
| 531 | OutIt->end = I->end; |
| 532 | } |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 533 | |
Chris Lattner | 6d8fbef | 2006-08-29 23:18:15 +0000 | [diff] [blame] | 534 | // Didn't merge, on to the next one. |
| 535 | ++OutIt; |
| 536 | } |
| 537 | } |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 538 | |
Chris Lattner | 6d8fbef | 2006-08-29 23:18:15 +0000 | [diff] [blame] | 539 | // If we merge some live ranges, chop off the end. |
| 540 | ranges.erase(OutIt, end()); |
| 541 | } |
Evan Cheng | 4f8ff16 | 2007-08-11 00:59:19 +0000 | [diff] [blame] | 542 | |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 543 | // Remember assignements because val# ids are changing. |
Evan Cheng | 3430135 | 2007-09-01 02:03:17 +0000 | [diff] [blame] | 544 | SmallVector<unsigned, 16> OtherAssignments; |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 545 | for (iterator I = Other.begin(), E = Other.end(); I != E; ++I) |
| 546 | OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]); |
| 547 | |
| 548 | // Update val# info. Renumber them and make sure they all belong to this |
Evan Cheng | f3bb2e6 | 2007-09-05 21:46:51 +0000 | [diff] [blame] | 549 | // LiveInterval now. Also remove dead val#'s. |
| 550 | unsigned NumValNos = 0; |
| 551 | for (unsigned i = 0; i < NumNewVals; ++i) { |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 552 | VNInfo *VNI = NewVNInfo[i]; |
Evan Cheng | f3bb2e6 | 2007-09-05 21:46:51 +0000 | [diff] [blame] | 553 | if (VNI) { |
Evan Cheng | 30590f5 | 2009-04-28 06:24:09 +0000 | [diff] [blame] | 554 | if (NumValNos >= NumVals) |
Evan Cheng | f3bb2e6 | 2007-09-05 21:46:51 +0000 | [diff] [blame] | 555 | valnos.push_back(VNI); |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 556 | else |
Evan Cheng | f3bb2e6 | 2007-09-05 21:46:51 +0000 | [diff] [blame] | 557 | valnos[NumValNos] = VNI; |
| 558 | VNI->id = NumValNos++; // Renumber val#. |
Evan Cheng | 3430135 | 2007-09-01 02:03:17 +0000 | [diff] [blame] | 559 | } |
| 560 | } |
Evan Cheng | 3430135 | 2007-09-01 02:03:17 +0000 | [diff] [blame] | 561 | if (NumNewVals < NumVals) |
| 562 | valnos.resize(NumNewVals); // shrinkify |
Evan Cheng | 4f8ff16 | 2007-08-11 00:59:19 +0000 | [diff] [blame] | 563 | |
Chris Lattner | 6d8fbef | 2006-08-29 23:18:15 +0000 | [diff] [blame] | 564 | // Okay, now insert the RHS live ranges into the LHS. |
Chris Lattner | c114b2c | 2006-08-25 23:41:24 +0000 | [diff] [blame] | 565 | iterator InsertPos = begin(); |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 566 | unsigned RangeNo = 0; |
| 567 | for (iterator I = Other.begin(), E = Other.end(); I != E; ++I, ++RangeNo) { |
| 568 | // Map the valno in the other live range to the current live range. |
| 569 | I->valno = NewVNInfo[OtherAssignments[RangeNo]]; |
Evan Cheng | f3bb2e6 | 2007-09-05 21:46:51 +0000 | [diff] [blame] | 570 | assert(I->valno && "Adding a dead range?"); |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 571 | InsertPos = addRangeFrom(*I, InsertPos); |
| 572 | } |
Chris Lattner | 6d8fbef | 2006-08-29 23:18:15 +0000 | [diff] [blame] | 573 | |
David Greene | 29ff37f | 2009-07-22 20:08:25 +0000 | [diff] [blame] | 574 | ComputeJoinedWeight(Other); |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Chris Lattner | f21f020 | 2006-09-02 05:26:59 +0000 | [diff] [blame] | 577 | /// MergeRangesInAsValue - Merge all of the intervals in RHS into this live |
| 578 | /// interval as the specified value number. The LiveRanges in RHS are |
| 579 | /// allowed to overlap with LiveRanges in the current interval, but only if |
| 580 | /// the overlapping LiveRanges have the specified value number. |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 581 | void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS, |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 582 | VNInfo *LHSValNo) { |
Chris Lattner | f21f020 | 2006-09-02 05:26:59 +0000 | [diff] [blame] | 583 | // TODO: Make this more efficient. |
| 584 | iterator InsertPos = begin(); |
| 585 | for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) { |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 586 | // Map the valno in the other live range to the current live range. |
Chris Lattner | f21f020 | 2006-09-02 05:26:59 +0000 | [diff] [blame] | 587 | LiveRange Tmp = *I; |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 588 | Tmp.valno = LHSValNo; |
Chris Lattner | f21f020 | 2006-09-02 05:26:59 +0000 | [diff] [blame] | 589 | InsertPos = addRangeFrom(Tmp, InsertPos); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | |
Evan Cheng | 32dfbea | 2007-10-12 08:50:34 +0000 | [diff] [blame] | 594 | /// MergeValueInAsValue - Merge all of the live ranges of a specific val# |
| 595 | /// in RHS into this live interval as the specified value number. |
| 596 | /// The LiveRanges in RHS are allowed to overlap with LiveRanges in the |
Evan Cheng | 3c1f4a4 | 2007-10-17 02:13:29 +0000 | [diff] [blame] | 597 | /// current interval, it will replace the value numbers of the overlaped |
| 598 | /// live ranges with the specified value number. |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 599 | void LiveInterval::MergeValueInAsValue( |
| 600 | const LiveInterval &RHS, |
| 601 | const VNInfo *RHSValNo, VNInfo *LHSValNo) { |
Evan Cheng | 3c1f4a4 | 2007-10-17 02:13:29 +0000 | [diff] [blame] | 602 | SmallVector<VNInfo*, 4> ReplacedValNos; |
| 603 | iterator IP = begin(); |
Evan Cheng | 32dfbea | 2007-10-12 08:50:34 +0000 | [diff] [blame] | 604 | for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) { |
Jakob Stoklund Olesen | 014b863 | 2010-06-23 15:34:36 +0000 | [diff] [blame] | 605 | assert(I->valno == RHS.getValNumInfo(I->valno->id) && "Bad VNInfo"); |
Evan Cheng | 32dfbea | 2007-10-12 08:50:34 +0000 | [diff] [blame] | 606 | if (I->valno != RHSValNo) |
| 607 | continue; |
Lang Hames | 233a60e | 2009-11-03 23:52:08 +0000 | [diff] [blame] | 608 | SlotIndex Start = I->start, End = I->end; |
Evan Cheng | 3c1f4a4 | 2007-10-17 02:13:29 +0000 | [diff] [blame] | 609 | IP = std::upper_bound(IP, end(), Start); |
| 610 | // If the start of this range overlaps with an existing liverange, trim it. |
| 611 | if (IP != begin() && IP[-1].end > Start) { |
Evan Cheng | 294e652 | 2008-01-30 22:44:55 +0000 | [diff] [blame] | 612 | if (IP[-1].valno != LHSValNo) { |
| 613 | ReplacedValNos.push_back(IP[-1].valno); |
| 614 | IP[-1].valno = LHSValNo; // Update val#. |
Evan Cheng | 3c1f4a4 | 2007-10-17 02:13:29 +0000 | [diff] [blame] | 615 | } |
| 616 | Start = IP[-1].end; |
| 617 | // Trimmed away the whole range? |
| 618 | if (Start >= End) continue; |
| 619 | } |
| 620 | // If the end of this range overlaps with an existing liverange, trim it. |
| 621 | if (IP != end() && End > IP->start) { |
| 622 | if (IP->valno != LHSValNo) { |
| 623 | ReplacedValNos.push_back(IP->valno); |
| 624 | IP->valno = LHSValNo; // Update val#. |
| 625 | } |
| 626 | End = IP->start; |
| 627 | // If this trimmed away the whole range, ignore it. |
| 628 | if (Start == End) continue; |
| 629 | } |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 630 | |
Evan Cheng | 32dfbea | 2007-10-12 08:50:34 +0000 | [diff] [blame] | 631 | // Map the valno in the other live range to the current live range. |
Evan Cheng | 3c1f4a4 | 2007-10-17 02:13:29 +0000 | [diff] [blame] | 632 | IP = addRangeFrom(LiveRange(Start, End, LHSValNo), IP); |
| 633 | } |
| 634 | |
| 635 | |
| 636 | SmallSet<VNInfo*, 4> Seen; |
| 637 | for (unsigned i = 0, e = ReplacedValNos.size(); i != e; ++i) { |
| 638 | VNInfo *V1 = ReplacedValNos[i]; |
| 639 | if (Seen.insert(V1)) { |
| 640 | bool isDead = true; |
| 641 | for (const_iterator I = begin(), E = end(); I != E; ++I) |
| 642 | if (I->valno == V1) { |
| 643 | isDead = false; |
| 644 | break; |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 645 | } |
Evan Cheng | 3c1f4a4 | 2007-10-17 02:13:29 +0000 | [diff] [blame] | 646 | if (isDead) { |
Lang Hames | 6f4e4df | 2010-07-26 01:49:41 +0000 | [diff] [blame] | 647 | // Now that V1 is dead, remove it. |
| 648 | markValNoForDeletion(V1); |
Evan Cheng | 3c1f4a4 | 2007-10-17 02:13:29 +0000 | [diff] [blame] | 649 | } |
| 650 | } |
Evan Cheng | 32dfbea | 2007-10-12 08:50:34 +0000 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
| 654 | |
Evan Cheng | a2e6435 | 2009-03-11 00:03:21 +0000 | [diff] [blame] | 655 | |
Chris Lattner | f7da2c7 | 2006-08-24 22:43:55 +0000 | [diff] [blame] | 656 | /// MergeValueNumberInto - This method is called when two value nubmers |
| 657 | /// are found to be equivalent. This eliminates V1, replacing all |
| 658 | /// LiveRanges with the V1 value number with the V2 value number. This can |
| 659 | /// cause merging of V1/V2 values numbers and compaction of the value space. |
Owen Anderson | 5b93f6f | 2009-02-02 22:42:01 +0000 | [diff] [blame] | 660 | VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) { |
Chris Lattner | f7da2c7 | 2006-08-24 22:43:55 +0000 | [diff] [blame] | 661 | assert(V1 != V2 && "Identical value#'s are always equivalent!"); |
| 662 | |
| 663 | // This code actually merges the (numerically) larger value number into the |
| 664 | // smaller value number, which is likely to allow us to compactify the value |
| 665 | // space. The only thing we have to be careful of is to preserve the |
| 666 | // instruction that defines the result value. |
| 667 | |
| 668 | // Make sure V2 is smaller than V1. |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 669 | if (V1->id < V2->id) { |
Lang Hames | 52c1afc | 2009-08-10 23:43:28 +0000 | [diff] [blame] | 670 | V1->copyFrom(*V2); |
Chris Lattner | f7da2c7 | 2006-08-24 22:43:55 +0000 | [diff] [blame] | 671 | std::swap(V1, V2); |
| 672 | } |
| 673 | |
| 674 | // Merge V1 live ranges into V2. |
| 675 | for (iterator I = begin(); I != end(); ) { |
| 676 | iterator LR = I++; |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 677 | if (LR->valno != V1) continue; // Not a V1 LiveRange. |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 678 | |
Chris Lattner | f7da2c7 | 2006-08-24 22:43:55 +0000 | [diff] [blame] | 679 | // Okay, we found a V1 live range. If it had a previous, touching, V2 live |
| 680 | // range, extend it. |
| 681 | if (LR != begin()) { |
| 682 | iterator Prev = LR-1; |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 683 | if (Prev->valno == V2 && Prev->end == LR->start) { |
Chris Lattner | f7da2c7 | 2006-08-24 22:43:55 +0000 | [diff] [blame] | 684 | Prev->end = LR->end; |
| 685 | |
| 686 | // Erase this live-range. |
| 687 | ranges.erase(LR); |
| 688 | I = Prev+1; |
| 689 | LR = Prev; |
| 690 | } |
| 691 | } |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 692 | |
Chris Lattner | f7da2c7 | 2006-08-24 22:43:55 +0000 | [diff] [blame] | 693 | // Okay, now we have a V1 or V2 live range that is maximally merged forward. |
| 694 | // Ensure that it is a V2 live-range. |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 695 | LR->valno = V2; |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 696 | |
Chris Lattner | f7da2c7 | 2006-08-24 22:43:55 +0000 | [diff] [blame] | 697 | // If we can merge it into later V2 live ranges, do so now. We ignore any |
| 698 | // following V1 live ranges, as they will be merged in subsequent iterations |
| 699 | // of the loop. |
| 700 | if (I != end()) { |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 701 | if (I->start == LR->end && I->valno == V2) { |
Chris Lattner | f7da2c7 | 2006-08-24 22:43:55 +0000 | [diff] [blame] | 702 | LR->end = I->end; |
| 703 | ranges.erase(I); |
| 704 | I = LR+1; |
| 705 | } |
| 706 | } |
| 707 | } |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 708 | |
Jakob Stoklund Olesen | e0a73ec | 2010-10-01 23:52:25 +0000 | [diff] [blame] | 709 | // Merge the relevant flags. |
| 710 | V2->mergeFlags(V1); |
| 711 | |
Lang Hames | 6f4e4df | 2010-07-26 01:49:41 +0000 | [diff] [blame] | 712 | // Now that V1 is dead, remove it. |
| 713 | markValNoForDeletion(V1); |
Jakob Stoklund Olesen | 1b29320 | 2010-08-12 20:01:23 +0000 | [diff] [blame] | 714 | |
Owen Anderson | 5b93f6f | 2009-02-02 22:42:01 +0000 | [diff] [blame] | 715 | return V2; |
Chris Lattner | f7da2c7 | 2006-08-24 22:43:55 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Evan Cheng | 32dfbea | 2007-10-12 08:50:34 +0000 | [diff] [blame] | 718 | void LiveInterval::Copy(const LiveInterval &RHS, |
Evan Cheng | 90f95f8 | 2009-06-14 20:22:55 +0000 | [diff] [blame] | 719 | MachineRegisterInfo *MRI, |
Benjamin Kramer | 991de14 | 2010-03-30 20:16:45 +0000 | [diff] [blame] | 720 | VNInfo::Allocator &VNInfoAllocator) { |
Evan Cheng | 32dfbea | 2007-10-12 08:50:34 +0000 | [diff] [blame] | 721 | ranges.clear(); |
| 722 | valnos.clear(); |
Evan Cheng | 358dec5 | 2009-06-15 08:28:29 +0000 | [diff] [blame] | 723 | std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(RHS.reg); |
Evan Cheng | 90f95f8 | 2009-06-14 20:22:55 +0000 | [diff] [blame] | 724 | MRI->setRegAllocationHint(reg, Hint.first, Hint.second); |
| 725 | |
Evan Cheng | 32dfbea | 2007-10-12 08:50:34 +0000 | [diff] [blame] | 726 | weight = RHS.weight; |
| 727 | for (unsigned i = 0, e = RHS.getNumValNums(); i != e; ++i) { |
| 728 | const VNInfo *VNI = RHS.getValNumInfo(i); |
Lang Hames | 857c4e0 | 2009-06-17 21:01:20 +0000 | [diff] [blame] | 729 | createValueCopy(VNI, VNInfoAllocator); |
Evan Cheng | 32dfbea | 2007-10-12 08:50:34 +0000 | [diff] [blame] | 730 | } |
| 731 | for (unsigned i = 0, e = RHS.ranges.size(); i != e; ++i) { |
| 732 | const LiveRange &LR = RHS.ranges[i]; |
| 733 | addRange(LiveRange(LR.start, LR.end, getValNumInfo(LR.valno->id))); |
| 734 | } |
| 735 | } |
| 736 | |
Evan Cheng | e52eef8 | 2007-04-17 20:25:11 +0000 | [diff] [blame] | 737 | unsigned LiveInterval::getSize() const { |
| 738 | unsigned Sum = 0; |
| 739 | for (const_iterator I = begin(), E = end(); I != E; ++I) |
Lang Hames | 8651125 | 2009-09-04 20:41:11 +0000 | [diff] [blame] | 740 | Sum += I->start.distance(I->end); |
Evan Cheng | e52eef8 | 2007-04-17 20:25:11 +0000 | [diff] [blame] | 741 | return Sum; |
| 742 | } |
| 743 | |
David Greene | 29ff37f | 2009-07-22 20:08:25 +0000 | [diff] [blame] | 744 | /// ComputeJoinedWeight - Set the weight of a live interval Joined |
| 745 | /// after Other has been merged into it. |
| 746 | void LiveInterval::ComputeJoinedWeight(const LiveInterval &Other) { |
| 747 | // If either of these intervals was spilled, the weight is the |
| 748 | // weight of the non-spilled interval. This can only happen with |
| 749 | // iterative coalescers. |
| 750 | |
David Greene | 92b78bb | 2009-07-22 22:32:19 +0000 | [diff] [blame] | 751 | if (Other.weight != HUGE_VALF) { |
| 752 | weight += Other.weight; |
| 753 | } |
| 754 | else if (weight == HUGE_VALF && |
David Greene | 29ff37f | 2009-07-22 20:08:25 +0000 | [diff] [blame] | 755 | !TargetRegisterInfo::isPhysicalRegister(reg)) { |
| 756 | // Remove this assert if you have an iterative coalescer |
| 757 | assert(0 && "Joining to spilled interval"); |
| 758 | weight = Other.weight; |
| 759 | } |
David Greene | 29ff37f | 2009-07-22 20:08:25 +0000 | [diff] [blame] | 760 | else { |
| 761 | // Otherwise the weight stays the same |
| 762 | // Remove this assert if you have an iterative coalescer |
| 763 | assert(0 && "Joining from spilled interval"); |
| 764 | } |
| 765 | } |
| 766 | |
Daniel Dunbar | 1cd1d98 | 2009-07-24 10:36:58 +0000 | [diff] [blame] | 767 | raw_ostream& llvm::operator<<(raw_ostream& os, const LiveRange &LR) { |
| 768 | return os << '[' << LR.start << ',' << LR.end << ':' << LR.valno->id << ")"; |
| 769 | } |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 770 | |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 771 | void LiveRange::dump() const { |
David Greene | 5242154 | 2010-01-04 22:41:43 +0000 | [diff] [blame] | 772 | dbgs() << *this << "\n"; |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 773 | } |
| 774 | |
Chris Lattner | c02497f | 2009-08-23 03:47:42 +0000 | [diff] [blame] | 775 | void LiveInterval::print(raw_ostream &OS, const TargetRegisterInfo *TRI) const { |
Jakob Stoklund Olesen | ccdb3fc | 2011-01-19 22:11:48 +0000 | [diff] [blame] | 776 | OS << PrintReg(reg, TRI); |
| 777 | if (weight != 0) |
| 778 | OS << ',' << weight; |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 779 | |
Chris Lattner | 38135af | 2005-05-14 05:34:15 +0000 | [diff] [blame] | 780 | if (empty()) |
Evan Cheng | 3f32d65 | 2008-06-04 09:18:41 +0000 | [diff] [blame] | 781 | OS << " EMPTY"; |
Chris Lattner | 38135af | 2005-05-14 05:34:15 +0000 | [diff] [blame] | 782 | else { |
| 783 | OS << " = "; |
| 784 | for (LiveInterval::Ranges::const_iterator I = ranges.begin(), |
Jakob Stoklund Olesen | 014b863 | 2010-06-23 15:34:36 +0000 | [diff] [blame] | 785 | E = ranges.end(); I != E; ++I) { |
| 786 | OS << *I; |
| 787 | assert(I->valno == getValNumInfo(I->valno->id) && "Bad VNInfo"); |
| 788 | } |
Chris Lattner | 38135af | 2005-05-14 05:34:15 +0000 | [diff] [blame] | 789 | } |
Jakob Stoklund Olesen | 15a5714 | 2010-06-25 22:53:05 +0000 | [diff] [blame] | 790 | |
Chris Lattner | be4f88a | 2006-08-22 18:19:46 +0000 | [diff] [blame] | 791 | // Print value number info. |
Chris Lattner | 6d8fbef | 2006-08-29 23:18:15 +0000 | [diff] [blame] | 792 | if (getNumValNums()) { |
Chris Lattner | be4f88a | 2006-08-22 18:19:46 +0000 | [diff] [blame] | 793 | OS << " "; |
Evan Cheng | 1a66f0a | 2007-08-28 08:28:51 +0000 | [diff] [blame] | 794 | unsigned vnum = 0; |
| 795 | for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e; |
| 796 | ++i, ++vnum) { |
Evan Cheng | 7ecb38b | 2007-08-29 20:45:00 +0000 | [diff] [blame] | 797 | const VNInfo *vni = *i; |
Evan Cheng | 1a66f0a | 2007-08-28 08:28:51 +0000 | [diff] [blame] | 798 | if (vnum) OS << " "; |
| 799 | OS << vnum << "@"; |
Lang Hames | 857c4e0 | 2009-06-17 21:01:20 +0000 | [diff] [blame] | 800 | if (vni->isUnused()) { |
Evan Cheng | 8df7860 | 2007-08-08 03:00:28 +0000 | [diff] [blame] | 801 | OS << "x"; |
Chris Lattner | be4f88a | 2006-08-22 18:19:46 +0000 | [diff] [blame] | 802 | } else { |
Lang Hames | 6e2968c | 2010-09-25 12:04:16 +0000 | [diff] [blame] | 803 | OS << vni->def; |
Jakob Stoklund Olesen | a818c07 | 2010-10-05 18:48:57 +0000 | [diff] [blame] | 804 | if (vni->isPHIDef()) |
| 805 | OS << "-phidef"; |
Jakob Stoklund Olesen | d9f6ec9 | 2010-07-13 21:19:05 +0000 | [diff] [blame] | 806 | if (vni->hasPHIKill()) |
| 807 | OS << "-phikill"; |
| 808 | if (vni->hasRedefByEC()) |
| 809 | OS << "-ec"; |
Evan Cheng | a8d94f1 | 2007-08-07 23:49:57 +0000 | [diff] [blame] | 810 | } |
Chris Lattner | be4f88a | 2006-08-22 18:19:46 +0000 | [diff] [blame] | 811 | } |
| 812 | } |
Chris Lattner | fb449b9 | 2004-07-23 17:49:16 +0000 | [diff] [blame] | 813 | } |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 814 | |
| 815 | void LiveInterval::dump() const { |
David Greene | 5242154 | 2010-01-04 22:41:43 +0000 | [diff] [blame] | 816 | dbgs() << *this << "\n"; |
Chris Lattner | abf295f | 2004-07-24 02:52:23 +0000 | [diff] [blame] | 817 | } |
Jeff Cohen | c21c5ee | 2006-12-15 22:57:14 +0000 | [diff] [blame] | 818 | |
| 819 | |
Daniel Dunbar | 1cd1d98 | 2009-07-24 10:36:58 +0000 | [diff] [blame] | 820 | void LiveRange::print(raw_ostream &os) const { |
| 821 | os << *this; |
| 822 | } |
Jakob Stoklund Olesen | 0253df9 | 2010-10-07 23:34:34 +0000 | [diff] [blame] | 823 | |
Jakob Stoklund Olesen | 0253df9 | 2010-10-07 23:34:34 +0000 | [diff] [blame] | 824 | unsigned ConnectedVNInfoEqClasses::Classify(const LiveInterval *LI) { |
Jakob Stoklund Olesen | 54f32e6 | 2010-10-08 21:19:28 +0000 | [diff] [blame] | 825 | // Create initial equivalence classes. |
Jakob Stoklund Olesen | 0253df9 | 2010-10-07 23:34:34 +0000 | [diff] [blame] | 826 | eqClass_.clear(); |
Jakob Stoklund Olesen | b907e8a | 2010-12-21 00:48:17 +0000 | [diff] [blame] | 827 | eqClass_.grow(LI->getNumValNums()); |
Jakob Stoklund Olesen | 54f32e6 | 2010-10-08 21:19:28 +0000 | [diff] [blame] | 828 | |
Jakob Stoklund Olesen | 6d30905 | 2010-10-29 17:37:29 +0000 | [diff] [blame] | 829 | const VNInfo *used = 0, *unused = 0; |
| 830 | |
Jakob Stoklund Olesen | 54f32e6 | 2010-10-08 21:19:28 +0000 | [diff] [blame] | 831 | // Determine connections. |
Jakob Stoklund Olesen | 0253df9 | 2010-10-07 23:34:34 +0000 | [diff] [blame] | 832 | for (LiveInterval::const_vni_iterator I = LI->vni_begin(), E = LI->vni_end(); |
| 833 | I != E; ++I) { |
| 834 | const VNInfo *VNI = *I; |
Jakob Stoklund Olesen | 6d30905 | 2010-10-29 17:37:29 +0000 | [diff] [blame] | 835 | // Group all unused values into one class. |
| 836 | if (VNI->isUnused()) { |
| 837 | if (unused) |
Jakob Stoklund Olesen | b907e8a | 2010-12-21 00:48:17 +0000 | [diff] [blame] | 838 | eqClass_.join(unused->id, VNI->id); |
Jakob Stoklund Olesen | 6d30905 | 2010-10-29 17:37:29 +0000 | [diff] [blame] | 839 | unused = VNI; |
| 840 | continue; |
| 841 | } |
| 842 | used = VNI; |
Jakob Stoklund Olesen | 0253df9 | 2010-10-07 23:34:34 +0000 | [diff] [blame] | 843 | if (VNI->isPHIDef()) { |
| 844 | const MachineBasicBlock *MBB = lis_.getMBBFromIndex(VNI->def); |
| 845 | assert(MBB && "Phi-def has no defining MBB"); |
| 846 | // Connect to values live out of predecessors. |
| 847 | for (MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(), |
| 848 | PE = MBB->pred_end(); PI != PE; ++PI) |
| 849 | if (const VNInfo *PVNI = |
| 850 | LI->getVNInfoAt(lis_.getMBBEndIdx(*PI).getPrevSlot())) |
Jakob Stoklund Olesen | b907e8a | 2010-12-21 00:48:17 +0000 | [diff] [blame] | 851 | eqClass_.join(VNI->id, PVNI->id); |
Jakob Stoklund Olesen | 0253df9 | 2010-10-07 23:34:34 +0000 | [diff] [blame] | 852 | } else { |
| 853 | // Normal value defined by an instruction. Check for two-addr redef. |
| 854 | // FIXME: This could be coincidental. Should we really check for a tied |
| 855 | // operand constraint? |
Jakob Stoklund Olesen | b907e8a | 2010-12-21 00:48:17 +0000 | [diff] [blame] | 856 | // Note that VNI->def may be a use slot for an early clobber def. |
| 857 | if (const VNInfo *UVNI = LI->getVNInfoAt(VNI->def.getPrevSlot())) |
| 858 | eqClass_.join(VNI->id, UVNI->id); |
Jakob Stoklund Olesen | 0253df9 | 2010-10-07 23:34:34 +0000 | [diff] [blame] | 859 | } |
| 860 | } |
Jakob Stoklund Olesen | 6d30905 | 2010-10-29 17:37:29 +0000 | [diff] [blame] | 861 | |
| 862 | // Lump all the unused values in with the last used value. |
| 863 | if (used && unused) |
Jakob Stoklund Olesen | b907e8a | 2010-12-21 00:48:17 +0000 | [diff] [blame] | 864 | eqClass_.join(used->id, unused->id); |
Jakob Stoklund Olesen | 6d30905 | 2010-10-29 17:37:29 +0000 | [diff] [blame] | 865 | |
Jakob Stoklund Olesen | b907e8a | 2010-12-21 00:48:17 +0000 | [diff] [blame] | 866 | eqClass_.compress(); |
| 867 | return eqClass_.getNumClasses(); |
Jakob Stoklund Olesen | 0253df9 | 2010-10-07 23:34:34 +0000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | void ConnectedVNInfoEqClasses::Distribute(LiveInterval *LIV[]) { |
| 871 | assert(LIV[0] && "LIV[0] must be set"); |
| 872 | LiveInterval &LI = *LIV[0]; |
Jakob Stoklund Olesen | 0253df9 | 2010-10-07 23:34:34 +0000 | [diff] [blame] | 873 | |
| 874 | // First move runs to new intervals. |
| 875 | LiveInterval::iterator J = LI.begin(), E = LI.end(); |
| 876 | while (J != E && eqClass_[J->valno->id] == 0) |
| 877 | ++J; |
| 878 | for (LiveInterval::iterator I = J; I != E; ++I) { |
| 879 | if (unsigned eq = eqClass_[I->valno->id]) { |
Benjamin Kramer | ccefe32 | 2010-10-09 16:36:44 +0000 | [diff] [blame] | 880 | assert((LIV[eq]->empty() || LIV[eq]->expiredAt(I->start)) && |
Jakob Stoklund Olesen | 0253df9 | 2010-10-07 23:34:34 +0000 | [diff] [blame] | 881 | "New intervals should be empty"); |
| 882 | LIV[eq]->ranges.push_back(*I); |
| 883 | } else |
| 884 | *J++ = *I; |
| 885 | } |
| 886 | LI.ranges.erase(J, E); |
| 887 | |
| 888 | // Transfer VNInfos to their new owners and renumber them. |
| 889 | unsigned j = 0, e = LI.getNumValNums(); |
| 890 | while (j != e && eqClass_[j] == 0) |
| 891 | ++j; |
| 892 | for (unsigned i = j; i != e; ++i) { |
| 893 | VNInfo *VNI = LI.getValNumInfo(i); |
| 894 | if (unsigned eq = eqClass_[i]) { |
| 895 | VNI->id = LIV[eq]->getNumValNums(); |
| 896 | LIV[eq]->valnos.push_back(VNI); |
| 897 | } else { |
| 898 | VNI->id = j; |
| 899 | LI.valnos[j++] = VNI; |
| 900 | } |
| 901 | } |
| 902 | LI.valnos.resize(j); |
| 903 | } |