blob: 0be4e9bed4127513c2b1f3c60a148782df966a8d [file] [log] [blame]
Chris Lattner78f62e32004-07-23 17:49:16 +00001//===-- LiveInterval.cpp - Live Interval Representation -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the LiveRange and LiveInterval classes. Given some
11// numbering of each the machine instructions an interval [i, j) is said to be a
12// live interval for register v if there is no instruction with number j' > j
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 Wendling3f6f0fd2006-11-28 02:08:17 +000021#include "llvm/CodeGen/LiveInterval.h"
Bill Wendlingbc0d5f82006-11-28 03:31:29 +000022#include "llvm/ADT/STLExtras.h"
Bill Wendling3f6f0fd2006-11-28 02:08:17 +000023#include "llvm/Support/Streams.h"
Chris Lattnerc08d7862005-05-14 05:34:15 +000024#include "llvm/Target/MRegisterInfo.h"
Alkis Evlogimenosfc59e0e2004-09-28 02:38:58 +000025#include <algorithm>
Chris Lattner038747f2004-07-24 02:52:23 +000026#include <map>
Jeff Cohenb82309f2006-12-15 22:57:14 +000027#include <ostream>
Chris Lattner78f62e32004-07-23 17:49:16 +000028using namespace llvm;
29
30// An example for liveAt():
31//
Chris Lattner2fcc5e42004-07-23 18:40:00 +000032// this = [1,4), liveAt(0) will return false. The instruction defining this
33// spans slots [0,3]. The interval belongs to an spilled definition of the
34// variable it represents. This is because slot 1 is used (def slot) and spans
35// up to slot 3 (store slot).
Chris Lattner78f62e32004-07-23 17:49:16 +000036//
Chris Lattnerc96d2992004-07-23 18:13:24 +000037bool LiveInterval::liveAt(unsigned I) const {
38 Ranges::const_iterator r = std::upper_bound(ranges.begin(), ranges.end(), I);
Misha Brukman835702a2005-04-21 22:36:52 +000039
Chris Lattner78f62e32004-07-23 17:49:16 +000040 if (r == ranges.begin())
41 return false;
42
43 --r;
Chris Lattner2fcc5e42004-07-23 18:40:00 +000044 return r->contains(I);
Chris Lattner78f62e32004-07-23 17:49:16 +000045}
46
Chris Lattnercb0c9652004-11-18 03:47:34 +000047// overlaps - Return true if the intersection of the two live intervals is
48// not empty.
49//
Chris Lattner78f62e32004-07-23 17:49:16 +000050// An example for overlaps():
51//
52// 0: A = ...
53// 4: B = ...
54// 8: C = A + B ;; last use of A
55//
56// The live intervals should look like:
57//
58// A = [3, 11)
59// B = [7, x)
60// C = [11, y)
61//
62// A->overlaps(C) should return false since we want to be able to join
63// A and C.
Chris Lattnercb0c9652004-11-18 03:47:34 +000064//
65bool LiveInterval::overlapsFrom(const LiveInterval& other,
66 const_iterator StartPos) const {
67 const_iterator i = begin();
68 const_iterator ie = end();
69 const_iterator j = StartPos;
70 const_iterator je = other.end();
71
72 assert((StartPos->start <= i->start || StartPos == other.begin()) &&
Chris Lattner7598c312004-11-18 04:02:11 +000073 StartPos != other.end() && "Bogus start position hint!");
Chris Lattnerccc75d4f2004-07-25 07:11:19 +000074
Chris Lattner78f62e32004-07-23 17:49:16 +000075 if (i->start < j->start) {
Chris Lattner2fcc5e42004-07-23 18:40:00 +000076 i = std::upper_bound(i, ie, j->start);
Chris Lattner78f62e32004-07-23 17:49:16 +000077 if (i != ranges.begin()) --i;
Chris Lattner2fcc5e42004-07-23 18:40:00 +000078 } else if (j->start < i->start) {
Chris Lattner5684f482004-12-04 01:22:09 +000079 ++StartPos;
80 if (StartPos != other.end() && StartPos->start <= i->start) {
81 assert(StartPos < other.end() && i < end());
Chris Lattner7598c312004-11-18 04:02:11 +000082 j = std::upper_bound(j, je, i->start);
83 if (j != other.ranges.begin()) --j;
84 }
Chris Lattner2fcc5e42004-07-23 18:40:00 +000085 } else {
86 return true;
Chris Lattner78f62e32004-07-23 17:49:16 +000087 }
88
Chris Lattnere3b9cb92004-11-18 05:28:21 +000089 if (j == je) return false;
90
91 while (i != ie) {
Chris Lattner78f62e32004-07-23 17:49:16 +000092 if (i->start > j->start) {
Alkis Evlogimenoscf72e7f2004-07-24 11:44:15 +000093 std::swap(i, j);
94 std::swap(ie, je);
Chris Lattner78f62e32004-07-23 17:49:16 +000095 }
Chris Lattner78f62e32004-07-23 17:49:16 +000096
97 if (i->end > j->start)
98 return true;
99 ++i;
100 }
101
102 return false;
103}
104
Chris Lattnerb4acba42004-07-23 19:38:44 +0000105/// extendIntervalEndTo - This method is used when we want to extend the range
106/// specified by I to end at the specified endpoint. To do this, we should
107/// merge and eliminate all ranges that this will overlap with. The iterator is
108/// not invalidated.
109void LiveInterval::extendIntervalEndTo(Ranges::iterator I, unsigned NewEnd) {
110 assert(I != ranges.end() && "Not a valid interval!");
Chris Lattner038747f2004-07-24 02:52:23 +0000111 unsigned ValId = I->ValId;
Evan Cheng74c69f72007-08-14 01:56:58 +0000112 unsigned OldEnd = I->end;
Chris Lattner78f62e32004-07-23 17:49:16 +0000113
Chris Lattnerb4acba42004-07-23 19:38:44 +0000114 // Search for the first interval that we can't merge with.
115 Ranges::iterator MergeTo = next(I);
Chris Lattner038747f2004-07-24 02:52:23 +0000116 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
117 assert(MergeTo->ValId == ValId && "Cannot merge with differing values!");
118 }
Chris Lattnerb4acba42004-07-23 19:38:44 +0000119
120 // If NewEnd was in the middle of an interval, make sure to get its endpoint.
121 I->end = std::max(NewEnd, prior(MergeTo)->end);
122
Chris Lattner3cf40792005-10-20 07:39:25 +0000123 // Erase any dead ranges.
Chris Lattnerb4acba42004-07-23 19:38:44 +0000124 ranges.erase(next(I), MergeTo);
Evan Cheng05cc4862007-08-11 00:59:19 +0000125
126 // Update kill info.
Evan Cheng74c69f72007-08-14 01:56:58 +0000127 removeKillForValNum(ValId, OldEnd, I->end-1);
Evan Cheng05cc4862007-08-11 00:59:19 +0000128
Chris Lattner3cf40792005-10-20 07:39:25 +0000129 // If the newly formed range now touches the range after it and if they have
130 // the same value number, merge the two ranges into one range.
Chris Lattnerb7b75e12005-10-20 22:50:10 +0000131 Ranges::iterator Next = next(I);
Chris Lattner76c97af2005-10-21 06:41:30 +0000132 if (Next != ranges.end() && Next->start <= I->end && Next->ValId == ValId) {
Chris Lattnerb7b75e12005-10-20 22:50:10 +0000133 I->end = Next->end;
134 ranges.erase(Next);
Chris Lattner3cf40792005-10-20 07:39:25 +0000135 }
Chris Lattnerb4acba42004-07-23 19:38:44 +0000136}
137
138
139/// extendIntervalStartTo - This method is used when we want to extend the range
140/// specified by I to start at the specified endpoint. To do this, we should
141/// merge and eliminate all ranges that this will overlap with.
Misha Brukman835702a2005-04-21 22:36:52 +0000142LiveInterval::Ranges::iterator
Chris Lattnerb4acba42004-07-23 19:38:44 +0000143LiveInterval::extendIntervalStartTo(Ranges::iterator I, unsigned NewStart) {
144 assert(I != ranges.end() && "Not a valid interval!");
Chris Lattner038747f2004-07-24 02:52:23 +0000145 unsigned ValId = I->ValId;
Chris Lattnerb4acba42004-07-23 19:38:44 +0000146
147 // Search for the first interval that we can't merge with.
148 Ranges::iterator MergeTo = I;
149 do {
150 if (MergeTo == ranges.begin()) {
151 I->start = NewStart;
Chris Lattner038747f2004-07-24 02:52:23 +0000152 ranges.erase(MergeTo, I);
Chris Lattnerb4acba42004-07-23 19:38:44 +0000153 return I;
154 }
Chris Lattner038747f2004-07-24 02:52:23 +0000155 assert(MergeTo->ValId == ValId && "Cannot merge with differing values!");
Chris Lattnerb4acba42004-07-23 19:38:44 +0000156 --MergeTo;
157 } while (NewStart <= MergeTo->start);
158
159 // If we start in the middle of another interval, just delete a range and
160 // extend that interval.
Chris Lattner038747f2004-07-24 02:52:23 +0000161 if (MergeTo->end >= NewStart && MergeTo->ValId == ValId) {
Chris Lattnerb4acba42004-07-23 19:38:44 +0000162 MergeTo->end = I->end;
163 } else {
164 // Otherwise, extend the interval right after.
165 ++MergeTo;
166 MergeTo->start = NewStart;
167 MergeTo->end = I->end;
168 }
169
170 ranges.erase(next(MergeTo), next(I));
171 return MergeTo;
172}
173
Chris Lattnerf4f0b192006-08-25 23:41:24 +0000174LiveInterval::iterator
175LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
Chris Lattnerb4acba42004-07-23 19:38:44 +0000176 unsigned Start = LR.start, End = LR.end;
Chris Lattnerf4f0b192006-08-25 23:41:24 +0000177 iterator it = std::upper_bound(From, ranges.end(), Start);
Chris Lattnerb4acba42004-07-23 19:38:44 +0000178
179 // If the inserted interval starts in the middle or right at the end of
180 // another interval, just extend that interval to contain the range of LR.
181 if (it != ranges.begin()) {
Chris Lattnerf4f0b192006-08-25 23:41:24 +0000182 iterator B = prior(it);
Chris Lattner038747f2004-07-24 02:52:23 +0000183 if (LR.ValId == B->ValId) {
184 if (B->start <= Start && B->end >= Start) {
185 extendIntervalEndTo(B, End);
186 return B;
187 }
188 } else {
189 // Check to make sure that we are not overlapping two live ranges with
190 // different ValId's.
191 assert(B->end <= Start &&
Brian Gaekea057cd22004-11-16 06:52:35 +0000192 "Cannot overlap two LiveRanges with differing ValID's"
193 " (did you def the same reg twice in a MachineInstr?)");
Chris Lattnerb4acba42004-07-23 19:38:44 +0000194 }
195 }
196
197 // Otherwise, if this range ends in the middle of, or right next to, another
198 // interval, merge it into that interval.
Chris Lattner038747f2004-07-24 02:52:23 +0000199 if (it != ranges.end())
200 if (LR.ValId == it->ValId) {
201 if (it->start <= End) {
202 it = extendIntervalStartTo(it, Start);
203
204 // If LR is a complete superset of an interval, we may need to grow its
205 // endpoint as well.
206 if (End > it->end)
207 extendIntervalEndTo(it, End);
208 return it;
209 }
210 } else {
211 // Check to make sure that we are not overlapping two live ranges with
212 // different ValId's.
213 assert(it->start >= End &&
214 "Cannot overlap two LiveRanges with differing ValID's");
215 }
Chris Lattnerb4acba42004-07-23 19:38:44 +0000216
217 // Otherwise, this is just a new range that doesn't interact with anything.
218 // Insert it.
219 return ranges.insert(it, LR);
Chris Lattner78f62e32004-07-23 17:49:16 +0000220}
221
Chris Lattner038747f2004-07-24 02:52:23 +0000222
223/// removeRange - Remove the specified range from this interval. Note that
224/// the range must already be in this interval in its entirety.
225void LiveInterval::removeRange(unsigned Start, unsigned End) {
226 // Find the LiveRange containing this span.
227 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
228 assert(I != ranges.begin() && "Range is not in interval!");
229 --I;
230 assert(I->contains(Start) && I->contains(End-1) &&
231 "Range is not entirely in interval!");
232
233 // If the span we are removing is at the start of the LiveRange, adjust it.
234 if (I->start == Start) {
Evan Cheng05cc4862007-08-11 00:59:19 +0000235 if (I->end == End) {
Evan Cheng5ca98c62007-08-13 07:12:23 +0000236 removeKillForValNum(I->ValId, Start, End);
Chris Lattner038747f2004-07-24 02:52:23 +0000237 ranges.erase(I); // Removed the whole LiveRange.
Evan Cheng05cc4862007-08-11 00:59:19 +0000238 } else
Chris Lattner038747f2004-07-24 02:52:23 +0000239 I->start = End;
240 return;
241 }
242
243 // Otherwise if the span we are removing is at the end of the LiveRange,
244 // adjust the other way.
245 if (I->end == End) {
Evan Cheng5ca98c62007-08-13 07:12:23 +0000246 removeKillForValNum(I->ValId, Start, End);
Chris Lattneraf7e8982004-07-25 05:43:53 +0000247 I->end = Start;
Chris Lattner038747f2004-07-24 02:52:23 +0000248 return;
249 }
250
251 // Otherwise, we are splitting the LiveRange into two pieces.
252 unsigned OldEnd = I->end;
253 I->end = Start; // Trim the old interval.
254
255 // Insert the new one.
256 ranges.insert(next(I), LiveRange(End, OldEnd, I->ValId));
257}
258
259/// getLiveRangeContaining - Return the live range that contains the
260/// specified index, or null if there is none.
Chris Lattnerbdf12102006-08-24 22:43:55 +0000261LiveInterval::const_iterator
262LiveInterval::FindLiveRangeContaining(unsigned Idx) const {
263 const_iterator It = std::upper_bound(begin(), end(), Idx);
Chris Lattner038747f2004-07-24 02:52:23 +0000264 if (It != ranges.begin()) {
Chris Lattnerbdf12102006-08-24 22:43:55 +0000265 --It;
266 if (It->contains(Idx))
267 return It;
Chris Lattner038747f2004-07-24 02:52:23 +0000268 }
269
Chris Lattnerbdf12102006-08-24 22:43:55 +0000270 return end();
Chris Lattner038747f2004-07-24 02:52:23 +0000271}
272
Chris Lattnerbdf12102006-08-24 22:43:55 +0000273LiveInterval::iterator
274LiveInterval::FindLiveRangeContaining(unsigned Idx) {
275 iterator It = std::upper_bound(begin(), end(), Idx);
Chris Lattner34434e92006-08-29 23:18:15 +0000276 if (It != begin()) {
Chris Lattnerbdf12102006-08-24 22:43:55 +0000277 --It;
278 if (It->contains(Idx))
279 return It;
280 }
281
282 return end();
283}
Chris Lattner038747f2004-07-24 02:52:23 +0000284
Chris Lattner34434e92006-08-29 23:18:15 +0000285/// join - Join two live intervals (this, and other) together. This applies
286/// mappings to the value numbers in the LHS/RHS intervals as specified. If
287/// the intervals are not joinable, this aborts.
288void LiveInterval::join(LiveInterval &Other, int *LHSValNoAssignments,
289 int *RHSValNoAssignments,
Evan Cheng0d0fee22007-08-07 23:49:57 +0000290 SmallVector<VNInfo, 16> &NewValueNumberInfo) {
Chris Lattner34434e92006-08-29 23:18:15 +0000291
292 // Determine if any of our live range values are mapped. This is uncommon, so
293 // we want to avoid the interval scan if not.
294 bool MustMapCurValNos = false;
295 for (unsigned i = 0, e = getNumValNums(); i != e; ++i) {
Evan Chenga5b10b32007-08-28 08:28:51 +0000296 if (getDefForValNum(i) == ~1U) continue; // tombstone value #
Chris Lattner34434e92006-08-29 23:18:15 +0000297 if (i != (unsigned)LHSValNoAssignments[i]) {
298 MustMapCurValNos = true;
299 break;
300 }
Chris Lattnerd9bbbb82004-07-24 03:41:50 +0000301 }
Chris Lattner122f2bc2006-08-26 01:28:16 +0000302
Chris Lattner34434e92006-08-29 23:18:15 +0000303 // If we have to apply a mapping to our base interval assignment, rewrite it
304 // now.
305 if (MustMapCurValNos) {
306 // Map the first live range.
307 iterator OutIt = begin();
308 OutIt->ValId = LHSValNoAssignments[OutIt->ValId];
309 ++OutIt;
310 for (iterator I = OutIt, E = end(); I != E; ++I) {
311 OutIt->ValId = LHSValNoAssignments[I->ValId];
312
313 // If this live range has the same value # as its immediate predecessor,
314 // and if they are neighbors, remove one LiveRange. This happens when we
315 // have [0,3:0)[4,7:1) and map 0/1 onto the same value #.
316 if (OutIt->ValId == (OutIt-1)->ValId && (OutIt-1)->end == OutIt->start) {
317 (OutIt-1)->end = OutIt->end;
318 } else {
319 if (I != OutIt) {
320 OutIt->start = I->start;
321 OutIt->end = I->end;
322 }
323
324 // Didn't merge, on to the next one.
325 ++OutIt;
326 }
327 }
328
329 // If we merge some live ranges, chop off the end.
330 ranges.erase(OutIt, end());
331 }
Evan Cheng05cc4862007-08-11 00:59:19 +0000332
333 // Update val# info first. Increasing live ranges may invalidate some kills.
334 ValueNumberInfo.clear();
Evan Chenga5b10b32007-08-28 08:28:51 +0000335 for (SmallVector<VNInfo, 16>::iterator I = NewValueNumberInfo.begin(),
336 E = NewValueNumberInfo.end(); I != E; ++I)
337 ValueNumberInfo.push_back(*I);
Evan Cheng05cc4862007-08-11 00:59:19 +0000338
Chris Lattner34434e92006-08-29 23:18:15 +0000339 // Okay, now insert the RHS live ranges into the LHS.
Chris Lattnerf4f0b192006-08-25 23:41:24 +0000340 iterator InsertPos = begin();
341 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I) {
Chris Lattner038747f2004-07-24 02:52:23 +0000342 // Map the ValId in the other live range to the current live range.
Chris Lattner34434e92006-08-29 23:18:15 +0000343 I->ValId = RHSValNoAssignments[I->ValId];
Chris Lattner038747f2004-07-24 02:52:23 +0000344 InsertPos = addRangeFrom(*I, InsertPos);
345 }
Chris Lattner34434e92006-08-29 23:18:15 +0000346
Chris Lattner038747f2004-07-24 02:52:23 +0000347 weight += Other.weight;
Evan Cheng57b52142007-04-17 20:25:11 +0000348 if (Other.preference && !preference)
349 preference = Other.preference;
Chris Lattner78f62e32004-07-23 17:49:16 +0000350}
351
Chris Lattner5a56d302006-09-02 05:26:59 +0000352/// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
353/// interval as the specified value number. The LiveRanges in RHS are
354/// allowed to overlap with LiveRanges in the current interval, but only if
355/// the overlapping LiveRanges have the specified value number.
356void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS,
357 unsigned LHSValNo) {
358 // TODO: Make this more efficient.
359 iterator InsertPos = begin();
360 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
361 // Map the ValId in the other live range to the current live range.
362 LiveRange Tmp = *I;
363 Tmp.ValId = LHSValNo;
364 InsertPos = addRangeFrom(Tmp, InsertPos);
365 }
366}
367
368
Chris Lattnerf4f0b192006-08-25 23:41:24 +0000369/// MergeInClobberRanges - For any live ranges that are not defined in the
370/// current interval, but are defined in the Clobbers interval, mark them
371/// used with an unknown definition value.
372void LiveInterval::MergeInClobberRanges(const LiveInterval &Clobbers) {
373 if (Clobbers.begin() == Clobbers.end()) return;
374
375 // Find a value # to use for the clobber ranges. If there is already a value#
376 // for unknown values, use it.
377 // FIXME: Use a single sentinal number for these!
Chris Lattneraa368082006-08-31 05:54:43 +0000378 unsigned ClobberValNo = getNextValue(~0U, 0);
Chris Lattnerf4f0b192006-08-25 23:41:24 +0000379
380 iterator IP = begin();
381 for (const_iterator I = Clobbers.begin(), E = Clobbers.end(); I != E; ++I) {
382 unsigned Start = I->start, End = I->end;
383 IP = std::upper_bound(IP, end(), Start);
384
385 // If the start of this range overlaps with an existing liverange, trim it.
386 if (IP != begin() && IP[-1].end > Start) {
387 Start = IP[-1].end;
388 // Trimmed away the whole range?
389 if (Start >= End) continue;
390 }
391 // If the end of this range overlaps with an existing liverange, trim it.
392 if (IP != end() && End > IP->start) {
393 End = IP->start;
394 // If this trimmed away the whole range, ignore it.
395 if (Start == End) continue;
396 }
397
398 // Insert the clobber interval.
399 IP = addRangeFrom(LiveRange(Start, End, ClobberValNo), IP);
400 }
401}
402
Chris Lattnerbdf12102006-08-24 22:43:55 +0000403/// MergeValueNumberInto - This method is called when two value nubmers
404/// are found to be equivalent. This eliminates V1, replacing all
405/// LiveRanges with the V1 value number with the V2 value number. This can
406/// cause merging of V1/V2 values numbers and compaction of the value space.
407void LiveInterval::MergeValueNumberInto(unsigned V1, unsigned V2) {
408 assert(V1 != V2 && "Identical value#'s are always equivalent!");
409
410 // This code actually merges the (numerically) larger value number into the
411 // smaller value number, which is likely to allow us to compactify the value
412 // space. The only thing we have to be careful of is to preserve the
413 // instruction that defines the result value.
414
415 // Make sure V2 is smaller than V1.
416 if (V1 < V2) {
Evan Cheng05cc4862007-08-11 00:59:19 +0000417 copyValNumInfo(V1, V2);
Chris Lattnerbdf12102006-08-24 22:43:55 +0000418 std::swap(V1, V2);
419 }
420
421 // Merge V1 live ranges into V2.
422 for (iterator I = begin(); I != end(); ) {
423 iterator LR = I++;
424 if (LR->ValId != V1) continue; // Not a V1 LiveRange.
425
426 // Okay, we found a V1 live range. If it had a previous, touching, V2 live
427 // range, extend it.
428 if (LR != begin()) {
429 iterator Prev = LR-1;
430 if (Prev->ValId == V2 && Prev->end == LR->start) {
431 Prev->end = LR->end;
432
433 // Erase this live-range.
434 ranges.erase(LR);
435 I = Prev+1;
436 LR = Prev;
437 }
438 }
439
440 // Okay, now we have a V1 or V2 live range that is maximally merged forward.
441 // Ensure that it is a V2 live-range.
442 LR->ValId = V2;
443
444 // If we can merge it into later V2 live ranges, do so now. We ignore any
445 // following V1 live ranges, as they will be merged in subsequent iterations
446 // of the loop.
447 if (I != end()) {
448 if (I->start == LR->end && I->ValId == V2) {
449 LR->end = I->end;
450 ranges.erase(I);
451 I = LR+1;
452 }
453 }
454 }
Chris Lattner24d42082006-08-24 23:22:59 +0000455
456 // Now that V1 is dead, remove it. If it is the largest value number, just
457 // nuke it (and any other deleted values neighboring it), otherwise mark it as
458 // ~1U so it can be nuked later.
Chris Lattner34434e92006-08-29 23:18:15 +0000459 if (V1 == getNumValNums()-1) {
Chris Lattner24d42082006-08-24 23:22:59 +0000460 do {
Chris Lattneraa368082006-08-31 05:54:43 +0000461 ValueNumberInfo.pop_back();
Evan Cheng0d0fee22007-08-07 23:49:57 +0000462 } while (ValueNumberInfo.back().def == ~1U);
Chris Lattner24d42082006-08-24 23:22:59 +0000463 } else {
Evan Chenga5b10b32007-08-28 08:28:51 +0000464 setDefForValNum(V1, ~1U);
Chris Lattner24d42082006-08-24 23:22:59 +0000465 }
Chris Lattnerbdf12102006-08-24 22:43:55 +0000466}
467
Evan Cheng57b52142007-04-17 20:25:11 +0000468unsigned LiveInterval::getSize() const {
469 unsigned Sum = 0;
470 for (const_iterator I = begin(), E = end(); I != E; ++I)
471 Sum += I->end - I->start;
472 return Sum;
473}
474
Chris Lattner78f62e32004-07-23 17:49:16 +0000475std::ostream& llvm::operator<<(std::ostream& os, const LiveRange &LR) {
Chris Lattner038747f2004-07-24 02:52:23 +0000476 return os << '[' << LR.start << ',' << LR.end << ':' << LR.ValId << ")";
Chris Lattner78f62e32004-07-23 17:49:16 +0000477}
478
Chris Lattner038747f2004-07-24 02:52:23 +0000479void LiveRange::dump() const {
Bill Wendlingf3baad32006-12-07 01:30:32 +0000480 cerr << *this << "\n";
Chris Lattner038747f2004-07-24 02:52:23 +0000481}
482
Bill Wendlinga77f1422006-12-17 05:15:13 +0000483void LiveInterval::print(std::ostream &OS, const MRegisterInfo *MRI) const {
Chris Lattnerc08d7862005-05-14 05:34:15 +0000484 if (MRI && MRegisterInfo::isPhysicalRegister(reg))
485 OS << MRI->getName(reg);
486 else
487 OS << "%reg" << reg;
Chris Lattner038747f2004-07-24 02:52:23 +0000488
Chris Lattnerc08d7862005-05-14 05:34:15 +0000489 OS << ',' << weight;
Chris Lattner78f62e32004-07-23 17:49:16 +0000490
Chris Lattnerc08d7862005-05-14 05:34:15 +0000491 if (empty())
492 OS << "EMPTY";
493 else {
494 OS << " = ";
495 for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
496 E = ranges.end(); I != E; ++I)
497 OS << *I;
498 }
Chris Lattner2e9f1bc2006-08-22 18:19:46 +0000499
500 // Print value number info.
Chris Lattner34434e92006-08-29 23:18:15 +0000501 if (getNumValNums()) {
Chris Lattner2e9f1bc2006-08-22 18:19:46 +0000502 OS << " ";
Evan Chenga5b10b32007-08-28 08:28:51 +0000503 unsigned vnum = 0;
504 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
505 ++i, ++vnum) {
506 const VNInfo &vni = *i;
507 if (vnum) OS << " ";
508 OS << vnum << "@";
509 if (vni.def == ~1U) {
Evan Chenga8c2f382007-08-08 03:00:28 +0000510 OS << "x";
Chris Lattner2e9f1bc2006-08-22 18:19:46 +0000511 } else {
Evan Chenga5b10b32007-08-28 08:28:51 +0000512 if (vni.def == ~0U)
Evan Cheng05cc4862007-08-11 00:59:19 +0000513 OS << "?";
514 else
Evan Chenga5b10b32007-08-28 08:28:51 +0000515 OS << vni.def;
516 unsigned ee = vni.kills.size();
517 if (ee) {
Evan Cheng05cc4862007-08-11 00:59:19 +0000518 OS << "-(";
Evan Chenga5b10b32007-08-28 08:28:51 +0000519 for (unsigned j = 0; j != ee; ++j) {
520 OS << vni.kills[j];
521 if (j != ee-1)
Evan Cheng05cc4862007-08-11 00:59:19 +0000522 OS << " ";
523 }
524 OS << ")";
525 }
Evan Cheng0d0fee22007-08-07 23:49:57 +0000526 }
Chris Lattner2e9f1bc2006-08-22 18:19:46 +0000527 }
528 }
Chris Lattner78f62e32004-07-23 17:49:16 +0000529}
Chris Lattner038747f2004-07-24 02:52:23 +0000530
531void LiveInterval::dump() const {
Bill Wendlingf3baad32006-12-07 01:30:32 +0000532 cerr << *this << "\n";
Chris Lattner038747f2004-07-24 02:52:23 +0000533}
Jeff Cohenb82309f2006-12-15 22:57:14 +0000534
535
Jeff Cohen29192e62006-12-16 02:15:42 +0000536void LiveRange::print(std::ostream &os) const {
537 os << *this;
Jeff Cohenb82309f2006-12-15 22:57:14 +0000538}