blob: 34b58515b68ccd6c082e9582a6cf754c1f1c5a97 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- LiveInterval.cpp - Live Interval Representation -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +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 Wilsonc244ae62010-01-12 22:18:56 +000013// such that v is live at j' and there is no instruction with number i' < i such
Dan Gohmanf17a25c2007-07-18 16:29:46 +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
21#include "llvm/CodeGen/LiveInterval.h"
Lang Hamesd6a717c2009-11-03 23:52:08 +000022#include "llvm/CodeGen/LiveIntervalAnalysis.h"
Evan Chengd78907d2009-06-14 20:22:55 +000023#include "llvm/CodeGen/MachineRegisterInfo.h"
Evan Cheng1068b722009-04-25 09:25:19 +000024#include "llvm/ADT/DenseMap.h"
Evan Cheng303fed82007-10-17 02:13:29 +000025#include "llvm/ADT/SmallSet.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000026#include "llvm/ADT/STLExtras.h"
David Greene23c23922010-01-04 22:41:43 +000027#include "llvm/Support/Debug.h"
Daniel Dunbarddea63b2009-07-24 10:47:20 +000028#include "llvm/Support/raw_ostream.h"
Dan Gohman1e57df32008-02-10 18:45:23 +000029#include "llvm/Target/TargetRegisterInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000030#include <algorithm>
Dan Gohmanf17a25c2007-07-18 16:29:46 +000031using namespace llvm;
32
33// An example for liveAt():
34//
35// 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).
39//
Lang Hamesd6a717c2009-11-03 23:52:08 +000040bool LiveInterval::liveAt(SlotIndex I) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000041 Ranges::const_iterator r = std::upper_bound(ranges.begin(), ranges.end(), I);
42
43 if (r == ranges.begin())
44 return false;
45
46 --r;
47 return r->contains(I);
48}
49
Evan Cheng7d2b9082008-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 Hamesd6a717c2009-11-03 23:52:08 +000053bool LiveInterval::liveBeforeAndAt(SlotIndex I) const {
Evan Cheng7d2b9082008-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 Olesen5ccea1a2010-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
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000102// overlaps - Return true if the intersection of the two live intervals is
103// not empty.
104//
105// An example for overlaps():
106//
107// 0: A = ...
108// 4: B = ...
109// 8: C = A + B ;; last use of A
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.
119//
120bool LiveInterval::overlapsFrom(const LiveInterval& other,
121 const_iterator StartPos) const {
122 const_iterator i = begin();
123 const_iterator ie = end();
124 const_iterator j = StartPos;
125 const_iterator je = other.end();
126
127 assert((StartPos->start <= i->start || StartPos == other.begin()) &&
128 StartPos != other.end() && "Bogus start position hint!");
129
130 if (i->start < j->start) {
131 i = std::upper_bound(i, ie, j->start);
132 if (i != ranges.begin()) --i;
133 } else if (j->start < i->start) {
134 ++StartPos;
135 if (StartPos != other.end() && StartPos->start <= i->start) {
136 assert(StartPos < other.end() && i < end());
137 j = std::upper_bound(j, je, i->start);
138 if (j != other.ranges.begin()) --j;
139 }
140 } else {
141 return true;
142 }
143
144 if (j == je) return false;
145
146 while (i != ie) {
147 if (i->start > j->start) {
148 std::swap(i, j);
149 std::swap(ie, je);
150 }
151
152 if (i->end > j->start)
153 return true;
154 ++i;
155 }
156
157 return false;
158}
159
Evan Cheng60c15e52009-04-18 08:52:15 +0000160/// overlaps - Return true if the live interval overlaps a range specified
161/// by [Start, End).
Lang Hamesd6a717c2009-11-03 23:52:08 +0000162bool LiveInterval::overlaps(SlotIndex Start, SlotIndex End) const {
Evan Cheng60c15e52009-04-18 08:52:15 +0000163 assert(Start < End && "Invalid range");
164 const_iterator I = begin();
165 const_iterator E = end();
166 const_iterator si = std::upper_bound(I, E, Start);
167 const_iterator ei = std::upper_bound(I, E, End);
168 if (si != ei)
169 return true;
170 if (si == I)
171 return false;
172 --si;
173 return si->contains(Start);
174}
175
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000176/// extendIntervalEndTo - This method is used when we want to extend the range
177/// specified by I to end at the specified endpoint. To do this, we should
178/// merge and eliminate all ranges that this will overlap with. The iterator is
179/// not invalidated.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000180void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000181 assert(I != ranges.end() && "Not a valid interval!");
Evan Cheng983b81d2007-08-29 20:45:00 +0000182 VNInfo *ValNo = I->valno;
Lang Hamesd6a717c2009-11-03 23:52:08 +0000183 SlotIndex OldEnd = I->end;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184
185 // Search for the first interval that we can't merge with.
186 Ranges::iterator MergeTo = next(I);
187 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000188 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000189 }
190
191 // If NewEnd was in the middle of an interval, make sure to get its endpoint.
192 I->end = std::max(NewEnd, prior(MergeTo)->end);
193
194 // Erase any dead ranges.
195 ranges.erase(next(I), MergeTo);
Evan Cheng816a7f32007-08-11 00:59:19 +0000196
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000197 // If the newly formed range now touches the range after it and if they have
198 // the same value number, merge the two ranges into one range.
199 Ranges::iterator Next = next(I);
Evan Cheng983b81d2007-08-29 20:45:00 +0000200 if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000201 I->end = Next->end;
202 ranges.erase(Next);
203 }
204}
205
206
207/// extendIntervalStartTo - This method is used when we want to extend the range
208/// specified by I to start at the specified endpoint. To do this, we should
209/// merge and eliminate all ranges that this will overlap with.
210LiveInterval::Ranges::iterator
Lang Hamesd6a717c2009-11-03 23:52:08 +0000211LiveInterval::extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStart) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000212 assert(I != ranges.end() && "Not a valid interval!");
Evan Cheng983b81d2007-08-29 20:45:00 +0000213 VNInfo *ValNo = I->valno;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000214
215 // Search for the first interval that we can't merge with.
216 Ranges::iterator MergeTo = I;
217 do {
218 if (MergeTo == ranges.begin()) {
219 I->start = NewStart;
220 ranges.erase(MergeTo, I);
221 return I;
222 }
Evan Cheng983b81d2007-08-29 20:45:00 +0000223 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224 --MergeTo;
225 } while (NewStart <= MergeTo->start);
226
227 // If we start in the middle of another interval, just delete a range and
228 // extend that interval.
Evan Cheng983b81d2007-08-29 20:45:00 +0000229 if (MergeTo->end >= NewStart && MergeTo->valno == ValNo) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000230 MergeTo->end = I->end;
231 } else {
232 // Otherwise, extend the interval right after.
233 ++MergeTo;
234 MergeTo->start = NewStart;
235 MergeTo->end = I->end;
236 }
237
238 ranges.erase(next(MergeTo), next(I));
239 return MergeTo;
240}
241
242LiveInterval::iterator
243LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
Lang Hamesd6a717c2009-11-03 23:52:08 +0000244 SlotIndex Start = LR.start, End = LR.end;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000245 iterator it = std::upper_bound(From, ranges.end(), Start);
246
247 // If the inserted interval starts in the middle or right at the end of
248 // another interval, just extend that interval to contain the range of LR.
249 if (it != ranges.begin()) {
250 iterator B = prior(it);
Evan Cheng983b81d2007-08-29 20:45:00 +0000251 if (LR.valno == B->valno) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000252 if (B->start <= Start && B->end >= Start) {
253 extendIntervalEndTo(B, End);
254 return B;
255 }
256 } else {
257 // Check to make sure that we are not overlapping two live ranges with
Evan Cheng983b81d2007-08-29 20:45:00 +0000258 // different valno's.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000259 assert(B->end <= Start &&
260 "Cannot overlap two LiveRanges with differing ValID's"
261 " (did you def the same reg twice in a MachineInstr?)");
262 }
263 }
264
265 // Otherwise, if this range ends in the middle of, or right next to, another
266 // interval, merge it into that interval.
Anton Korobeynikov53422f62008-02-20 11:10:28 +0000267 if (it != ranges.end()) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000268 if (LR.valno == it->valno) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000269 if (it->start <= End) {
270 it = extendIntervalStartTo(it, Start);
271
272 // If LR is a complete superset of an interval, we may need to grow its
273 // endpoint as well.
274 if (End > it->end)
275 extendIntervalEndTo(it, End);
276 return it;
277 }
278 } else {
279 // Check to make sure that we are not overlapping two live ranges with
Evan Cheng983b81d2007-08-29 20:45:00 +0000280 // different valno's.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000281 assert(it->start >= End &&
282 "Cannot overlap two LiveRanges with differing ValID's");
283 }
Anton Korobeynikov53422f62008-02-20 11:10:28 +0000284 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000285
286 // Otherwise, this is just a new range that doesn't interact with anything.
287 // Insert it.
288 return ranges.insert(it, LR);
289}
290
Lang Hamesd8f30992009-09-04 20:41:11 +0000291/// isInOneLiveRange - Return true if the range specified is entirely in
Evan Cheng548bc502009-01-29 02:20:59 +0000292/// a single LiveRange of the live interval.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000293bool LiveInterval::isInOneLiveRange(SlotIndex Start, SlotIndex End) {
Evan Cheng548bc502009-01-29 02:20:59 +0000294 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
295 if (I == ranges.begin())
296 return false;
297 --I;
Lang Hamesd8f30992009-09-04 20:41:11 +0000298 return I->containsRange(Start, End);
Evan Cheng548bc502009-01-29 02:20:59 +0000299}
300
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000301
302/// removeRange - Remove the specified range from this interval. Note that
Evan Chengeb80af62009-01-29 00:06:09 +0000303/// the range must be in a single LiveRange in its entirety.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000304void LiveInterval::removeRange(SlotIndex Start, SlotIndex End,
Evan Cheng49208cf2008-02-13 02:48:26 +0000305 bool RemoveDeadValNo) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000306 // Find the LiveRange containing this span.
307 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
308 assert(I != ranges.begin() && "Range is not in interval!");
309 --I;
Lang Hamesd8f30992009-09-04 20:41:11 +0000310 assert(I->containsRange(Start, End) && "Range is not entirely in interval!");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000311
312 // If the span we are removing is at the start of the LiveRange, adjust it.
Evan Cheng49208cf2008-02-13 02:48:26 +0000313 VNInfo *ValNo = I->valno;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000314 if (I->start == Start) {
Evan Cheng816a7f32007-08-11 00:59:19 +0000315 if (I->end == End) {
Evan Cheng49208cf2008-02-13 02:48:26 +0000316 if (RemoveDeadValNo) {
317 // Check if val# is dead.
318 bool isDead = true;
319 for (const_iterator II = begin(), EE = end(); II != EE; ++II)
320 if (II != I && II->valno == ValNo) {
321 isDead = false;
322 break;
Jakob Stoklund Olesen5ccea1a2010-06-25 22:53:05 +0000323 }
Evan Cheng49208cf2008-02-13 02:48:26 +0000324 if (isDead) {
325 // Now that ValNo is dead, remove it. If it is the largest value
326 // number, just nuke it (and any other deleted values neighboring it),
327 // otherwise mark it as ~1U so it can be nuked later.
328 if (ValNo->id == getNumValNums()-1) {
329 do {
Evan Cheng49208cf2008-02-13 02:48:26 +0000330 valnos.pop_back();
Lang Hames4eb8fc82009-06-17 21:01:20 +0000331 } while (!valnos.empty() && valnos.back()->isUnused());
Evan Cheng49208cf2008-02-13 02:48:26 +0000332 } else {
Lang Hames4eb8fc82009-06-17 21:01:20 +0000333 ValNo->setIsUnused(true);
Evan Cheng49208cf2008-02-13 02:48:26 +0000334 }
335 }
336 }
337
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000338 ranges.erase(I); // Removed the whole LiveRange.
Evan Cheng816a7f32007-08-11 00:59:19 +0000339 } else
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000340 I->start = End;
341 return;
342 }
343
344 // Otherwise if the span we are removing is at the end of the LiveRange,
345 // adjust the other way.
346 if (I->end == End) {
347 I->end = Start;
348 return;
349 }
350
351 // Otherwise, we are splitting the LiveRange into two pieces.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000352 SlotIndex OldEnd = I->end;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000353 I->end = Start; // Trim the old interval.
354
355 // Insert the new one.
Evan Cheng49208cf2008-02-13 02:48:26 +0000356 ranges.insert(next(I), LiveRange(End, OldEnd, ValNo));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000357}
358
Evan Cheng49208cf2008-02-13 02:48:26 +0000359/// removeValNo - Remove all the ranges defined by the specified value#.
360/// Also remove the value# from value# list.
361void LiveInterval::removeValNo(VNInfo *ValNo) {
362 if (empty()) return;
363 Ranges::iterator I = ranges.end();
364 Ranges::iterator E = ranges.begin();
365 do {
366 --I;
367 if (I->valno == ValNo)
368 ranges.erase(I);
369 } while (I != E);
370 // Now that ValNo is dead, remove it. If it is the largest value
371 // number, just nuke it (and any other deleted values neighboring it),
372 // otherwise mark it as ~1U so it can be nuked later.
373 if (ValNo->id == getNumValNums()-1) {
374 do {
Evan Cheng49208cf2008-02-13 02:48:26 +0000375 valnos.pop_back();
Lang Hames4eb8fc82009-06-17 21:01:20 +0000376 } while (!valnos.empty() && valnos.back()->isUnused());
Evan Cheng49208cf2008-02-13 02:48:26 +0000377 } else {
Lang Hames4eb8fc82009-06-17 21:01:20 +0000378 ValNo->setIsUnused(true);
Evan Cheng49208cf2008-02-13 02:48:26 +0000379 }
380}
Lang Hamesd8f30992009-09-04 20:41:11 +0000381
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000382/// getLiveRangeContaining - Return the live range that contains the
383/// specified index, or null if there is none.
384LiveInterval::const_iterator
Lang Hamesd6a717c2009-11-03 23:52:08 +0000385LiveInterval::FindLiveRangeContaining(SlotIndex Idx) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000386 const_iterator It = std::upper_bound(begin(), end(), Idx);
387 if (It != ranges.begin()) {
388 --It;
389 if (It->contains(Idx))
390 return It;
391 }
392
393 return end();
394}
395
396LiveInterval::iterator
Lang Hamesd6a717c2009-11-03 23:52:08 +0000397LiveInterval::FindLiveRangeContaining(SlotIndex Idx) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000398 iterator It = std::upper_bound(begin(), end(), Idx);
399 if (It != begin()) {
400 --It;
401 if (It->contains(Idx))
402 return It;
403 }
404
405 return end();
406}
407
Lang Hamesd8f30992009-09-04 20:41:11 +0000408/// findDefinedVNInfo - Find the VNInfo defined by the specified
409/// index (register interval).
Lang Hamesd6a717c2009-11-03 23:52:08 +0000410VNInfo *LiveInterval::findDefinedVNInfoForRegInt(SlotIndex Idx) const {
Evan Cheng14f8a502008-06-04 09:18:41 +0000411 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
Lang Hamesd8f30992009-09-04 20:41:11 +0000412 i != e; ++i) {
413 if ((*i)->def == Idx)
414 return *i;
415 }
416
417 return 0;
418}
419
420/// findDefinedVNInfo - Find the VNInfo defined by the specified
421/// register (stack inteval).
422VNInfo *LiveInterval::findDefinedVNInfoForStackInt(unsigned reg) const {
423 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
424 i != e; ++i) {
425 if ((*i)->getReg() == reg)
426 return *i;
427 }
428 return 0;
Evan Cheng14f8a502008-06-04 09:18:41 +0000429}
430
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000431/// join - Join two live intervals (this, and other) together. This applies
432/// mappings to the value numbers in the LHS/RHS intervals as specified. If
433/// the intervals are not joinable, this aborts.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000434void LiveInterval::join(LiveInterval &Other,
435 const int *LHSValNoAssignments,
David Greenee97f0772007-09-06 19:46:46 +0000436 const int *RHSValNoAssignments,
Evan Chengd78907d2009-06-14 20:22:55 +0000437 SmallVector<VNInfo*, 16> &NewVNInfo,
438 MachineRegisterInfo *MRI) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000439 // Determine if any of our live range values are mapped. This is uncommon, so
Evan Cheng8b7533e2007-09-01 02:03:17 +0000440 // we want to avoid the interval scan if not.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000441 bool MustMapCurValNos = false;
Evan Cheng8b7533e2007-09-01 02:03:17 +0000442 unsigned NumVals = getNumValNums();
443 unsigned NumNewVals = NewVNInfo.size();
444 for (unsigned i = 0; i != NumVals; ++i) {
445 unsigned LHSValID = LHSValNoAssignments[i];
446 if (i != LHSValID ||
Evan Cheng319802c2007-09-05 21:46:51 +0000447 (NewVNInfo[LHSValID] && NewVNInfo[LHSValID] != getValNumInfo(i)))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000448 MustMapCurValNos = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000449 }
Evan Cheng983b81d2007-08-29 20:45:00 +0000450
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000451 // If we have to apply a mapping to our base interval assignment, rewrite it
452 // now.
453 if (MustMapCurValNos) {
454 // Map the first live range.
455 iterator OutIt = begin();
Evan Cheng983b81d2007-08-29 20:45:00 +0000456 OutIt->valno = NewVNInfo[LHSValNoAssignments[OutIt->valno->id]];
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000457 ++OutIt;
458 for (iterator I = OutIt, E = end(); I != E; ++I) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000459 OutIt->valno = NewVNInfo[LHSValNoAssignments[I->valno->id]];
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000460
461 // If this live range has the same value # as its immediate predecessor,
462 // and if they are neighbors, remove one LiveRange. This happens when we
463 // have [0,3:0)[4,7:1) and map 0/1 onto the same value #.
Evan Cheng983b81d2007-08-29 20:45:00 +0000464 if (OutIt->valno == (OutIt-1)->valno && (OutIt-1)->end == OutIt->start) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000465 (OutIt-1)->end = OutIt->end;
466 } else {
467 if (I != OutIt) {
468 OutIt->start = I->start;
469 OutIt->end = I->end;
470 }
471
472 // Didn't merge, on to the next one.
473 ++OutIt;
474 }
475 }
476
477 // If we merge some live ranges, chop off the end.
478 ranges.erase(OutIt, end());
479 }
Evan Cheng816a7f32007-08-11 00:59:19 +0000480
Evan Cheng983b81d2007-08-29 20:45:00 +0000481 // Remember assignements because val# ids are changing.
Evan Cheng8b7533e2007-09-01 02:03:17 +0000482 SmallVector<unsigned, 16> OtherAssignments;
Evan Cheng983b81d2007-08-29 20:45:00 +0000483 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
484 OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]);
485
486 // Update val# info. Renumber them and make sure they all belong to this
Evan Cheng319802c2007-09-05 21:46:51 +0000487 // LiveInterval now. Also remove dead val#'s.
488 unsigned NumValNos = 0;
489 for (unsigned i = 0; i < NumNewVals; ++i) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000490 VNInfo *VNI = NewVNInfo[i];
Evan Cheng319802c2007-09-05 21:46:51 +0000491 if (VNI) {
Evan Chengffba3de2009-04-28 06:24:09 +0000492 if (NumValNos >= NumVals)
Evan Cheng319802c2007-09-05 21:46:51 +0000493 valnos.push_back(VNI);
494 else
495 valnos[NumValNos] = VNI;
496 VNI->id = NumValNos++; // Renumber val#.
Evan Cheng8b7533e2007-09-01 02:03:17 +0000497 }
498 }
Evan Cheng8b7533e2007-09-01 02:03:17 +0000499 if (NumNewVals < NumVals)
500 valnos.resize(NumNewVals); // shrinkify
Evan Cheng816a7f32007-08-11 00:59:19 +0000501
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000502 // Okay, now insert the RHS live ranges into the LHS.
503 iterator InsertPos = begin();
Evan Cheng983b81d2007-08-29 20:45:00 +0000504 unsigned RangeNo = 0;
505 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I, ++RangeNo) {
506 // Map the valno in the other live range to the current live range.
507 I->valno = NewVNInfo[OtherAssignments[RangeNo]];
Evan Cheng319802c2007-09-05 21:46:51 +0000508 assert(I->valno && "Adding a dead range?");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000509 InsertPos = addRangeFrom(*I, InsertPos);
510 }
511
David Greenea7f6e082009-07-22 20:08:25 +0000512 ComputeJoinedWeight(Other);
Evan Chengd78907d2009-06-14 20:22:55 +0000513
514 // Update regalloc hint if currently there isn't one.
515 if (TargetRegisterInfo::isVirtualRegister(reg) &&
516 TargetRegisterInfo::isVirtualRegister(Other.reg)) {
Evan Cheng41169552009-06-15 08:28:29 +0000517 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(reg);
518 if (Hint.first == 0 && Hint.second == 0) {
519 std::pair<unsigned, unsigned> OtherHint =
Evan Chengd78907d2009-06-14 20:22:55 +0000520 MRI->getRegAllocationHint(Other.reg);
Evan Cheng41169552009-06-15 08:28:29 +0000521 if (OtherHint.first || OtherHint.second)
Evan Chengd78907d2009-06-14 20:22:55 +0000522 MRI->setRegAllocationHint(reg, OtherHint.first, OtherHint.second);
523 }
524 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000525}
526
527/// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
528/// interval as the specified value number. The LiveRanges in RHS are
529/// allowed to overlap with LiveRanges in the current interval, but only if
530/// the overlapping LiveRanges have the specified value number.
531void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS,
Evan Cheng983b81d2007-08-29 20:45:00 +0000532 VNInfo *LHSValNo) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000533 // TODO: Make this more efficient.
534 iterator InsertPos = begin();
535 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000536 // Map the valno in the other live range to the current live range.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000537 LiveRange Tmp = *I;
Evan Cheng983b81d2007-08-29 20:45:00 +0000538 Tmp.valno = LHSValNo;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000539 InsertPos = addRangeFrom(Tmp, InsertPos);
540 }
541}
542
543
Evan Cheng687d1082007-10-12 08:50:34 +0000544/// MergeValueInAsValue - Merge all of the live ranges of a specific val#
545/// in RHS into this live interval as the specified value number.
546/// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
Evan Cheng303fed82007-10-17 02:13:29 +0000547/// current interval, it will replace the value numbers of the overlaped
548/// live ranges with the specified value number.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000549void LiveInterval::MergeValueInAsValue(
550 const LiveInterval &RHS,
551 const VNInfo *RHSValNo, VNInfo *LHSValNo) {
Evan Cheng303fed82007-10-17 02:13:29 +0000552 SmallVector<VNInfo*, 4> ReplacedValNos;
553 iterator IP = begin();
Evan Cheng687d1082007-10-12 08:50:34 +0000554 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
Jakob Stoklund Olesen529c7132010-06-23 15:34:36 +0000555 assert(I->valno == RHS.getValNumInfo(I->valno->id) && "Bad VNInfo");
Evan Cheng687d1082007-10-12 08:50:34 +0000556 if (I->valno != RHSValNo)
557 continue;
Lang Hamesd6a717c2009-11-03 23:52:08 +0000558 SlotIndex Start = I->start, End = I->end;
Evan Cheng303fed82007-10-17 02:13:29 +0000559 IP = std::upper_bound(IP, end(), Start);
560 // If the start of this range overlaps with an existing liverange, trim it.
561 if (IP != begin() && IP[-1].end > Start) {
Evan Chengc7fe7be2008-01-30 22:44:55 +0000562 if (IP[-1].valno != LHSValNo) {
563 ReplacedValNos.push_back(IP[-1].valno);
564 IP[-1].valno = LHSValNo; // Update val#.
Evan Cheng303fed82007-10-17 02:13:29 +0000565 }
566 Start = IP[-1].end;
567 // Trimmed away the whole range?
568 if (Start >= End) continue;
569 }
570 // If the end of this range overlaps with an existing liverange, trim it.
571 if (IP != end() && End > IP->start) {
572 if (IP->valno != LHSValNo) {
573 ReplacedValNos.push_back(IP->valno);
574 IP->valno = LHSValNo; // Update val#.
575 }
576 End = IP->start;
577 // If this trimmed away the whole range, ignore it.
578 if (Start == End) continue;
579 }
580
Evan Cheng687d1082007-10-12 08:50:34 +0000581 // Map the valno in the other live range to the current live range.
Evan Cheng303fed82007-10-17 02:13:29 +0000582 IP = addRangeFrom(LiveRange(Start, End, LHSValNo), IP);
583 }
584
585
586 SmallSet<VNInfo*, 4> Seen;
587 for (unsigned i = 0, e = ReplacedValNos.size(); i != e; ++i) {
588 VNInfo *V1 = ReplacedValNos[i];
589 if (Seen.insert(V1)) {
590 bool isDead = true;
591 for (const_iterator I = begin(), E = end(); I != E; ++I)
592 if (I->valno == V1) {
593 isDead = false;
594 break;
595 }
596 if (isDead) {
597 // Now that V1 is dead, remove it. If it is the largest value number,
598 // just nuke it (and any other deleted values neighboring it), otherwise
599 // mark it as ~1U so it can be nuked later.
600 if (V1->id == getNumValNums()-1) {
601 do {
Evan Cheng303fed82007-10-17 02:13:29 +0000602 valnos.pop_back();
Lang Hames4eb8fc82009-06-17 21:01:20 +0000603 } while (!valnos.empty() && valnos.back()->isUnused());
Evan Cheng303fed82007-10-17 02:13:29 +0000604 } else {
Lang Hames4eb8fc82009-06-17 21:01:20 +0000605 V1->setIsUnused(true);
Evan Cheng303fed82007-10-17 02:13:29 +0000606 }
607 }
608 }
Evan Cheng687d1082007-10-12 08:50:34 +0000609 }
610}
611
612
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000613/// MergeInClobberRanges - For any live ranges that are not defined in the
614/// current interval, but are defined in the Clobbers interval, mark them
615/// used with an unknown definition value.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000616void LiveInterval::MergeInClobberRanges(LiveIntervals &li_,
617 const LiveInterval &Clobbers,
Benjamin Kramer128fdd92010-03-30 20:16:45 +0000618 VNInfo::Allocator &VNInfoAllocator) {
Dan Gohmanc8424de2008-08-14 18:13:49 +0000619 if (Clobbers.empty()) return;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000620
Evan Cheng1068b722009-04-25 09:25:19 +0000621 DenseMap<VNInfo*, VNInfo*> ValNoMaps;
Evan Cheng4cc387f2009-04-25 20:20:15 +0000622 VNInfo *UnusedValNo = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000623 iterator IP = begin();
624 for (const_iterator I = Clobbers.begin(), E = Clobbers.end(); I != E; ++I) {
Evan Cheng1068b722009-04-25 09:25:19 +0000625 // For every val# in the Clobbers interval, create a new "unknown" val#.
626 VNInfo *ClobberValNo = 0;
627 DenseMap<VNInfo*, VNInfo*>::iterator VI = ValNoMaps.find(I->valno);
628 if (VI != ValNoMaps.end())
629 ClobberValNo = VI->second;
Evan Cheng4cc387f2009-04-25 20:20:15 +0000630 else if (UnusedValNo)
631 ClobberValNo = UnusedValNo;
Evan Cheng1068b722009-04-25 09:25:19 +0000632 else {
Lang Hamesd8f30992009-09-04 20:41:11 +0000633 UnusedValNo = ClobberValNo =
Lang Hamesd6a717c2009-11-03 23:52:08 +0000634 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
Evan Cheng1068b722009-04-25 09:25:19 +0000635 ValNoMaps.insert(std::make_pair(I->valno, ClobberValNo));
636 }
637
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000638 bool Done = false;
Lang Hamesd6a717c2009-11-03 23:52:08 +0000639 SlotIndex Start = I->start, End = I->end;
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000640 // If a clobber range starts before an existing range and ends after
641 // it, the clobber range will need to be split into multiple ranges.
642 // Loop until the entire clobber range is handled.
643 while (!Done) {
644 Done = true;
645 IP = std::upper_bound(IP, end(), Start);
Lang Hamesd6a717c2009-11-03 23:52:08 +0000646 SlotIndex SubRangeStart = Start;
647 SlotIndex SubRangeEnd = End;
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000648
649 // If the start of this range overlaps with an existing liverange, trim it.
650 if (IP != begin() && IP[-1].end > SubRangeStart) {
651 SubRangeStart = IP[-1].end;
652 // Trimmed away the whole range?
653 if (SubRangeStart >= SubRangeEnd) continue;
654 }
655 // If the end of this range overlaps with an existing liverange, trim it.
656 if (IP != end() && SubRangeEnd > IP->start) {
657 // If the clobber live range extends beyond the existing live range,
658 // it'll need at least another live range, so set the flag to keep
659 // iterating.
660 if (SubRangeEnd > IP->end) {
661 Start = IP->end;
662 Done = false;
663 }
664 SubRangeEnd = IP->start;
665 // If this trimmed away the whole range, ignore it.
666 if (SubRangeStart == SubRangeEnd) continue;
667 }
668
669 // Insert the clobber interval.
670 IP = addRangeFrom(LiveRange(SubRangeStart, SubRangeEnd, ClobberValNo),
671 IP);
Evan Cheng4cc387f2009-04-25 20:20:15 +0000672 UnusedValNo = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000673 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000674 }
Evan Chenga6458fe2009-04-27 17:35:19 +0000675
676 if (UnusedValNo) {
677 // Delete the last unused val#.
678 valnos.pop_back();
Evan Chenga6458fe2009-04-27 17:35:19 +0000679 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000680}
681
Lang Hamesd6a717c2009-11-03 23:52:08 +0000682void LiveInterval::MergeInClobberRange(LiveIntervals &li_,
683 SlotIndex Start,
684 SlotIndex End,
Benjamin Kramer128fdd92010-03-30 20:16:45 +0000685 VNInfo::Allocator &VNInfoAllocator) {
Evan Chenged642cb2009-03-11 00:03:21 +0000686 // Find a value # to use for the clobber ranges. If there is already a value#
687 // for unknown values, use it.
Lang Hamesd8f30992009-09-04 20:41:11 +0000688 VNInfo *ClobberValNo =
Lang Hamesd6a717c2009-11-03 23:52:08 +0000689 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
Evan Chenged642cb2009-03-11 00:03:21 +0000690
691 iterator IP = begin();
692 IP = std::upper_bound(IP, end(), Start);
693
694 // If the start of this range overlaps with an existing liverange, trim it.
695 if (IP != begin() && IP[-1].end > Start) {
696 Start = IP[-1].end;
697 // Trimmed away the whole range?
698 if (Start >= End) return;
699 }
700 // If the end of this range overlaps with an existing liverange, trim it.
701 if (IP != end() && End > IP->start) {
702 End = IP->start;
703 // If this trimmed away the whole range, ignore it.
704 if (Start == End) return;
705 }
706
707 // Insert the clobber interval.
708 addRangeFrom(LiveRange(Start, End, ClobberValNo), IP);
709}
710
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000711/// MergeValueNumberInto - This method is called when two value nubmers
712/// are found to be equivalent. This eliminates V1, replacing all
713/// LiveRanges with the V1 value number with the V2 value number. This can
714/// cause merging of V1/V2 values numbers and compaction of the value space.
Owen Anderson85f86f32009-02-02 22:42:01 +0000715VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000716 assert(V1 != V2 && "Identical value#'s are always equivalent!");
717
718 // This code actually merges the (numerically) larger value number into the
719 // smaller value number, which is likely to allow us to compactify the value
720 // space. The only thing we have to be careful of is to preserve the
721 // instruction that defines the result value.
722
723 // Make sure V2 is smaller than V1.
Evan Cheng983b81d2007-08-29 20:45:00 +0000724 if (V1->id < V2->id) {
Lang Hames87972832009-08-10 23:43:28 +0000725 V1->copyFrom(*V2);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000726 std::swap(V1, V2);
727 }
728
729 // Merge V1 live ranges into V2.
730 for (iterator I = begin(); I != end(); ) {
731 iterator LR = I++;
Evan Cheng983b81d2007-08-29 20:45:00 +0000732 if (LR->valno != V1) continue; // Not a V1 LiveRange.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000733
734 // Okay, we found a V1 live range. If it had a previous, touching, V2 live
735 // range, extend it.
736 if (LR != begin()) {
737 iterator Prev = LR-1;
Evan Cheng983b81d2007-08-29 20:45:00 +0000738 if (Prev->valno == V2 && Prev->end == LR->start) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000739 Prev->end = LR->end;
740
741 // Erase this live-range.
742 ranges.erase(LR);
743 I = Prev+1;
744 LR = Prev;
745 }
746 }
747
748 // Okay, now we have a V1 or V2 live range that is maximally merged forward.
749 // Ensure that it is a V2 live-range.
Evan Cheng983b81d2007-08-29 20:45:00 +0000750 LR->valno = V2;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000751
752 // If we can merge it into later V2 live ranges, do so now. We ignore any
753 // following V1 live ranges, as they will be merged in subsequent iterations
754 // of the loop.
755 if (I != end()) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000756 if (I->start == LR->end && I->valno == V2) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000757 LR->end = I->end;
758 ranges.erase(I);
759 I = LR+1;
760 }
761 }
762 }
763
764 // Now that V1 is dead, remove it. If it is the largest value number, just
765 // nuke it (and any other deleted values neighboring it), otherwise mark it as
766 // ~1U so it can be nuked later.
Evan Cheng983b81d2007-08-29 20:45:00 +0000767 if (V1->id == getNumValNums()-1) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000768 do {
Evan Cheng983b81d2007-08-29 20:45:00 +0000769 valnos.pop_back();
Lang Hames4eb8fc82009-06-17 21:01:20 +0000770 } while (valnos.back()->isUnused());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000771 } else {
Lang Hames4eb8fc82009-06-17 21:01:20 +0000772 V1->setIsUnused(true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000773 }
Owen Anderson85f86f32009-02-02 22:42:01 +0000774
775 return V2;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000776}
777
Evan Cheng687d1082007-10-12 08:50:34 +0000778void LiveInterval::Copy(const LiveInterval &RHS,
Evan Chengd78907d2009-06-14 20:22:55 +0000779 MachineRegisterInfo *MRI,
Benjamin Kramer128fdd92010-03-30 20:16:45 +0000780 VNInfo::Allocator &VNInfoAllocator) {
Evan Cheng687d1082007-10-12 08:50:34 +0000781 ranges.clear();
782 valnos.clear();
Evan Cheng41169552009-06-15 08:28:29 +0000783 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(RHS.reg);
Evan Chengd78907d2009-06-14 20:22:55 +0000784 MRI->setRegAllocationHint(reg, Hint.first, Hint.second);
785
Evan Cheng687d1082007-10-12 08:50:34 +0000786 weight = RHS.weight;
787 for (unsigned i = 0, e = RHS.getNumValNums(); i != e; ++i) {
788 const VNInfo *VNI = RHS.getValNumInfo(i);
Lang Hames4eb8fc82009-06-17 21:01:20 +0000789 createValueCopy(VNI, VNInfoAllocator);
Evan Cheng687d1082007-10-12 08:50:34 +0000790 }
791 for (unsigned i = 0, e = RHS.ranges.size(); i != e; ++i) {
792 const LiveRange &LR = RHS.ranges[i];
793 addRange(LiveRange(LR.start, LR.end, getValNumInfo(LR.valno->id)));
794 }
795}
796
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000797unsigned LiveInterval::getSize() const {
798 unsigned Sum = 0;
799 for (const_iterator I = begin(), E = end(); I != E; ++I)
Lang Hamesd8f30992009-09-04 20:41:11 +0000800 Sum += I->start.distance(I->end);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000801 return Sum;
802}
803
David Greenea7f6e082009-07-22 20:08:25 +0000804/// ComputeJoinedWeight - Set the weight of a live interval Joined
805/// after Other has been merged into it.
806void LiveInterval::ComputeJoinedWeight(const LiveInterval &Other) {
807 // If either of these intervals was spilled, the weight is the
808 // weight of the non-spilled interval. This can only happen with
809 // iterative coalescers.
810
David Greened7d71ae2009-07-22 22:32:19 +0000811 if (Other.weight != HUGE_VALF) {
812 weight += Other.weight;
813 }
814 else if (weight == HUGE_VALF &&
David Greenea7f6e082009-07-22 20:08:25 +0000815 !TargetRegisterInfo::isPhysicalRegister(reg)) {
816 // Remove this assert if you have an iterative coalescer
817 assert(0 && "Joining to spilled interval");
818 weight = Other.weight;
819 }
David Greenea7f6e082009-07-22 20:08:25 +0000820 else {
821 // Otherwise the weight stays the same
822 // Remove this assert if you have an iterative coalescer
823 assert(0 && "Joining from spilled interval");
824 }
825}
826
Daniel Dunbarf55f61f2009-07-24 10:36:58 +0000827raw_ostream& llvm::operator<<(raw_ostream& os, const LiveRange &LR) {
828 return os << '[' << LR.start << ',' << LR.end << ':' << LR.valno->id << ")";
829}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000830
831void LiveRange::dump() const {
David Greene23c23922010-01-04 22:41:43 +0000832 dbgs() << *this << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000833}
834
Chris Lattner15be2672009-08-23 03:47:42 +0000835void LiveInterval::print(raw_ostream &OS, const TargetRegisterInfo *TRI) const {
Evan Cheng922e5f62008-06-23 21:03:19 +0000836 if (isStackSlot())
837 OS << "SS#" << getStackSlotIndex();
Evan Cheng14f8a502008-06-04 09:18:41 +0000838 else if (TRI && TargetRegisterInfo::isPhysicalRegister(reg))
Bill Wendling9b0baeb2008-02-26 21:47:57 +0000839 OS << TRI->getName(reg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000840 else
841 OS << "%reg" << reg;
842
843 OS << ',' << weight;
844
845 if (empty())
Evan Cheng14f8a502008-06-04 09:18:41 +0000846 OS << " EMPTY";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000847 else {
848 OS << " = ";
849 for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
Jakob Stoklund Olesen529c7132010-06-23 15:34:36 +0000850 E = ranges.end(); I != E; ++I) {
851 OS << *I;
852 assert(I->valno == getValNumInfo(I->valno->id) && "Bad VNInfo");
853 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000854 }
Jakob Stoklund Olesen5ccea1a2010-06-25 22:53:05 +0000855
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000856 // Print value number info.
857 if (getNumValNums()) {
858 OS << " ";
Evan Chengba990522007-08-28 08:28:51 +0000859 unsigned vnum = 0;
860 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
861 ++i, ++vnum) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000862 const VNInfo *vni = *i;
Evan Chengba990522007-08-28 08:28:51 +0000863 if (vnum) OS << " ";
864 OS << vnum << "@";
Lang Hames4eb8fc82009-06-17 21:01:20 +0000865 if (vni->isUnused()) {
Evan Cheng58c2b762007-08-08 03:00:28 +0000866 OS << "x";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000867 } else {
Lang Hames75730ab2009-12-09 05:39:12 +0000868 if (!vni->isDefAccurate() && !vni->isPHIDef())
Evan Cheng816a7f32007-08-11 00:59:19 +0000869 OS << "?";
870 else
Evan Cheng983b81d2007-08-29 20:45:00 +0000871 OS << vni->def;
Evan Cheng4151fde2007-08-07 23:49:57 +0000872 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000873 }
874 }
875}
876
877void LiveInterval::dump() const {
David Greene23c23922010-01-04 22:41:43 +0000878 dbgs() << *this << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000879}
880
881
Daniel Dunbarf55f61f2009-07-24 10:36:58 +0000882void LiveRange::print(raw_ostream &os) const {
883 os << *this;
884}