blob: 8990360a7215a60f8d88545fbed6ed74b3d9a7bf [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
Jakob Stoklund Olesen4e53a402012-06-05 21:54:09 +000051VNInfo *LiveInterval::createDeadDef(SlotIndex Def,
52 VNInfo::Allocator &VNInfoAllocator) {
53 assert(!Def.isDead() && "Cannot define a value at the dead slot");
54 iterator I = find(Def);
55 if (I == end()) {
56 VNInfo *VNI = getNextValue(Def, VNInfoAllocator);
57 ranges.push_back(LiveRange(Def, Def.getDeadSlot(), VNI));
58 return VNI;
59 }
60 if (SlotIndex::isSameInstr(Def, I->start)) {
61 assert(I->start == Def && "Cannot insert def, already live");
62 assert(I->valno->def == Def && "Inconsistent existing value def");
63 return I->valno;
64 }
65 assert(SlotIndex::isEarlierInstr(Def, I->start) && "Already live at def");
66 VNInfo *VNI = getNextValue(Def, VNInfoAllocator);
67 ranges.insert(I, LiveRange(Def, Def.getDeadSlot(), VNI));
68 return VNI;
69}
70
Jakob Stoklund Olesen15a57142010-06-25 22:53:05 +000071/// killedInRange - Return true if the interval has kills in [Start,End).
72bool LiveInterval::killedInRange(SlotIndex Start, SlotIndex End) const {
73 Ranges::const_iterator r =
74 std::lower_bound(ranges.begin(), ranges.end(), End);
75
76 // Now r points to the first interval with start >= End, or ranges.end().
77 if (r == ranges.begin())
78 return false;
79
80 --r;
81 // Now r points to the last interval with end <= End.
82 // r->end is the kill point.
83 return r->end >= Start && r->end < End;
84}
85
Chris Lattnerbae74d92004-11-18 03:47:34 +000086// overlaps - Return true if the intersection of the two live intervals is
87// not empty.
88//
Chris Lattnerfb449b92004-07-23 17:49:16 +000089// An example for overlaps():
90//
91// 0: A = ...
92// 4: B = ...
93// 8: C = A + B ;; last use of A
94//
95// The live intervals should look like:
96//
97// A = [3, 11)
98// B = [7, x)
99// C = [11, y)
100//
101// A->overlaps(C) should return false since we want to be able to join
102// A and C.
Chris Lattnerbae74d92004-11-18 03:47:34 +0000103//
104bool LiveInterval::overlapsFrom(const LiveInterval& other,
105 const_iterator StartPos) const {
Jakob Stoklund Olesen6382d2c2010-07-13 19:56:28 +0000106 assert(!empty() && "empty interval");
Chris Lattnerbae74d92004-11-18 03:47:34 +0000107 const_iterator i = begin();
108 const_iterator ie = end();
109 const_iterator j = StartPos;
110 const_iterator je = other.end();
111
112 assert((StartPos->start <= i->start || StartPos == other.begin()) &&
Chris Lattner8c68b6a2004-11-18 04:02:11 +0000113 StartPos != other.end() && "Bogus start position hint!");
Chris Lattnerf5426492004-07-25 07:11:19 +0000114
Chris Lattnerfb449b92004-07-23 17:49:16 +0000115 if (i->start < j->start) {
Chris Lattneraa141472004-07-23 18:40:00 +0000116 i = std::upper_bound(i, ie, j->start);
Chris Lattnerfb449b92004-07-23 17:49:16 +0000117 if (i != ranges.begin()) --i;
Chris Lattneraa141472004-07-23 18:40:00 +0000118 } else if (j->start < i->start) {
Chris Lattneread1b3f2004-12-04 01:22:09 +0000119 ++StartPos;
120 if (StartPos != other.end() && StartPos->start <= i->start) {
121 assert(StartPos < other.end() && i < end());
Chris Lattner8c68b6a2004-11-18 04:02:11 +0000122 j = std::upper_bound(j, je, i->start);
123 if (j != other.ranges.begin()) --j;
124 }
Chris Lattneraa141472004-07-23 18:40:00 +0000125 } else {
126 return true;
Chris Lattnerfb449b92004-07-23 17:49:16 +0000127 }
128
Chris Lattner9fddc122004-11-18 05:28:21 +0000129 if (j == je) return false;
130
131 while (i != ie) {
Chris Lattnerfb449b92004-07-23 17:49:16 +0000132 if (i->start > j->start) {
Alkis Evlogimenosa1613db2004-07-24 11:44:15 +0000133 std::swap(i, j);
134 std::swap(ie, je);
Chris Lattnerfb449b92004-07-23 17:49:16 +0000135 }
Chris Lattnerfb449b92004-07-23 17:49:16 +0000136
137 if (i->end > j->start)
138 return true;
139 ++i;
140 }
141
142 return false;
143}
144
Evan Chengcccdb2b2009-04-18 08:52:15 +0000145/// overlaps - Return true if the live interval overlaps a range specified
146/// by [Start, End).
Lang Hames233a60e2009-11-03 23:52:08 +0000147bool LiveInterval::overlaps(SlotIndex Start, SlotIndex End) const {
Evan Chengcccdb2b2009-04-18 08:52:15 +0000148 assert(Start < End && "Invalid range");
Jakob Stoklund Olesen186eb732010-07-13 19:42:20 +0000149 const_iterator I = std::lower_bound(begin(), end(), End);
150 return I != begin() && (--I)->end > Start;
Evan Chengcccdb2b2009-04-18 08:52:15 +0000151}
152
Lang Hames6f4e4df2010-07-26 01:49:41 +0000153
154/// ValNo is dead, remove it. If it is the largest value number, just nuke it
155/// (and any other deleted values neighboring it), otherwise mark it as ~1U so
156/// it can be nuked later.
157void LiveInterval::markValNoForDeletion(VNInfo *ValNo) {
158 if (ValNo->id == getNumValNums()-1) {
159 do {
160 valnos.pop_back();
161 } while (!valnos.empty() && valnos.back()->isUnused());
162 } else {
163 ValNo->setIsUnused(true);
164 }
165}
166
Jakob Stoklund Olesen23436592010-08-06 18:46:59 +0000167/// RenumberValues - Renumber all values in order of appearance and delete the
168/// remaining unused values.
Jakob Stoklund Olesenfff2c472010-08-12 20:38:03 +0000169void LiveInterval::RenumberValues(LiveIntervals &lis) {
Jakob Stoklund Olesen23436592010-08-06 18:46:59 +0000170 SmallPtrSet<VNInfo*, 8> Seen;
171 valnos.clear();
172 for (const_iterator I = begin(), E = end(); I != E; ++I) {
173 VNInfo *VNI = I->valno;
174 if (!Seen.insert(VNI))
175 continue;
176 assert(!VNI->isUnused() && "Unused valno used by live range");
177 VNI->id = (unsigned)valnos.size();
178 valnos.push_back(VNI);
179 }
180}
181
Chris Lattnerb26c2152004-07-23 19:38:44 +0000182/// extendIntervalEndTo - This method is used when we want to extend the range
183/// specified by I to end at the specified endpoint. To do this, we should
184/// merge and eliminate all ranges that this will overlap with. The iterator is
185/// not invalidated.
Lang Hames233a60e2009-11-03 23:52:08 +0000186void LiveInterval::extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd) {
Chris Lattnerb26c2152004-07-23 19:38:44 +0000187 assert(I != ranges.end() && "Not a valid interval!");
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000188 VNInfo *ValNo = I->valno;
Chris Lattnerfb449b92004-07-23 17:49:16 +0000189
Chris Lattnerb26c2152004-07-23 19:38:44 +0000190 // Search for the first interval that we can't merge with.
Oscar Fuentesee56c422010-08-02 06:00:15 +0000191 Ranges::iterator MergeTo = llvm::next(I);
Chris Lattnerabf295f2004-07-24 02:52:23 +0000192 for (; MergeTo != ranges.end() && NewEnd >= MergeTo->end; ++MergeTo) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000193 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
Chris Lattnerabf295f2004-07-24 02:52:23 +0000194 }
Chris Lattnerb26c2152004-07-23 19:38:44 +0000195
196 // If NewEnd was in the middle of an interval, make sure to get its endpoint.
197 I->end = std::max(NewEnd, prior(MergeTo)->end);
198
Chris Lattnerb0fa11c2005-10-20 07:39:25 +0000199 // Erase any dead ranges.
Oscar Fuentesee56c422010-08-02 06:00:15 +0000200 ranges.erase(llvm::next(I), MergeTo);
Evan Cheng4f8ff162007-08-11 00:59:19 +0000201
Chris Lattnerb0fa11c2005-10-20 07:39:25 +0000202 // If the newly formed range now touches the range after it and if they have
203 // the same value number, merge the two ranges into one range.
Oscar Fuentesee56c422010-08-02 06:00:15 +0000204 Ranges::iterator Next = llvm::next(I);
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000205 if (Next != ranges.end() && Next->start <= I->end && Next->valno == ValNo) {
Chris Lattnercef60102005-10-20 22:50:10 +0000206 I->end = Next->end;
207 ranges.erase(Next);
Chris Lattnerb0fa11c2005-10-20 07:39:25 +0000208 }
Chris Lattnerb26c2152004-07-23 19:38:44 +0000209}
210
211
212/// extendIntervalStartTo - This method is used when we want to extend the range
213/// specified by I to start at the specified endpoint. To do this, we should
214/// merge and eliminate all ranges that this will overlap with.
Misha Brukmanedf128a2005-04-21 22:36:52 +0000215LiveInterval::Ranges::iterator
Lang Hames233a60e2009-11-03 23:52:08 +0000216LiveInterval::extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStart) {
Chris Lattnerb26c2152004-07-23 19:38:44 +0000217 assert(I != ranges.end() && "Not a valid interval!");
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000218 VNInfo *ValNo = I->valno;
Chris Lattnerb26c2152004-07-23 19:38:44 +0000219
220 // Search for the first interval that we can't merge with.
221 Ranges::iterator MergeTo = I;
222 do {
223 if (MergeTo == ranges.begin()) {
224 I->start = NewStart;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000225 ranges.erase(MergeTo, I);
Chris Lattnerb26c2152004-07-23 19:38:44 +0000226 return I;
227 }
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000228 assert(MergeTo->valno == ValNo && "Cannot merge with differing values!");
Chris Lattnerb26c2152004-07-23 19:38:44 +0000229 --MergeTo;
230 } while (NewStart <= MergeTo->start);
231
232 // If we start in the middle of another interval, just delete a range and
233 // extend that interval.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000234 if (MergeTo->end >= NewStart && MergeTo->valno == ValNo) {
Chris Lattnerb26c2152004-07-23 19:38:44 +0000235 MergeTo->end = I->end;
236 } else {
237 // Otherwise, extend the interval right after.
238 ++MergeTo;
239 MergeTo->start = NewStart;
240 MergeTo->end = I->end;
241 }
242
Oscar Fuentesee56c422010-08-02 06:00:15 +0000243 ranges.erase(llvm::next(MergeTo), llvm::next(I));
Chris Lattnerb26c2152004-07-23 19:38:44 +0000244 return MergeTo;
245}
246
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000247LiveInterval::iterator
248LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
Lang Hames233a60e2009-11-03 23:52:08 +0000249 SlotIndex Start = LR.start, End = LR.end;
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000250 iterator it = std::upper_bound(From, ranges.end(), Start);
Chris Lattnerb26c2152004-07-23 19:38:44 +0000251
252 // If the inserted interval starts in the middle or right at the end of
253 // another interval, just extend that interval to contain the range of LR.
254 if (it != ranges.begin()) {
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000255 iterator B = prior(it);
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000256 if (LR.valno == B->valno) {
Chris Lattnerabf295f2004-07-24 02:52:23 +0000257 if (B->start <= Start && B->end >= Start) {
258 extendIntervalEndTo(B, End);
259 return B;
260 }
261 } else {
262 // Check to make sure that we are not overlapping two live ranges with
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000263 // different valno's.
Chris Lattnerabf295f2004-07-24 02:52:23 +0000264 assert(B->end <= Start &&
Brian Gaeke8311bef2004-11-16 06:52:35 +0000265 "Cannot overlap two LiveRanges with differing ValID's"
266 " (did you def the same reg twice in a MachineInstr?)");
Chris Lattnerb26c2152004-07-23 19:38:44 +0000267 }
268 }
269
270 // Otherwise, if this range ends in the middle of, or right next to, another
271 // interval, merge it into that interval.
Anton Korobeynikov4c71dfe2008-02-20 11:10:28 +0000272 if (it != ranges.end()) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000273 if (LR.valno == it->valno) {
Chris Lattnerabf295f2004-07-24 02:52:23 +0000274 if (it->start <= End) {
275 it = extendIntervalStartTo(it, Start);
276
277 // If LR is a complete superset of an interval, we may need to grow its
278 // endpoint as well.
279 if (End > it->end)
280 extendIntervalEndTo(it, End);
281 return it;
282 }
283 } else {
284 // Check to make sure that we are not overlapping two live ranges with
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000285 // different valno's.
Chris Lattnerabf295f2004-07-24 02:52:23 +0000286 assert(it->start >= End &&
287 "Cannot overlap two LiveRanges with differing ValID's");
288 }
Anton Korobeynikov4c71dfe2008-02-20 11:10:28 +0000289 }
Chris Lattnerb26c2152004-07-23 19:38:44 +0000290
291 // Otherwise, this is just a new range that doesn't interact with anything.
292 // Insert it.
293 return ranges.insert(it, LR);
Chris Lattnerfb449b92004-07-23 17:49:16 +0000294}
295
Jakob Stoklund Olesenee5655d2011-09-13 16:47:56 +0000296/// extendInBlock - If this interval is live before Kill in the basic
297/// block that starts at StartIdx, extend it to be live up to Kill and return
298/// the value. If there is no live range before Kill, return NULL.
299VNInfo *LiveInterval::extendInBlock(SlotIndex StartIdx, SlotIndex Kill) {
Jakob Stoklund Olesen9763e2b2011-03-02 00:06:15 +0000300 if (empty())
301 return 0;
Jakob Stoklund Olesenee5655d2011-09-13 16:47:56 +0000302 iterator I = std::upper_bound(begin(), end(), Kill.getPrevSlot());
Jakob Stoklund Olesen9763e2b2011-03-02 00:06:15 +0000303 if (I == begin())
304 return 0;
305 --I;
306 if (I->end <= StartIdx)
307 return 0;
Jakob Stoklund Olesenee5655d2011-09-13 16:47:56 +0000308 if (I->end < Kill)
309 extendIntervalEndTo(I, Kill);
Jakob Stoklund Olesen9763e2b2011-03-02 00:06:15 +0000310 return I->valno;
311}
Chris Lattnerabf295f2004-07-24 02:52:23 +0000312
313/// removeRange - Remove the specified range from this interval. Note that
Evan Cheng42cc6e32009-01-29 00:06:09 +0000314/// the range must be in a single LiveRange in its entirety.
Lang Hames233a60e2009-11-03 23:52:08 +0000315void LiveInterval::removeRange(SlotIndex Start, SlotIndex End,
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000316 bool RemoveDeadValNo) {
Chris Lattnerabf295f2004-07-24 02:52:23 +0000317 // Find the LiveRange containing this span.
Jakob Stoklund Olesenf568b272010-09-21 17:12:18 +0000318 Ranges::iterator I = find(Start);
319 assert(I != ranges.end() && "Range is not in interval!");
Lang Hames86511252009-09-04 20:41:11 +0000320 assert(I->containsRange(Start, End) && "Range is not entirely in interval!");
Chris Lattnerabf295f2004-07-24 02:52:23 +0000321
322 // If the span we are removing is at the start of the LiveRange, adjust it.
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000323 VNInfo *ValNo = I->valno;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000324 if (I->start == Start) {
Evan Cheng4f8ff162007-08-11 00:59:19 +0000325 if (I->end == End) {
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000326 if (RemoveDeadValNo) {
327 // Check if val# is dead.
328 bool isDead = true;
329 for (const_iterator II = begin(), EE = end(); II != EE; ++II)
330 if (II != I && II->valno == ValNo) {
331 isDead = false;
332 break;
Jakob Stoklund Olesen15a57142010-06-25 22:53:05 +0000333 }
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000334 if (isDead) {
Lang Hames6f4e4df2010-07-26 01:49:41 +0000335 // Now that ValNo is dead, remove it.
336 markValNoForDeletion(ValNo);
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000337 }
338 }
339
Chris Lattnerabf295f2004-07-24 02:52:23 +0000340 ranges.erase(I); // Removed the whole LiveRange.
Evan Cheng4f8ff162007-08-11 00:59:19 +0000341 } else
Chris Lattnerabf295f2004-07-24 02:52:23 +0000342 I->start = End;
343 return;
344 }
345
346 // Otherwise if the span we are removing is at the end of the LiveRange,
347 // adjust the other way.
348 if (I->end == End) {
Chris Lattner6925a9f2004-07-25 05:43:53 +0000349 I->end = Start;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000350 return;
351 }
352
353 // Otherwise, we are splitting the LiveRange into two pieces.
Lang Hames233a60e2009-11-03 23:52:08 +0000354 SlotIndex OldEnd = I->end;
Chris Lattnerabf295f2004-07-24 02:52:23 +0000355 I->end = Start; // Trim the old interval.
356
357 // Insert the new one.
Oscar Fuentesee56c422010-08-02 06:00:15 +0000358 ranges.insert(llvm::next(I), LiveRange(End, OldEnd, ValNo));
Chris Lattnerabf295f2004-07-24 02:52:23 +0000359}
360
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000361/// removeValNo - Remove all the ranges defined by the specified value#.
362/// Also remove the value# from value# list.
363void LiveInterval::removeValNo(VNInfo *ValNo) {
364 if (empty()) return;
365 Ranges::iterator I = ranges.end();
366 Ranges::iterator E = ranges.begin();
367 do {
368 --I;
369 if (I->valno == ValNo)
370 ranges.erase(I);
371 } while (I != E);
Lang Hames6f4e4df2010-07-26 01:49:41 +0000372 // Now that ValNo is dead, remove it.
373 markValNoForDeletion(ValNo);
Evan Chengd2b8d7b2008-02-13 02:48:26 +0000374}
Lang Hames86511252009-09-04 20:41:11 +0000375
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000376/// join - Join two live intervals (this, and other) together. This applies
377/// mappings to the value numbers in the LHS/RHS intervals as specified. If
378/// the intervals are not joinable, this aborts.
Lang Hames233a60e2009-11-03 23:52:08 +0000379void LiveInterval::join(LiveInterval &Other,
380 const int *LHSValNoAssignments,
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000381 const int *RHSValNoAssignments,
Evan Cheng90f95f82009-06-14 20:22:55 +0000382 SmallVector<VNInfo*, 16> &NewVNInfo,
383 MachineRegisterInfo *MRI) {
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000384 // Determine if any of our live range values are mapped. This is uncommon, so
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000385 // we want to avoid the interval scan if not.
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000386 bool MustMapCurValNos = false;
Evan Cheng34301352007-09-01 02:03:17 +0000387 unsigned NumVals = getNumValNums();
388 unsigned NumNewVals = NewVNInfo.size();
389 for (unsigned i = 0; i != NumVals; ++i) {
390 unsigned LHSValID = LHSValNoAssignments[i];
391 if (i != LHSValID ||
Lang Hamesd88710a2012-02-02 06:55:45 +0000392 (NewVNInfo[LHSValID] && NewVNInfo[LHSValID] != getValNumInfo(i))) {
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000393 MustMapCurValNos = true;
Lang Hamesd88710a2012-02-02 06:55:45 +0000394 break;
395 }
Chris Lattnerdeb99712004-07-24 03:41:50 +0000396 }
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000397
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000398 // If we have to apply a mapping to our base interval assignment, rewrite it
399 // now.
400 if (MustMapCurValNos) {
401 // Map the first live range.
Lang Hames02e08d52012-02-02 05:37:34 +0000402
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000403 iterator OutIt = begin();
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000404 OutIt->valno = NewVNInfo[LHSValNoAssignments[OutIt->valno->id]];
Lang Hames02e08d52012-02-02 05:37:34 +0000405 for (iterator I = next(OutIt), E = end(); I != E; ++I) {
406 VNInfo* nextValNo = NewVNInfo[LHSValNoAssignments[I->valno->id]];
407 assert(nextValNo != 0 && "Huh?");
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000408
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000409 // If this live range has the same value # as its immediate predecessor,
410 // and if they are neighbors, remove one LiveRange. This happens when we
Lang Hames02e08d52012-02-02 05:37:34 +0000411 // have [0,4:0)[4,7:1) and map 0/1 onto the same value #.
412 if (OutIt->valno == nextValNo && OutIt->end == I->start) {
413 OutIt->end = I->end;
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000414 } else {
Lang Hames02e08d52012-02-02 05:37:34 +0000415 // Didn't merge. Move OutIt to the next interval,
416 ++OutIt;
417 OutIt->valno = nextValNo;
418 if (OutIt != I) {
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000419 OutIt->start = I->start;
420 OutIt->end = I->end;
421 }
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000422 }
423 }
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000424 // If we merge some live ranges, chop off the end.
Lang Hames02e08d52012-02-02 05:37:34 +0000425 ++OutIt;
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000426 ranges.erase(OutIt, end());
427 }
Evan Cheng4f8ff162007-08-11 00:59:19 +0000428
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000429 // Remember assignements because val# ids are changing.
Evan Cheng34301352007-09-01 02:03:17 +0000430 SmallVector<unsigned, 16> OtherAssignments;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000431 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I)
432 OtherAssignments.push_back(RHSValNoAssignments[I->valno->id]);
433
434 // Update val# info. Renumber them and make sure they all belong to this
Evan Chengf3bb2e62007-09-05 21:46:51 +0000435 // LiveInterval now. Also remove dead val#'s.
436 unsigned NumValNos = 0;
437 for (unsigned i = 0; i < NumNewVals; ++i) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000438 VNInfo *VNI = NewVNInfo[i];
Evan Chengf3bb2e62007-09-05 21:46:51 +0000439 if (VNI) {
Evan Cheng30590f52009-04-28 06:24:09 +0000440 if (NumValNos >= NumVals)
Evan Chengf3bb2e62007-09-05 21:46:51 +0000441 valnos.push_back(VNI);
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000442 else
Evan Chengf3bb2e62007-09-05 21:46:51 +0000443 valnos[NumValNos] = VNI;
444 VNI->id = NumValNos++; // Renumber val#.
Evan Cheng34301352007-09-01 02:03:17 +0000445 }
446 }
Evan Cheng34301352007-09-01 02:03:17 +0000447 if (NumNewVals < NumVals)
448 valnos.resize(NumNewVals); // shrinkify
Evan Cheng4f8ff162007-08-11 00:59:19 +0000449
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000450 // Okay, now insert the RHS live ranges into the LHS.
Chris Lattnerc114b2c2006-08-25 23:41:24 +0000451 iterator InsertPos = begin();
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000452 unsigned RangeNo = 0;
453 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I, ++RangeNo) {
454 // Map the valno in the other live range to the current live range.
455 I->valno = NewVNInfo[OtherAssignments[RangeNo]];
Evan Chengf3bb2e62007-09-05 21:46:51 +0000456 assert(I->valno && "Adding a dead range?");
Chris Lattnerabf295f2004-07-24 02:52:23 +0000457 InsertPos = addRangeFrom(*I, InsertPos);
458 }
Chris Lattnerfb449b92004-07-23 17:49:16 +0000459}
460
Chris Lattnerf21f0202006-09-02 05:26:59 +0000461/// MergeRangesInAsValue - Merge all of the intervals in RHS into this live
462/// interval as the specified value number. The LiveRanges in RHS are
463/// allowed to overlap with LiveRanges in the current interval, but only if
464/// the overlapping LiveRanges have the specified value number.
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000465void LiveInterval::MergeRangesInAsValue(const LiveInterval &RHS,
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000466 VNInfo *LHSValNo) {
Chris Lattnerf21f0202006-09-02 05:26:59 +0000467 // TODO: Make this more efficient.
468 iterator InsertPos = begin();
469 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000470 // Map the valno in the other live range to the current live range.
Chris Lattnerf21f0202006-09-02 05:26:59 +0000471 LiveRange Tmp = *I;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000472 Tmp.valno = LHSValNo;
Chris Lattnerf21f0202006-09-02 05:26:59 +0000473 InsertPos = addRangeFrom(Tmp, InsertPos);
474 }
475}
476
477
Evan Cheng32dfbea2007-10-12 08:50:34 +0000478/// MergeValueInAsValue - Merge all of the live ranges of a specific val#
479/// in RHS into this live interval as the specified value number.
480/// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
Evan Cheng3c1f4a42007-10-17 02:13:29 +0000481/// current interval, it will replace the value numbers of the overlaped
482/// live ranges with the specified value number.
Lang Hames233a60e2009-11-03 23:52:08 +0000483void LiveInterval::MergeValueInAsValue(
484 const LiveInterval &RHS,
485 const VNInfo *RHSValNo, VNInfo *LHSValNo) {
Jakob Stoklund Olesend2eff132011-03-19 23:02:49 +0000486 // TODO: Make this more efficient.
487 iterator InsertPos = begin();
Evan Cheng32dfbea2007-10-12 08:50:34 +0000488 for (const_iterator I = RHS.begin(), E = RHS.end(); I != E; ++I) {
489 if (I->valno != RHSValNo)
490 continue;
491 // Map the valno in the other live range to the current live range.
Jakob Stoklund Olesend2eff132011-03-19 23:02:49 +0000492 LiveRange Tmp = *I;
493 Tmp.valno = LHSValNo;
494 InsertPos = addRangeFrom(Tmp, InsertPos);
Evan Cheng32dfbea2007-10-12 08:50:34 +0000495 }
496}
497
498
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000499/// MergeValueNumberInto - This method is called when two value nubmers
500/// are found to be equivalent. This eliminates V1, replacing all
501/// LiveRanges with the V1 value number with the V2 value number. This can
502/// cause merging of V1/V2 values numbers and compaction of the value space.
Owen Anderson5b93f6f2009-02-02 22:42:01 +0000503VNInfo* LiveInterval::MergeValueNumberInto(VNInfo *V1, VNInfo *V2) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000504 assert(V1 != V2 && "Identical value#'s are always equivalent!");
505
506 // This code actually merges the (numerically) larger value number into the
507 // smaller value number, which is likely to allow us to compactify the value
508 // space. The only thing we have to be careful of is to preserve the
509 // instruction that defines the result value.
510
511 // Make sure V2 is smaller than V1.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000512 if (V1->id < V2->id) {
Lang Hames52c1afc2009-08-10 23:43:28 +0000513 V1->copyFrom(*V2);
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000514 std::swap(V1, V2);
515 }
516
517 // Merge V1 live ranges into V2.
518 for (iterator I = begin(); I != end(); ) {
519 iterator LR = I++;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000520 if (LR->valno != V1) continue; // Not a V1 LiveRange.
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000521
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000522 // Okay, we found a V1 live range. If it had a previous, touching, V2 live
523 // range, extend it.
524 if (LR != begin()) {
525 iterator Prev = LR-1;
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000526 if (Prev->valno == V2 && Prev->end == LR->start) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000527 Prev->end = LR->end;
528
529 // Erase this live-range.
530 ranges.erase(LR);
531 I = Prev+1;
532 LR = Prev;
533 }
534 }
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000535
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000536 // Okay, now we have a V1 or V2 live range that is maximally merged forward.
537 // Ensure that it is a V2 live-range.
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000538 LR->valno = V2;
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000539
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000540 // If we can merge it into later V2 live ranges, do so now. We ignore any
541 // following V1 live ranges, as they will be merged in subsequent iterations
542 // of the loop.
543 if (I != end()) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000544 if (I->start == LR->end && I->valno == V2) {
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000545 LR->end = I->end;
546 ranges.erase(I);
547 I = LR+1;
548 }
549 }
550 }
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000551
Jakob Stoklund Olesene0a73ec2010-10-01 23:52:25 +0000552 // Merge the relevant flags.
553 V2->mergeFlags(V1);
554
Lang Hames6f4e4df2010-07-26 01:49:41 +0000555 // Now that V1 is dead, remove it.
556 markValNoForDeletion(V1);
Jakob Stoklund Olesen1b293202010-08-12 20:01:23 +0000557
Owen Anderson5b93f6f2009-02-02 22:42:01 +0000558 return V2;
Chris Lattnerf7da2c72006-08-24 22:43:55 +0000559}
560
Evan Cheng32dfbea2007-10-12 08:50:34 +0000561void LiveInterval::Copy(const LiveInterval &RHS,
Evan Cheng90f95f82009-06-14 20:22:55 +0000562 MachineRegisterInfo *MRI,
Benjamin Kramer991de142010-03-30 20:16:45 +0000563 VNInfo::Allocator &VNInfoAllocator) {
Evan Cheng32dfbea2007-10-12 08:50:34 +0000564 ranges.clear();
565 valnos.clear();
Evan Cheng358dec52009-06-15 08:28:29 +0000566 std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(RHS.reg);
Evan Cheng90f95f82009-06-14 20:22:55 +0000567 MRI->setRegAllocationHint(reg, Hint.first, Hint.second);
568
Evan Cheng32dfbea2007-10-12 08:50:34 +0000569 weight = RHS.weight;
570 for (unsigned i = 0, e = RHS.getNumValNums(); i != e; ++i) {
571 const VNInfo *VNI = RHS.getValNumInfo(i);
Lang Hames857c4e02009-06-17 21:01:20 +0000572 createValueCopy(VNI, VNInfoAllocator);
Evan Cheng32dfbea2007-10-12 08:50:34 +0000573 }
574 for (unsigned i = 0, e = RHS.ranges.size(); i != e; ++i) {
575 const LiveRange &LR = RHS.ranges[i];
576 addRange(LiveRange(LR.start, LR.end, getValNumInfo(LR.valno->id)));
577 }
578}
579
Evan Chenge52eef82007-04-17 20:25:11 +0000580unsigned LiveInterval::getSize() const {
581 unsigned Sum = 0;
582 for (const_iterator I = begin(), E = end(); I != E; ++I)
Lang Hames86511252009-09-04 20:41:11 +0000583 Sum += I->start.distance(I->end);
Evan Chenge52eef82007-04-17 20:25:11 +0000584 return Sum;
585}
586
Daniel Dunbar1cd1d982009-07-24 10:36:58 +0000587raw_ostream& llvm::operator<<(raw_ostream& os, const LiveRange &LR) {
588 return os << '[' << LR.start << ',' << LR.end << ':' << LR.valno->id << ")";
589}
Chris Lattnerfb449b92004-07-23 17:49:16 +0000590
Chris Lattnerabf295f2004-07-24 02:52:23 +0000591void LiveRange::dump() const {
David Greene52421542010-01-04 22:41:43 +0000592 dbgs() << *this << "\n";
Chris Lattnerabf295f2004-07-24 02:52:23 +0000593}
594
Jakob Stoklund Olesenb77ec7d2012-06-05 22:51:54 +0000595void LiveInterval::print(raw_ostream &OS) const {
Chris Lattner38135af2005-05-14 05:34:15 +0000596 if (empty())
Jakob Stoklund Olesenb77ec7d2012-06-05 22:51:54 +0000597 OS << "EMPTY";
Chris Lattner38135af2005-05-14 05:34:15 +0000598 else {
Chris Lattner38135af2005-05-14 05:34:15 +0000599 for (LiveInterval::Ranges::const_iterator I = ranges.begin(),
Jakob Stoklund Olesen014b8632010-06-23 15:34:36 +0000600 E = ranges.end(); I != E; ++I) {
601 OS << *I;
602 assert(I->valno == getValNumInfo(I->valno->id) && "Bad VNInfo");
603 }
Chris Lattner38135af2005-05-14 05:34:15 +0000604 }
Jakob Stoklund Olesen15a57142010-06-25 22:53:05 +0000605
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000606 // Print value number info.
Chris Lattner6d8fbef2006-08-29 23:18:15 +0000607 if (getNumValNums()) {
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000608 OS << " ";
Evan Cheng1a66f0a2007-08-28 08:28:51 +0000609 unsigned vnum = 0;
610 for (const_vni_iterator i = vni_begin(), e = vni_end(); i != e;
611 ++i, ++vnum) {
Evan Cheng7ecb38b2007-08-29 20:45:00 +0000612 const VNInfo *vni = *i;
Evan Cheng1a66f0a2007-08-28 08:28:51 +0000613 if (vnum) OS << " ";
614 OS << vnum << "@";
Lang Hames857c4e02009-06-17 21:01:20 +0000615 if (vni->isUnused()) {
Evan Cheng8df78602007-08-08 03:00:28 +0000616 OS << "x";
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000617 } else {
Lang Hames6e2968c2010-09-25 12:04:16 +0000618 OS << vni->def;
Jakob Stoklund Olesena818c072010-10-05 18:48:57 +0000619 if (vni->isPHIDef())
620 OS << "-phidef";
Jakob Stoklund Olesend9f6ec92010-07-13 21:19:05 +0000621 if (vni->hasPHIKill())
622 OS << "-phikill";
Evan Chenga8d94f12007-08-07 23:49:57 +0000623 }
Chris Lattnerbe4f88a2006-08-22 18:19:46 +0000624 }
625 }
Chris Lattnerfb449b92004-07-23 17:49:16 +0000626}
Chris Lattnerabf295f2004-07-24 02:52:23 +0000627
628void LiveInterval::dump() const {
David Greene52421542010-01-04 22:41:43 +0000629 dbgs() << *this << "\n";
Chris Lattnerabf295f2004-07-24 02:52:23 +0000630}
Jeff Cohenc21c5ee2006-12-15 22:57:14 +0000631
632
Daniel Dunbar1cd1d982009-07-24 10:36:58 +0000633void LiveRange::print(raw_ostream &os) const {
634 os << *this;
635}
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000636
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000637unsigned ConnectedVNInfoEqClasses::Classify(const LiveInterval *LI) {
Jakob Stoklund Olesen54f32e62010-10-08 21:19:28 +0000638 // Create initial equivalence classes.
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000639 EqClass.clear();
640 EqClass.grow(LI->getNumValNums());
Jakob Stoklund Olesen54f32e62010-10-08 21:19:28 +0000641
Jakob Stoklund Olesen6d309052010-10-29 17:37:29 +0000642 const VNInfo *used = 0, *unused = 0;
643
Jakob Stoklund Olesen54f32e62010-10-08 21:19:28 +0000644 // Determine connections.
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000645 for (LiveInterval::const_vni_iterator I = LI->vni_begin(), E = LI->vni_end();
646 I != E; ++I) {
647 const VNInfo *VNI = *I;
Jakob Stoklund Olesen6d309052010-10-29 17:37:29 +0000648 // Group all unused values into one class.
649 if (VNI->isUnused()) {
650 if (unused)
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000651 EqClass.join(unused->id, VNI->id);
Jakob Stoklund Olesen6d309052010-10-29 17:37:29 +0000652 unused = VNI;
653 continue;
654 }
655 used = VNI;
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000656 if (VNI->isPHIDef()) {
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000657 const MachineBasicBlock *MBB = LIS.getMBBFromIndex(VNI->def);
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000658 assert(MBB && "Phi-def has no defining MBB");
659 // Connect to values live out of predecessors.
660 for (MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(),
661 PE = MBB->pred_end(); PI != PE; ++PI)
Jakob Stoklund Olesen194eb712011-11-14 01:39:36 +0000662 if (const VNInfo *PVNI = LI->getVNInfoBefore(LIS.getMBBEndIdx(*PI)))
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000663 EqClass.join(VNI->id, PVNI->id);
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000664 } else {
665 // Normal value defined by an instruction. Check for two-addr redef.
666 // FIXME: This could be coincidental. Should we really check for a tied
667 // operand constraint?
Jakob Stoklund Olesenb907e8a2010-12-21 00:48:17 +0000668 // Note that VNI->def may be a use slot for an early clobber def.
Jakob Stoklund Olesen194eb712011-11-14 01:39:36 +0000669 if (const VNInfo *UVNI = LI->getVNInfoBefore(VNI->def))
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000670 EqClass.join(VNI->id, UVNI->id);
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000671 }
672 }
Jakob Stoklund Olesen6d309052010-10-29 17:37:29 +0000673
674 // Lump all the unused values in with the last used value.
675 if (used && unused)
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000676 EqClass.join(used->id, unused->id);
Jakob Stoklund Olesen6d309052010-10-29 17:37:29 +0000677
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000678 EqClass.compress();
679 return EqClass.getNumClasses();
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000680}
681
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000682void ConnectedVNInfoEqClasses::Distribute(LiveInterval *LIV[],
683 MachineRegisterInfo &MRI) {
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000684 assert(LIV[0] && "LIV[0] must be set");
685 LiveInterval &LI = *LIV[0];
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000686
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000687 // Rewrite instructions.
688 for (MachineRegisterInfo::reg_iterator RI = MRI.reg_begin(LI.reg),
689 RE = MRI.reg_end(); RI != RE;) {
690 MachineOperand &MO = RI.getOperand();
691 MachineInstr *MI = MO.getParent();
692 ++RI;
693 if (MO.isUse() && MO.isUndef())
694 continue;
695 // DBG_VALUE instructions should have been eliminated earlier.
696 SlotIndex Idx = LIS.getInstructionIndex(MI);
Jakob Stoklund Olesen2debd482011-11-13 20:45:27 +0000697 Idx = Idx.getRegSlot(MO.isUse());
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000698 const VNInfo *VNI = LI.getVNInfoAt(Idx);
Jakob Stoklund Olesenbd6f44a2012-05-19 05:25:50 +0000699 // FIXME: We should be able to assert(VNI) here, but the coalescer leaves
700 // dangling defs around.
701 if (!VNI)
702 continue;
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000703 MO.setReg(LIV[getEqClass(VNI)]->reg);
704 }
705
706 // Move runs to new intervals.
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000707 LiveInterval::iterator J = LI.begin(), E = LI.end();
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000708 while (J != E && EqClass[J->valno->id] == 0)
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000709 ++J;
710 for (LiveInterval::iterator I = J; I != E; ++I) {
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000711 if (unsigned eq = EqClass[I->valno->id]) {
Benjamin Kramerccefe322010-10-09 16:36:44 +0000712 assert((LIV[eq]->empty() || LIV[eq]->expiredAt(I->start)) &&
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000713 "New intervals should be empty");
714 LIV[eq]->ranges.push_back(*I);
715 } else
716 *J++ = *I;
717 }
718 LI.ranges.erase(J, E);
719
720 // Transfer VNInfos to their new owners and renumber them.
721 unsigned j = 0, e = LI.getNumValNums();
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000722 while (j != e && EqClass[j] == 0)
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000723 ++j;
724 for (unsigned i = j; i != e; ++i) {
725 VNInfo *VNI = LI.getValNumInfo(i);
Jakob Stoklund Olesen22542272011-03-17 00:23:45 +0000726 if (unsigned eq = EqClass[i]) {
Jakob Stoklund Olesen0253df92010-10-07 23:34:34 +0000727 VNI->id = LIV[eq]->getNumValNums();
728 LIV[eq]->valnos.push_back(VNI);
729 } else {
730 VNI->id = j;
731 LI.valnos[j++] = VNI;
732 }
733 }
734 LI.valnos.resize(j);
735}