blob: bf0bdd183c8fd0705e918ec22d66a94394981709 [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
Dan Gohmanf17a25c2007-07-18 16:29:46 +000071// overlaps - Return true if the intersection of the two live intervals is
72// not empty.
73//
74// An example for overlaps():
75//
76// 0: A = ...
77// 4: B = ...
78// 8: C = A + B ;; last use of A
79//
80// The live intervals should look like:
81//
82// A = [3, 11)
83// B = [7, x)
84// C = [11, y)
85//
86// A->overlaps(C) should return false since we want to be able to join
87// A and C.
88//
89bool LiveInterval::overlapsFrom(const LiveInterval& other,
90 const_iterator StartPos) const {
91 const_iterator i = begin();
92 const_iterator ie = end();
93 const_iterator j = StartPos;
94 const_iterator je = other.end();
95
96 assert((StartPos->start <= i->start || StartPos == other.begin()) &&
97 StartPos != other.end() && "Bogus start position hint!");
98
99 if (i->start < j->start) {
100 i = std::upper_bound(i, ie, j->start);
101 if (i != ranges.begin()) --i;
102 } else if (j->start < i->start) {
103 ++StartPos;
104 if (StartPos != other.end() && StartPos->start <= i->start) {
105 assert(StartPos < other.end() && i < end());
106 j = std::upper_bound(j, je, i->start);
107 if (j != other.ranges.begin()) --j;
108 }
109 } else {
110 return true;
111 }
112
113 if (j == je) return false;
114
115 while (i != ie) {
116 if (i->start > j->start) {
117 std::swap(i, j);
118 std::swap(ie, je);
119 }
120
121 if (i->end > j->start)
122 return true;
123 ++i;
124 }
125
126 return false;
127}
128
Evan Cheng60c15e52009-04-18 08:52:15 +0000129/// overlaps - Return true if the live interval overlaps a range specified
130/// by [Start, End).
Lang Hamesd6a717c2009-11-03 23:52:08 +0000131bool LiveInterval::overlaps(SlotIndex Start, SlotIndex End) const {
Evan Cheng60c15e52009-04-18 08:52:15 +0000132 assert(Start < End && "Invalid range");
133 const_iterator I = begin();
134 const_iterator E = end();
135 const_iterator si = std::upper_bound(I, E, Start);
136 const_iterator ei = std::upper_bound(I, E, End);
137 if (si != ei)
138 return true;
139 if (si == I)
140 return false;
141 --si;
142 return si->contains(Start);
143}
144
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000145/// extendIntervalEndTo - This method is used when we want to extend the range
146/// specified by I to end at the specified endpoint. To do this, we should
147/// merge and eliminate all ranges that this will overlap with. The iterator is
148/// not invalidated.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000149void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000150 assert(I != ranges.end() && "Not a valid interval!");
Evan Cheng983b81d2007-08-29 20:45:00 +0000151 VNInfo *ValNo = I->valno;
Lang Hamesd6a717c2009-11-03 23:52:08 +0000152 SlotIndex OldEnd = I->end;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000153
154 // Search for the first interval that we can't merge with.
155 Ranges::iterator MergeTo = next(I);
156 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000157 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000158 }
159
160 // If NewEnd was in the middle of an interval, make sure to get its endpoint.
161 I->end = std::max(NewEnd, prior(MergeTo)->end);
162
163 // Erase any dead ranges.
164 ranges.erase(next(I), MergeTo);
Evan Cheng816a7f32007-08-11 00:59:19 +0000165
166 // Update kill info.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000167 ValNo->removeKills(OldEnd, I->end.getPrevSlot());
Evan Cheng816a7f32007-08-11 00:59:19 +0000168
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000169 // If the newly formed range now touches the range after it and if they have
170 // the same value number, merge the two ranges into one range.
171 Ranges::iterator Next = next(I);
Evan Cheng983b81d2007-08-29 20:45:00 +0000172 if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000173 I->end = Next->end;
174 ranges.erase(Next);
175 }
176}
177
178
179/// extendIntervalStartTo - This method is used when we want to extend the range
180/// specified by I to start at the specified endpoint. To do this, we should
181/// merge and eliminate all ranges that this will overlap with.
182LiveInterval::Ranges::iterator
Lang Hamesd6a717c2009-11-03 23:52:08 +0000183LiveInterval::extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStart) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184 assert(I != ranges.end() && "Not a valid interval!");
Evan Cheng983b81d2007-08-29 20:45:00 +0000185 VNInfo *ValNo = I->valno;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000186
187 // Search for the first interval that we can't merge with.
188 Ranges::iterator MergeTo = I;
189 do {
190 if (MergeTo == ranges.begin()) {
191 I->start = NewStart;
192 ranges.erase(MergeTo, I);
193 return I;
194 }
Evan Cheng983b81d2007-08-29 20:45:00 +0000195 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000196 --MergeTo;
197 } while (NewStart <= MergeTo->start);
198
199 // If we start in the middle of another interval, just delete a range and
200 // extend that interval.
Evan Cheng983b81d2007-08-29 20:45:00 +0000201 if (MergeTo->end >= NewStart && MergeTo->valno == ValNo) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000202 MergeTo->end = I->end;
203 } else {
204 // Otherwise, extend the interval right after.
205 ++MergeTo;
206 MergeTo->start = NewStart;
207 MergeTo->end = I->end;
208 }
209
210 ranges.erase(next(MergeTo), next(I));
211 return MergeTo;
212}
213
214LiveInterval::iterator
215LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
Lang Hamesd6a717c2009-11-03 23:52:08 +0000216 SlotIndex Start = LR.start, End = LR.end;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000217 iterator it = std::upper_bound(From, ranges.end(), Start);
218
219 // If the inserted interval starts in the middle or right at the end of
220 // another interval, just extend that interval to contain the range of LR.
221 if (it != ranges.begin()) {
222 iterator B = prior(it);
Evan Cheng983b81d2007-08-29 20:45:00 +0000223 if (LR.valno == B->valno) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224 if (B->start <= Start && B->end >= Start) {
225 extendIntervalEndTo(B, End);
226 return B;
227 }
228 } else {
229 // Check to make sure that we are not overlapping two live ranges with
Evan Cheng983b81d2007-08-29 20:45:00 +0000230 // different valno's.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000231 assert(B->end <= Start &&
232 "Cannot overlap two LiveRanges with differing ValID's"
233 " (did you def the same reg twice in a MachineInstr?)");
234 }
235 }
236
237 // Otherwise, if this range ends in the middle of, or right next to, another
238 // interval, merge it into that interval.
Anton Korobeynikov53422f62008-02-20 11:10:28 +0000239 if (it != ranges.end()) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000240 if (LR.valno == it->valno) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000241 if (it->start <= End) {
242 it = extendIntervalStartTo(it, Start);
243
244 // If LR is a complete superset of an interval, we may need to grow its
245 // endpoint as well.
246 if (End > it->end)
247 extendIntervalEndTo(it, End);
Evan Cheng8b70e632007-11-29 09:49:23 +0000248 else if (End < it->end)
Evan Cheng1f458152007-11-29 01:05:47 +0000249 // Overlapping intervals, there might have been a kill here.
Lang Hamesd8f30992009-09-04 20:41:11 +0000250 it->valno->removeKill(End);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000251 return it;
252 }
253 } else {
254 // Check to make sure that we are not overlapping two live ranges with
Evan Cheng983b81d2007-08-29 20:45:00 +0000255 // different valno's.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000256 assert(it->start >= End &&
257 "Cannot overlap two LiveRanges with differing ValID's");
258 }
Anton Korobeynikov53422f62008-02-20 11:10:28 +0000259 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000260
261 // Otherwise, this is just a new range that doesn't interact with anything.
262 // Insert it.
263 return ranges.insert(it, LR);
264}
265
Lang Hamesd8f30992009-09-04 20:41:11 +0000266/// isInOneLiveRange - Return true if the range specified is entirely in
Evan Cheng548bc502009-01-29 02:20:59 +0000267/// a single LiveRange of the live interval.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000268bool LiveInterval::isInOneLiveRange(SlotIndex Start, SlotIndex End) {
Evan Cheng548bc502009-01-29 02:20:59 +0000269 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
270 if (I == ranges.begin())
271 return false;
272 --I;
Lang Hamesd8f30992009-09-04 20:41:11 +0000273 return I->containsRange(Start, End);
Evan Cheng548bc502009-01-29 02:20:59 +0000274}
275
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000276
277/// removeRange - Remove the specified range from this interval. Note that
Evan Chengeb80af62009-01-29 00:06:09 +0000278/// the range must be in a single LiveRange in its entirety.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000279void LiveInterval::removeRange(SlotIndex Start, SlotIndex End,
Evan Cheng49208cf2008-02-13 02:48:26 +0000280 bool RemoveDeadValNo) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000281 // Find the LiveRange containing this span.
282 Ranges::iterator I = std::upper_bound(ranges.begin(), ranges.end(), Start);
283 assert(I != ranges.begin() && "Range is not in interval!");
284 --I;
Lang Hamesd8f30992009-09-04 20:41:11 +0000285 assert(I->containsRange(Start, End) && "Range is not entirely in interval!");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000286
287 // If the span we are removing is at the start of the LiveRange, adjust it.
Evan Cheng49208cf2008-02-13 02:48:26 +0000288 VNInfo *ValNo = I->valno;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000289 if (I->start == Start) {
Evan Cheng816a7f32007-08-11 00:59:19 +0000290 if (I->end == End) {
Lang Hamesd8f30992009-09-04 20:41:11 +0000291 ValNo->removeKills(Start, End);
Evan Cheng49208cf2008-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 {
Evan Cheng49208cf2008-02-13 02:48:26 +0000306 valnos.pop_back();
Lang Hames4eb8fc82009-06-17 21:01:20 +0000307 } while (!valnos.empty() && valnos.back()->isUnused());
Evan Cheng49208cf2008-02-13 02:48:26 +0000308 } else {
Lang Hames4eb8fc82009-06-17 21:01:20 +0000309 ValNo->setIsUnused(true);
Evan Cheng49208cf2008-02-13 02:48:26 +0000310 }
311 }
312 }
313
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000314 ranges.erase(I); // Removed the whole LiveRange.
Evan Cheng816a7f32007-08-11 00:59:19 +0000315 } else
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000316 I->start = End;
317 return;
318 }
319
320 // Otherwise if the span we are removing is at the end of the LiveRange,
321 // adjust the other way.
322 if (I->end == End) {
Lang Hamesd8f30992009-09-04 20:41:11 +0000323 ValNo->removeKills(Start, End);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000324 I->end = Start;
325 return;
326 }
327
328 // Otherwise, we are splitting the LiveRange into two pieces.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000329 SlotIndex OldEnd = I->end;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000330 I->end = Start; // Trim the old interval.
331
332 // Insert the new one.
Evan Cheng49208cf2008-02-13 02:48:26 +0000333 ranges.insert(next(I), LiveRange(End, OldEnd, ValNo));
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000334}
335
Evan Cheng49208cf2008-02-13 02:48:26 +0000336/// removeValNo - Remove all the ranges defined by the specified value#.
337/// Also remove the value# from value# list.
338void LiveInterval::removeValNo(VNInfo *ValNo) {
339 if (empty()) return;
340 Ranges::iterator I = ranges.end();
341 Ranges::iterator E = ranges.begin();
342 do {
343 --I;
344 if (I->valno == ValNo)
345 ranges.erase(I);
346 } while (I != E);
347 // Now that ValNo is dead, remove it. If it is the largest value
348 // number, just nuke it (and any other deleted values neighboring it),
349 // otherwise mark it as ~1U so it can be nuked later.
350 if (ValNo->id == getNumValNums()-1) {
351 do {
Evan Cheng49208cf2008-02-13 02:48:26 +0000352 valnos.pop_back();
Lang Hames4eb8fc82009-06-17 21:01:20 +0000353 } while (!valnos.empty() && valnos.back()->isUnused());
Evan Cheng49208cf2008-02-13 02:48:26 +0000354 } else {
Lang Hames4eb8fc82009-06-17 21:01:20 +0000355 ValNo->setIsUnused(true);
Evan Cheng49208cf2008-02-13 02:48:26 +0000356 }
357}
Lang Hamesd8f30992009-09-04 20:41:11 +0000358
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000359/// getLiveRangeContaining - Return the live range that contains the
360/// specified index, or null if there is none.
361LiveInterval::const_iterator
Lang Hamesd6a717c2009-11-03 23:52:08 +0000362LiveInterval::FindLiveRangeContaining(SlotIndex Idx) const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000363 const_iterator It = std::upper_bound(begin(), end(), Idx);
364 if (It != ranges.begin()) {
365 --It;
366 if (It->contains(Idx))
367 return It;
368 }
369
370 return end();
371}
372
373LiveInterval::iterator
Lang Hamesd6a717c2009-11-03 23:52:08 +0000374LiveInterval::FindLiveRangeContaining(SlotIndex Idx) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000375 iterator It = std::upper_bound(begin(), end(), Idx);
376 if (It != begin()) {
377 --It;
378 if (It->contains(Idx))
379 return It;
380 }
381
382 return end();
383}
384
Lang Hamesd8f30992009-09-04 20:41:11 +0000385/// findDefinedVNInfo - Find the VNInfo defined by the specified
386/// index (register interval).
Lang Hamesd6a717c2009-11-03 23:52:08 +0000387VNInfo *LiveInterval::findDefinedVNInfoForRegInt(SlotIndex Idx) const {
Evan Cheng14f8a502008-06-04 09:18:41 +0000388 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
Lang Hamesd8f30992009-09-04 20:41:11 +0000389 i != e; ++i) {
390 if ((*i)->def == Idx)
391 return *i;
392 }
393
394 return 0;
395}
396
397/// findDefinedVNInfo - Find the VNInfo defined by the specified
398/// register (stack inteval).
399VNInfo *LiveInterval::findDefinedVNInfoForStackInt(unsigned reg) const {
400 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
401 i != e; ++i) {
402 if ((*i)->getReg() == reg)
403 return *i;
404 }
405 return 0;
Evan Cheng14f8a502008-06-04 09:18:41 +0000406}
407
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000408/// join - Join two live intervals (this, and other) together. This applies
409/// mappings to the value numbers in the LHS/RHS intervals as specified. If
410/// the intervals are not joinable, this aborts.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000411void LiveInterval::join(LiveInterval &Other,
412 const int *LHSValNoAssignments,
David Greenee97f0772007-09-06 19:46:46 +0000413 const int *RHSValNoAssignments,
Evan Chengd78907d2009-06-14 20:22:55 +0000414 SmallVector<VNInfo*, 16> &NewVNInfo,
415 MachineRegisterInfo *MRI) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000416 // Determine if any of our live range values are mapped. This is uncommon, so
Evan Cheng8b7533e2007-09-01 02:03:17 +0000417 // we want to avoid the interval scan if not.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000418 bool MustMapCurValNos = false;
Evan Cheng8b7533e2007-09-01 02:03:17 +0000419 unsigned NumVals = getNumValNums();
420 unsigned NumNewVals = NewVNInfo.size();
421 for (unsigned i = 0; i != NumVals; ++i) {
422 unsigned LHSValID = LHSValNoAssignments[i];
423 if (i != LHSValID ||
Evan Cheng319802c2007-09-05 21:46:51 +0000424 (NewVNInfo[LHSValID] && NewVNInfo[LHSValID] != getValNumInfo(i)))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000425 MustMapCurValNos = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000426 }
Evan Cheng983b81d2007-08-29 20:45:00 +0000427
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000428 // If we have to apply a mapping to our base interval assignment, rewrite it
429 // now.
430 if (MustMapCurValNos) {
431 // Map the first live range.
432 iterator OutIt = begin();
Evan Cheng983b81d2007-08-29 20:45:00 +0000433 OutIt->valno = NewVNInfo[LHSValNoAssignments[OutIt->valno->id]];
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000434 ++OutIt;
435 for (iterator I = OutIt, E = end(); I != E; ++I) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000436 OutIt->valno = NewVNInfo[LHSValNoAssignments[I->valno->id]];
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000437
438 // If this live range has the same value # as its immediate predecessor,
439 // and if they are neighbors, remove one LiveRange. This happens when we
440 // have [0,3:0)[4,7:1) and map 0/1 onto the same value #.
Evan Cheng983b81d2007-08-29 20:45:00 +0000441 if (OutIt->valno == (OutIt-1)->valno && (OutIt-1)->end == OutIt->start) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000442 (OutIt-1)->end = OutIt->end;
443 } else {
444 if (I != OutIt) {
445 OutIt->start = I->start;
446 OutIt->end = I->end;
447 }
448
449 // Didn't merge, on to the next one.
450 ++OutIt;
451 }
452 }
453
454 // If we merge some live ranges, chop off the end.
455 ranges.erase(OutIt, end());
456 }
Evan Cheng816a7f32007-08-11 00:59:19 +0000457
Evan Cheng983b81d2007-08-29 20:45:00 +0000458 // Remember assignements because val# ids are changing.
Evan Cheng8b7533e2007-09-01 02:03:17 +0000459 SmallVector<unsigned, 16> OtherAssignments;
Evan Cheng983b81d2007-08-29 20:45:00 +0000460 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
461 OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]);
462
463 // Update val# info. Renumber them and make sure they all belong to this
Evan Cheng319802c2007-09-05 21:46:51 +0000464 // LiveInterval now. Also remove dead val#'s.
465 unsigned NumValNos = 0;
466 for (unsigned i = 0; i < NumNewVals; ++i) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000467 VNInfo *VNI = NewVNInfo[i];
Evan Cheng319802c2007-09-05 21:46:51 +0000468 if (VNI) {
Evan Chengffba3de2009-04-28 06:24:09 +0000469 if (NumValNos >= NumVals)
Evan Cheng319802c2007-09-05 21:46:51 +0000470 valnos.push_back(VNI);
471 else
472 valnos[NumValNos] = VNI;
473 VNI->id = NumValNos++; // Renumber val#.
Evan Cheng8b7533e2007-09-01 02:03:17 +0000474 }
475 }
Evan Cheng8b7533e2007-09-01 02:03:17 +0000476 if (NumNewVals < NumVals)
477 valnos.resize(NumNewVals); // shrinkify
Evan Cheng816a7f32007-08-11 00:59:19 +0000478
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000479 // Okay, now insert the RHS live ranges into the LHS.
480 iterator InsertPos = begin();
Evan Cheng983b81d2007-08-29 20:45:00 +0000481 unsigned RangeNo = 0;
482 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I, ++RangeNo) {
483 // Map the valno in the other live range to the current live range.
484 I->valno = NewVNInfo[OtherAssignments[RangeNo]];
Evan Cheng319802c2007-09-05 21:46:51 +0000485 assert(I->valno && "Adding a dead range?");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000486 InsertPos = addRangeFrom(*I, InsertPos);
Jakob Stoklund Olesen535617a2010-06-24 23:57:35 +0000487 InsertPos->valno->removeKills(InsertPos->start,
488 InsertPos->end.getPrevSlot());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000489 }
490
David Greenea7f6e082009-07-22 20:08:25 +0000491 ComputeJoinedWeight(Other);
Evan Chengd78907d2009-06-14 20:22:55 +0000492
493 // Update regalloc hint if currently there isn't one.
494 if (TargetRegisterInfo::isVirtualRegister(reg) &&
495 TargetRegisterInfo::isVirtualRegister(Other.reg)) {
Evan Cheng41169552009-06-15 08:28:29 +0000496 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(reg);
497 if (Hint.first == 0 && Hint.second == 0) {
498 std::pair<unsigned, unsigned> OtherHint =
Evan Chengd78907d2009-06-14 20:22:55 +0000499 MRI->getRegAllocationHint(Other.reg);
Evan Cheng41169552009-06-15 08:28:29 +0000500 if (OtherHint.first || OtherHint.second)
Evan Chengd78907d2009-06-14 20:22:55 +0000501 MRI->setRegAllocationHint(reg, OtherHint.first, OtherHint.second);
502 }
503 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000504}
505
506/// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
507/// interval as the specified value number. The LiveRanges in RHS are
508/// allowed to overlap with LiveRanges in the current interval, but only if
509/// the overlapping LiveRanges have the specified value number.
510void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS,
Evan Cheng983b81d2007-08-29 20:45:00 +0000511 VNInfo *LHSValNo) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000512 // TODO: Make this more efficient.
513 iterator InsertPos = begin();
514 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000515 // Map the valno in the other live range to the current live range.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000516 LiveRange Tmp = *I;
Evan Cheng983b81d2007-08-29 20:45:00 +0000517 Tmp.valno = LHSValNo;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000518 InsertPos = addRangeFrom(Tmp, InsertPos);
519 }
520}
521
522
Evan Cheng687d1082007-10-12 08:50:34 +0000523/// MergeValueInAsValue - Merge all of the live ranges of a specific val#
524/// in RHS into this live interval as the specified value number.
525/// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
Evan Cheng303fed82007-10-17 02:13:29 +0000526/// current interval, it will replace the value numbers of the overlaped
527/// live ranges with the specified value number.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000528void LiveInterval::MergeValueInAsValue(
529 const LiveInterval &RHS,
530 const VNInfo *RHSValNo, VNInfo *LHSValNo) {
Evan Cheng303fed82007-10-17 02:13:29 +0000531 SmallVector<VNInfo*, 4> ReplacedValNos;
532 iterator IP = begin();
Evan Cheng687d1082007-10-12 08:50:34 +0000533 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
Jakob Stoklund Olesen529c7132010-06-23 15:34:36 +0000534 assert(I->valno == RHS.getValNumInfo(I->valno->id) && "Bad VNInfo");
Evan Cheng687d1082007-10-12 08:50:34 +0000535 if (I->valno != RHSValNo)
536 continue;
Lang Hamesd6a717c2009-11-03 23:52:08 +0000537 SlotIndex Start = I->start, End = I->end;
Evan Cheng303fed82007-10-17 02:13:29 +0000538 IP = std::upper_bound(IP, end(), Start);
539 // If the start of this range overlaps with an existing liverange, trim it.
540 if (IP != begin() && IP[-1].end > Start) {
Evan Chengc7fe7be2008-01-30 22:44:55 +0000541 if (IP[-1].valno != LHSValNo) {
542 ReplacedValNos.push_back(IP[-1].valno);
543 IP[-1].valno = LHSValNo; // Update val#.
Evan Cheng303fed82007-10-17 02:13:29 +0000544 }
545 Start = IP[-1].end;
546 // Trimmed away the whole range?
547 if (Start >= End) continue;
548 }
549 // If the end of this range overlaps with an existing liverange, trim it.
550 if (IP != end() && End > IP->start) {
551 if (IP->valno != LHSValNo) {
552 ReplacedValNos.push_back(IP->valno);
553 IP->valno = LHSValNo; // Update val#.
554 }
555 End = IP->start;
556 // If this trimmed away the whole range, ignore it.
557 if (Start == End) continue;
558 }
559
Evan Cheng687d1082007-10-12 08:50:34 +0000560 // Map the valno in the other live range to the current live range.
Evan Cheng303fed82007-10-17 02:13:29 +0000561 IP = addRangeFrom(LiveRange(Start, End, LHSValNo), IP);
562 }
563
564
565 SmallSet<VNInfo*, 4> Seen;
566 for (unsigned i = 0, e = ReplacedValNos.size(); i != e; ++i) {
567 VNInfo *V1 = ReplacedValNos[i];
568 if (Seen.insert(V1)) {
569 bool isDead = true;
570 for (const_iterator I = begin(), E = end(); I != E; ++I)
571 if (I->valno == V1) {
572 isDead = false;
573 break;
574 }
575 if (isDead) {
576 // Now that V1 is dead, remove it. If it is the largest value number,
577 // just nuke it (and any other deleted values neighboring it), otherwise
578 // mark it as ~1U so it can be nuked later.
579 if (V1->id == getNumValNums()-1) {
580 do {
Evan Cheng303fed82007-10-17 02:13:29 +0000581 valnos.pop_back();
Lang Hames4eb8fc82009-06-17 21:01:20 +0000582 } while (!valnos.empty() && valnos.back()->isUnused());
Evan Cheng303fed82007-10-17 02:13:29 +0000583 } else {
Lang Hames4eb8fc82009-06-17 21:01:20 +0000584 V1->setIsUnused(true);
Evan Cheng303fed82007-10-17 02:13:29 +0000585 }
586 }
587 }
Evan Cheng687d1082007-10-12 08:50:34 +0000588 }
589}
590
591
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000592/// MergeInClobberRanges - For any live ranges that are not defined in the
593/// current interval, but are defined in the Clobbers interval, mark them
594/// used with an unknown definition value.
Lang Hamesd6a717c2009-11-03 23:52:08 +0000595void LiveInterval::MergeInClobberRanges(LiveIntervals &li_,
596 const LiveInterval &Clobbers,
Benjamin Kramer128fdd92010-03-30 20:16:45 +0000597 VNInfo::Allocator &VNInfoAllocator) {
Dan Gohmanc8424de2008-08-14 18:13:49 +0000598 if (Clobbers.empty()) return;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000599
Evan Cheng1068b722009-04-25 09:25:19 +0000600 DenseMap<VNInfo*, VNInfo*> ValNoMaps;
Evan Cheng4cc387f2009-04-25 20:20:15 +0000601 VNInfo *UnusedValNo = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000602 iterator IP = begin();
603 for (const_iterator I = Clobbers.begin(), E = Clobbers.end(); I != E; ++I) {
Evan Cheng1068b722009-04-25 09:25:19 +0000604 // For every val# in the Clobbers interval, create a new "unknown" val#.
605 VNInfo *ClobberValNo = 0;
606 DenseMap<VNInfo*, VNInfo*>::iterator VI = ValNoMaps.find(I->valno);
607 if (VI != ValNoMaps.end())
608 ClobberValNo = VI->second;
Evan Cheng4cc387f2009-04-25 20:20:15 +0000609 else if (UnusedValNo)
610 ClobberValNo = UnusedValNo;
Evan Cheng1068b722009-04-25 09:25:19 +0000611 else {
Lang Hamesd8f30992009-09-04 20:41:11 +0000612 UnusedValNo = ClobberValNo =
Lang Hamesd6a717c2009-11-03 23:52:08 +0000613 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
Evan Cheng1068b722009-04-25 09:25:19 +0000614 ValNoMaps.insert(std::make_pair(I->valno, ClobberValNo));
615 }
616
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000617 bool Done = false;
Lang Hamesd6a717c2009-11-03 23:52:08 +0000618 SlotIndex Start = I->start, End = I->end;
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000619 // If a clobber range starts before an existing range and ends after
620 // it, the clobber range will need to be split into multiple ranges.
621 // Loop until the entire clobber range is handled.
622 while (!Done) {
623 Done = true;
624 IP = std::upper_bound(IP, end(), Start);
Lang Hamesd6a717c2009-11-03 23:52:08 +0000625 SlotIndex SubRangeStart = Start;
626 SlotIndex SubRangeEnd = End;
Dan Gohman4cedb1c2009-04-08 00:15:30 +0000627
628 // If the start of this range overlaps with an existing liverange, trim it.
629 if (IP != begin() && IP[-1].end > SubRangeStart) {
630 SubRangeStart = IP[-1].end;
631 // Trimmed away the whole range?
632 if (SubRangeStart >= SubRangeEnd) continue;
633 }
634 // If the end of this range overlaps with an existing liverange, trim it.
635 if (IP != end() && SubRangeEnd > IP->start) {
636 // If the clobber live range extends beyond the existing live range,
637 // it'll need at least another live range, so set the flag to keep
638 // iterating.
639 if (SubRangeEnd > IP->end) {
640 Start = IP->end;
641 Done = false;
642 }
643 SubRangeEnd = IP->start;
644 // If this trimmed away the whole range, ignore it.
645 if (SubRangeStart == SubRangeEnd) continue;
646 }
647
648 // Insert the clobber interval.
649 IP = addRangeFrom(LiveRange(SubRangeStart, SubRangeEnd, ClobberValNo),
650 IP);
Evan Cheng4cc387f2009-04-25 20:20:15 +0000651 UnusedValNo = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000652 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000653 }
Evan Chenga6458fe2009-04-27 17:35:19 +0000654
655 if (UnusedValNo) {
656 // Delete the last unused val#.
657 valnos.pop_back();
Evan Chenga6458fe2009-04-27 17:35:19 +0000658 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000659}
660
Lang Hamesd6a717c2009-11-03 23:52:08 +0000661void LiveInterval::MergeInClobberRange(LiveIntervals &li_,
662 SlotIndex Start,
663 SlotIndex End,
Benjamin Kramer128fdd92010-03-30 20:16:45 +0000664 VNInfo::Allocator &VNInfoAllocator) {
Evan Chenged642cb2009-03-11 00:03:21 +0000665 // Find a value # to use for the clobber ranges. If there is already a value#
666 // for unknown values, use it.
Lang Hamesd8f30992009-09-04 20:41:11 +0000667 VNInfo *ClobberValNo =
Lang Hamesd6a717c2009-11-03 23:52:08 +0000668 getNextValue(li_.getInvalidIndex(), 0, false, VNInfoAllocator);
Evan Chenged642cb2009-03-11 00:03:21 +0000669
670 iterator IP = begin();
671 IP = std::upper_bound(IP, end(), Start);
672
673 // If the start of this range overlaps with an existing liverange, trim it.
674 if (IP != begin() && IP[-1].end > Start) {
675 Start = IP[-1].end;
676 // Trimmed away the whole range?
677 if (Start >= End) return;
678 }
679 // If the end of this range overlaps with an existing liverange, trim it.
680 if (IP != end() && End > IP->start) {
681 End = IP->start;
682 // If this trimmed away the whole range, ignore it.
683 if (Start == End) return;
684 }
685
686 // Insert the clobber interval.
687 addRangeFrom(LiveRange(Start, End, ClobberValNo), IP);
688}
689
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000690/// MergeValueNumberInto - This method is called when two value nubmers
691/// are found to be equivalent. This eliminates V1, replacing all
692/// LiveRanges with the V1 value number with the V2 value number. This can
693/// cause merging of V1/V2 values numbers and compaction of the value space.
Owen Anderson85f86f32009-02-02 22:42:01 +0000694VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000695 assert(V1 != V2 && "Identical value#'s are always equivalent!");
696
697 // This code actually merges the (numerically) larger value number into the
698 // smaller value number, which is likely to allow us to compactify the value
699 // space. The only thing we have to be careful of is to preserve the
700 // instruction that defines the result value.
701
702 // Make sure V2 is smaller than V1.
Evan Cheng983b81d2007-08-29 20:45:00 +0000703 if (V1->id < V2->id) {
Lang Hames87972832009-08-10 23:43:28 +0000704 V1->copyFrom(*V2);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000705 std::swap(V1, V2);
706 }
707
708 // Merge V1 live ranges into V2.
709 for (iterator I = begin(); I != end(); ) {
710 iterator LR = I++;
Evan Cheng983b81d2007-08-29 20:45:00 +0000711 if (LR->valno != V1) continue; // Not a V1 LiveRange.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000712
713 // Okay, we found a V1 live range. If it had a previous, touching, V2 live
714 // range, extend it.
715 if (LR != begin()) {
716 iterator Prev = LR-1;
Evan Cheng983b81d2007-08-29 20:45:00 +0000717 if (Prev->valno == V2 && Prev->end == LR->start) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000718 Prev->end = LR->end;
719
720 // Erase this live-range.
721 ranges.erase(LR);
722 I = Prev+1;
723 LR = Prev;
724 }
725 }
726
727 // Okay, now we have a V1 or V2 live range that is maximally merged forward.
728 // Ensure that it is a V2 live-range.
Evan Cheng983b81d2007-08-29 20:45:00 +0000729 LR->valno = V2;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000730
731 // If we can merge it into later V2 live ranges, do so now. We ignore any
732 // following V1 live ranges, as they will be merged in subsequent iterations
733 // of the loop.
734 if (I != end()) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000735 if (I->start == LR->end && I->valno == V2) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000736 LR->end = I->end;
737 ranges.erase(I);
738 I = LR+1;
739 }
740 }
741 }
742
743 // Now that V1 is dead, remove it. If it is the largest value number, just
744 // nuke it (and any other deleted values neighboring it), otherwise mark it as
745 // ~1U so it can be nuked later.
Evan Cheng983b81d2007-08-29 20:45:00 +0000746 if (V1->id == getNumValNums()-1) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000747 do {
Evan Cheng983b81d2007-08-29 20:45:00 +0000748 valnos.pop_back();
Lang Hames4eb8fc82009-06-17 21:01:20 +0000749 } while (valnos.back()->isUnused());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000750 } else {
Lang Hames4eb8fc82009-06-17 21:01:20 +0000751 V1->setIsUnused(true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000752 }
Owen Anderson85f86f32009-02-02 22:42:01 +0000753
754 return V2;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000755}
756
Evan Cheng687d1082007-10-12 08:50:34 +0000757void LiveInterval::Copy(const LiveInterval &RHS,
Evan Chengd78907d2009-06-14 20:22:55 +0000758 MachineRegisterInfo *MRI,
Benjamin Kramer128fdd92010-03-30 20:16:45 +0000759 VNInfo::Allocator &VNInfoAllocator) {
Evan Cheng687d1082007-10-12 08:50:34 +0000760 ranges.clear();
761 valnos.clear();
Evan Cheng41169552009-06-15 08:28:29 +0000762 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(RHS.reg);
Evan Chengd78907d2009-06-14 20:22:55 +0000763 MRI->setRegAllocationHint(reg, Hint.first, Hint.second);
764
Evan Cheng687d1082007-10-12 08:50:34 +0000765 weight = RHS.weight;
766 for (unsigned i = 0, e = RHS.getNumValNums(); i != e; ++i) {
767 const VNInfo *VNI = RHS.getValNumInfo(i);
Lang Hames4eb8fc82009-06-17 21:01:20 +0000768 createValueCopy(VNI, VNInfoAllocator);
Evan Cheng687d1082007-10-12 08:50:34 +0000769 }
770 for (unsigned i = 0, e = RHS.ranges.size(); i != e; ++i) {
771 const LiveRange &LR = RHS.ranges[i];
772 addRange(LiveRange(LR.start, LR.end, getValNumInfo(LR.valno->id)));
773 }
774}
775
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000776unsigned LiveInterval::getSize() const {
777 unsigned Sum = 0;
778 for (const_iterator I = begin(), E = end(); I != E; ++I)
Lang Hamesd8f30992009-09-04 20:41:11 +0000779 Sum += I->start.distance(I->end);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000780 return Sum;
781}
782
David Greenea7f6e082009-07-22 20:08:25 +0000783/// ComputeJoinedWeight - Set the weight of a live interval Joined
784/// after Other has been merged into it.
785void LiveInterval::ComputeJoinedWeight(const LiveInterval &Other) {
786 // If either of these intervals was spilled, the weight is the
787 // weight of the non-spilled interval. This can only happen with
788 // iterative coalescers.
789
David Greened7d71ae2009-07-22 22:32:19 +0000790 if (Other.weight != HUGE_VALF) {
791 weight += Other.weight;
792 }
793 else if (weight == HUGE_VALF &&
David Greenea7f6e082009-07-22 20:08:25 +0000794 !TargetRegisterInfo::isPhysicalRegister(reg)) {
795 // Remove this assert if you have an iterative coalescer
796 assert(0 && "Joining to spilled interval");
797 weight = Other.weight;
798 }
David Greenea7f6e082009-07-22 20:08:25 +0000799 else {
800 // Otherwise the weight stays the same
801 // Remove this assert if you have an iterative coalescer
802 assert(0 && "Joining from spilled interval");
803 }
804}
805
Daniel Dunbarf55f61f2009-07-24 10:36:58 +0000806raw_ostream& llvm::operator<<(raw_ostream& os, const LiveRange &LR) {
807 return os << '[' << LR.start << ',' << LR.end << ':' << LR.valno->id << ")";
808}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000809
810void LiveRange::dump() const {
David Greene23c23922010-01-04 22:41:43 +0000811 dbgs() << *this << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000812}
813
Chris Lattner15be2672009-08-23 03:47:42 +0000814void LiveInterval::print(raw_ostream &OS, const TargetRegisterInfo *TRI) const {
Evan Cheng922e5f62008-06-23 21:03:19 +0000815 if (isStackSlot())
816 OS << "SS#" << getStackSlotIndex();
Evan Cheng14f8a502008-06-04 09:18:41 +0000817 else if (TRI && TargetRegisterInfo::isPhysicalRegister(reg))
Bill Wendling9b0baeb2008-02-26 21:47:57 +0000818 OS << TRI->getName(reg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000819 else
820 OS << "%reg" << reg;
821
822 OS << ',' << weight;
823
824 if (empty())
Evan Cheng14f8a502008-06-04 09:18:41 +0000825 OS << " EMPTY";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000826 else {
827 OS << " = ";
828 for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
Jakob Stoklund Olesen529c7132010-06-23 15:34:36 +0000829 E = ranges.end(); I != E; ++I) {
830 OS << *I;
831 assert(I->valno == getValNumInfo(I->valno->id) && "Bad VNInfo");
832 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000833 }
834
835 // Print value number info.
836 if (getNumValNums()) {
837 OS << " ";
Evan Chengba990522007-08-28 08:28:51 +0000838 unsigned vnum = 0;
839 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
840 ++i, ++vnum) {
Evan Cheng983b81d2007-08-29 20:45:00 +0000841 const VNInfo *vni = *i;
Evan Chengba990522007-08-28 08:28:51 +0000842 if (vnum) OS << " ";
843 OS << vnum << "@";
Lang Hames4eb8fc82009-06-17 21:01:20 +0000844 if (vni->isUnused()) {
Evan Cheng58c2b762007-08-08 03:00:28 +0000845 OS << "x";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000846 } else {
Lang Hames75730ab2009-12-09 05:39:12 +0000847 if (!vni->isDefAccurate() && !vni->isPHIDef())
Evan Cheng816a7f32007-08-11 00:59:19 +0000848 OS << "?";
849 else
Evan Cheng983b81d2007-08-29 20:45:00 +0000850 OS << vni->def;
851 unsigned ee = vni->kills.size();
Lang Hames4eb8fc82009-06-17 21:01:20 +0000852 if (ee || vni->hasPHIKill()) {
Evan Cheng816a7f32007-08-11 00:59:19 +0000853 OS << "-(";
Evan Chengba990522007-08-28 08:28:51 +0000854 for (unsigned j = 0; j != ee; ++j) {
Lang Hamesd8f30992009-09-04 20:41:11 +0000855 OS << vni->kills[j];
Evan Chengba990522007-08-28 08:28:51 +0000856 if (j != ee-1)
Evan Cheng816a7f32007-08-11 00:59:19 +0000857 OS << " ";
858 }
Lang Hames4eb8fc82009-06-17 21:01:20 +0000859 if (vni->hasPHIKill()) {
Evan Cheng49208cf2008-02-13 02:48:26 +0000860 if (ee)
861 OS << " ";
862 OS << "phi";
863 }
Evan Cheng816a7f32007-08-11 00:59:19 +0000864 OS << ")";
865 }
Evan Cheng4151fde2007-08-07 23:49:57 +0000866 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000867 }
868 }
869}
870
871void LiveInterval::dump() const {
David Greene23c23922010-01-04 22:41:43 +0000872 dbgs() << *this << "\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000873}
874
875
Daniel Dunbarf55f61f2009-07-24 10:36:58 +0000876void LiveRange::print(raw_ostream &os) const {
877 os << *this;
878}