blob: 0dbaaf804b62cefe36e16463ae5fbd8fb776e54d [file] [log] [blame]
Chris Lattnerfb449b92004-07-23 17:49:16 +00001//===-- LiveInterval.cpp - Live Interval Representation -------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerfb449b92004-07-23 17:49:16 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the LiveRange and LiveInterval classes. Given some
11// numbering of each the machine instructions an interval [i, j) is said to be a
12// live interval for register v if there is no instruction with number j' > j
Bob Wilson86af6552010-01-12 22:18:56 +000013// such that v is live at j' and there is no instruction with number i' < i such
Chris Lattnerfb449b92004-07-23 17:49:16 +000014// that v is live at i'. In this implementation intervals can have holes,
15// i.e. an interval might look like [1,20), [50,65), [1000,1001). Each
16// individual range is represented as an instance of LiveRange, and the whole
17// interval is represented as an instance of LiveInterval.
18//
19//===----------------------------------------------------------------------===//
20
Bill Wendlingd9fd2ac2006-11-28 02:08:17 +000021#include "llvm/CodeGen/LiveInterval.h"
Lang Hames233a60e2009-11-03 23:52:08 +000022#include "llvm/CodeGen/LiveIntervalAnalysis.h"
Evan Cheng90f95f82009-06-14 20:22:55 +000023#include "llvm/CodeGen/MachineRegisterInfo.h"
Evan Cheng0adb5272009-04-25 09:25:19 +000024#include "llvm/ADT/DenseMap.h"
Evan Cheng3c1f4a42007-10-17 02:13:29 +000025#include "llvm/ADT/SmallSet.h"
Bill Wendling38b0e7b2006-11-28 03:31:29 +000026#include "llvm/ADT/STLExtras.h"
David Greene52421542010-01-04 22:41:43 +000027#include "llvm/Support/Debug.h"
Daniel Dunbara717b7b2009-07-24 10:47:20 +000028#include "llvm/Support/raw_ostream.h"
Dan Gohman6f0d0242008-02-10 18:45:23 +000029#include "llvm/Target/TargetRegisterInfo.h"
Alkis Evlogimenosc4d3b912004-09-28 02:38:58 +000030#include <algorithm>
Chris Lattnerfb449b92004-07-23 17:49:16 +000031using namespace llvm;
32
Jakob Stoklund Olesenf568b272010-09-21 17:12:18 +000033LiveInterval::iterator LiveInterval::find(SlotIndex Pos) {
Jakob Stoklund Olesen55768d72011-03-12 01:50:35 +000034 // This algorithm is basically std::upper_bound.
35 // Unfortunately, std::upper_bound cannot be used with mixed types until we
36 // adopt C++0x. Many libraries can do it, but not all.
37 if (empty() || Pos >= endIndex())
38 return end();
39 iterator I = begin();
40 size_t Len = ranges.size();
41 do {
42 size_t Mid = Len >> 1;
43 if (Pos < I[Mid].end)
44 Len = Mid;
45 else
46 I += Mid + 1, Len -= Mid + 1;
47 } while (Len);
48 return I;
Jakob Stoklund Olesen15a57142010-06-25 22:53:05 +000049}
50
51/// killedInRange - Return true if the interval has kills in [Start,End).
52bool LiveInterval::killedInRange(SlotIndex Start, SlotIndex End) const {
53 Ranges::const_iterator r =
54 std::lower_bound(ranges.begin(), ranges.end(), End);
55
56 // Now r points to the first interval with start >= End, or ranges.end().
57 if (r == ranges.begin())
58 return false;
59
60 --r;
61 // Now r points to the last interval with end <= End.
62 // r->end is the kill point.
63 return r->end >= Start && r->end < End;
64}
65
Chris Lattnerbae74d92004-11-18 03:47:34 +000066// overlaps - Return true if the intersection of the two live intervals is
67// not empty.
68//
Chris Lattnerfb449b92004-07-23 17:49:16 +000069// An example for overlaps():
70//
71// 0: A = ...
72// 4: B = ...
73// 8: C = A + B ;; last use of A
74//
75// The live intervals should look like:
76//
77// A = [3, 11)
78// B = [7, x)
79// C = [11, y)
80//
81// A->overlaps(C) should return false since we want to be able to join
82// A and C.
Chris Lattnerbae74d92004-11-18 03:47:34 +000083//
84bool LiveInterval::overlapsFrom(const LiveInterval& other,
85 const_iterator StartPos) const {
Jakob Stoklund Olesen6382d2c2010-07-13 19:56:28 +000086 assert(!empty() && "empty interval");
Chris Lattnerbae74d92004-11-18 03:47:34 +000087 const_iterator i = begin();
88 const_iterator ie = end();
89 const_iterator j = StartPos;
90 const_iterator je = other.end();
91
92 assert((StartPos->start <= i->start || StartPos == other.begin()) &&
Chris Lattner8c68b6a2004-11-18 04:02:11 +000093 StartPos != other.end() && "Bogus start position hint!");
Chris Lattnerf5426492004-07-25 07:11:19 +000094
Chris Lattnerfb449b92004-07-23 17:49:16 +000095 if (i->start < j->start) {
Chris Lattneraa141472004-07-23 18:40:00 +000096 i = std::upper_bound(i, ie, j->start);
Chris Lattnerfb449b92004-07-23 17:49:16 +000097 if (i != ranges.begin()) --i;
Chris Lattneraa141472004-07-23 18:40:00 +000098 } else if (j->start < i->start) {
Chris Lattneread1b3f2004-12-04 01:22:09 +000099 ++StartPos;
100 if (StartPos != other.end() && StartPos->start <= i->start) {
101 assert(StartPos < other.end() && i < end());
Chris Lattner8c68b6a2004-11-18 04:02:11 +0000102 j = std::upper_bound(j, je, i->start);
103 if (j != other.ranges.begin()) --j;
104 }
Chris Lattneraa141472004-07-23 18:40:00 +0000105 } else {
106 return true;
Chris Lattnerfb449b92004-07-23 17:49:16 +0000107 }
108
Chris Lattner9fddc122004-11-18 05:28:21 +0000109 if (j == je) return false;
110
111 while (i != ie) {
Chris Lattnerfb449b92004-07-23 17:49:16 +0000112 if (i->start > j->start) {
Alkis Evlogimenosa1613db2004-07-24 11:44:15 +0000113 std::swap(i, j);
114 std::swap(ie, je);
Chris Lattnerfb449b92004-07-23 17:49:16 +0000115 }
Chris Lattnerfb449b92004-07-23 17:49:16 +0000116
117 if (i->end > j->start)
118 return true;
119 ++i;
120 }
121
122 return false;
123}
124
Evan Chengcccdb2b2009-04-18 08:52:15 +0000125/// overlaps - Return true if the live interval overlaps a range specified
126/// by [Start, End).
Lang Hames233a60e2009-11-03 23:52:08 +0000127bool LiveInterval::overlaps(SlotIndex Start, SlotIndex End) const {
Evan Chengcccdb2b2009-04-18 08:52:15 +0000128 assert(Start < End && "Invalid range");
Jakob Stoklund Olesen186eb732010-07-13 19:42:20 +0000129 const_iterator I = std::lower_bound(begin(), end(), End);
130 return I != begin() && (--I)->end > Start;
Evan Chengcccdb2b2009-04-18 08:52:15 +0000131}
132
Lang Hames6f4e4df2010-07-26 01:49:41 +0000133
134/// ValNo is dead, remove it. If it is the largest value number, just nuke it
135/// (and any other deleted values neighboring it), otherwise mark it as ~1U so
136/// it can be nuked later.
137void LiveInterval::markValNoForDeletion(VNInfo *ValNo) {
138 if (ValNo->id == getNumValNums()-1) {
139 do {
140 valnos.pop_back();
141 } while (!valnos.empty() && valnos.back()->isUnused());
142 } else {
143 ValNo->setIsUnused(true);
144 }
145}
146
Jakob Stoklund Olesen23436592010-08-06 18:46:59 +0000147/// RenumberValues - Renumber all values in order of appearance and delete the
148/// remaining unused values.
Jakob Stoklund Olesenfff2c472010-08-12 20:38:03 +0000149void LiveInterval::RenumberValues(LiveIntervals &lis) {
Jakob Stoklund Olesen23436592010-08-06 18:46:59 +0000150 SmallPtrSet<VNInfo*, 8> Seen;
151 valnos.clear();
152 for (const_iterator I = begin(), E = end(); I != E; ++I) {
153 VNInfo *VNI = I->valno;
154 if (!Seen.insert(VNI))
155 continue;
156 assert(!VNI->isUnused() && "Unused valno used by live range");
157 VNI->id = (unsigned)valnos.size();
158 valnos.push_back(VNI);
159 }
160}
161
Chris Lattnerb26c2152004-07-23 19:38:44 +0000162/// extendIntervalEndTo - This method is used when we want to extend the range
163/// specified by I to end at the specified endpoint. To do this, we should
164/// merge and eliminate all ranges that this will overlap with. The iterator is
165/// not invalidated.
Lang Hames233a60e2009-11-03 23:52:08 +0000166void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) {
Chris Lattnerb26c2152004-07-23 19:38:44 +0000167 assert(I != ranges.end() && "Not a valid interval!");
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000168 VNInfo *ValNo = I->valno;
Chris Lattnerfb449b92004-07-23 17:49:16 +0000169
Chris Lattnerb26c2152004-07-23 19:38:44 +0000170 // Search for the first interval that we can't merge with.
Oscar Fuentesee56c422010-08-02 06:00:15 +0000171 Ranges::iterator MergeTo = llvm::next(I);
Chris Lattnerabf295f2004-07-24 02:52:23 +0000172 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000173 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
Chris Lattnerabf295f2004-07-24 02:52:23 +0000174 }
Chris Lattnerb26c2152004-07-23 19:38:44 +0000175
176 // If NewEnd was in the middle of an interval, make sure to get its endpoint.
177 I->end = std::max(NewEnd, prior(MergeTo)->end);
178
Chris Lattnerb0fa11c2005-10-20 07:39:25 +0000179 // Erase any dead ranges.
Oscar Fuentesee56c422010-08-02 06:00:15 +0000180 ranges.erase(llvm::next(I), MergeTo);
Evan Cheng4f8ff162007-08-11 00:59:19 +0000181
Chris Lattnerb0fa11c2005-10-20 07:39:25 +0000182 // If the newly formed range now touches the range after it and if they have
183 // the same value number, merge the two ranges into one range.
Oscar Fuentesee56c422010-08-02 06:00:15 +0000184 Ranges::iterator Next = llvm::next(I);
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000185 if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) {
Chris Lattnercef60102005-10-20 22:50:10 +0000186 I->end = Next->end;
187 ranges.erase(Next);
Chris Lattnerb0fa11c2005-10-20 07:39:25 +0000188 }
Chris Lattnerb26c2152004-07-23 19:38:44 +0000189}
190
191
192/// extendIntervalStartTo - This method is used when we want to extend the range
193/// specified by I to start at the specified endpoint. To do this, we should
194/// merge and eliminate all ranges that this will overlap with.
Misha Brukmanedf128a2005-04-21 22:36:52 +0000195LiveInterval::Ranges::iterator
Lang Hames233a60e2009-11-03 23:52:08 +0000196LiveInterval::extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStart) {
Chris Lattnerb26c2152004-07-23 19:38:44 +0000197 assert(I != ranges.end() && "Not a valid interval!");
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000198 VNInfo *ValNo = I->valno;
Chris Lattnerb26c2152004-07-23 19:38:44 +0000199
200 // Search for the first interval that we can't merge with.
201 Ranges::iterator MergeTo = I;
202 do {
203 if (MergeTo == ranges.begin()) {
204 I->start = NewStart;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000205 ranges.erase(MergeTo, I);
Chris Lattnerb26c2152004-07-23 19:38:44 +0000206 return I;
207 }
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000208 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
Chris Lattnerb26c2152004-07-23 19:38:44 +0000209 --MergeTo;
210 } while (NewStart <= MergeTo->start);
211
212 // If we start in the middle of another interval, just delete a range and
213 // extend that interval.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000214 if (MergeTo->end >= NewStart && MergeTo->valno == ValNo) {
Chris Lattnerb26c2152004-07-23 19:38:44 +0000215 MergeTo->end = I->end;
216 } else {
217 // Otherwise, extend the interval right after.
218 ++MergeTo;
219 MergeTo->start = NewStart;
220 MergeTo->end = I->end;
221 }
222
Oscar Fuentesee56c422010-08-02 06:00:15 +0000223 ranges.erase(llvm::next(MergeTo), llvm::next(I));
Chris Lattnerb26c2152004-07-23 19:38:44 +0000224 return MergeTo;
225}
226
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000227LiveInterval::iterator
228LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
Lang Hames233a60e2009-11-03 23:52:08 +0000229 SlotIndex Start = LR.start, End = LR.end;
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000230 iterator it = std::upper_bound(From, ranges.end(), Start);
Chris Lattnerb26c2152004-07-23 19:38:44 +0000231
232 // If the inserted interval starts in the middle or right at the end of
233 // another interval, just extend that interval to contain the range of LR.
234 if (it != ranges.begin()) {
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000235 iterator B = prior(it);
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000236 if (LR.valno == B->valno) {
Chris Lattnerabf295f2004-07-24 02:52:23 +0000237 if (B->start <= Start && B->end >= Start) {
238 extendIntervalEndTo(B, End);
239 return B;
240 }
241 } else {
242 // Check to make sure that we are not overlapping two live ranges with
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000243 // different valno's.
Chris Lattnerabf295f2004-07-24 02:52:23 +0000244 assert(B->end <= Start &&
Brian Gaeke8311bef2004-11-16 06:52:35 +0000245 "Cannot overlap two LiveRanges with differing ValID's"
246 " (did you def the same reg twice in a MachineInstr?)");
Chris Lattnerb26c2152004-07-23 19:38:44 +0000247 }
248 }
249
250 // Otherwise, if this range ends in the middle of, or right next to, another
251 // interval, merge it into that interval.
Anton Korobeynikov4c71dfe2008-02-20 11:10:28 +0000252 if (it != ranges.end()) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000253 if (LR.valno == it->valno) {
Chris Lattnerabf295f2004-07-24 02:52:23 +0000254 if (it->start <= End) {
255 it = extendIntervalStartTo(it, Start);
256
257 // If LR is a complete superset of an interval, we may need to grow its
258 // endpoint as well.
259 if (End > it->end)
260 extendIntervalEndTo(it, End);
261 return it;
262 }
263 } else {
264 // Check to make sure that we are not overlapping two live ranges with
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000265 // different valno's.
Chris Lattnerabf295f2004-07-24 02:52:23 +0000266 assert(it->start >= End &&
267 "Cannot overlap two LiveRanges with differing ValID's");
268 }
Anton Korobeynikov4c71dfe2008-02-20 11:10:28 +0000269 }
Chris Lattnerb26c2152004-07-23 19:38:44 +0000270
271 // Otherwise, this is just a new range that doesn't interact with anything.
272 // Insert it.
273 return ranges.insert(it, LR);
Chris Lattnerfb449b92004-07-23 17:49:16 +0000274}
275
Jakob Stoklund Olesenee5655d2011-09-13 16:47:56 +0000276/// extendInBlock - If this interval is live before Kill in the basic
277/// block that starts at StartIdx, extend it to be live up to Kill and return
278/// the value. If there is no live range before Kill, return NULL.
279VNInfo *LiveInterval::extendInBlock(SlotIndex StartIdx, SlotIndex Kill) {
Jakob Stoklund Olesen9763e2b2011-03-02 00:06:15 +0000280 if (empty())
281 return 0;
Jakob Stoklund Olesenee5655d2011-09-13 16:47:56 +0000282 iterator I = std::upper_bound(begin(), end(), Kill.getPrevSlot());
Jakob Stoklund Olesen9763e2b2011-03-02 00:06:15 +0000283 if (I == begin())
284 return 0;
285 --I;
286 if (I->end <= StartIdx)
287 return 0;
Jakob Stoklund Olesenee5655d2011-09-13 16:47:56 +0000288 if (I->end < Kill)
289 extendIntervalEndTo(I, Kill);
Jakob Stoklund Olesen9763e2b2011-03-02 00:06:15 +0000290 return I->valno;
291}
Chris Lattnerabf295f2004-07-24 02:52:23 +0000292
293/// removeRange - Remove the specified range from this interval. Note that
Evan Cheng42cc6e32009-01-29 00:06:09 +0000294/// the range must be in a single LiveRange in its entirety.
Lang Hames233a60e2009-11-03 23:52:08 +0000295void LiveInterval::removeRange(SlotIndex Start, SlotIndex End,
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000296 bool RemoveDeadValNo) {
Chris Lattnerabf295f2004-07-24 02:52:23 +0000297 // Find the LiveRange containing this span.
Jakob Stoklund Olesenf568b272010-09-21 17:12:18 +0000298 Ranges::iterator I = find(Start);
299 assert(I != ranges.end() && "Range is not in interval!");
Lang Hames86511252009-09-04 20:41:11 +0000300 assert(I->containsRange(Start, End) && "Range is not entirely in interval!");
Chris Lattnerabf295f2004-07-24 02:52:23 +0000301
302 // If the span we are removing is at the start of the LiveRange, adjust it.
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000303 VNInfo *ValNo = I->valno;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000304 if (I->start == Start) {
Evan Cheng4f8ff162007-08-11 00:59:19 +0000305 if (I->end == End) {
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000306 if (RemoveDeadValNo) {
307 // Check if val# is dead.
308 bool isDead = true;
309 for (const_iterator II = begin(), EE = end(); II != EE; ++II)
310 if (II != I && II->valno == ValNo) {
311 isDead = false;
312 break;
Jakob Stoklund Olesen15a57142010-06-25 22:53:05 +0000313 }
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000314 if (isDead) {
Lang Hames6f4e4df2010-07-26 01:49:41 +0000315 // Now that ValNo is dead, remove it.
316 markValNoForDeletion(ValNo);
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000317 }
318 }
319
Chris Lattnerabf295f2004-07-24 02:52:23 +0000320 ranges.erase(I); // Removed the whole LiveRange.
Evan Cheng4f8ff162007-08-11 00:59:19 +0000321 } else
Chris Lattnerabf295f2004-07-24 02:52:23 +0000322 I->start = End;
323 return;
324 }
325
326 // Otherwise if the span we are removing is at the end of the LiveRange,
327 // adjust the other way.
328 if (I->end == End) {
Chris Lattner6925a9f2004-07-25 05:43:53 +0000329 I->end = Start;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000330 return;
331 }
332
333 // Otherwise, we are splitting the LiveRange into two pieces.
Lang Hames233a60e2009-11-03 23:52:08 +0000334 SlotIndex OldEnd = I->end;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000335 I->end = Start; // Trim the old interval.
336
337 // Insert the new one.
Oscar Fuentesee56c422010-08-02 06:00:15 +0000338 ranges.insert(llvm::next(I), LiveRange(End, OldEnd, ValNo));
Chris Lattnerabf295f2004-07-24 02:52:23 +0000339}
340
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000341/// removeValNo - Remove all the ranges defined by the specified value#.
342/// Also remove the value# from value# list.
343void LiveInterval::removeValNo(VNInfo *ValNo) {
344 if (empty()) return;
345 Ranges::iterator I = ranges.end();
346 Ranges::iterator E = ranges.begin();
347 do {
348 --I;
349 if (I->valno == ValNo)
350 ranges.erase(I);
351 } while (I != E);
Lang Hames6f4e4df2010-07-26 01:49:41 +0000352 // Now that ValNo is dead, remove it.
353 markValNoForDeletion(ValNo);
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000354}
Lang Hames86511252009-09-04 20:41:11 +0000355
Lang Hames86511252009-09-04 20:41:11 +0000356/// findDefinedVNInfo - Find the VNInfo defined by the specified
357/// index (register interval).
Lang Hames233a60e2009-11-03 23:52:08 +0000358VNInfo *LiveInterval::findDefinedVNInfoForRegInt(SlotIndex Idx) const {
Evan Cheng3f32d652008-06-04 09:18:41 +0000359 for (LiveInterval::const_vni_iterator i = vni_begin(), e = vni_end();
Lang Hames86511252009-09-04 20:41:11 +0000360 i != e; ++i) {
361 if ((*i)->def == Idx)
362 return *i;
363 }
364
365 return 0;
366}
367
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000368/// join - Join two live intervals (this, and other) together. This applies
369/// mappings to the value numbers in the LHS/RHS intervals as specified. If
370/// the intervals are not joinable, this aborts.
Lang Hames233a60e2009-11-03 23:52:08 +0000371void LiveInterval::join(LiveInterval &Other,
372 const int *LHSValNoAssignments,
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000373 const int *RHSValNoAssignments,
Evan Cheng90f95f82009-06-14 20:22:55 +0000374 SmallVector<VNInfo*, 16> &NewVNInfo,
375 MachineRegisterInfo *MRI) {
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000376 // Determine if any of our live range values are mapped. This is uncommon, so
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000377 // we want to avoid the interval scan if not.
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000378 bool MustMapCurValNos = false;
Evan Cheng34301352007-09-01 02:03:17 +0000379 unsigned NumVals = getNumValNums();
380 unsigned NumNewVals = NewVNInfo.size();
381 for (unsigned i = 0; i != NumVals; ++i) {
382 unsigned LHSValID = LHSValNoAssignments[i];
383 if (i != LHSValID ||
Evan Chengf3bb2e62007-09-05 21:46:51 +0000384 (NewVNInfo[LHSValID] && NewVNInfo[LHSValID] != getValNumInfo(i)))
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000385 MustMapCurValNos = true;
Chris Lattnerdeb99712004-07-24 03:41:50 +0000386 }
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000387
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000388 // If we have to apply a mapping to our base interval assignment, rewrite it
389 // now.
390 if (MustMapCurValNos) {
391 // Map the first live range.
Lang Hames02e08d52012-02-02 05:37:34 +0000392
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000393 iterator OutIt = begin();
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000394 OutIt->valno = NewVNInfo[LHSValNoAssignments[OutIt->valno->id]];
Lang Hames02e08d52012-02-02 05:37:34 +0000395 for (iterator I = next(OutIt), E = end(); I != E; ++I) {
396 VNInfo* nextValNo = NewVNInfo[LHSValNoAssignments[I->valno->id]];
397 assert(nextValNo != 0 && "Huh?");
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000398
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000399 // If this live range has the same value # as its immediate predecessor,
400 // and if they are neighbors, remove one LiveRange. This happens when we
Lang Hames02e08d52012-02-02 05:37:34 +0000401 // have [0,4:0)[4,7:1) and map 0/1 onto the same value #.
402 if (OutIt->valno == nextValNo && OutIt->end == I->start) {
403 OutIt->end = I->end;
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000404 } else {
Lang Hames02e08d52012-02-02 05:37:34 +0000405 // Didn't merge. Move OutIt to the next interval,
406 ++OutIt;
407 OutIt->valno = nextValNo;
408 if (OutIt != I) {
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000409 OutIt->start = I->start;
410 OutIt->end = I->end;
411 }
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000412 }
413 }
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000414 // If we merge some live ranges, chop off the end.
Lang Hames02e08d52012-02-02 05:37:34 +0000415 ++OutIt;
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000416 ranges.erase(OutIt, end());
417 }
Evan Cheng4f8ff162007-08-11 00:59:19 +0000418
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000419 // Remember assignements because val# ids are changing.
Evan Cheng34301352007-09-01 02:03:17 +0000420 SmallVector<unsigned, 16> OtherAssignments;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000421 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
422 OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]);
423
424 // Update val# info. Renumber them and make sure they all belong to this
Evan Chengf3bb2e62007-09-05 21:46:51 +0000425 // LiveInterval now. Also remove dead val#'s.
426 unsigned NumValNos = 0;
427 for (unsigned i = 0; i < NumNewVals; ++i) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000428 VNInfo *VNI = NewVNInfo[i];
Evan Chengf3bb2e62007-09-05 21:46:51 +0000429 if (VNI) {
Evan Cheng30590f52009-04-28 06:24:09 +0000430 if (NumValNos >= NumVals)
Evan Chengf3bb2e62007-09-05 21:46:51 +0000431 valnos.push_back(VNI);
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000432 else
Evan Chengf3bb2e62007-09-05 21:46:51 +0000433 valnos[NumValNos] = VNI;
434 VNI->id = NumValNos++; // Renumber val#.
Evan Cheng34301352007-09-01 02:03:17 +0000435 }
436 }
Evan Cheng34301352007-09-01 02:03:17 +0000437 if (NumNewVals < NumVals)
438 valnos.resize(NumNewVals); // shrinkify
Evan Cheng4f8ff162007-08-11 00:59:19 +0000439
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000440 // Okay, now insert the RHS live ranges into the LHS.
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000441 iterator InsertPos = begin();
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000442 unsigned RangeNo = 0;
443 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I, ++RangeNo) {
444 // Map the valno in the other live range to the current live range.
445 I->valno = NewVNInfo[OtherAssignments[RangeNo]];
Evan Chengf3bb2e62007-09-05 21:46:51 +0000446 assert(I->valno && "Adding a dead range?");
Chris Lattnerabf295f2004-07-24 02:52:23 +0000447 InsertPos = addRangeFrom(*I, InsertPos);
448 }
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000449
David Greene29ff37f2009-07-22 20:08:25 +0000450 ComputeJoinedWeight(Other);
Chris Lattnerfb449b92004-07-23 17:49:16 +0000451}
452
Chris Lattnerf21f0202006-09-02 05:26:59 +0000453/// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
454/// interval as the specified value number. The LiveRanges in RHS are
455/// allowed to overlap with LiveRanges in the current interval, but only if
456/// the overlapping LiveRanges have the specified value number.
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000457void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS,
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000458 VNInfo *LHSValNo) {
Chris Lattnerf21f0202006-09-02 05:26:59 +0000459 // TODO: Make this more efficient.
460 iterator InsertPos = begin();
461 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000462 // Map the valno in the other live range to the current live range.
Chris Lattnerf21f0202006-09-02 05:26:59 +0000463 LiveRange Tmp = *I;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000464 Tmp.valno = LHSValNo;
Chris Lattnerf21f0202006-09-02 05:26:59 +0000465 InsertPos = addRangeFrom(Tmp, InsertPos);
466 }
467}
468
469
Evan Cheng32dfbea2007-10-12 08:50:34 +0000470/// MergeValueInAsValue - Merge all of the live ranges of a specific val#
471/// in RHS into this live interval as the specified value number.
472/// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000473/// current interval, it will replace the value numbers of the overlaped
474/// live ranges with the specified value number.
Lang Hames233a60e2009-11-03 23:52:08 +0000475void LiveInterval::MergeValueInAsValue(
476 const LiveInterval &RHS,
477 const VNInfo *RHSValNo, VNInfo *LHSValNo) {
Jakob Stoklund Olesend2eff132011-03-19 23:02:49 +0000478 // TODO: Make this more efficient.
479 iterator InsertPos = begin();
Evan Cheng32dfbea2007-10-12 08:50:34 +0000480 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
481 if (I->valno != RHSValNo)
482 continue;
483 // Map the valno in the other live range to the current live range.
Jakob Stoklund Olesend2eff132011-03-19 23:02:49 +0000484 LiveRange Tmp = *I;
485 Tmp.valno = LHSValNo;
486 InsertPos = addRangeFrom(Tmp, InsertPos);
Evan Cheng32dfbea2007-10-12 08:50:34 +0000487 }
488}
489
490
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000491/// MergeValueNumberInto - This method is called when two value nubmers
492/// are found to be equivalent. This eliminates V1, replacing all
493/// LiveRanges with the V1 value number with the V2 value number. This can
494/// cause merging of V1/V2 values numbers and compaction of the value space.
Owen Anderson5b93f6f2009-02-02 22:42:01 +0000495VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000496 assert(V1 != V2 && "Identical value#'s are always equivalent!");
497
498 // This code actually merges the (numerically) larger value number into the
499 // smaller value number, which is likely to allow us to compactify the value
500 // space. The only thing we have to be careful of is to preserve the
501 // instruction that defines the result value.
502
503 // Make sure V2 is smaller than V1.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000504 if (V1->id < V2->id) {
Lang Hames52c1afc2009-08-10 23:43:28 +0000505 V1->copyFrom(*V2);
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000506 std::swap(V1, V2);
507 }
508
509 // Merge V1 live ranges into V2.
510 for (iterator I = begin(); I != end(); ) {
511 iterator LR = I++;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000512 if (LR->valno != V1) continue; // Not a V1 LiveRange.
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000513
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000514 // Okay, we found a V1 live range. If it had a previous, touching, V2 live
515 // range, extend it.
516 if (LR != begin()) {
517 iterator Prev = LR-1;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000518 if (Prev->valno == V2 && Prev->end == LR->start) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000519 Prev->end = LR->end;
520
521 // Erase this live-range.
522 ranges.erase(LR);
523 I = Prev+1;
524 LR = Prev;
525 }
526 }
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000527
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000528 // Okay, now we have a V1 or V2 live range that is maximally merged forward.
529 // Ensure that it is a V2 live-range.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000530 LR->valno = V2;
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000531
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000532 // If we can merge it into later V2 live ranges, do so now. We ignore any
533 // following V1 live ranges, as they will be merged in subsequent iterations
534 // of the loop.
535 if (I != end()) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000536 if (I->start == LR->end && I->valno == V2) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000537 LR->end = I->end;
538 ranges.erase(I);
539 I = LR+1;
540 }
541 }
542 }
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000543
Jakob Stoklund Olesene0a73ec2010-10-01 23:52:25 +0000544 // Merge the relevant flags.
545 V2->mergeFlags(V1);
546
Lang Hames6f4e4df2010-07-26 01:49:41 +0000547 // Now that V1 is dead, remove it.
548 markValNoForDeletion(V1);
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000549
Owen Anderson5b93f6f2009-02-02 22:42:01 +0000550 return V2;
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000551}
552
Evan Cheng32dfbea2007-10-12 08:50:34 +0000553void LiveInterval::Copy(const LiveInterval &RHS,
Evan Cheng90f95f82009-06-14 20:22:55 +0000554 MachineRegisterInfo *MRI,
Benjamin Kramer991de142010-03-30 20:16:45 +0000555 VNInfo::Allocator &VNInfoAllocator) {
Evan Cheng32dfbea2007-10-12 08:50:34 +0000556 ranges.clear();
557 valnos.clear();
Evan Cheng358dec52009-06-15 08:28:29 +0000558 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(RHS.reg);
Evan Cheng90f95f82009-06-14 20:22:55 +0000559 MRI->setRegAllocationHint(reg, Hint.first, Hint.second);
560
Evan Cheng32dfbea2007-10-12 08:50:34 +0000561 weight = RHS.weight;
562 for (unsigned i = 0, e = RHS.getNumValNums(); i != e; ++i) {
563 const VNInfo *VNI = RHS.getValNumInfo(i);
Lang Hames857c4e02009-06-17 21:01:20 +0000564 createValueCopy(VNI, VNInfoAllocator);
Evan Cheng32dfbea2007-10-12 08:50:34 +0000565 }
566 for (unsigned i = 0, e = RHS.ranges.size(); i != e; ++i) {
567 const LiveRange &LR = RHS.ranges[i];
568 addRange(LiveRange(LR.start, LR.end, getValNumInfo(LR.valno->id)));
569 }
570}
571
Evan Chenge52eef82007-04-17 20:25:11 +0000572unsigned LiveInterval::getSize() const {
573 unsigned Sum = 0;
574 for (const_iterator I = begin(), E = end(); I != E; ++I)
Lang Hames86511252009-09-04 20:41:11 +0000575 Sum += I->start.distance(I->end);
Evan Chenge52eef82007-04-17 20:25:11 +0000576 return Sum;
577}
578
David Greene29ff37f2009-07-22 20:08:25 +0000579/// ComputeJoinedWeight - Set the weight of a live interval Joined
580/// after Other has been merged into it.
581void LiveInterval::ComputeJoinedWeight(const LiveInterval &Other) {
582 // If either of these intervals was spilled, the weight is the
583 // weight of the non-spilled interval. This can only happen with
584 // iterative coalescers.
585
David Greene92b78bb2009-07-22 22:32:19 +0000586 if (Other.weight != HUGE_VALF) {
587 weight += Other.weight;
588 }
589 else if (weight == HUGE_VALF &&
David Greene29ff37f2009-07-22 20:08:25 +0000590 !TargetRegisterInfo::isPhysicalRegister(reg)) {
591 // Remove this assert if you have an iterative coalescer
592 assert(0 && "Joining to spilled interval");
593 weight = Other.weight;
594 }
David Greene29ff37f2009-07-22 20:08:25 +0000595 else {
596 // Otherwise the weight stays the same
597 // Remove this assert if you have an iterative coalescer
598 assert(0 && "Joining from spilled interval");
599 }
600}
601
Daniel Dunbar1cd1d982009-07-24 10:36:58 +0000602raw_ostream& llvm::operator<<(raw_ostream& os, const LiveRange &LR) {
603 return os << '[' << LR.start << ',' << LR.end << ':' << LR.valno->id << ")";
604}
Chris Lattnerfb449b92004-07-23 17:49:16 +0000605
Chris Lattnerabf295f2004-07-24 02:52:23 +0000606void LiveRange::dump() const {
David Greene52421542010-01-04 22:41:43 +0000607 dbgs() << *this << "\n";
Chris Lattnerabf295f2004-07-24 02:52:23 +0000608}
609
Chris Lattnerc02497f2009-08-23 03:47:42 +0000610void LiveInterval::print(raw_ostream &OS, const TargetRegisterInfo *TRI) const {
Jakob Stoklund Olesenccdb3fc2011-01-19 22:11:48 +0000611 OS << PrintReg(reg, TRI);
612 if (weight != 0)
613 OS << ',' << weight;
Chris Lattnerfb449b92004-07-23 17:49:16 +0000614
Chris Lattner38135af2005-05-14 05:34:15 +0000615 if (empty())
Evan Cheng3f32d652008-06-04 09:18:41 +0000616 OS << " EMPTY";
Chris Lattner38135af2005-05-14 05:34:15 +0000617 else {
618 OS << " = ";
619 for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
Jakob Stoklund Olesen014b8632010-06-23 15:34:36 +0000620 E = ranges.end(); I != E; ++I) {
621 OS << *I;
622 assert(I->valno == getValNumInfo(I->valno->id) && "Bad VNInfo");
623 }
Chris Lattner38135af2005-05-14 05:34:15 +0000624 }
Jakob Stoklund Olesen15a57142010-06-25 22:53:05 +0000625
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000626 // Print value number info.
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000627 if (getNumValNums()) {
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000628 OS << " ";
Evan Cheng1a66f0a2007-08-28 08:28:51 +0000629 unsigned vnum = 0;
630 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
631 ++i, ++vnum) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000632 const VNInfo *vni = *i;
Evan Cheng1a66f0a2007-08-28 08:28:51 +0000633 if (vnum) OS << " ";
634 OS << vnum << "@";
Lang Hames857c4e02009-06-17 21:01:20 +0000635 if (vni->isUnused()) {
Evan Cheng8df78602007-08-08 03:00:28 +0000636 OS << "x";
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000637 } else {
Lang Hames6e2968c2010-09-25 12:04:16 +0000638 OS << vni->def;
Jakob Stoklund Olesena818c072010-10-05 18:48:57 +0000639 if (vni->isPHIDef())
640 OS << "-phidef";
Jakob Stoklund Olesend9f6ec92010-07-13 21:19:05 +0000641 if (vni->hasPHIKill())
642 OS << "-phikill";
643 if (vni->hasRedefByEC())
644 OS << "-ec";
Evan Chenga8d94f12007-08-07 23:49:57 +0000645 }
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000646 }
647 }
Chris Lattnerfb449b92004-07-23 17:49:16 +0000648}
Chris Lattnerabf295f2004-07-24 02:52:23 +0000649
650void LiveInterval::dump() const {
David Greene52421542010-01-04 22:41:43 +0000651 dbgs() << *this << "\n";
Chris Lattnerabf295f2004-07-24 02:52:23 +0000652}
Jeff Cohenc21c5ee2006-12-15 22:57:14 +0000653
654
Daniel Dunbar1cd1d982009-07-24 10:36:58 +0000655void LiveRange::print(raw_ostream &os) const {
656 os << *this;
657}
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000658
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000659unsigned ConnectedVNInfoEqClasses::Classify(const LiveInterval *LI) {
Jakob Stoklund Olesen54f32e62010-10-08 21:19:28 +0000660 // Create initial equivalence classes.
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000661 EqClass.clear();
662 EqClass.grow(LI->getNumValNums());
Jakob Stoklund Olesen54f32e62010-10-08 21:19:28 +0000663
Jakob Stoklund Olesen6d309052010-10-29 17:37:29 +0000664 const VNInfo *used = 0, *unused = 0;
665
Jakob Stoklund Olesen54f32e62010-10-08 21:19:28 +0000666 // Determine connections.
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000667 for (LiveInterval::const_vni_iterator I = LI->vni_begin(), E = LI->vni_end();
668 I != E; ++I) {
669 const VNInfo *VNI = *I;
Jakob Stoklund Olesen6d309052010-10-29 17:37:29 +0000670 // Group all unused values into one class.
671 if (VNI->isUnused()) {
672 if (unused)
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000673 EqClass.join(unused->id, VNI->id);
Jakob Stoklund Olesen6d309052010-10-29 17:37:29 +0000674 unused = VNI;
675 continue;
676 }
677 used = VNI;
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000678 if (VNI->isPHIDef()) {
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000679 const MachineBasicBlock *MBB = LIS.getMBBFromIndex(VNI->def);
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000680 assert(MBB && "Phi-def has no defining MBB");
681 // Connect to values live out of predecessors.
682 for (MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(),
683 PE = MBB->pred_end(); PI != PE; ++PI)
Jakob Stoklund Olesen194eb712011-11-14 01:39:36 +0000684 if (const VNInfo *PVNI = LI->getVNInfoBefore(LIS.getMBBEndIdx(*PI)))
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000685 EqClass.join(VNI->id, PVNI->id);
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000686 } else {
687 // Normal value defined by an instruction. Check for two-addr redef.
688 // FIXME: This could be coincidental. Should we really check for a tied
689 // operand constraint?
Jakob Stoklund Olesenb907e8a2010-12-21 00:48:17 +0000690 // Note that VNI->def may be a use slot for an early clobber def.
Jakob Stoklund Olesen194eb712011-11-14 01:39:36 +0000691 if (const VNInfo *UVNI = LI->getVNInfoBefore(VNI->def))
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000692 EqClass.join(VNI->id, UVNI->id);
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000693 }
694 }
Jakob Stoklund Olesen6d309052010-10-29 17:37:29 +0000695
696 // Lump all the unused values in with the last used value.
697 if (used && unused)
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000698 EqClass.join(used->id, unused->id);
Jakob Stoklund Olesen6d309052010-10-29 17:37:29 +0000699
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000700 EqClass.compress();
701 return EqClass.getNumClasses();
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000702}
703
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000704void ConnectedVNInfoEqClasses::Distribute(LiveInterval *LIV[],
705 MachineRegisterInfo &MRI) {
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000706 assert(LIV[0] && "LIV[0] must be set");
707 LiveInterval &LI = *LIV[0];
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000708
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000709 // Rewrite instructions.
710 for (MachineRegisterInfo::reg_iterator RI = MRI.reg_begin(LI.reg),
711 RE = MRI.reg_end(); RI != RE;) {
712 MachineOperand &MO = RI.getOperand();
713 MachineInstr *MI = MO.getParent();
714 ++RI;
715 if (MO.isUse() && MO.isUndef())
716 continue;
717 // DBG_VALUE instructions should have been eliminated earlier.
718 SlotIndex Idx = LIS.getInstructionIndex(MI);
Jakob Stoklund Olesen2debd482011-11-13 20:45:27 +0000719 Idx = Idx.getRegSlot(MO.isUse());
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000720 const VNInfo *VNI = LI.getVNInfoAt(Idx);
721 assert(VNI && "Interval not live at use.");
722 MO.setReg(LIV[getEqClass(VNI)]->reg);
723 }
724
725 // Move runs to new intervals.
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000726 LiveInterval::iterator J = LI.begin(), E = LI.end();
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000727 while (J != E && EqClass[J->valno->id] == 0)
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000728 ++J;
729 for (LiveInterval::iterator I = J; I != E; ++I) {
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000730 if (unsigned eq = EqClass[I->valno->id]) {
Benjamin Kramerccefe322010-10-09 16:36:44 +0000731 assert((LIV[eq]->empty() || LIV[eq]->expiredAt(I->start)) &&
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000732 "New intervals should be empty");
733 LIV[eq]->ranges.push_back(*I);
734 } else
735 *J++ = *I;
736 }
737 LI.ranges.erase(J, E);
738
739 // Transfer VNInfos to their new owners and renumber them.
740 unsigned j = 0, e = LI.getNumValNums();
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000741 while (j != e && EqClass[j] == 0)
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000742 ++j;
743 for (unsigned i = j; i != e; ++i) {
744 VNInfo *VNI = LI.getValNumInfo(i);
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000745 if (unsigned eq = EqClass[i]) {
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000746 VNI->id = LIV[eq]->getNumValNums();
747 LIV[eq]->valnos.push_back(VNI);
748 } else {
749 VNI->id = j;
750 LI.valnos[j++] = VNI;
751 }
752 }
753 LI.valnos.resize(j);
754}