blob: 97926dd6fd58aded412c37d1f1077837128d5a69 [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
13// such that v is live at j' abd there is no instruction with number i' < i such
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 Wendlingd9fd2ac2006-11-28 02:08:17 +000021#include "llvm/CodeGen/LiveInterval.h"
Evan Cheng90f95f82009-06-14 20:22:55 +000022#include "llvm/CodeGen/MachineRegisterInfo.h"
Evan Cheng0adb5272009-04-25 09:25:19 +000023#include "llvm/ADT/DenseMap.h"
Evan Cheng3c1f4a42007-10-17 02:13:29 +000024#include "llvm/ADT/SmallSet.h"
Bill Wendling38b0e7b2006-11-28 03:31:29 +000025#include "llvm/ADT/STLExtras.h"
Bill Wendlingd9fd2ac2006-11-28 02:08:17 +000026#include "llvm/Support/Streams.h"
Dan Gohman6f0d0242008-02-10 18:45:23 +000027#include "llvm/Target/TargetRegisterInfo.h"
Alkis Evlogimenosc4d3b912004-09-28 02:38:58 +000028#include <algorithm>
Jeff Cohenc21c5ee2006-12-15 22:57:14 +000029#include <ostream>
Chris Lattnerfb449b92004-07-23 17:49:16 +000030using namespace llvm;
31
32// An example for liveAt():
33//
Chris Lattneraa141472004-07-23 18:40:00 +000034// this = [1,4), liveAt(0) will return false. The instruction defining this
35// spans slots [0,3]. The interval belongs to an spilled definition of the
36// variable it represents. This is because slot 1 is used (def slot) and spans
37// up to slot 3 (store slot).
Chris Lattnerfb449b92004-07-23 17:49:16 +000038//
Chris Lattnerebd7e6c2004-07-23 18:13:24 +000039bool LiveInterval::liveAt(unsigned I) const {
40 Ranges::const_iterator r = std::upper_bound(ranges.begin(), ranges.end(), I);
Misha Brukmanedf128a2005-04-21 22:36:52 +000041
Chris Lattnerfb449b92004-07-23 17:49:16 +000042 if (r == ranges.begin())
43 return false;
44
45 --r;
Chris Lattneraa141472004-07-23 18:40:00 +000046 return r->contains(I);
Chris Lattnerfb449b92004-07-23 17:49:16 +000047}
48
Evan Chengc8d044e2008-02-15 18:24:29 +000049// liveBeforeAndAt - Check if the interval is live at the index and the index
50// just before it. If index is liveAt, check if it starts a new live range.
51// If it does, then check if the previous live range ends at index-1.
52bool LiveInterval::liveBeforeAndAt(unsigned I) const {
53 Ranges::const_iterator r = std::upper_bound(ranges.begin(), ranges.end(), I);
54
55 if (r == ranges.begin())
56 return false;
57
58 --r;
59 if (!r->contains(I))
60 return false;
61 if (I != r->start)
62 return true;
63 // I is the start of a live range. Check if the previous live range ends
64 // at I-1.
65 if (r == ranges.begin())
66 return false;
67 return r->end == I;
68}
69
Chris Lattnerbae74d92004-11-18 03:47:34 +000070// overlaps - Return true if the intersection of the two live intervals is
71// not empty.
72//
Chris Lattnerfb449b92004-07-23 17:49:16 +000073// An example for overlaps():
74//
75// 0: A = ...
76// 4: B = ...
77// 8: C = A + B ;; last use of A
78//
79// The live intervals should look like:
80//
81// A = [3, 11)
82// B = [7, x)
83// C = [11, y)
84//
85// A->overlaps(C) should return false since we want to be able to join
86// A and C.
Chris Lattnerbae74d92004-11-18 03:47:34 +000087//
88bool LiveInterval::overlapsFrom(const LiveInterval& other,
89 const_iterator StartPos) const {
90 const_iterator i = begin();
91 const_iterator ie = end();
92 const_iterator j = StartPos;
93 const_iterator je = other.end();
94
95 assert((StartPos->start <= i->start || StartPos == other.begin()) &&
Chris Lattner8c68b6a2004-11-18 04:02:11 +000096 StartPos != other.end() && "Bogus start position hint!");
Chris Lattnerf5426492004-07-25 07:11:19 +000097
Chris Lattnerfb449b92004-07-23 17:49:16 +000098 if (i->start < j->start) {
Chris Lattneraa141472004-07-23 18:40:00 +000099 i = std::upper_bound(i, ie, j->start);
Chris Lattnerfb449b92004-07-23 17:49:16 +0000100 if (i != ranges.begin()) --i;
Chris Lattneraa141472004-07-23 18:40:00 +0000101 } else if (j->start < i->start) {
Chris Lattneread1b3f2004-12-04 01:22:09 +0000102 ++StartPos;
103 if (StartPos != other.end() && StartPos->start <= i->start) {
104 assert(StartPos < other.end() && i < end());
Chris Lattner8c68b6a2004-11-18 04:02:11 +0000105 j = std::upper_bound(j, je, i->start);
106 if (j != other.ranges.begin()) --j;
107 }
Chris Lattneraa141472004-07-23 18:40:00 +0000108 } else {
109 return true;
Chris Lattnerfb449b92004-07-23 17:49:16 +0000110 }
111
Chris Lattner9fddc122004-11-18 05:28:21 +0000112 if (j == je) return false;
113
114 while (i != ie) {
Chris Lattnerfb449b92004-07-23 17:49:16 +0000115 if (i->start > j->start) {
Alkis Evlogimenosa1613db2004-07-24 11:44:15 +0000116 std::swap(i, j);
117 std::swap(ie, je);
Chris Lattnerfb449b92004-07-23 17:49:16 +0000118 }
Chris Lattnerfb449b92004-07-23 17:49:16 +0000119
120 if (i->end > j->start)
121 return true;
122 ++i;
123 }
124
125 return false;
126}
127
Evan Chengcccdb2b2009-04-18 08:52:15 +0000128/// overlaps - Return true if the live interval overlaps a range specified
129/// by [Start, End).
130bool LiveInterval::overlaps(unsigned Start, unsigned End) const {
131 assert(Start < End && "Invalid range");
132 const_iterator I = begin();
133 const_iterator E = end();
134 const_iterator si = std::upper_bound(I, E, Start);
135 const_iterator ei = std::upper_bound(I, E, End);
136 if (si != ei)
137 return true;
138 if (si == I)
139 return false;
140 --si;
141 return si->contains(Start);
142}
143
Chris Lattnerb26c2152004-07-23 19:38:44 +0000144/// extendIntervalEndTo - This method is used when we want to extend the range
145/// specified by I to end at the specified endpoint. To do this, we should
146/// merge and eliminate all ranges that this will overlap with. The iterator is
147/// not invalidated.
148void LiveInterval::extendIntervalEndTo(Ranges::iterator I, unsigned NewEnd) {
149 assert(I != ranges.end() && "Not a valid interval!");
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000150 VNInfo *ValNo = I->valno;
Evan Cheng430a7b02007-08-14 01:56:58 +0000151 unsigned OldEnd = I->end;
Chris Lattnerfb449b92004-07-23 17:49:16 +0000152
Chris Lattnerb26c2152004-07-23 19:38:44 +0000153 // Search for the first interval that we can't merge with.
154 Ranges::iterator MergeTo = next(I);
Chris Lattnerabf295f2004-07-24 02:52:23 +0000155 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000156 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
Chris Lattnerabf295f2004-07-24 02:52:23 +0000157 }
Chris Lattnerb26c2152004-07-23 19:38:44 +0000158
159 // If NewEnd was in the middle of an interval, make sure to get its endpoint.
160 I->end = std::max(NewEnd, prior(MergeTo)->end);
161
Chris Lattnerb0fa11c2005-10-20 07:39:25 +0000162 // Erase any dead ranges.
Chris Lattnerb26c2152004-07-23 19:38:44 +0000163 ranges.erase(next(I), MergeTo);
Evan Cheng4f8ff162007-08-11 00:59:19 +0000164
165 // Update kill info.
Evan Chengf3bb2e62007-09-05 21:46:51 +0000166 removeKills(ValNo, OldEnd, I->end-1);
Evan Cheng4f8ff162007-08-11 00:59:19 +0000167
Chris Lattnerb0fa11c2005-10-20 07:39:25 +0000168 // If the newly formed range now touches the range after it and if they have
169 // the same value number, merge the two ranges into one range.
Chris Lattnercef60102005-10-20 22:50:10 +0000170 Ranges::iterator Next = next(I);
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000171 if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) {
Chris Lattnercef60102005-10-20 22:50:10 +0000172 I->end = Next->end;
173 ranges.erase(Next);
Chris Lattnerb0fa11c2005-10-20 07:39:25 +0000174 }
Chris Lattnerb26c2152004-07-23 19:38:44 +0000175}
176
177
178/// extendIntervalStartTo - This method is used when we want to extend the range
179/// specified by I to start at the specified endpoint. To do this, we should
180/// merge and eliminate all ranges that this will overlap with.
Misha Brukmanedf128a2005-04-21 22:36:52 +0000181LiveInterval::Ranges::iterator
Chris Lattnerb26c2152004-07-23 19:38:44 +0000182LiveInterval::extendIntervalStartTo(Ranges::iterator I, unsigned NewStart) {
183 assert(I != ranges.end() && "Not a valid interval!");
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000184 VNInfo *ValNo = I->valno;
Chris Lattnerb26c2152004-07-23 19:38:44 +0000185
186 // Search for the first interval that we can't merge with.
187 Ranges::iterator MergeTo = I;
188 do {
189 if (MergeTo == ranges.begin()) {
190 I->start = NewStart;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000191 ranges.erase(MergeTo, I);
Chris Lattnerb26c2152004-07-23 19:38:44 +0000192 return I;
193 }
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000194 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
Chris Lattnerb26c2152004-07-23 19:38:44 +0000195 --MergeTo;
196 } while (NewStart <= MergeTo->start);
197
198 // If we start in the middle of another interval, just delete a range and
199 // extend that interval.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000200 if (MergeTo->end >= NewStart && MergeTo->valno == ValNo) {
Chris Lattnerb26c2152004-07-23 19:38:44 +0000201 MergeTo->end = I->end;
202 } else {
203 // Otherwise, extend the interval right after.
204 ++MergeTo;
205 MergeTo->start = NewStart;
206 MergeTo->end = I->end;
207 }
208
209 ranges.erase(next(MergeTo), next(I));
210 return MergeTo;
211}
212
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000213LiveInterval::iterator
214LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
Chris Lattnerb26c2152004-07-23 19:38:44 +0000215 unsigned Start = LR.start, End = LR.end;
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000216 iterator it = std::upper_bound(From, ranges.end(), Start);
Chris Lattnerb26c2152004-07-23 19:38:44 +0000217
218 // If the inserted interval starts in the middle or right at the end of
219 // another interval, just extend that interval to contain the range of LR.
220 if (it != ranges.begin()) {
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000221 iterator B = prior(it);
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000222 if (LR.valno == B->valno) {
Chris Lattnerabf295f2004-07-24 02:52:23 +0000223 if (B->start <= Start && B->end >= Start) {
224 extendIntervalEndTo(B, End);
225 return B;
226 }
227 } else {
228 // Check to make sure that we are not overlapping two live ranges with
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000229 // different valno's.
Chris Lattnerabf295f2004-07-24 02:52:23 +0000230 assert(B->end <= Start &&
Brian Gaeke8311bef2004-11-16 06:52:35 +0000231 "Cannot overlap two LiveRanges with differing ValID's"
232 " (did you def the same reg twice in a MachineInstr?)");
Chris Lattnerb26c2152004-07-23 19:38:44 +0000233 }
234 }
235
236 // Otherwise, if this range ends in the middle of, or right next to, another
237 // interval, merge it into that interval.
Anton Korobeynikov4c71dfe2008-02-20 11:10:28 +0000238 if (it != ranges.end()) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000239 if (LR.valno == it->valno) {
Chris Lattnerabf295f2004-07-24 02:52:23 +0000240 if (it->start <= End) {
241 it = extendIntervalStartTo(it, Start);
242
243 // If LR is a complete superset of an interval, we may need to grow its
244 // endpoint as well.
245 if (End > it->end)
246 extendIntervalEndTo(it, End);
Evan Chengc3fc7d92007-11-29 09:49:23 +0000247 else if (End < it->end)
Evan Chengc3868e02007-11-29 01:05:47 +0000248 // Overlapping intervals, there might have been a kill here.
249 removeKill(it->valno, End);
Chris Lattnerabf295f2004-07-24 02:52:23 +0000250 return it;
251 }
252 } else {
253 // Check to make sure that we are not overlapping two live ranges with
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000254 // different valno's.
Chris Lattnerabf295f2004-07-24 02:52:23 +0000255 assert(it->start >= End &&
256 "Cannot overlap two LiveRanges with differing ValID's");
257 }
Anton Korobeynikov4c71dfe2008-02-20 11:10:28 +0000258 }
Chris Lattnerb26c2152004-07-23 19:38:44 +0000259
260 // Otherwise, this is just a new range that doesn't interact with anything.
261 // Insert it.
262 return ranges.insert(it, LR);
Chris Lattnerfb449b92004-07-23 17:49:16 +0000263}
264
Evan Cheng5a3c6a82009-01-29 02:20:59 +0000265/// isInOneLiveRange - Return true if the range specified is entirely in the
266/// a single LiveRange of the live interval.
267bool LiveInterval::isInOneLiveRange(unsigned Start, unsigned End) {
268 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
269 if (I == ranges.begin())
270 return false;
271 --I;
272 return I->contains(Start) && I->contains(End-1);
273}
274
Chris Lattnerabf295f2004-07-24 02:52:23 +0000275
276/// removeRange - Remove the specified range from this interval. Note that
Evan Cheng42cc6e32009-01-29 00:06:09 +0000277/// the range must be in a single LiveRange in its entirety.
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000278void LiveInterval::removeRange(unsigned Start, unsigned End,
279 bool RemoveDeadValNo) {
Chris Lattnerabf295f2004-07-24 02:52:23 +0000280 // Find the LiveRange containing this span.
281 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
282 assert(I != ranges.begin() && "Range is not in interval!");
283 --I;
284 assert(I->contains(Start) && I->contains(End-1) &&
285 "Range is not entirely in interval!");
286
287 // If the span we are removing is at the start of the LiveRange, adjust it.
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000288 VNInfo *ValNo = I->valno;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000289 if (I->start == Start) {
Evan Cheng4f8ff162007-08-11 00:59:19 +0000290 if (I->end == End) {
Evan Chengf3bb2e62007-09-05 21:46:51 +0000291 removeKills(I->valno, Start, End);
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000292 if (RemoveDeadValNo) {
293 // Check if val# is dead.
294 bool isDead = true;
295 for (const_iterator II = begin(), EE = end(); II != EE; ++II)
296 if (II != I && II->valno == ValNo) {
297 isDead = false;
298 break;
299 }
300 if (isDead) {
301 // Now that ValNo is dead, remove it. If it is the largest value
302 // number, just nuke it (and any other deleted values neighboring it),
303 // otherwise mark it as ~1U so it can be nuked later.
304 if (ValNo->id == getNumValNums()-1) {
305 do {
306 VNInfo *VNI = valnos.back();
307 valnos.pop_back();
308 VNI->~VNInfo();
309 } while (!valnos.empty() && valnos.back()->def == ~1U);
310 } else {
311 ValNo->def = ~1U;
312 }
313 }
314 }
315
Chris Lattnerabf295f2004-07-24 02:52:23 +0000316 ranges.erase(I); // Removed the whole LiveRange.
Evan Cheng4f8ff162007-08-11 00:59:19 +0000317 } else
Chris Lattnerabf295f2004-07-24 02:52:23 +0000318 I->start = End;
319 return;
320 }
321
322 // Otherwise if the span we are removing is at the end of the LiveRange,
323 // adjust the other way.
324 if (I->end == End) {
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000325 removeKills(ValNo, Start, End);
Chris Lattner6925a9f2004-07-25 05:43:53 +0000326 I->end = Start;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000327 return;
328 }
329
330 // Otherwise, we are splitting the LiveRange into two pieces.
331 unsigned OldEnd = I->end;
332 I->end = Start; // Trim the old interval.
333
334 // Insert the new one.
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000335 ranges.insert(next(I), LiveRange(End, OldEnd, ValNo));
Chris Lattnerabf295f2004-07-24 02:52:23 +0000336}
337
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000338/// removeValNo - Remove all the ranges defined by the specified value#.
339/// Also remove the value# from value# list.
340void LiveInterval::removeValNo(VNInfo *ValNo) {
341 if (empty()) return;
342 Ranges::iterator I = ranges.end();
343 Ranges::iterator E = ranges.begin();
344 do {
345 --I;
346 if (I->valno == ValNo)
347 ranges.erase(I);
348 } while (I != E);
349 // Now that ValNo is dead, remove it. If it is the largest value
350 // number, just nuke it (and any other deleted values neighboring it),
351 // otherwise mark it as ~1U so it can be nuked later.
352 if (ValNo->id == getNumValNums()-1) {
353 do {
354 VNInfo *VNI = valnos.back();
355 valnos.pop_back();
356 VNI->~VNInfo();
357 } while (!valnos.empty() && valnos.back()->def == ~1U);
358 } else {
359 ValNo->def = ~1U;
360 }
361}
362
Lang Hamesf41538d2009-06-02 16:53:25 +0000363/// scaleNumbering - Renumber VNI and ranges to provide gaps for new
364/// instructions.
365void LiveInterval::scaleNumbering(unsigned factor) {
366 // Scale ranges.
367 for (iterator RI = begin(), RE = end(); RI != RE; ++RI) {
368 RI->start = InstrSlots::scale(RI->start, factor);
369 RI->end = InstrSlots::scale(RI->end, factor);
370 }
371
372 // Scale VNI info.
373 for (vni_iterator VNI = vni_begin(), VNIE = vni_end(); VNI != VNIE; ++VNI) {
374 VNInfo *vni = *VNI;
375 if (vni->def != ~0U && vni->def != ~1U) {
376 vni->def = InstrSlots::scale(vni->def, factor);
377 }
378
379 for (unsigned i = 0; i < vni->kills.size(); ++i) {
380 if (vni->kills[i] != 0)
381 vni->kills[i] = InstrSlots::scale(vni->kills[i], factor);
382 }
383 }
384}
385
Chris Lattnerabf295f2004-07-24 02:52:23 +0000386/// getLiveRangeContaining - Return the live range that contains the
387/// specified index, or null if there is none.
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000388LiveInterval::const_iterator
389LiveInterval::FindLiveRangeContaining(unsigned Idx) const {
390 const_iterator It = std::upper_bound(begin(), end(), Idx);
Chris Lattnerabf295f2004-07-24 02:52:23 +0000391 if (It != ranges.begin()) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000392 --It;
393 if (It->contains(Idx))
394 return It;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000395 }
396
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000397 return end();
Chris Lattnerabf295f2004-07-24 02:52:23 +0000398}
399
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000400LiveInterval::iterator
401LiveInterval::FindLiveRangeContaining(unsigned Idx) {
402 iterator It = std::upper_bound(begin(), end(), Idx);
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000403 if (It != begin()) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000404 --It;
405 if (It->contains(Idx))
406 return It;
407 }
408
409 return end();
410}
Chris Lattnerabf295f2004-07-24 02:52:23 +0000411
Evan Cheng3f32d652008-06-04 09:18:41 +0000412/// findDefinedVNInfo - Find the VNInfo that's defined at the specified index
413/// (register interval) or defined by the specified register (stack inteval).
414VNInfo *LiveInterval::findDefinedVNInfo(unsigned DefIdxOrReg) const {
415 VNInfo *VNI = NULL;
416 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
417 i != e; ++i)
418 if ((*i)->def == DefIdxOrReg) {
419 VNI = *i;
420 break;
421 }
422 return VNI;
423}
424
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000425/// join - Join two live intervals (this, and other) together. This applies
426/// mappings to the value numbers in the LHS/RHS intervals as specified. If
427/// the intervals are not joinable, this aborts.
David Greeneaf992f72007-09-06 19:46:46 +0000428void LiveInterval::join(LiveInterval &Other, const int *LHSValNoAssignments,
429 const int *RHSValNoAssignments,
Evan Cheng90f95f82009-06-14 20:22:55 +0000430 SmallVector<VNInfo*, 16> &NewVNInfo,
431 MachineRegisterInfo *MRI) {
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000432 // Determine if any of our live range values are mapped. This is uncommon, so
Evan Cheng34301352007-09-01 02:03:17 +0000433 // we want to avoid the interval scan if not.
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000434 bool MustMapCurValNos = false;
Evan Cheng34301352007-09-01 02:03:17 +0000435 unsigned NumVals = getNumValNums();
436 unsigned NumNewVals = NewVNInfo.size();
437 for (unsigned i = 0; i != NumVals; ++i) {
438 unsigned LHSValID = LHSValNoAssignments[i];
439 if (i != LHSValID ||
Evan Chengf3bb2e62007-09-05 21:46:51 +0000440 (NewVNInfo[LHSValID] && NewVNInfo[LHSValID] != getValNumInfo(i)))
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000441 MustMapCurValNos = true;
Chris Lattnerdeb99712004-07-24 03:41:50 +0000442 }
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000443
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000444 // If we have to apply a mapping to our base interval assignment, rewrite it
445 // now.
446 if (MustMapCurValNos) {
447 // Map the first live range.
448 iterator OutIt = begin();
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000449 OutIt->valno = NewVNInfo[LHSValNoAssignments[OutIt->valno->id]];
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000450 ++OutIt;
451 for (iterator I = OutIt, E = end(); I != E; ++I) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000452 OutIt->valno = NewVNInfo[LHSValNoAssignments[I->valno->id]];
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000453
454 // If this live range has the same value # as its immediate predecessor,
455 // and if they are neighbors, remove one LiveRange. This happens when we
456 // have [0,3:0)[4,7:1) and map 0/1 onto the same value #.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000457 if (OutIt->valno == (OutIt-1)->valno && (OutIt-1)->end == OutIt->start) {
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000458 (OutIt-1)->end = OutIt->end;
459 } else {
460 if (I != OutIt) {
461 OutIt->start = I->start;
462 OutIt->end = I->end;
463 }
464
465 // Didn't merge, on to the next one.
466 ++OutIt;
467 }
468 }
469
470 // If we merge some live ranges, chop off the end.
471 ranges.erase(OutIt, end());
472 }
Evan Cheng4f8ff162007-08-11 00:59:19 +0000473
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000474 // Remember assignements because val# ids are changing.
Evan Cheng34301352007-09-01 02:03:17 +0000475 SmallVector<unsigned, 16> OtherAssignments;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000476 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
477 OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]);
478
479 // Update val# info. Renumber them and make sure they all belong to this
Evan Chengf3bb2e62007-09-05 21:46:51 +0000480 // LiveInterval now. Also remove dead val#'s.
481 unsigned NumValNos = 0;
482 for (unsigned i = 0; i < NumNewVals; ++i) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000483 VNInfo *VNI = NewVNInfo[i];
Evan Chengf3bb2e62007-09-05 21:46:51 +0000484 if (VNI) {
Evan Cheng30590f52009-04-28 06:24:09 +0000485 if (NumValNos >= NumVals)
Evan Chengf3bb2e62007-09-05 21:46:51 +0000486 valnos.push_back(VNI);
487 else
488 valnos[NumValNos] = VNI;
489 VNI->id = NumValNos++; // Renumber val#.
Evan Cheng34301352007-09-01 02:03:17 +0000490 }
491 }
Evan Cheng34301352007-09-01 02:03:17 +0000492 if (NumNewVals < NumVals)
493 valnos.resize(NumNewVals); // shrinkify
Evan Cheng4f8ff162007-08-11 00:59:19 +0000494
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000495 // Okay, now insert the RHS live ranges into the LHS.
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000496 iterator InsertPos = begin();
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000497 unsigned RangeNo = 0;
498 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I, ++RangeNo) {
499 // Map the valno in the other live range to the current live range.
500 I->valno = NewVNInfo[OtherAssignments[RangeNo]];
Evan Chengf3bb2e62007-09-05 21:46:51 +0000501 assert(I->valno && "Adding a dead range?");
Chris Lattnerabf295f2004-07-24 02:52:23 +0000502 InsertPos = addRangeFrom(*I, InsertPos);
503 }
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000504
Chris Lattnerabf295f2004-07-24 02:52:23 +0000505 weight += Other.weight;
Evan Cheng90f95f82009-06-14 20:22:55 +0000506
507 // Update regalloc hint if currently there isn't one.
508 if (TargetRegisterInfo::isVirtualRegister(reg) &&
509 TargetRegisterInfo::isVirtualRegister(Other.reg)) {
510 std::pair<MachineRegisterInfo::RegAllocHintType, unsigned> Hint =
511 MRI->getRegAllocationHint(reg);
512 if (Hint.first == MachineRegisterInfo::RA_None) {
513 std::pair<MachineRegisterInfo::RegAllocHintType, unsigned> OtherHint =
514 MRI->getRegAllocationHint(Other.reg);
515 if (OtherHint.first != MachineRegisterInfo::RA_None)
516 MRI->setRegAllocationHint(reg, OtherHint.first, OtherHint.second);
517 }
518 }
Chris Lattnerfb449b92004-07-23 17:49:16 +0000519}
520
Chris Lattnerf21f0202006-09-02 05:26:59 +0000521/// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
522/// interval as the specified value number. The LiveRanges in RHS are
523/// allowed to overlap with LiveRanges in the current interval, but only if
524/// the overlapping LiveRanges have the specified value number.
525void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS,
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000526 VNInfo *LHSValNo) {
Chris Lattnerf21f0202006-09-02 05:26:59 +0000527 // TODO: Make this more efficient.
528 iterator InsertPos = begin();
529 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000530 // Map the valno in the other live range to the current live range.
Chris Lattnerf21f0202006-09-02 05:26:59 +0000531 LiveRange Tmp = *I;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000532 Tmp.valno = LHSValNo;
Chris Lattnerf21f0202006-09-02 05:26:59 +0000533 InsertPos = addRangeFrom(Tmp, InsertPos);
534 }
535}
536
537
Evan Cheng32dfbea2007-10-12 08:50:34 +0000538/// MergeValueInAsValue - Merge all of the live ranges of a specific val#
539/// in RHS into this live interval as the specified value number.
540/// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000541/// current interval, it will replace the value numbers of the overlaped
542/// live ranges with the specified value number.
Evan Cheng32dfbea2007-10-12 08:50:34 +0000543void LiveInterval::MergeValueInAsValue(const LiveInterval &RHS,
Evan Cheng34729252007-10-14 10:08:34 +0000544 const VNInfo *RHSValNo, VNInfo *LHSValNo) {
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000545 SmallVector<VNInfo*, 4> ReplacedValNos;
546 iterator IP = begin();
Evan Cheng32dfbea2007-10-12 08:50:34 +0000547 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
548 if (I->valno != RHSValNo)
549 continue;
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000550 unsigned Start = I->start, End = I->end;
551 IP = std::upper_bound(IP, end(), Start);
552 // If the start of this range overlaps with an existing liverange, trim it.
553 if (IP != begin() && IP[-1].end > Start) {
Evan Cheng294e6522008-01-30 22:44:55 +0000554 if (IP[-1].valno != LHSValNo) {
555 ReplacedValNos.push_back(IP[-1].valno);
556 IP[-1].valno = LHSValNo; // Update val#.
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000557 }
558 Start = IP[-1].end;
559 // Trimmed away the whole range?
560 if (Start >= End) continue;
561 }
562 // If the end of this range overlaps with an existing liverange, trim it.
563 if (IP != end() && End > IP->start) {
564 if (IP->valno != LHSValNo) {
565 ReplacedValNos.push_back(IP->valno);
566 IP->valno = LHSValNo; // Update val#.
567 }
568 End = IP->start;
569 // If this trimmed away the whole range, ignore it.
570 if (Start == End) continue;
571 }
572
Evan Cheng32dfbea2007-10-12 08:50:34 +0000573 // Map the valno in the other live range to the current live range.
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000574 IP = addRangeFrom(LiveRange(Start, End, LHSValNo), IP);
575 }
576
577
578 SmallSet<VNInfo*, 4> Seen;
579 for (unsigned i = 0, e = ReplacedValNos.size(); i != e; ++i) {
580 VNInfo *V1 = ReplacedValNos[i];
581 if (Seen.insert(V1)) {
582 bool isDead = true;
583 for (const_iterator I = begin(), E = end(); I != E; ++I)
584 if (I->valno == V1) {
585 isDead = false;
586 break;
587 }
588 if (isDead) {
589 // Now that V1 is dead, remove it. If it is the largest value number,
590 // just nuke it (and any other deleted values neighboring it), otherwise
591 // mark it as ~1U so it can be nuked later.
592 if (V1->id == getNumValNums()-1) {
593 do {
594 VNInfo *VNI = valnos.back();
595 valnos.pop_back();
596 VNI->~VNInfo();
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000597 } while (!valnos.empty() && valnos.back()->def == ~1U);
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000598 } else {
599 V1->def = ~1U;
600 }
601 }
602 }
Evan Cheng32dfbea2007-10-12 08:50:34 +0000603 }
604}
605
606
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000607/// MergeInClobberRanges - For any live ranges that are not defined in the
608/// current interval, but are defined in the Clobbers interval, mark them
609/// used with an unknown definition value.
Evan Chengf3bb2e62007-09-05 21:46:51 +0000610void LiveInterval::MergeInClobberRanges(const LiveInterval &Clobbers,
611 BumpPtrAllocator &VNInfoAllocator) {
Dan Gohmana8c763b2008-08-14 18:13:49 +0000612 if (Clobbers.empty()) return;
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000613
Evan Cheng0adb5272009-04-25 09:25:19 +0000614 DenseMap<VNInfo*, VNInfo*> ValNoMaps;
Evan Chenga4b2bab2009-04-25 20:20:15 +0000615 VNInfo *UnusedValNo = 0;
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000616 iterator IP = begin();
617 for (const_iterator I = Clobbers.begin(), E = Clobbers.end(); I != E; ++I) {
Evan Cheng0adb5272009-04-25 09:25:19 +0000618 // For every val# in the Clobbers interval, create a new "unknown" val#.
619 VNInfo *ClobberValNo = 0;
620 DenseMap<VNInfo*, VNInfo*>::iterator VI = ValNoMaps.find(I->valno);
621 if (VI != ValNoMaps.end())
622 ClobberValNo = VI->second;
Evan Chenga4b2bab2009-04-25 20:20:15 +0000623 else if (UnusedValNo)
624 ClobberValNo = UnusedValNo;
Evan Cheng0adb5272009-04-25 09:25:19 +0000625 else {
Evan Chenga4b2bab2009-04-25 20:20:15 +0000626 UnusedValNo = ClobberValNo = getNextValue(~0U, 0, VNInfoAllocator);
Evan Cheng0adb5272009-04-25 09:25:19 +0000627 ValNoMaps.insert(std::make_pair(I->valno, ClobberValNo));
628 }
629
Dan Gohman97121ba2009-04-08 00:15:30 +0000630 bool Done = false;
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000631 unsigned Start = I->start, End = I->end;
Dan Gohman97121ba2009-04-08 00:15:30 +0000632 // If a clobber range starts before an existing range and ends after
633 // it, the clobber range will need to be split into multiple ranges.
634 // Loop until the entire clobber range is handled.
635 while (!Done) {
636 Done = true;
637 IP = std::upper_bound(IP, end(), Start);
638 unsigned SubRangeStart = Start;
639 unsigned SubRangeEnd = End;
640
641 // If the start of this range overlaps with an existing liverange, trim it.
642 if (IP != begin() && IP[-1].end > SubRangeStart) {
643 SubRangeStart = IP[-1].end;
644 // Trimmed away the whole range?
645 if (SubRangeStart >= SubRangeEnd) continue;
646 }
647 // If the end of this range overlaps with an existing liverange, trim it.
648 if (IP != end() && SubRangeEnd > IP->start) {
649 // If the clobber live range extends beyond the existing live range,
650 // it'll need at least another live range, so set the flag to keep
651 // iterating.
652 if (SubRangeEnd > IP->end) {
653 Start = IP->end;
654 Done = false;
655 }
656 SubRangeEnd = IP->start;
657 // If this trimmed away the whole range, ignore it.
658 if (SubRangeStart == SubRangeEnd) continue;
659 }
660
661 // Insert the clobber interval.
662 IP = addRangeFrom(LiveRange(SubRangeStart, SubRangeEnd, ClobberValNo),
663 IP);
Evan Chenga4b2bab2009-04-25 20:20:15 +0000664 UnusedValNo = 0;
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000665 }
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000666 }
Evan Cheng27e46662009-04-27 17:35:19 +0000667
668 if (UnusedValNo) {
669 // Delete the last unused val#.
670 valnos.pop_back();
671 UnusedValNo->~VNInfo();
672 }
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000673}
674
Evan Chenga2e64352009-03-11 00:03:21 +0000675void LiveInterval::MergeInClobberRange(unsigned Start, unsigned End,
676 BumpPtrAllocator &VNInfoAllocator) {
677 // Find a value # to use for the clobber ranges. If there is already a value#
678 // for unknown values, use it.
Evan Cheng0adb5272009-04-25 09:25:19 +0000679 VNInfo *ClobberValNo = getNextValue(~0U, 0, VNInfoAllocator);
Evan Chenga2e64352009-03-11 00:03:21 +0000680
681 iterator IP = begin();
682 IP = std::upper_bound(IP, end(), Start);
683
684 // If the start of this range overlaps with an existing liverange, trim it.
685 if (IP != begin() && IP[-1].end > Start) {
686 Start = IP[-1].end;
687 // Trimmed away the whole range?
688 if (Start >= End) return;
689 }
690 // If the end of this range overlaps with an existing liverange, trim it.
691 if (IP != end() && End > IP->start) {
692 End = IP->start;
693 // If this trimmed away the whole range, ignore it.
694 if (Start == End) return;
695 }
696
697 // Insert the clobber interval.
698 addRangeFrom(LiveRange(Start, End, ClobberValNo), IP);
699}
700
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000701/// MergeValueNumberInto - This method is called when two value nubmers
702/// are found to be equivalent. This eliminates V1, replacing all
703/// LiveRanges with the V1 value number with the V2 value number. This can
704/// cause merging of V1/V2 values numbers and compaction of the value space.
Owen Anderson5b93f6f2009-02-02 22:42:01 +0000705VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000706 assert(V1 != V2 && "Identical value#'s are always equivalent!");
707
708 // This code actually merges the (numerically) larger value number into the
709 // smaller value number, which is likely to allow us to compactify the value
710 // space. The only thing we have to be careful of is to preserve the
711 // instruction that defines the result value.
712
713 // Make sure V2 is smaller than V1.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000714 if (V1->id < V2->id) {
Evan Chengf3bb2e62007-09-05 21:46:51 +0000715 copyValNumInfo(V1, V2);
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000716 std::swap(V1, V2);
717 }
718
719 // Merge V1 live ranges into V2.
720 for (iterator I = begin(); I != end(); ) {
721 iterator LR = I++;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000722 if (LR->valno != V1) continue; // Not a V1 LiveRange.
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000723
724 // Okay, we found a V1 live range. If it had a previous, touching, V2 live
725 // range, extend it.
726 if (LR != begin()) {
727 iterator Prev = LR-1;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000728 if (Prev->valno == V2 && Prev->end == LR->start) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000729 Prev->end = LR->end;
730
731 // Erase this live-range.
732 ranges.erase(LR);
733 I = Prev+1;
734 LR = Prev;
735 }
736 }
737
738 // Okay, now we have a V1 or V2 live range that is maximally merged forward.
739 // Ensure that it is a V2 live-range.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000740 LR->valno = V2;
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000741
742 // If we can merge it into later V2 live ranges, do so now. We ignore any
743 // following V1 live ranges, as they will be merged in subsequent iterations
744 // of the loop.
745 if (I != end()) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000746 if (I->start == LR->end && I->valno == V2) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000747 LR->end = I->end;
748 ranges.erase(I);
749 I = LR+1;
750 }
751 }
752 }
Chris Lattnerc82b3aa2006-08-24 23:22:59 +0000753
754 // Now that V1 is dead, remove it. If it is the largest value number, just
755 // nuke it (and any other deleted values neighboring it), otherwise mark it as
756 // ~1U so it can be nuked later.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000757 if (V1->id == getNumValNums()-1) {
Chris Lattnerc82b3aa2006-08-24 23:22:59 +0000758 do {
Evan Chengdd199d22007-09-06 01:07:24 +0000759 VNInfo *VNI = valnos.back();
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000760 valnos.pop_back();
Evan Chengdd199d22007-09-06 01:07:24 +0000761 VNI->~VNInfo();
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000762 } while (valnos.back()->def == ~1U);
Chris Lattnerc82b3aa2006-08-24 23:22:59 +0000763 } else {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000764 V1->def = ~1U;
Chris Lattnerc82b3aa2006-08-24 23:22:59 +0000765 }
Owen Anderson5b93f6f2009-02-02 22:42:01 +0000766
767 return V2;
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000768}
769
Evan Cheng32dfbea2007-10-12 08:50:34 +0000770void LiveInterval::Copy(const LiveInterval &RHS,
Evan Cheng90f95f82009-06-14 20:22:55 +0000771 MachineRegisterInfo *MRI,
Evan Cheng32dfbea2007-10-12 08:50:34 +0000772 BumpPtrAllocator &VNInfoAllocator) {
773 ranges.clear();
774 valnos.clear();
Evan Cheng90f95f82009-06-14 20:22:55 +0000775 std::pair<MachineRegisterInfo::RegAllocHintType, unsigned> Hint =
776 MRI->getRegAllocationHint(RHS.reg);
777 MRI->setRegAllocationHint(reg, Hint.first, Hint.second);
778
Evan Cheng32dfbea2007-10-12 08:50:34 +0000779 weight = RHS.weight;
780 for (unsigned i = 0, e = RHS.getNumValNums(); i != e; ++i) {
781 const VNInfo *VNI = RHS.getValNumInfo(i);
782 VNInfo *NewVNI = getNextValue(~0U, 0, VNInfoAllocator);
783 copyValNumInfo(NewVNI, VNI);
784 }
785 for (unsigned i = 0, e = RHS.ranges.size(); i != e; ++i) {
786 const LiveRange &LR = RHS.ranges[i];
787 addRange(LiveRange(LR.start, LR.end, getValNumInfo(LR.valno->id)));
788 }
789}
790
Evan Chenge52eef82007-04-17 20:25:11 +0000791unsigned LiveInterval::getSize() const {
792 unsigned Sum = 0;
793 for (const_iterator I = begin(), E = end(); I != E; ++I)
794 Sum += I->end - I->start;
795 return Sum;
796}
797
Chris Lattnerfb449b92004-07-23 17:49:16 +0000798std::ostream& llvm::operator<<(std::ostream& os, const LiveRange &LR) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000799 return os << '[' << LR.start << ',' << LR.end << ':' << LR.valno->id << ")";
Chris Lattnerfb449b92004-07-23 17:49:16 +0000800}
801
Chris Lattnerabf295f2004-07-24 02:52:23 +0000802void LiveRange::dump() const {
Bill Wendlinge8156192006-12-07 01:30:32 +0000803 cerr << *this << "\n";
Chris Lattnerabf295f2004-07-24 02:52:23 +0000804}
805
Dan Gohman6f0d0242008-02-10 18:45:23 +0000806void LiveInterval::print(std::ostream &OS,
807 const TargetRegisterInfo *TRI) const {
Evan Cheng99ec7792008-06-23 21:03:19 +0000808 if (isStackSlot())
809 OS << "SS#" << getStackSlotIndex();
Evan Cheng3f32d652008-06-04 09:18:41 +0000810 else if (TRI && TargetRegisterInfo::isPhysicalRegister(reg))
Bill Wendlinge6d088a2008-02-26 21:47:57 +0000811 OS << TRI->getName(reg);
Chris Lattner38135af2005-05-14 05:34:15 +0000812 else
813 OS << "%reg" << reg;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000814
Chris Lattner38135af2005-05-14 05:34:15 +0000815 OS << ',' << weight;
Chris Lattnerfb449b92004-07-23 17:49:16 +0000816
Chris Lattner38135af2005-05-14 05:34:15 +0000817 if (empty())
Evan Cheng3f32d652008-06-04 09:18:41 +0000818 OS << " EMPTY";
Chris Lattner38135af2005-05-14 05:34:15 +0000819 else {
820 OS << " = ";
821 for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
822 E = ranges.end(); I != E; ++I)
823 OS << *I;
824 }
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000825
826 // Print value number info.
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000827 if (getNumValNums()) {
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000828 OS << " ";
Evan Cheng1a66f0a2007-08-28 08:28:51 +0000829 unsigned vnum = 0;
830 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
831 ++i, ++vnum) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000832 const VNInfo *vni = *i;
Evan Cheng1a66f0a2007-08-28 08:28:51 +0000833 if (vnum) OS << " ";
834 OS << vnum << "@";
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000835 if (vni->def == ~1U) {
Evan Cheng8df78602007-08-08 03:00:28 +0000836 OS << "x";
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000837 } else {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000838 if (vni->def == ~0U)
Evan Cheng4f8ff162007-08-11 00:59:19 +0000839 OS << "?";
840 else
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000841 OS << vni->def;
842 unsigned ee = vni->kills.size();
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000843 if (ee || vni->hasPHIKill) {
Evan Cheng4f8ff162007-08-11 00:59:19 +0000844 OS << "-(";
Evan Cheng1a66f0a2007-08-28 08:28:51 +0000845 for (unsigned j = 0; j != ee; ++j) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000846 OS << vni->kills[j];
Evan Cheng1a66f0a2007-08-28 08:28:51 +0000847 if (j != ee-1)
Evan Cheng4f8ff162007-08-11 00:59:19 +0000848 OS << " ";
849 }
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000850 if (vni->hasPHIKill) {
851 if (ee)
852 OS << " ";
853 OS << "phi";
854 }
Evan Cheng4f8ff162007-08-11 00:59:19 +0000855 OS << ")";
856 }
Evan Chenga8d94f12007-08-07 23:49:57 +0000857 }
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000858 }
859 }
Chris Lattnerfb449b92004-07-23 17:49:16 +0000860}
Chris Lattnerabf295f2004-07-24 02:52:23 +0000861
862void LiveInterval::dump() const {
Bill Wendlinge8156192006-12-07 01:30:32 +0000863 cerr << *this << "\n";
Chris Lattnerabf295f2004-07-24 02:52:23 +0000864}
Jeff Cohenc21c5ee2006-12-15 22:57:14 +0000865
866
Jeff Cohen4b607742006-12-16 02:15:42 +0000867void LiveRange::print(std::ostream &os) const {
868 os << *this;
Jeff Cohenc21c5ee2006-12-15 22:57:14 +0000869}