blob: 14b10d18256054fcc3169298f4a58129b2fd895f [file] [log] [blame]
Chris Lattnerfb449b92004-07-23 17:49:16 +00001//===-- LiveInterval.cpp - Live Interval Representation -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerfb449b92004-07-23 17:49:16 +00007//
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 Wilson86af6552010-01-12 22:18:56 +000013// such that v is live at j' and there is no instruction with number i' < i such
Chris Lattnerfb449b92004-07-23 17:49:16 +000014// 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 Wendlingd9fd2ac2006-11-28 02:08:17 +000021#include "llvm/CodeGen/LiveInterval.h"
Lang Hames233a60e2009-11-03 23:52:08 +000022#include "llvm/CodeGen/LiveIntervalAnalysis.h"
Evan Cheng90f95f82009-06-14 20:22:55 +000023#include "llvm/CodeGen/MachineRegisterInfo.h"
Evan Cheng0adb5272009-04-25 09:25:19 +000024#include "llvm/ADT/DenseMap.h"
Evan Cheng3c1f4a42007-10-17 02:13:29 +000025#include "llvm/ADT/SmallSet.h"
Bill Wendling38b0e7b2006-11-28 03:31:29 +000026#include "llvm/ADT/STLExtras.h"
David Greene52421542010-01-04 22:41:43 +000027#include "llvm/Support/Debug.h"
Daniel Dunbara717b7b2009-07-24 10:47:20 +000028#include "llvm/Support/raw_ostream.h"
Dan Gohman6f0d0242008-02-10 18:45:23 +000029#include "llvm/Target/TargetRegisterInfo.h"
Alkis Evlogimenosc4d3b912004-09-28 02:38:58 +000030#include <algorithm>
Chris Lattnerfb449b92004-07-23 17:49:16 +000031using namespace llvm;
32
33// An example for liveAt():
34//
Chris Lattneraa141472004-07-23 18:40:00 +000035// this = [1,4), liveAt(0) will return false. The instruction defining this
36// spans slots [0,3]. The interval belongs to an spilled definition of the
37// variable it represents. This is because slot 1 is used (def slot) and spans
38// up to slot 3 (store slot).
Chris Lattnerfb449b92004-07-23 17:49:16 +000039//
Lang Hames233a60e2009-11-03 23:52:08 +000040bool LiveInterval::liveAt(SlotIndex I) const {
Chris Lattnerebd7e6c2004-07-23 18:13:24 +000041 Ranges::const_iterator r = std::upper_bound(ranges.begin(), ranges.end(), I);
Misha Brukmanedf128a2005-04-21 22:36:52 +000042
Chris Lattnerfb449b92004-07-23 17:49:16 +000043 if (r == ranges.begin())
44 return false;
45
46 --r;
Chris Lattneraa141472004-07-23 18:40:00 +000047 return r->contains(I);
Chris Lattnerfb449b92004-07-23 17:49:16 +000048}
49
Evan Chengc8d044e2008-02-15 18:24:29 +000050// liveBeforeAndAt - Check if the interval is live at the index and the index
51// just before it. If index is liveAt, check if it starts a new live range.
52// If it does, then check if the previous live range ends at index-1.
Lang Hames233a60e2009-11-03 23:52:08 +000053bool LiveInterval::liveBeforeAndAt(SlotIndex I) const {
Evan Chengc8d044e2008-02-15 18:24:29 +000054 Ranges::const_iterator r = std::upper_bound(ranges.begin(), ranges.end(), I);
55
56 if (r == ranges.begin())
57 return false;
58
59 --r;
60 if (!r->contains(I))
61 return false;
62 if (I != r->start)
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
Jakob Stoklund Olesen15a57142010-06-25 22:53:05 +000071/// 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
Chris Lattnerbae74d92004-11-18 03:47:34 +0000102// overlaps - Return true if the intersection of the two live intervals is
103// not empty.
104//
Chris Lattnerfb449b92004-07-23 17:49:16 +0000105// An example for overlaps():
106//
107// 0: A = ...
108// 4: B = ...
109// 8: C = A + B ;; last use of A
110//
111// The live intervals should look like:
112//
113// A = [3, 11)
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.
Chris Lattnerbae74d92004-11-18 03:47:34 +0000119//
120bool LiveInterval::overlapsFrom(const LiveInterval& other,
121 const_iterator StartPos) const {
Jakob Stoklund Olesen6382d2c2010-07-13 19:56:28 +0000122 assert(!empty() && "empty interval");
Chris Lattnerbae74d92004-11-18 03:47:34 +0000123 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()) &&
Chris Lattner8c68b6a2004-11-18 04:02:11 +0000129 StartPos != other.end() && "Bogus start position hint!");
Chris Lattnerf5426492004-07-25 07:11:19 +0000130
Chris Lattnerfb449b92004-07-23 17:49:16 +0000131 if (i->start < j->start) {
Chris Lattneraa141472004-07-23 18:40:00 +0000132 i = std::upper_bound(i, ie, j->start);
Chris Lattnerfb449b92004-07-23 17:49:16 +0000133 if (i != ranges.begin()) --i;
Chris Lattneraa141472004-07-23 18:40:00 +0000134 } else if (j->start < i->start) {
Chris Lattneread1b3f2004-12-04 01:22:09 +0000135 ++StartPos;
136 if (StartPos != other.end() && StartPos->start <= i->start) {
137 assert(StartPos < other.end() && i < end());
Chris Lattner8c68b6a2004-11-18 04:02:11 +0000138 j = std::upper_bound(j, je, i->start);
139 if (j != other.ranges.begin()) --j;
140 }
Chris Lattneraa141472004-07-23 18:40:00 +0000141 } else {
142 return true;
Chris Lattnerfb449b92004-07-23 17:49:16 +0000143 }
144
Chris Lattner9fddc122004-11-18 05:28:21 +0000145 if (j == je) return false;
146
147 while (i != ie) {
Chris Lattnerfb449b92004-07-23 17:49:16 +0000148 if (i->start > j->start) {
Alkis Evlogimenosa1613db2004-07-24 11:44:15 +0000149 std::swap(i, j);
150 std::swap(ie, je);
Chris Lattnerfb449b92004-07-23 17:49:16 +0000151 }
Chris Lattnerfb449b92004-07-23 17:49:16 +0000152
153 if (i->end > j->start)
154 return true;
155 ++i;
156 }
157
158 return false;
159}
160
Evan Chengcccdb2b2009-04-18 08:52:15 +0000161/// overlaps - Return true if the live interval overlaps a range specified
162/// by [Start, End).
Lang Hames233a60e2009-11-03 23:52:08 +0000163bool LiveInterval::overlaps(SlotIndex Start, SlotIndex End) const {
Evan Chengcccdb2b2009-04-18 08:52:15 +0000164 assert(Start < End && "Invalid range");
Jakob Stoklund Olesen186eb732010-07-13 19:42:20 +0000165 const_iterator I = std::lower_bound(begin(), end(), End);
166 return I != begin() && (--I)->end > Start;
Evan Chengcccdb2b2009-04-18 08:52:15 +0000167}
168
Lang Hames6f4e4df2010-07-26 01:49:41 +0000169
170/// ValNo is dead, remove it. If it is the largest value number, just nuke it
171/// (and any other deleted values neighboring it), otherwise mark it as ~1U so
172/// it can be nuked later.
173void LiveInterval::markValNoForDeletion(VNInfo *ValNo) {
174 if (ValNo->id == getNumValNums()-1) {
175 do {
176 valnos.pop_back();
177 } while (!valnos.empty() && valnos.back()->isUnused());
178 } else {
179 ValNo->setIsUnused(true);
180 }
181}
182
Chris Lattnerb26c2152004-07-23 19:38:44 +0000183/// extendIntervalEndTo - This method is used when we want to extend the range
184/// specified by I to end at the specified endpoint. To do this, we should
185/// merge and eliminate all ranges that this will overlap with. The iterator is
186/// not invalidated.
Lang Hames233a60e2009-11-03 23:52:08 +0000187void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) {
Chris Lattnerb26c2152004-07-23 19:38:44 +0000188 assert(I != ranges.end() && "Not a valid interval!");
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000189 VNInfo *ValNo = I->valno;
Chris Lattnerfb449b92004-07-23 17:49:16 +0000190
Chris Lattnerb26c2152004-07-23 19:38:44 +0000191 // Search for the first interval that we can't merge with.
Oscar Fuentesee56c422010-08-02 06:00:15 +0000192 Ranges::iterator MergeTo = llvm::next(I);
Chris Lattnerabf295f2004-07-24 02:52:23 +0000193 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000194 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
Chris Lattnerabf295f2004-07-24 02:52:23 +0000195 }
Chris Lattnerb26c2152004-07-23 19:38:44 +0000196
197 // If NewEnd was in the middle of an interval, make sure to get its endpoint.
198 I->end = std::max(NewEnd, prior(MergeTo)->end);
199
Chris Lattnerb0fa11c2005-10-20 07:39:25 +0000200 // Erase any dead ranges.
Oscar Fuentesee56c422010-08-02 06:00:15 +0000201 ranges.erase(llvm::next(I), MergeTo);
Evan Cheng4f8ff162007-08-11 00:59:19 +0000202
Chris Lattnerb0fa11c2005-10-20 07:39:25 +0000203 // If the newly formed range now touches the range after it and if they have
204 // the same value number, merge the two ranges into one range.
Oscar Fuentesee56c422010-08-02 06:00:15 +0000205 Ranges::iterator Next = llvm::next(I);
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000206 if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) {
Chris Lattnercef60102005-10-20 22:50:10 +0000207 I->end = Next->end;
208 ranges.erase(Next);
Chris Lattnerb0fa11c2005-10-20 07:39:25 +0000209 }
Chris Lattnerb26c2152004-07-23 19:38:44 +0000210}
211
212
213/// extendIntervalStartTo - This method is used when we want to extend the range
214/// specified by I to start at the specified endpoint. To do this, we should
215/// merge and eliminate all ranges that this will overlap with.
Misha Brukmanedf128a2005-04-21 22:36:52 +0000216LiveInterval::Ranges::iterator
Lang Hames233a60e2009-11-03 23:52:08 +0000217LiveInterval::extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStart) {
Chris Lattnerb26c2152004-07-23 19:38:44 +0000218 assert(I != ranges.end() && "Not a valid interval!");
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000219 VNInfo *ValNo = I->valno;
Chris Lattnerb26c2152004-07-23 19:38:44 +0000220
221 // Search for the first interval that we can't merge with.
222 Ranges::iterator MergeTo = I;
223 do {
224 if (MergeTo == ranges.begin()) {
225 I->start = NewStart;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000226 ranges.erase(MergeTo, I);
Chris Lattnerb26c2152004-07-23 19:38:44 +0000227 return I;
228 }
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000229 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
Chris Lattnerb26c2152004-07-23 19:38:44 +0000230 --MergeTo;
231 } while (NewStart <= MergeTo->start);
232
233 // If we start in the middle of another interval, just delete a range and
234 // extend that interval.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000235 if (MergeTo->end >= NewStart && MergeTo->valno == ValNo) {
Chris Lattnerb26c2152004-07-23 19:38:44 +0000236 MergeTo->end = I->end;
237 } else {
238 // Otherwise, extend the interval right after.
239 ++MergeTo;
240 MergeTo->start = NewStart;
241 MergeTo->end = I->end;
242 }
243
Oscar Fuentesee56c422010-08-02 06:00:15 +0000244 ranges.erase(llvm::next(MergeTo), llvm::next(I));
Chris Lattnerb26c2152004-07-23 19:38:44 +0000245 return MergeTo;
246}
247
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000248LiveInterval::iterator
249LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
Lang Hames233a60e2009-11-03 23:52:08 +0000250 SlotIndex Start = LR.start, End = LR.end;
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000251 iterator it = std::upper_bound(From, ranges.end(), Start);
Chris Lattnerb26c2152004-07-23 19:38:44 +0000252
253 // If the inserted interval starts in the middle or right at the end of
254 // another interval, just extend that interval to contain the range of LR.
255 if (it != ranges.begin()) {
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000256 iterator B = prior(it);
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000257 if (LR.valno == B->valno) {
Chris Lattnerabf295f2004-07-24 02:52:23 +0000258 if (B->start <= Start && B->end >= Start) {
259 extendIntervalEndTo(B, End);
260 return B;
261 }
262 } else {
263 // Check to make sure that we are not overlapping two live ranges with
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000264 // different valno's.
Chris Lattnerabf295f2004-07-24 02:52:23 +0000265 assert(B->end <= Start &&
Brian Gaeke8311bef2004-11-16 06:52:35 +0000266 "Cannot overlap two LiveRanges with differing ValID's"
267 " (did you def the same reg twice in a MachineInstr?)");
Chris Lattnerb26c2152004-07-23 19:38:44 +0000268 }
269 }
270
271 // Otherwise, if this range ends in the middle of, or right next to, another
272 // interval, merge it into that interval.
Anton Korobeynikov4c71dfe2008-02-20 11:10:28 +0000273 if (it != ranges.end()) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000274 if (LR.valno == it->valno) {
Chris Lattnerabf295f2004-07-24 02:52:23 +0000275 if (it->start <= End) {
276 it = extendIntervalStartTo(it, Start);
277
278 // If LR is a complete superset of an interval, we may need to grow its
279 // endpoint as well.
280 if (End > it->end)
281 extendIntervalEndTo(it, End);
282 return it;
283 }
284 } else {
285 // Check to make sure that we are not overlapping two live ranges with
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000286 // different valno's.
Chris Lattnerabf295f2004-07-24 02:52:23 +0000287 assert(it->start >= End &&
288 "Cannot overlap two LiveRanges with differing ValID's");
289 }
Anton Korobeynikov4c71dfe2008-02-20 11:10:28 +0000290 }
Chris Lattnerb26c2152004-07-23 19:38:44 +0000291
292 // Otherwise, this is just a new range that doesn't interact with anything.
293 // Insert it.
294 return ranges.insert(it, LR);
Chris Lattnerfb449b92004-07-23 17:49:16 +0000295}
296
Lang Hames86511252009-09-04 20:41:11 +0000297/// isInOneLiveRange - Return true if the range specified is entirely in
Evan Cheng5a3c6a82009-01-29 02:20:59 +0000298/// a single LiveRange of the live interval.
Lang Hames233a60e2009-11-03 23:52:08 +0000299bool LiveInterval::isInOneLiveRange(SlotIndex Start, SlotIndex End) {
Evan Cheng5a3c6a82009-01-29 02:20:59 +0000300 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
301 if (I == ranges.begin())
302 return false;
303 --I;
Lang Hames86511252009-09-04 20:41:11 +0000304 return I->containsRange(Start, End);
Evan Cheng5a3c6a82009-01-29 02:20:59 +0000305}
306
Chris Lattnerabf295f2004-07-24 02:52:23 +0000307
308/// removeRange - Remove the specified range from this interval. Note that
Evan Cheng42cc6e32009-01-29 00:06:09 +0000309/// the range must be in a single LiveRange in its entirety.
Lang Hames233a60e2009-11-03 23:52:08 +0000310void LiveInterval::removeRange(SlotIndex Start, SlotIndex End,
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000311 bool RemoveDeadValNo) {
Chris Lattnerabf295f2004-07-24 02:52:23 +0000312 // Find the LiveRange containing this span.
313 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
314 assert(I != ranges.begin() && "Range is not in interval!");
315 --I;
Lang Hames86511252009-09-04 20:41:11 +0000316 assert(I->containsRange(Start, End) && "Range is not entirely in interval!");
Chris Lattnerabf295f2004-07-24 02:52:23 +0000317
318 // If the span we are removing is at the start of the LiveRange, adjust it.
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000319 VNInfo *ValNo = I->valno;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000320 if (I->start == Start) {
Evan Cheng4f8ff162007-08-11 00:59:19 +0000321 if (I->end == End) {
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000322 if (RemoveDeadValNo) {
323 // Check if val# is dead.
324 bool isDead = true;
325 for (const_iterator II = begin(), EE = end(); II != EE; ++II)
326 if (II != I && II->valno == ValNo) {
327 isDead = false;
328 break;
Jakob Stoklund Olesen15a57142010-06-25 22:53:05 +0000329 }
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000330 if (isDead) {
Lang Hames6f4e4df2010-07-26 01:49:41 +0000331 // Now that ValNo is dead, remove it.
332 markValNoForDeletion(ValNo);
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000333 }
334 }
335
Chris Lattnerabf295f2004-07-24 02:52:23 +0000336 ranges.erase(I); // Removed the whole LiveRange.
Evan Cheng4f8ff162007-08-11 00:59:19 +0000337 } else
Chris Lattnerabf295f2004-07-24 02:52:23 +0000338 I->start = End;
339 return;
340 }
341
342 // Otherwise if the span we are removing is at the end of the LiveRange,
343 // adjust the other way.
344 if (I->end == End) {
Chris Lattner6925a9f2004-07-25 05:43:53 +0000345 I->end = Start;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000346 return;
347 }
348
349 // Otherwise, we are splitting the LiveRange into two pieces.
Lang Hames233a60e2009-11-03 23:52:08 +0000350 SlotIndex OldEnd = I->end;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000351 I->end = Start; // Trim the old interval.
352
353 // Insert the new one.
Oscar Fuentesee56c422010-08-02 06:00:15 +0000354 ranges.insert(llvm::next(I), LiveRange(End, OldEnd, ValNo));
Chris Lattnerabf295f2004-07-24 02:52:23 +0000355}
356
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000357/// removeValNo - Remove all the ranges defined by the specified value#.
358/// Also remove the value# from value# list.
359void LiveInterval::removeValNo(VNInfo *ValNo) {
360 if (empty()) return;
361 Ranges::iterator I = ranges.end();
362 Ranges::iterator E = ranges.begin();
363 do {
364 --I;
365 if (I->valno == ValNo)
366 ranges.erase(I);
367 } while (I != E);
Lang Hames6f4e4df2010-07-26 01:49:41 +0000368 // Now that ValNo is dead, remove it.
369 markValNoForDeletion(ValNo);
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000370}
Lang Hames86511252009-09-04 20:41:11 +0000371
Chris Lattnerabf295f2004-07-24 02:52:23 +0000372/// getLiveRangeContaining - Return the live range that contains the
373/// specified index, or null if there is none.
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000374LiveInterval::const_iterator
Lang Hames233a60e2009-11-03 23:52:08 +0000375LiveInterval::FindLiveRangeContaining(SlotIndex Idx) const {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000376 const_iterator It = std::upper_bound(begin(), end(), Idx);
Chris Lattnerabf295f2004-07-24 02:52:23 +0000377 if (It != ranges.begin()) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000378 --It;
379 if (It->contains(Idx))
380 return It;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000381 }
382
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000383 return end();
Chris Lattnerabf295f2004-07-24 02:52:23 +0000384}
385
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000386LiveInterval::iterator
Lang Hames233a60e2009-11-03 23:52:08 +0000387LiveInterval::FindLiveRangeContaining(SlotIndex Idx) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000388 iterator It = std::upper_bound(begin(), end(), Idx);
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000389 if (It != begin()) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000390 --It;
391 if (It->contains(Idx))
392 return It;
393 }
394
395 return end();
396}
Chris Lattnerabf295f2004-07-24 02:52:23 +0000397
Lang Hames86511252009-09-04 20:41:11 +0000398/// findDefinedVNInfo - Find the VNInfo defined by the specified
399/// index (register interval).
Lang Hames233a60e2009-11-03 23:52:08 +0000400VNInfo *LiveInterval::findDefinedVNInfoForRegInt(SlotIndex Idx) const {
Evan Cheng3f32d652008-06-04 09:18:41 +0000401 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
Lang Hames86511252009-09-04 20:41:11 +0000402 i != e; ++i) {
403 if ((*i)->def == Idx)
404 return *i;
405 }
406
407 return 0;
408}
409
410/// findDefinedVNInfo - Find the VNInfo defined by the specified
411/// register (stack inteval).
412VNInfo *LiveInterval::findDefinedVNInfoForStackInt(unsigned reg) const {
413 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
414 i != e; ++i) {
415 if ((*i)->getReg() == reg)
416 return *i;
417 }
418 return 0;
Evan Cheng3f32d652008-06-04 09:18:41 +0000419}
420
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000421/// join - Join two live intervals (this, and other) together. This applies
422/// mappings to the value numbers in the LHS/RHS intervals as specified. If
423/// the intervals are not joinable, this aborts.
Lang Hames233a60e2009-11-03 23:52:08 +0000424void LiveInterval::join(LiveInterval &Other,
425 const int *LHSValNoAssignments,
David Greeneaf992f72007-09-06 19:46:46 +0000426 const int *RHSValNoAssignments,
Evan Cheng90f95f82009-06-14 20:22:55 +0000427 SmallVector<VNInfo*, 16> &NewVNInfo,
428 MachineRegisterInfo *MRI) {
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000429 // Determine if any of our live range values are mapped. This is uncommon, so
Evan Cheng34301352007-09-01 02:03:17 +0000430 // we want to avoid the interval scan if not.
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000431 bool MustMapCurValNos = false;
Evan Cheng34301352007-09-01 02:03:17 +0000432 unsigned NumVals = getNumValNums();
433 unsigned NumNewVals = NewVNInfo.size();
434 for (unsigned i = 0; i != NumVals; ++i) {
435 unsigned LHSValID = LHSValNoAssignments[i];
436 if (i != LHSValID ||
Evan Chengf3bb2e62007-09-05 21:46:51 +0000437 (NewVNInfo[LHSValID] && NewVNInfo[LHSValID] != getValNumInfo(i)))
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000438 MustMapCurValNos = true;
Chris Lattnerdeb99712004-07-24 03:41:50 +0000439 }
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000440
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000441 // If we have to apply a mapping to our base interval assignment, rewrite it
442 // now.
443 if (MustMapCurValNos) {
444 // Map the first live range.
445 iterator OutIt = begin();
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000446 OutIt->valno = NewVNInfo[LHSValNoAssignments[OutIt->valno->id]];
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000447 ++OutIt;
448 for (iterator I = OutIt, E = end(); I != E; ++I) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000449 OutIt->valno = NewVNInfo[LHSValNoAssignments[I->valno->id]];
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000450
451 // If this live range has the same value # as its immediate predecessor,
452 // and if they are neighbors, remove one LiveRange. This happens when we
453 // have [0,3:0)[4,7:1) and map 0/1 onto the same value #.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000454 if (OutIt->valno == (OutIt-1)->valno && (OutIt-1)->end == OutIt->start) {
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000455 (OutIt-1)->end = OutIt->end;
456 } else {
457 if (I != OutIt) {
458 OutIt->start = I->start;
459 OutIt->end = I->end;
460 }
461
462 // Didn't merge, on to the next one.
463 ++OutIt;
464 }
465 }
466
467 // If we merge some live ranges, chop off the end.
468 ranges.erase(OutIt, end());
469 }
Evan Cheng4f8ff162007-08-11 00:59:19 +0000470
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000471 // Remember assignements because val# ids are changing.
Evan Cheng34301352007-09-01 02:03:17 +0000472 SmallVector<unsigned, 16> OtherAssignments;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000473 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
474 OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]);
475
476 // Update val# info. Renumber them and make sure they all belong to this
Evan Chengf3bb2e62007-09-05 21:46:51 +0000477 // LiveInterval now. Also remove dead val#'s.
478 unsigned NumValNos = 0;
479 for (unsigned i = 0; i < NumNewVals; ++i) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000480 VNInfo *VNI = NewVNInfo[i];
Evan Chengf3bb2e62007-09-05 21:46:51 +0000481 if (VNI) {
Evan Cheng30590f52009-04-28 06:24:09 +0000482 if (NumValNos >= NumVals)
Evan Chengf3bb2e62007-09-05 21:46:51 +0000483 valnos.push_back(VNI);
484 else
485 valnos[NumValNos] = VNI;
486 VNI->id = NumValNos++; // Renumber val#.
Evan Cheng34301352007-09-01 02:03:17 +0000487 }
488 }
Evan Cheng34301352007-09-01 02:03:17 +0000489 if (NumNewVals < NumVals)
490 valnos.resize(NumNewVals); // shrinkify
Evan Cheng4f8ff162007-08-11 00:59:19 +0000491
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000492 // Okay, now insert the RHS live ranges into the LHS.
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000493 iterator InsertPos = begin();
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000494 unsigned RangeNo = 0;
495 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I, ++RangeNo) {
496 // Map the valno in the other live range to the current live range.
497 I->valno = NewVNInfo[OtherAssignments[RangeNo]];
Evan Chengf3bb2e62007-09-05 21:46:51 +0000498 assert(I->valno && "Adding a dead range?");
Chris Lattnerabf295f2004-07-24 02:52:23 +0000499 InsertPos = addRangeFrom(*I, InsertPos);
500 }
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000501
David Greene29ff37f2009-07-22 20:08:25 +0000502 ComputeJoinedWeight(Other);
Evan Cheng90f95f82009-06-14 20:22:55 +0000503
504 // Update regalloc hint if currently there isn't one.
505 if (TargetRegisterInfo::isVirtualRegister(reg) &&
506 TargetRegisterInfo::isVirtualRegister(Other.reg)) {
Evan Cheng358dec52009-06-15 08:28:29 +0000507 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(reg);
508 if (Hint.first == 0 && Hint.second == 0) {
509 std::pair<unsigned, unsigned> OtherHint =
Evan Cheng90f95f82009-06-14 20:22:55 +0000510 MRI->getRegAllocationHint(Other.reg);
Evan Cheng358dec52009-06-15 08:28:29 +0000511 if (OtherHint.first || OtherHint.second)
Evan Cheng90f95f82009-06-14 20:22:55 +0000512 MRI->setRegAllocationHint(reg, OtherHint.first, OtherHint.second);
513 }
514 }
Chris Lattnerfb449b92004-07-23 17:49:16 +0000515}
516
Chris Lattnerf21f0202006-09-02 05:26:59 +0000517/// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
518/// interval as the specified value number. The LiveRanges in RHS are
519/// allowed to overlap with LiveRanges in the current interval, but only if
520/// the overlapping LiveRanges have the specified value number.
521void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS,
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000522 VNInfo *LHSValNo) {
Chris Lattnerf21f0202006-09-02 05:26:59 +0000523 // TODO: Make this more efficient.
524 iterator InsertPos = begin();
525 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000526 // Map the valno in the other live range to the current live range.
Chris Lattnerf21f0202006-09-02 05:26:59 +0000527 LiveRange Tmp = *I;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000528 Tmp.valno = LHSValNo;
Chris Lattnerf21f0202006-09-02 05:26:59 +0000529 InsertPos = addRangeFrom(Tmp, InsertPos);
530 }
531}
532
533
Evan Cheng32dfbea2007-10-12 08:50:34 +0000534/// MergeValueInAsValue - Merge all of the live ranges of a specific val#
535/// in RHS into this live interval as the specified value number.
536/// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000537/// current interval, it will replace the value numbers of the overlaped
538/// live ranges with the specified value number.
Lang Hames233a60e2009-11-03 23:52:08 +0000539void LiveInterval::MergeValueInAsValue(
540 const LiveInterval &RHS,
541 const VNInfo *RHSValNo, VNInfo *LHSValNo) {
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000542 SmallVector<VNInfo*, 4> ReplacedValNos;
543 iterator IP = begin();
Evan Cheng32dfbea2007-10-12 08:50:34 +0000544 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
Jakob Stoklund Olesen014b8632010-06-23 15:34:36 +0000545 assert(I->valno == RHS.getValNumInfo(I->valno->id) && "Bad VNInfo");
Evan Cheng32dfbea2007-10-12 08:50:34 +0000546 if (I->valno != RHSValNo)
547 continue;
Lang Hames233a60e2009-11-03 23:52:08 +0000548 SlotIndex Start = I->start, End = I->end;
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000549 IP = std::upper_bound(IP, end(), Start);
550 // If the start of this range overlaps with an existing liverange, trim it.
551 if (IP != begin() && IP[-1].end > Start) {
Evan Cheng294e6522008-01-30 22:44:55 +0000552 if (IP[-1].valno != LHSValNo) {
553 ReplacedValNos.push_back(IP[-1].valno);
554 IP[-1].valno = LHSValNo; // Update val#.
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000555 }
556 Start = IP[-1].end;
557 // Trimmed away the whole range?
558 if (Start >= End) continue;
559 }
560 // If the end of this range overlaps with an existing liverange, trim it.
561 if (IP != end() && End > IP->start) {
562 if (IP->valno != LHSValNo) {
563 ReplacedValNos.push_back(IP->valno);
564 IP->valno = LHSValNo; // Update val#.
565 }
566 End = IP->start;
567 // If this trimmed away the whole range, ignore it.
568 if (Start == End) continue;
569 }
570
Evan Cheng32dfbea2007-10-12 08:50:34 +0000571 // Map the valno in the other live range to the current live range.
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000572 IP = addRangeFrom(LiveRange(Start, End, LHSValNo), IP);
573 }
574
575
576 SmallSet<VNInfo*, 4> Seen;
577 for (unsigned i = 0, e = ReplacedValNos.size(); i != e; ++i) {
578 VNInfo *V1 = ReplacedValNos[i];
579 if (Seen.insert(V1)) {
580 bool isDead = true;
581 for (const_iterator I = begin(), E = end(); I != E; ++I)
582 if (I->valno == V1) {
583 isDead = false;
584 break;
585 }
586 if (isDead) {
Lang Hames6f4e4df2010-07-26 01:49:41 +0000587 // Now that V1 is dead, remove it.
588 markValNoForDeletion(V1);
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000589 }
590 }
Evan Cheng32dfbea2007-10-12 08:50:34 +0000591 }
592}
593
594
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000595/// MergeInClobberRanges - For any live ranges that are not defined in the
596/// current interval, but are defined in the Clobbers interval, mark them
597/// used with an unknown definition value.
Lang Hames233a60e2009-11-03 23:52:08 +0000598void LiveInterval::MergeInClobberRanges(LiveIntervals &li_,
599 const LiveInterval &Clobbers,
Benjamin Kramer991de142010-03-30 20:16:45 +0000600 VNInfo::Allocator &VNInfoAllocator) {
Dan Gohmana8c763b2008-08-14 18:13:49 +0000601 if (Clobbers.empty()) return;
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000602
Evan Cheng0adb5272009-04-25 09:25:19 +0000603 DenseMap<VNInfo*, VNInfo*> ValNoMaps;
Evan Chenga4b2bab2009-04-25 20:20:15 +0000604 VNInfo *UnusedValNo = 0;
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000605 iterator IP = begin();
606 for (const_iterator I = Clobbers.begin(), E = Clobbers.end(); I != E; ++I) {
Evan Cheng0adb5272009-04-25 09:25:19 +0000607 // For every val# in the Clobbers interval, create a new "unknown" val#.
608 VNInfo *ClobberValNo = 0;
609 DenseMap<VNInfo*, VNInfo*>::iterator VI = ValNoMaps.find(I->valno);
610 if (VI != ValNoMaps.end())
611 ClobberValNo = VI->second;
Evan Chenga4b2bab2009-04-25 20:20:15 +0000612 else if (UnusedValNo)
613 ClobberValNo = UnusedValNo;
Evan Cheng0adb5272009-04-25 09:25:19 +0000614 else {
Lang Hames86511252009-09-04 20:41:11 +0000615 UnusedValNo = ClobberValNo =
Lang Hames233a60e2009-11-03 23:52:08 +0000616 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
Evan Cheng0adb5272009-04-25 09:25:19 +0000617 ValNoMaps.insert(std::make_pair(I->valno, ClobberValNo));
618 }
619
Dan Gohman97121ba2009-04-08 00:15:30 +0000620 bool Done = false;
Lang Hames233a60e2009-11-03 23:52:08 +0000621 SlotIndex Start = I->start, End = I->end;
Dan Gohman97121ba2009-04-08 00:15:30 +0000622 // If a clobber range starts before an existing range and ends after
623 // it, the clobber range will need to be split into multiple ranges.
624 // Loop until the entire clobber range is handled.
625 while (!Done) {
626 Done = true;
627 IP = std::upper_bound(IP, end(), Start);
Lang Hames233a60e2009-11-03 23:52:08 +0000628 SlotIndex SubRangeStart = Start;
629 SlotIndex SubRangeEnd = End;
Dan Gohman97121ba2009-04-08 00:15:30 +0000630
631 // If the start of this range overlaps with an existing liverange, trim it.
632 if (IP != begin() && IP[-1].end > SubRangeStart) {
633 SubRangeStart = IP[-1].end;
634 // Trimmed away the whole range?
635 if (SubRangeStart >= SubRangeEnd) continue;
636 }
637 // If the end of this range overlaps with an existing liverange, trim it.
638 if (IP != end() && SubRangeEnd > IP->start) {
639 // If the clobber live range extends beyond the existing live range,
640 // it'll need at least another live range, so set the flag to keep
641 // iterating.
642 if (SubRangeEnd > IP->end) {
643 Start = IP->end;
644 Done = false;
645 }
646 SubRangeEnd = IP->start;
647 // If this trimmed away the whole range, ignore it.
648 if (SubRangeStart == SubRangeEnd) continue;
649 }
650
651 // Insert the clobber interval.
652 IP = addRangeFrom(LiveRange(SubRangeStart, SubRangeEnd, ClobberValNo),
653 IP);
Evan Chenga4b2bab2009-04-25 20:20:15 +0000654 UnusedValNo = 0;
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000655 }
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000656 }
Evan Cheng27e46662009-04-27 17:35:19 +0000657
658 if (UnusedValNo) {
659 // Delete the last unused val#.
660 valnos.pop_back();
Evan Cheng27e46662009-04-27 17:35:19 +0000661 }
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000662}
663
Lang Hames233a60e2009-11-03 23:52:08 +0000664void LiveInterval::MergeInClobberRange(LiveIntervals &li_,
665 SlotIndex Start,
666 SlotIndex End,
Benjamin Kramer991de142010-03-30 20:16:45 +0000667 VNInfo::Allocator &VNInfoAllocator) {
Evan Chenga2e64352009-03-11 00:03:21 +0000668 // Find a value # to use for the clobber ranges. If there is already a value#
669 // for unknown values, use it.
Lang Hames86511252009-09-04 20:41:11 +0000670 VNInfo *ClobberValNo =
Lang Hames233a60e2009-11-03 23:52:08 +0000671 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
Evan Chenga2e64352009-03-11 00:03:21 +0000672
673 iterator IP = begin();
674 IP = std::upper_bound(IP, end(), Start);
675
676 // If the start of this range overlaps with an existing liverange, trim it.
677 if (IP != begin() && IP[-1].end > Start) {
678 Start = IP[-1].end;
679 // Trimmed away the whole range?
680 if (Start >= End) return;
681 }
682 // If the end of this range overlaps with an existing liverange, trim it.
683 if (IP != end() && End > IP->start) {
684 End = IP->start;
685 // If this trimmed away the whole range, ignore it.
686 if (Start == End) return;
687 }
688
689 // Insert the clobber interval.
690 addRangeFrom(LiveRange(Start, End, ClobberValNo), IP);
691}
692
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000693/// MergeValueNumberInto - This method is called when two value nubmers
694/// are found to be equivalent. This eliminates V1, replacing all
695/// LiveRanges with the V1 value number with the V2 value number. This can
696/// cause merging of V1/V2 values numbers and compaction of the value space.
Owen Anderson5b93f6f2009-02-02 22:42:01 +0000697VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000698 assert(V1 != V2 && "Identical value#'s are always equivalent!");
699
700 // This code actually merges the (numerically) larger value number into the
701 // smaller value number, which is likely to allow us to compactify the value
702 // space. The only thing we have to be careful of is to preserve the
703 // instruction that defines the result value.
704
705 // Make sure V2 is smaller than V1.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000706 if (V1->id < V2->id) {
Lang Hames52c1afc2009-08-10 23:43:28 +0000707 V1->copyFrom(*V2);
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000708 std::swap(V1, V2);
709 }
710
711 // Merge V1 live ranges into V2.
712 for (iterator I = begin(); I != end(); ) {
713 iterator LR = I++;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000714 if (LR->valno != V1) continue; // Not a V1 LiveRange.
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000715
716 // Okay, we found a V1 live range. If it had a previous, touching, V2 live
717 // range, extend it.
718 if (LR != begin()) {
719 iterator Prev = LR-1;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000720 if (Prev->valno == V2 && Prev->end == LR->start) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000721 Prev->end = LR->end;
722
723 // Erase this live-range.
724 ranges.erase(LR);
725 I = Prev+1;
726 LR = Prev;
727 }
728 }
729
730 // Okay, now we have a V1 or V2 live range that is maximally merged forward.
731 // Ensure that it is a V2 live-range.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000732 LR->valno = V2;
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000733
734 // If we can merge it into later V2 live ranges, do so now. We ignore any
735 // following V1 live ranges, as they will be merged in subsequent iterations
736 // of the loop.
737 if (I != end()) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000738 if (I->start == LR->end && I->valno == V2) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000739 LR->end = I->end;
740 ranges.erase(I);
741 I = LR+1;
742 }
743 }
744 }
Chris Lattnerc82b3aa2006-08-24 23:22:59 +0000745
Lang Hames6f4e4df2010-07-26 01:49:41 +0000746 // Now that V1 is dead, remove it.
747 markValNoForDeletion(V1);
Owen Anderson5b93f6f2009-02-02 22:42:01 +0000748
749 return V2;
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000750}
751
Evan Cheng32dfbea2007-10-12 08:50:34 +0000752void LiveInterval::Copy(const LiveInterval &RHS,
Evan Cheng90f95f82009-06-14 20:22:55 +0000753 MachineRegisterInfo *MRI,
Benjamin Kramer991de142010-03-30 20:16:45 +0000754 VNInfo::Allocator &VNInfoAllocator) {
Evan Cheng32dfbea2007-10-12 08:50:34 +0000755 ranges.clear();
756 valnos.clear();
Evan Cheng358dec52009-06-15 08:28:29 +0000757 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(RHS.reg);
Evan Cheng90f95f82009-06-14 20:22:55 +0000758 MRI->setRegAllocationHint(reg, Hint.first, Hint.second);
759
Evan Cheng32dfbea2007-10-12 08:50:34 +0000760 weight = RHS.weight;
761 for (unsigned i = 0, e = RHS.getNumValNums(); i != e; ++i) {
762 const VNInfo *VNI = RHS.getValNumInfo(i);
Lang Hames857c4e02009-06-17 21:01:20 +0000763 createValueCopy(VNI, VNInfoAllocator);
Evan Cheng32dfbea2007-10-12 08:50:34 +0000764 }
765 for (unsigned i = 0, e = RHS.ranges.size(); i != e; ++i) {
766 const LiveRange &LR = RHS.ranges[i];
767 addRange(LiveRange(LR.start, LR.end, getValNumInfo(LR.valno->id)));
768 }
769}
770
Evan Chenge52eef82007-04-17 20:25:11 +0000771unsigned LiveInterval::getSize() const {
772 unsigned Sum = 0;
773 for (const_iterator I = begin(), E = end(); I != E; ++I)
Lang Hames86511252009-09-04 20:41:11 +0000774 Sum += I->start.distance(I->end);
Evan Chenge52eef82007-04-17 20:25:11 +0000775 return Sum;
776}
777
David Greene29ff37f2009-07-22 20:08:25 +0000778/// ComputeJoinedWeight - Set the weight of a live interval Joined
779/// after Other has been merged into it.
780void LiveInterval::ComputeJoinedWeight(const LiveInterval &Other) {
781 // If either of these intervals was spilled, the weight is the
782 // weight of the non-spilled interval. This can only happen with
783 // iterative coalescers.
784
David Greene92b78bb2009-07-22 22:32:19 +0000785 if (Other.weight != HUGE_VALF) {
786 weight += Other.weight;
787 }
788 else if (weight == HUGE_VALF &&
David Greene29ff37f2009-07-22 20:08:25 +0000789 !TargetRegisterInfo::isPhysicalRegister(reg)) {
790 // Remove this assert if you have an iterative coalescer
791 assert(0 && "Joining to spilled interval");
792 weight = Other.weight;
793 }
David Greene29ff37f2009-07-22 20:08:25 +0000794 else {
795 // Otherwise the weight stays the same
796 // Remove this assert if you have an iterative coalescer
797 assert(0 && "Joining from spilled interval");
798 }
799}
800
Daniel Dunbar1cd1d982009-07-24 10:36:58 +0000801raw_ostream& llvm::operator<<(raw_ostream& os, const LiveRange &LR) {
802 return os << '[' << LR.start << ',' << LR.end << ':' << LR.valno->id << ")";
803}
Chris Lattnerfb449b92004-07-23 17:49:16 +0000804
Chris Lattnerabf295f2004-07-24 02:52:23 +0000805void LiveRange::dump() const {
David Greene52421542010-01-04 22:41:43 +0000806 dbgs() << *this << "\n";
Chris Lattnerabf295f2004-07-24 02:52:23 +0000807}
808
Chris Lattnerc02497f2009-08-23 03:47:42 +0000809void LiveInterval::print(raw_ostream &OS, const TargetRegisterInfo *TRI) const {
Evan Cheng99ec7792008-06-23 21:03:19 +0000810 if (isStackSlot())
811 OS << "SS#" << getStackSlotIndex();
Evan Cheng3f32d652008-06-04 09:18:41 +0000812 else if (TRI && TargetRegisterInfo::isPhysicalRegister(reg))
Bill Wendlinge6d088a2008-02-26 21:47:57 +0000813 OS << TRI->getName(reg);
Chris Lattner38135af2005-05-14 05:34:15 +0000814 else
815 OS << "%reg" << reg;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000816
Chris Lattner38135af2005-05-14 05:34:15 +0000817 OS << ',' << weight;
Chris Lattnerfb449b92004-07-23 17:49:16 +0000818
Chris Lattner38135af2005-05-14 05:34:15 +0000819 if (empty())
Evan Cheng3f32d652008-06-04 09:18:41 +0000820 OS << " EMPTY";
Chris Lattner38135af2005-05-14 05:34:15 +0000821 else {
822 OS << " = ";
823 for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
Jakob Stoklund Olesen014b8632010-06-23 15:34:36 +0000824 E = ranges.end(); I != E; ++I) {
825 OS << *I;
826 assert(I->valno == getValNumInfo(I->valno->id) && "Bad VNInfo");
827 }
Chris Lattner38135af2005-05-14 05:34:15 +0000828 }
Jakob Stoklund Olesen15a57142010-06-25 22:53:05 +0000829
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000830 // Print value number info.
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000831 if (getNumValNums()) {
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000832 OS << " ";
Evan Cheng1a66f0a2007-08-28 08:28:51 +0000833 unsigned vnum = 0;
834 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
835 ++i, ++vnum) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000836 const VNInfo *vni = *i;
Evan Cheng1a66f0a2007-08-28 08:28:51 +0000837 if (vnum) OS << " ";
838 OS << vnum << "@";
Lang Hames857c4e02009-06-17 21:01:20 +0000839 if (vni->isUnused()) {
Evan Cheng8df78602007-08-08 03:00:28 +0000840 OS << "x";
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000841 } else {
Lang Hames61945692009-12-09 05:39:12 +0000842 if (!vni->isDefAccurate() && !vni->isPHIDef())
Evan Cheng4f8ff162007-08-11 00:59:19 +0000843 OS << "?";
844 else
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000845 OS << vni->def;
Jakob Stoklund Olesend9f6ec92010-07-13 21:19:05 +0000846 if (vni->hasPHIKill())
847 OS << "-phikill";
848 if (vni->hasRedefByEC())
849 OS << "-ec";
Evan Chenga8d94f12007-08-07 23:49:57 +0000850 }
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000851 }
852 }
Chris Lattnerfb449b92004-07-23 17:49:16 +0000853}
Chris Lattnerabf295f2004-07-24 02:52:23 +0000854
855void LiveInterval::dump() const {
David Greene52421542010-01-04 22:41:43 +0000856 dbgs() << *this << "\n";
Chris Lattnerabf295f2004-07-24 02:52:23 +0000857}
Jeff Cohenc21c5ee2006-12-15 22:57:14 +0000858
859
Daniel Dunbar1cd1d982009-07-24 10:36:58 +0000860void LiveRange::print(raw_ostream &os) const {
861 os << *this;
862}