39
39
/// This class holds information about a machine level values, including
40
40
/// definition and use points.
42
/// Care must be taken in interpreting the def index of the value. The
42
/// Care must be taken in interpreting the def index of the value. The
43
43
/// following rules apply:
45
45
/// If the isDefAccurate() method returns false then def does not contain the
71
typedef SmallVector<SlotIndex, 4> KillSet;
70
typedef BumpPtrAllocator Allocator;
73
72
/// The ID number of this value.
76
75
/// The index of the defining instruction (if isDefAccurate() returns true).
82
VNInfo(LiveIntervals &li_)
83
: defflags(IS_UNUSED), id(~1U) { cr.copy = 0; }
86
78
/// VNInfo constructor.
87
79
/// d is presumed to point to the actual defining instr. If it doesn't
88
80
/// setIsDefAccurate(false) should be called after construction.
92
84
/// VNInfo construtor, copies values from orig, except for the value number.
93
85
VNInfo(unsigned i, const VNInfo &orig)
94
: flags(orig.flags), cr(orig.cr), id(i), def(orig.def), kills(orig.kills)
86
: flags(orig.flags), cr(orig.cr), id(i), def(orig.def)
97
89
/// Copy from the parameter into this VNInfo.
114
105
/// This method should not be called on stack intervals as it may lead to
115
106
/// undefined behavior.
116
107
void setCopy(MachineInstr *c) { cr.copy = c; }
118
109
/// For a stack interval, returns the reg which this stack interval was
119
110
/// defined from.
120
/// For a register interval the behaviour of this method is undefined.
111
/// For a register interval the behaviour of this method is undefined.
121
112
unsigned getReg() const { return cr.reg; }
122
113
/// For a stack interval, set the defining register.
123
114
/// This method should not be called on register intervals as it may lead
172
163
void setIsDefAccurate(bool defAccurate) {
174
165
flags |= IS_DEF_ACCURATE;
176
167
flags &= ~IS_DEF_ACCURATE;
179
/// Returns true if the given index is a kill of this value.
180
bool isKill(SlotIndex k) const {
181
KillSet::const_iterator
182
i = std::lower_bound(kills.begin(), kills.end(), k);
183
return (i != kills.end() && *i == k);
186
/// addKill - Add a kill instruction index to the specified value
188
void addKill(SlotIndex k) {
193
i = std::lower_bound(kills.begin(), kills.end(), k);
198
/// Remove the specified kill index from this value's kills list.
199
/// Returns true if the value was present, otherwise returns false.
200
bool removeKill(SlotIndex k) {
201
KillSet::iterator i = std::lower_bound(kills.begin(), kills.end(), k);
202
if (i != kills.end() && *i == k) {
209
/// Remove all kills in the range [s, e).
210
void removeKills(SlotIndex s, SlotIndex e) {
212
si = std::lower_bound(kills.begin(), kills.end(), s),
213
se = std::upper_bound(kills.begin(), kills.end(), e);
220
171
/// LiveRange structure - This represents a simple register range in the
240
191
/// containsRange - Return true if the given range, [S, E), is covered by
242
193
bool containsRange(SlotIndex S, SlotIndex E) const {
243
194
assert((S < E) && "Backwards interval?");
244
195
return (start <= S && S < end) && (start < E && E <= end);
352
305
bool containsOneValue() const { return valnos.size() == 1; }
354
307
unsigned getNumValNums() const { return (unsigned)valnos.size(); }
356
309
/// getValNumInfo - Returns pointer to the specified val#.
358
311
inline VNInfo *getValNumInfo(unsigned ValNo) {
365
318
/// getNextValue - Create a new value number and return it. MIIdx specifies
366
319
/// the instruction that defines the value number.
367
320
VNInfo *getNextValue(SlotIndex def, MachineInstr *CopyMI,
368
bool isDefAccurate, BumpPtrAllocator &VNInfoAllocator){
321
bool isDefAccurate, VNInfo::Allocator &VNInfoAllocator) {
370
static_cast<VNInfo*>(VNInfoAllocator.Allocate((unsigned)sizeof(VNInfo),
372
new (VNI) VNInfo((unsigned)valnos.size(), def, CopyMI);
323
new (VNInfoAllocator) VNInfo((unsigned)valnos.size(), def, CopyMI);
373
324
VNI->setIsDefAccurate(isDefAccurate);
374
325
valnos.push_back(VNI);
378
329
/// Create a copy of the given value. The new value will be identical except
379
330
/// for the Value number.
380
331
VNInfo *createValueCopy(const VNInfo *orig,
381
BumpPtrAllocator &VNInfoAllocator) {
332
VNInfo::Allocator &VNInfoAllocator) {
383
static_cast<VNInfo*>(VNInfoAllocator.Allocate((unsigned)sizeof(VNInfo),
386
new (VNI) VNInfo((unsigned)valnos.size(), *orig);
334
new (VNInfoAllocator) VNInfo((unsigned)valnos.size(), *orig);
387
335
valnos.push_back(VNI);
391
/// addKills - Add a number of kills into the VNInfo kill vector. If this
392
/// interval is live at a kill point, then the kill is not added.
393
void addKills(VNInfo *VNI, const VNInfo::KillSet &kills) {
394
for (unsigned i = 0, e = static_cast<unsigned>(kills.size());
396
if (!liveBeforeAndAt(kills[i])) {
397
VNI->addKill(kills[i]);
339
/// RenumberValues - Renumber all values in order of appearance and remove
341
/// Recalculate phi-kill flags in case any phi-def values were removed.
342
void RenumberValues(LiveIntervals &lis);
402
344
/// isOnlyLROfValNo - Return true if the specified live range is the only
403
345
/// one defined by the its val#.
422
364
/// VNInfoAllocator since it will create a new val#.
423
365
void MergeInClobberRanges(LiveIntervals &li_,
424
366
const LiveInterval &Clobbers,
425
BumpPtrAllocator &VNInfoAllocator);
367
VNInfo::Allocator &VNInfoAllocator);
427
369
/// MergeInClobberRange - Same as MergeInClobberRanges except it merge in a
428
370
/// single LiveRange only.
429
371
void MergeInClobberRange(LiveIntervals &li_,
432
BumpPtrAllocator &VNInfoAllocator);
374
VNInfo::Allocator &VNInfoAllocator);
434
376
/// MergeValueInAsValue - Merge all of the live ranges of a specific val#
435
377
/// in RHS into this live interval as the specified value number.
449
391
/// Copy - Copy the specified live interval. This copies all the fields
450
392
/// except for the register of the interval.
451
393
void Copy(const LiveInterval &RHS, MachineRegisterInfo *MRI,
452
BumpPtrAllocator &VNInfoAllocator);
394
VNInfo::Allocator &VNInfoAllocator);
454
396
bool empty() const { return ranges.empty(); }
456
398
/// beginIndex - Return the lowest numbered slot covered by interval.
477
419
// range.If it does, then check if the previous live range ends at index-1.
478
420
bool liveBeforeAndAt(SlotIndex index) const;
422
/// killedAt - Return true if a live range ends at index. Note that the kill
423
/// point is not contained in the half-open live range. It is usually the
424
/// getDefIndex() slot following its last use.
425
bool killedAt(SlotIndex index) const;
427
/// killedInRange - Return true if the interval has kills in [Start,End).
428
/// Note that the kill point is considered the end of a live range, so it is
429
/// not contained in the live range. If a live range ends at End, it won't
430
/// be counted as a kill by this method.
431
bool killedInRange(SlotIndex Start, SlotIndex End) const;
480
433
/// getLiveRangeContaining - Return the live range that contains the
481
434
/// specified index, or null if there is none.
482
435
const LiveRange *getLiveRangeContaining(SlotIndex Idx) const {
491
444
return I == end() ? 0 : &*I;
447
/// getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
448
VNInfo *getVNInfoAt(SlotIndex Idx) const {
449
const_iterator I = FindLiveRangeContaining(Idx);
450
return I == end() ? 0 : I->valno;
494
453
/// FindLiveRangeContaining - Return an iterator to the live range that
495
454
/// contains the specified index, or end() if there is none.
496
455
const_iterator FindLiveRangeContaining(SlotIndex Idx) const;
500
459
iterator FindLiveRangeContaining(SlotIndex Idx);
502
461
/// findDefinedVNInfo - Find the by the specified
503
/// index (register interval) or defined
462
/// index (register interval) or defined
504
463
VNInfo *findDefinedVNInfoForRegInt(SlotIndex Idx) const;
506
465
/// findDefinedVNInfo - Find the VNInfo that's defined by the specified
507
466
/// register (stack inteval only).
508
467
VNInfo *findDefinedVNInfoForStackInt(unsigned Reg) const;
511
470
/// overlaps - Return true if the intersection of the two live intervals is
513
472
bool overlaps(const LiveInterval& other) const {
514
475
return overlapsFrom(other, other.begin());
556
517
/// Also remove the value# from value# list.
557
518
void removeValNo(VNInfo *ValNo);
559
/// scaleNumbering - Renumber VNI and ranges to provide gaps for new
561
void scaleNumbering(unsigned factor);
563
520
/// getSize - Returns the sum of sizes of all the LiveRange's.
565
522
unsigned getSize() const;
524
/// Returns true if the live interval is zero length, i.e. no live ranges
525
/// span instructions. It doesn't pay to spill such an interval.
526
bool isZeroLength() const {
527
for (const_iterator i = begin(), e = end(); i != e; ++i)
528
if (i->end.getPrevIndex() > i->start)
567
533
/// isSpillable - Can this interval be spilled?
568
534
bool isSpillable() const {
569
535
return weight != HUGE_VALF;
593
559
Ranges::iterator addRangeFrom(LiveRange LR, Ranges::iterator From);
594
560
void extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd);
595
561
Ranges::iterator extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStr);
562
void markValNoForDeletion(VNInfo *V);
597
564
LiveInterval& operator=(const LiveInterval& rhs); // DO NOT IMPLEMENT