2004-07-23 17:49:16 +00:00
|
|
|
//===-- llvm/CodeGen/LiveInterval.h - Interval representation ---*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2004-07-23 17:49:16 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2013-10-10 21:28:47 +00:00
|
|
|
// This file implements the LiveRange and LiveInterval classes. Given some
|
|
|
|
// numbering of each the machine instructions an interval [i, j) is said to be a
|
|
|
|
// live range for register v if there is no instruction with number j' >= j
|
2004-07-24 02:52:23 +00:00
|
|
|
// such that v is live at j' and there is no instruction with number i' < i such
|
2013-10-10 21:28:47 +00:00
|
|
|
// that v is live at i'. In this implementation ranges can have holes,
|
|
|
|
// i.e. a range might look like [1,20), [50,65), [1000,1001). Each
|
|
|
|
// individual segment is represented as an instance of LiveRange::Segment,
|
|
|
|
// and the whole range is represented as an instance of LiveRange.
|
2004-07-23 17:49:16 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_LIVEINTERVAL_H
|
|
|
|
#define LLVM_CODEGEN_LIVEINTERVAL_H
|
|
|
|
|
2010-12-21 00:48:17 +00:00
|
|
|
#include "llvm/ADT/IntEqClasses.h"
|
2009-11-03 23:52:08 +00:00
|
|
|
#include "llvm/CodeGen/SlotIndexes.h"
|
2012-12-03 17:02:12 +00:00
|
|
|
#include "llvm/Support/AlignOf.h"
|
|
|
|
#include "llvm/Support/Allocator.h"
|
2004-07-23 17:49:16 +00:00
|
|
|
#include <cassert>
|
2009-04-01 18:45:54 +00:00
|
|
|
#include <climits>
|
2004-07-23 17:49:16 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2012-09-06 18:15:23 +00:00
|
|
|
class CoalescerPair;
|
2009-11-03 23:52:08 +00:00
|
|
|
class LiveIntervals;
|
2007-03-20 08:13:50 +00:00
|
|
|
class MachineInstr;
|
2009-06-14 20:22:55 +00:00
|
|
|
class MachineRegisterInfo;
|
2008-02-10 18:45:23 +00:00
|
|
|
class TargetRegisterInfo;
|
2009-07-24 10:36:58 +00:00
|
|
|
class raw_ostream;
|
2013-10-10 21:28:47 +00:00
|
|
|
template <typename T, unsigned Small> class SmallPtrSet;
|
2007-08-29 20:45:00 +00:00
|
|
|
|
2009-06-17 21:01:20 +00:00
|
|
|
/// VNInfo - Value Number Information.
|
|
|
|
/// This class holds information about a machine level values, including
|
|
|
|
/// definition and use points.
|
|
|
|
///
|
|
|
|
class VNInfo {
|
|
|
|
public:
|
2010-06-26 11:30:59 +00:00
|
|
|
typedef BumpPtrAllocator Allocator;
|
2009-07-09 03:57:02 +00:00
|
|
|
|
2009-06-17 21:01:20 +00:00
|
|
|
/// The ID number of this value.
|
2007-08-29 20:45:00 +00:00
|
|
|
unsigned id;
|
2010-06-25 22:53:05 +00:00
|
|
|
|
2012-01-05 01:01:01 +00:00
|
|
|
/// The index of the defining instruction.
|
2009-11-03 23:52:08 +00:00
|
|
|
SlotIndex def;
|
2009-08-10 23:43:28 +00:00
|
|
|
|
2009-06-17 21:01:20 +00:00
|
|
|
/// VNInfo constructor.
|
2012-02-04 05:20:49 +00:00
|
|
|
VNInfo(unsigned i, SlotIndex d)
|
2012-08-03 20:59:32 +00:00
|
|
|
: id(i), def(d)
|
2010-09-08 23:54:00 +00:00
|
|
|
{ }
|
2009-06-17 21:01:20 +00:00
|
|
|
|
|
|
|
/// VNInfo construtor, copies values from orig, except for the value number.
|
|
|
|
VNInfo(unsigned i, const VNInfo &orig)
|
2012-08-03 20:59:32 +00:00
|
|
|
: id(i), def(orig.def)
|
2009-08-10 23:43:28 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
/// Copy from the parameter into this VNInfo.
|
|
|
|
void copyFrom(VNInfo &src) {
|
|
|
|
def = src.def;
|
|
|
|
}
|
2009-06-17 21:01:20 +00:00
|
|
|
|
|
|
|
/// Returns true if this value is defined by a PHI instruction (or was,
|
2013-09-28 13:42:22 +00:00
|
|
|
/// PHI instructions may have been eliminated).
|
2012-07-27 21:11:14 +00:00
|
|
|
/// PHI-defs begin at a block boundary, all other defs begin at register or
|
|
|
|
/// EC slots.
|
|
|
|
bool isPHIDef() const { return def.isBlock(); }
|
2009-06-17 21:01:20 +00:00
|
|
|
|
|
|
|
/// Returns true if this value is unused.
|
2012-08-03 20:59:32 +00:00
|
|
|
bool isUnused() const { return !def.isValid(); }
|
|
|
|
|
|
|
|
/// Mark this value as unused.
|
|
|
|
void markUnused() { def = SlotIndex(); }
|
2009-09-04 20:41:11 +00:00
|
|
|
};
|
2009-07-09 03:57:02 +00:00
|
|
|
|
2013-10-10 21:28:52 +00:00
|
|
|
/// Result of a LiveRange query. This class hides the implementation details
|
|
|
|
/// of live ranges, and it should be used as the primary interface for
|
|
|
|
/// examining live ranges around instructions.
|
|
|
|
class LiveQueryResult {
|
|
|
|
VNInfo *const EarlyVal;
|
|
|
|
VNInfo *const LateVal;
|
|
|
|
const SlotIndex EndPoint;
|
|
|
|
const bool Kill;
|
|
|
|
|
|
|
|
public:
|
|
|
|
LiveQueryResult(VNInfo *EarlyVal, VNInfo *LateVal, SlotIndex EndPoint,
|
|
|
|
bool Kill)
|
|
|
|
: EarlyVal(EarlyVal), LateVal(LateVal), EndPoint(EndPoint), Kill(Kill)
|
|
|
|
{}
|
|
|
|
|
|
|
|
/// Return the value that is live-in to the instruction. This is the value
|
|
|
|
/// that will be read by the instruction's use operands. Return NULL if no
|
|
|
|
/// value is live-in.
|
|
|
|
VNInfo *valueIn() const {
|
|
|
|
return EarlyVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return true if the live-in value is killed by this instruction. This
|
|
|
|
/// means that either the live range ends at the instruction, or it changes
|
|
|
|
/// value.
|
|
|
|
bool isKill() const {
|
|
|
|
return Kill;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return true if this instruction has a dead def.
|
|
|
|
bool isDeadDef() const {
|
|
|
|
return EndPoint.isDead();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return the value leaving the instruction, if any. This can be a
|
|
|
|
/// live-through value, or a live def. A dead def returns NULL.
|
|
|
|
VNInfo *valueOut() const {
|
2014-04-14 00:51:57 +00:00
|
|
|
return isDeadDef() ? nullptr : LateVal;
|
2013-10-10 21:28:52 +00:00
|
|
|
}
|
|
|
|
|
2014-12-10 01:12:33 +00:00
|
|
|
/// Returns the value alive at the end of the instruction, if any. This can
|
|
|
|
/// be a live-through value, a live def or a dead def.
|
|
|
|
VNInfo *valueOutOrDead() const {
|
|
|
|
return LateVal;
|
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:52 +00:00
|
|
|
/// Return the value defined by this instruction, if any. This includes
|
|
|
|
/// dead defs, it is the value created by the instruction's def operands.
|
|
|
|
VNInfo *valueDefined() const {
|
2014-04-14 00:51:57 +00:00
|
|
|
return EarlyVal == LateVal ? nullptr : LateVal;
|
2013-10-10 21:28:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Return the end point of the last live range segment to interact with
|
|
|
|
/// the instruction, if any.
|
|
|
|
///
|
|
|
|
/// The end point is an invalid SlotIndex only if the live range doesn't
|
|
|
|
/// intersect the instruction at all.
|
|
|
|
///
|
|
|
|
/// The end point may be at or past the end of the instruction's basic
|
|
|
|
/// block. That means the value was live out of the block.
|
|
|
|
SlotIndex endPoint() const {
|
|
|
|
return EndPoint;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// This class represents the liveness of a register, stack slot, etc.
|
|
|
|
/// It manages an ordered list of Segment objects.
|
|
|
|
/// The Segments are organized in a static single assignment form: At places
|
|
|
|
/// where a new value is defined or different values reach a CFG join a new
|
|
|
|
/// segment with a new value number is used.
|
|
|
|
class LiveRange {
|
2009-07-14 02:05:37 +00:00
|
|
|
public:
|
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
/// This represents a simple continuous liveness interval for a value.
|
|
|
|
/// The start point is inclusive, the end point exclusive. These intervals
|
|
|
|
/// are rendered as [start,end).
|
|
|
|
struct Segment {
|
|
|
|
SlotIndex start; // Start point of the interval (inclusive)
|
|
|
|
SlotIndex end; // End point of the interval (exclusive)
|
|
|
|
VNInfo *valno; // identifier for the value contained in this segment.
|
|
|
|
|
2014-04-14 00:51:57 +00:00
|
|
|
Segment() : valno(nullptr) {}
|
2013-10-10 21:28:43 +00:00
|
|
|
|
|
|
|
Segment(SlotIndex S, SlotIndex E, VNInfo *V)
|
|
|
|
: start(S), end(E), valno(V) {
|
|
|
|
assert(S < E && "Cannot create empty or backwards segment");
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return true if the index is covered by this segment.
|
|
|
|
bool contains(SlotIndex I) const {
|
|
|
|
return start <= I && I < end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return true if the given interval, [S, E), is covered by this segment.
|
|
|
|
bool containsInterval(SlotIndex S, SlotIndex E) const {
|
|
|
|
assert((S < E) && "Backwards interval?");
|
|
|
|
return (start <= S && S < end) && (start < E && E <= end);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const Segment &Other) const {
|
2014-03-03 19:58:30 +00:00
|
|
|
return std::tie(start, end) < std::tie(Other.start, Other.end);
|
2013-10-10 21:28:43 +00:00
|
|
|
}
|
|
|
|
bool operator==(const Segment &Other) const {
|
|
|
|
return start == Other.start && end == Other.end;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef SmallVector<Segment,4> Segments;
|
2007-08-29 20:45:00 +00:00
|
|
|
typedef SmallVector<VNInfo*,4> VNInfoList;
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
Segments segments; // the liveness segments
|
2007-08-29 20:45:00 +00:00
|
|
|
VNInfoList valnos; // value#'s
|
2010-08-12 20:01:23 +00:00
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
typedef Segments::iterator iterator;
|
|
|
|
iterator begin() { return segments.begin(); }
|
|
|
|
iterator end() { return segments.end(); }
|
2004-11-18 01:29:39 +00:00
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
typedef Segments::const_iterator const_iterator;
|
|
|
|
const_iterator begin() const { return segments.begin(); }
|
|
|
|
const_iterator end() const { return segments.end(); }
|
2004-11-18 03:47:34 +00:00
|
|
|
|
2007-08-28 08:28:51 +00:00
|
|
|
typedef VNInfoList::iterator vni_iterator;
|
2007-08-29 20:45:00 +00:00
|
|
|
vni_iterator vni_begin() { return valnos.begin(); }
|
2013-10-10 21:28:47 +00:00
|
|
|
vni_iterator vni_end() { return valnos.end(); }
|
2007-08-28 08:28:51 +00:00
|
|
|
|
|
|
|
typedef VNInfoList::const_iterator const_vni_iterator;
|
2007-08-29 20:45:00 +00:00
|
|
|
const_vni_iterator vni_begin() const { return valnos.begin(); }
|
2013-10-10 21:28:47 +00:00
|
|
|
const_vni_iterator vni_end() const { return valnos.end(); }
|
2007-08-29 20:45:00 +00:00
|
|
|
|
2014-12-10 01:12:10 +00:00
|
|
|
/// Constructs a new LiveRange object.
|
|
|
|
LiveRange() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Constructs a new LiveRange object by copying segments and valnos from
|
|
|
|
/// another LiveRange.
|
|
|
|
LiveRange(const LiveRange &Other, BumpPtrAllocator &Allocator) {
|
|
|
|
// Duplicate valnos.
|
2014-12-10 23:07:54 +00:00
|
|
|
for (const VNInfo *VNI : Other.valnos) {
|
|
|
|
createValueCopy(VNI, Allocator);
|
2014-12-10 01:12:10 +00:00
|
|
|
}
|
|
|
|
// Now we can copy segments and remap their valnos.
|
2014-12-10 23:07:54 +00:00
|
|
|
for (const Segment &S : Other.segments) {
|
|
|
|
segments.push_back(Segment(S.start, S.end, valnos[S.valno->id]));
|
2014-12-10 01:12:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
/// advanceTo - Advance the specified iterator to point to the Segment
|
2004-11-18 02:37:31 +00:00
|
|
|
/// containing the specified position, or end() if the position is past the
|
2013-10-10 21:28:47 +00:00
|
|
|
/// end of the range. If no Segment contains this position, but the
|
2010-02-10 20:04:19 +00:00
|
|
|
/// position is in a hole, this method returns an iterator pointing to the
|
2013-10-10 21:28:43 +00:00
|
|
|
/// Segment immediately after the hole.
|
2009-11-03 23:52:08 +00:00
|
|
|
iterator advanceTo(iterator I, SlotIndex Pos) {
|
2010-12-17 23:16:38 +00:00
|
|
|
assert(I != end());
|
2009-09-04 20:41:11 +00:00
|
|
|
if (Pos >= endIndex())
|
2004-11-18 02:37:31 +00:00
|
|
|
return end();
|
|
|
|
while (I->end <= Pos) ++I;
|
|
|
|
return I;
|
|
|
|
}
|
2010-08-12 20:01:23 +00:00
|
|
|
|
2014-12-10 01:12:02 +00:00
|
|
|
const_iterator advanceTo(const_iterator I, SlotIndex Pos) const {
|
|
|
|
assert(I != end());
|
|
|
|
if (Pos >= endIndex())
|
|
|
|
return end();
|
|
|
|
while (I->end <= Pos) ++I;
|
|
|
|
return I;
|
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
/// find - Return an iterator pointing to the first segment that ends after
|
2010-09-21 17:12:18 +00:00
|
|
|
/// Pos, or end(). This is the same as advanceTo(begin(), Pos), but faster
|
2013-10-10 21:28:47 +00:00
|
|
|
/// when searching large ranges.
|
2010-09-21 17:12:18 +00:00
|
|
|
///
|
2013-10-10 21:28:43 +00:00
|
|
|
/// If Pos is contained in a Segment, that segment is returned.
|
|
|
|
/// If Pos is in a hole, the following Segment is returned.
|
2010-09-21 17:12:18 +00:00
|
|
|
/// If Pos is beyond endIndex, end() is returned.
|
|
|
|
iterator find(SlotIndex Pos);
|
|
|
|
|
|
|
|
const_iterator find(SlotIndex Pos) const {
|
2013-10-10 21:28:47 +00:00
|
|
|
return const_cast<LiveRange*>(this)->find(Pos);
|
2010-09-21 17:12:18 +00:00
|
|
|
}
|
|
|
|
|
2008-12-28 21:57:02 +00:00
|
|
|
void clear() {
|
2010-03-30 11:17:48 +00:00
|
|
|
valnos.clear();
|
2013-10-10 21:28:43 +00:00
|
|
|
segments.clear();
|
2008-12-28 21:57:02 +00:00
|
|
|
}
|
2004-11-18 02:37:31 +00:00
|
|
|
|
2013-09-06 16:44:32 +00:00
|
|
|
size_t size() const {
|
2013-10-10 21:28:43 +00:00
|
|
|
return segments.size();
|
2013-09-06 16:44:32 +00:00
|
|
|
}
|
|
|
|
|
2008-10-29 08:39:34 +00:00
|
|
|
bool hasAtLeastOneValue() const { return !valnos.empty(); }
|
|
|
|
|
2007-08-31 08:26:44 +00:00
|
|
|
bool containsOneValue() const { return valnos.size() == 1; }
|
2004-07-24 02:52:23 +00:00
|
|
|
|
2008-05-05 18:30:58 +00:00
|
|
|
unsigned getNumValNums() const { return (unsigned)valnos.size(); }
|
2010-08-12 20:01:23 +00:00
|
|
|
|
2007-09-05 21:46:51 +00:00
|
|
|
/// getValNumInfo - Returns pointer to the specified val#.
|
2007-08-28 08:28:51 +00:00
|
|
|
///
|
2007-09-05 21:46:51 +00:00
|
|
|
inline VNInfo *getValNumInfo(unsigned ValNo) {
|
|
|
|
return valnos[ValNo];
|
2007-08-28 08:28:51 +00:00
|
|
|
}
|
2007-09-05 21:46:51 +00:00
|
|
|
inline const VNInfo *getValNumInfo(unsigned ValNo) const {
|
|
|
|
return valnos[ValNo];
|
2007-08-28 08:28:51 +00:00
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// containsValue - Returns true if VNI belongs to this range.
|
2011-04-30 06:42:21 +00:00
|
|
|
bool containsValue(const VNInfo *VNI) const {
|
|
|
|
return VNI && VNI->id < getNumValNums() && VNI == getValNumInfo(VNI->id);
|
|
|
|
}
|
|
|
|
|
2006-08-22 18:19:46 +00:00
|
|
|
/// getNextValue - Create a new value number and return it. MIIdx specifies
|
|
|
|
/// the instruction that defines the value number.
|
2012-02-04 05:20:49 +00:00
|
|
|
VNInfo *getNextValue(SlotIndex def, VNInfo::Allocator &VNInfoAllocator) {
|
2010-06-26 11:30:59 +00:00
|
|
|
VNInfo *VNI =
|
2012-02-04 05:20:49 +00:00
|
|
|
new (VNInfoAllocator) VNInfo((unsigned)valnos.size(), def);
|
2009-06-17 21:01:20 +00:00
|
|
|
valnos.push_back(VNI);
|
|
|
|
return VNI;
|
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// createDeadDef - Make sure the range has a value defined at Def.
|
2012-06-05 21:54:09 +00:00
|
|
|
/// If one already exists, return it. Otherwise allocate a new value and
|
|
|
|
/// add liveness for a dead def.
|
|
|
|
VNInfo *createDeadDef(SlotIndex Def, VNInfo::Allocator &VNInfoAllocator);
|
|
|
|
|
2009-06-17 21:01:20 +00:00
|
|
|
/// Create a copy of the given value. The new value will be identical except
|
|
|
|
/// for the Value number.
|
2009-08-23 03:47:42 +00:00
|
|
|
VNInfo *createValueCopy(const VNInfo *orig,
|
2010-03-30 20:16:45 +00:00
|
|
|
VNInfo::Allocator &VNInfoAllocator) {
|
2010-06-26 11:30:59 +00:00
|
|
|
VNInfo *VNI =
|
|
|
|
new (VNInfoAllocator) VNInfo((unsigned)valnos.size(), *orig);
|
2007-08-29 20:45:00 +00:00
|
|
|
valnos.push_back(VNI);
|
|
|
|
return VNI;
|
2007-08-08 03:00:28 +00:00
|
|
|
}
|
2007-08-11 00:59:19 +00:00
|
|
|
|
2010-08-06 18:46:59 +00:00
|
|
|
/// RenumberValues - Renumber all values in order of appearance and remove
|
|
|
|
/// unused values.
|
2013-08-14 17:28:52 +00:00
|
|
|
void RenumberValues();
|
2010-08-06 18:46:59 +00:00
|
|
|
|
2013-09-06 16:19:22 +00:00
|
|
|
/// MergeValueNumberInto - This method is called when two value numbers
|
2006-08-24 22:43:55 +00:00
|
|
|
/// are found to be equivalent. This eliminates V1, replacing all
|
2013-10-10 21:28:43 +00:00
|
|
|
/// segments with the V1 value number with the V2 value number. This can
|
2006-08-24 22:43:55 +00:00
|
|
|
/// cause merging of V1/V2 values numbers and compaction of the value space.
|
2009-02-02 22:42:01 +00:00
|
|
|
VNInfo* MergeValueNumberInto(VNInfo *V1, VNInfo *V2);
|
2006-08-22 18:19:46 +00:00
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
/// Merge all of the live segments of a specific val# in RHS into this live
|
2013-10-10 21:28:47 +00:00
|
|
|
/// range as the specified value number. The segments in RHS are allowed
|
|
|
|
/// to overlap with segments in the current range, it will replace the
|
2013-10-10 21:28:43 +00:00
|
|
|
/// value numbers of the overlaped live segments with the specified value
|
|
|
|
/// number.
|
2013-10-10 21:28:47 +00:00
|
|
|
void MergeSegmentsInAsValue(const LiveRange &RHS, VNInfo *LHSValNo);
|
2007-10-12 08:50:34 +00:00
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
/// MergeValueInAsValue - Merge all of the segments of a specific val#
|
2013-10-10 21:28:47 +00:00
|
|
|
/// in RHS into this live range as the specified value number.
|
2013-10-10 21:28:43 +00:00
|
|
|
/// The segments in RHS are allowed to overlap with segments in the
|
2013-10-10 21:28:47 +00:00
|
|
|
/// current range, but only if the overlapping segments have the
|
2007-10-12 08:50:34 +00:00
|
|
|
/// specified value number.
|
2013-10-10 21:28:47 +00:00
|
|
|
void MergeValueInAsValue(const LiveRange &RHS,
|
2007-10-14 10:08:34 +00:00
|
|
|
const VNInfo *RHSValNo, VNInfo *LHSValNo);
|
2007-10-12 08:50:34 +00:00
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
bool empty() const { return segments.empty(); }
|
2004-07-23 17:49:16 +00:00
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// beginIndex - Return the lowest numbered slot covered.
|
2009-11-03 23:52:08 +00:00
|
|
|
SlotIndex beginIndex() const {
|
2013-10-10 21:28:47 +00:00
|
|
|
assert(!empty() && "Call to beginIndex() on empty range.");
|
2013-10-10 21:28:43 +00:00
|
|
|
return segments.front().start;
|
2004-07-23 17:49:16 +00:00
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// endNumber - return the maximum point of the range of the whole,
|
2004-07-23 17:49:16 +00:00
|
|
|
/// exclusive.
|
2009-11-03 23:52:08 +00:00
|
|
|
SlotIndex endIndex() const {
|
2013-10-10 21:28:47 +00:00
|
|
|
assert(!empty() && "Call to endIndex() on empty range.");
|
2013-10-10 21:28:43 +00:00
|
|
|
return segments.back().end;
|
2004-07-23 17:49:16 +00:00
|
|
|
}
|
|
|
|
|
2009-11-03 23:52:08 +00:00
|
|
|
bool expiredAt(SlotIndex index) const {
|
2009-09-04 20:41:11 +00:00
|
|
|
return index >= endIndex();
|
2004-07-23 17:49:16 +00:00
|
|
|
}
|
|
|
|
|
2010-09-21 17:12:18 +00:00
|
|
|
bool liveAt(SlotIndex index) const {
|
|
|
|
const_iterator r = find(index);
|
|
|
|
return r != end() && r->start <= index;
|
|
|
|
}
|
2004-07-23 17:49:16 +00:00
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
/// Return the segment that contains the specified index, or null if there
|
|
|
|
/// is none.
|
|
|
|
const Segment *getSegmentContaining(SlotIndex Idx) const {
|
|
|
|
const_iterator I = FindSegmentContaining(Idx);
|
2014-04-14 00:51:57 +00:00
|
|
|
return I == end() ? nullptr : &*I;
|
2006-08-24 22:43:55 +00:00
|
|
|
}
|
2004-07-24 02:52:23 +00:00
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
/// Return the live segment that contains the specified index, or null if
|
|
|
|
/// there is none.
|
|
|
|
Segment *getSegmentContaining(SlotIndex Idx) {
|
|
|
|
iterator I = FindSegmentContaining(Idx);
|
2014-04-14 00:51:57 +00:00
|
|
|
return I == end() ? nullptr : &*I;
|
2009-07-09 03:57:02 +00:00
|
|
|
}
|
|
|
|
|
2010-07-02 17:44:57 +00:00
|
|
|
/// getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
|
|
|
|
VNInfo *getVNInfoAt(SlotIndex Idx) const {
|
2013-10-10 21:28:43 +00:00
|
|
|
const_iterator I = FindSegmentContaining(Idx);
|
2014-04-14 00:51:57 +00:00
|
|
|
return I == end() ? nullptr : I->valno;
|
2010-07-02 17:44:57 +00:00
|
|
|
}
|
|
|
|
|
2011-09-15 01:09:33 +00:00
|
|
|
/// getVNInfoBefore - Return the VNInfo that is live up to but not
|
|
|
|
/// necessarilly including Idx, or NULL. Use this to find the reaching def
|
|
|
|
/// used by an instruction at this SlotIndex position.
|
|
|
|
VNInfo *getVNInfoBefore(SlotIndex Idx) const {
|
2013-10-10 21:28:43 +00:00
|
|
|
const_iterator I = FindSegmentContaining(Idx.getPrevSlot());
|
2014-04-14 00:51:57 +00:00
|
|
|
return I == end() ? nullptr : I->valno;
|
2011-09-15 01:09:33 +00:00
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
/// Return an iterator to the segment that contains the specified index, or
|
|
|
|
/// end() if there is none.
|
|
|
|
iterator FindSegmentContaining(SlotIndex Idx) {
|
2010-09-21 17:12:18 +00:00
|
|
|
iterator I = find(Idx);
|
|
|
|
return I != end() && I->start <= Idx ? I : end();
|
|
|
|
}
|
2004-07-24 02:52:23 +00:00
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
const_iterator FindSegmentContaining(SlotIndex Idx) const {
|
2010-09-21 17:12:18 +00:00
|
|
|
const_iterator I = find(Idx);
|
|
|
|
return I != end() && I->start <= Idx ? I : end();
|
|
|
|
}
|
2009-09-04 20:41:11 +00:00
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// overlaps - Return true if the intersection of the two live ranges is
|
2004-11-18 03:47:34 +00:00
|
|
|
/// not empty.
|
2013-10-10 21:28:47 +00:00
|
|
|
bool overlaps(const LiveRange &other) const {
|
2010-07-22 02:05:10 +00:00
|
|
|
if (other.empty())
|
|
|
|
return false;
|
2004-11-18 03:47:34 +00:00
|
|
|
return overlapsFrom(other, other.begin());
|
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// overlaps - Return true if the two ranges have overlapping segments
|
2012-09-06 18:15:23 +00:00
|
|
|
/// that are not coalescable according to CP.
|
|
|
|
///
|
2013-10-10 21:28:47 +00:00
|
|
|
/// Overlapping segments where one range is defined by a coalescable
|
2012-09-06 18:15:23 +00:00
|
|
|
/// copy are allowed.
|
2013-10-10 21:28:47 +00:00
|
|
|
bool overlaps(const LiveRange &Other, const CoalescerPair &CP,
|
2012-09-06 18:15:23 +00:00
|
|
|
const SlotIndexes&) const;
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// overlaps - Return true if the live range overlaps an interval specified
|
|
|
|
/// by [Start, End).
|
2009-11-03 23:52:08 +00:00
|
|
|
bool overlaps(SlotIndex Start, SlotIndex End) const;
|
2009-04-18 08:52:15 +00:00
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// overlapsFrom - Return true if the intersection of the two live ranges
|
2004-11-18 03:47:34 +00:00
|
|
|
/// is not empty. The specified iterator is a hint that we can begin
|
2013-10-10 21:28:47 +00:00
|
|
|
/// scanning the Other range starting at I.
|
|
|
|
bool overlapsFrom(const LiveRange &Other, const_iterator I) const;
|
2004-07-23 17:49:16 +00:00
|
|
|
|
2014-12-10 01:12:06 +00:00
|
|
|
/// Returns true if all segments of the @p Other live range are completely
|
|
|
|
/// covered by this live range.
|
|
|
|
/// Adjacent live ranges do not affect the covering:the liverange
|
|
|
|
/// [1,5](5,10] covers (3,7].
|
|
|
|
bool covers(const LiveRange &Other) const;
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// Add the specified Segment to this range, merging segments as
|
2013-10-10 21:28:43 +00:00
|
|
|
/// appropriate. This returns an iterator to the inserted segment (which
|
|
|
|
/// may have grown since it was inserted).
|
|
|
|
iterator addSegment(Segment S) {
|
|
|
|
return addSegmentFrom(S, segments.begin());
|
2004-07-23 19:38:44 +00:00
|
|
|
}
|
2004-07-23 17:49:16 +00:00
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// extendInBlock - If this range is live before Kill in the basic block
|
2011-09-13 16:47:56 +00:00
|
|
|
/// that starts at StartIdx, extend it to be live up to Kill, and return
|
2013-10-10 21:28:43 +00:00
|
|
|
/// the value. If there is no segment before Kill, return NULL.
|
2011-09-13 16:47:56 +00:00
|
|
|
VNInfo *extendInBlock(SlotIndex StartIdx, SlotIndex Kill);
|
2011-03-02 00:06:15 +00:00
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// join - Join two live ranges (this, and other) together. This applies
|
|
|
|
/// mappings to the value numbers in the LHS/RHS ranges as specified. If
|
|
|
|
/// the ranges are not joinable, this aborts.
|
|
|
|
void join(LiveRange &Other,
|
2009-11-03 23:52:08 +00:00
|
|
|
const int *ValNoAssignments,
|
2007-09-06 19:46:46 +00:00
|
|
|
const int *RHSValNoAssignments,
|
2013-09-06 16:44:29 +00:00
|
|
|
SmallVectorImpl<VNInfo *> &NewVNInfo);
|
2004-07-24 02:52:23 +00:00
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
/// True iff this segment is a single segment that lies between the
|
2013-04-24 15:54:43 +00:00
|
|
|
/// specified boundaries, exclusively. Vregs live across a backedge are not
|
|
|
|
/// considered local. The boundaries are expected to lie within an extended
|
|
|
|
/// basic block, so vregs that are not live out should contain no holes.
|
|
|
|
bool isLocal(SlotIndex Start, SlotIndex End) const {
|
|
|
|
return beginIndex() > Start.getBaseIndex() &&
|
|
|
|
endIndex() < End.getBoundaryIndex();
|
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// Remove the specified segment from this range. Note that the segment
|
2013-10-10 21:28:43 +00:00
|
|
|
/// must be a single Segment in its entirety.
|
|
|
|
void removeSegment(SlotIndex Start, SlotIndex End,
|
|
|
|
bool RemoveDeadValNo = false);
|
2004-07-23 17:49:16 +00:00
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
void removeSegment(Segment S, bool RemoveDeadValNo = false) {
|
|
|
|
removeSegment(S.start, S.end, RemoveDeadValNo);
|
2006-11-16 02:43:32 +00:00
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:52 +00:00
|
|
|
/// Query Liveness at Idx.
|
|
|
|
/// The sub-instruction slot of Idx doesn't matter, only the instruction
|
|
|
|
/// it refers to is considered.
|
|
|
|
LiveQueryResult Query(SlotIndex Idx) const {
|
|
|
|
// Find the segment that enters the instruction.
|
|
|
|
const_iterator I = find(Idx.getBaseIndex());
|
|
|
|
const_iterator E = end();
|
|
|
|
if (I == E)
|
2014-04-14 00:51:57 +00:00
|
|
|
return LiveQueryResult(nullptr, nullptr, SlotIndex(), false);
|
2013-10-10 21:28:52 +00:00
|
|
|
|
|
|
|
// Is this an instruction live-in segment?
|
|
|
|
// If Idx is the start index of a basic block, include live-in segments
|
|
|
|
// that start at Idx.getBaseIndex().
|
2014-04-14 00:51:57 +00:00
|
|
|
VNInfo *EarlyVal = nullptr;
|
|
|
|
VNInfo *LateVal = nullptr;
|
2013-10-10 21:28:52 +00:00
|
|
|
SlotIndex EndPoint;
|
|
|
|
bool Kill = false;
|
|
|
|
if (I->start <= Idx.getBaseIndex()) {
|
|
|
|
EarlyVal = I->valno;
|
|
|
|
EndPoint = I->end;
|
|
|
|
// Move to the potentially live-out segment.
|
|
|
|
if (SlotIndex::isSameInstr(Idx, I->end)) {
|
|
|
|
Kill = true;
|
|
|
|
if (++I == E)
|
|
|
|
return LiveQueryResult(EarlyVal, LateVal, EndPoint, Kill);
|
|
|
|
}
|
|
|
|
// Special case: A PHIDef value can have its def in the middle of a
|
|
|
|
// segment if the value happens to be live out of the layout
|
|
|
|
// predecessor.
|
|
|
|
// Such a value is not live-in.
|
|
|
|
if (EarlyVal->def == Idx.getBaseIndex())
|
2014-04-14 00:51:57 +00:00
|
|
|
EarlyVal = nullptr;
|
2013-10-10 21:28:52 +00:00
|
|
|
}
|
|
|
|
// I now points to the segment that may be live-through, or defined by
|
|
|
|
// this instr. Ignore segments starting after the current instr.
|
|
|
|
if (!SlotIndex::isEarlierInstr(Idx, I->start)) {
|
|
|
|
LateVal = I->valno;
|
|
|
|
EndPoint = I->end;
|
|
|
|
}
|
|
|
|
return LiveQueryResult(EarlyVal, LateVal, EndPoint, Kill);
|
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
/// removeValNo - Remove all the segments defined by the specified value#.
|
2008-02-13 02:48:26 +00:00
|
|
|
/// Also remove the value# from value# list.
|
|
|
|
void removeValNo(VNInfo *ValNo);
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// Returns true if the live range is zero length, i.e. no live segments
|
|
|
|
/// span instructions. It doesn't pay to spill such a range.
|
2011-05-16 23:50:05 +00:00
|
|
|
bool isZeroLength(SlotIndexes *Indexes) const {
|
2014-12-10 23:07:54 +00:00
|
|
|
for (const Segment &S : segments)
|
|
|
|
if (Indexes->getNextNonNullIndex(S.start).getBaseIndex() <
|
|
|
|
S.end.getBaseIndex())
|
2010-08-10 00:02:26 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
bool operator<(const LiveRange& other) const {
|
2009-11-03 23:52:08 +00:00
|
|
|
const SlotIndex &thisIndex = beginIndex();
|
|
|
|
const SlotIndex &otherIndex = other.beginIndex();
|
2013-10-10 21:28:47 +00:00
|
|
|
return thisIndex < otherIndex;
|
2004-07-23 17:49:16 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 22:51:54 +00:00
|
|
|
void print(raw_ostream &OS) const;
|
2004-07-24 02:52:23 +00:00
|
|
|
void dump() const;
|
2004-07-23 17:49:16 +00:00
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// \brief Walk the range and assert if any invariants fail to hold.
|
2012-07-10 05:06:03 +00:00
|
|
|
///
|
|
|
|
/// Note that this is a no-op when asserts are disabled.
|
|
|
|
#ifdef NDEBUG
|
|
|
|
void verify() const {}
|
|
|
|
#else
|
|
|
|
void verify() const;
|
|
|
|
#endif
|
|
|
|
|
2009-07-14 02:17:17 +00:00
|
|
|
private:
|
|
|
|
|
2013-10-10 21:28:43 +00:00
|
|
|
iterator addSegmentFrom(Segment S, iterator From);
|
|
|
|
void extendSegmentEndTo(iterator I, SlotIndex NewEnd);
|
|
|
|
iterator extendSegmentStartTo(iterator I, SlotIndex NewStr);
|
2010-07-26 01:49:41 +00:00
|
|
|
void markValNoForDeletion(VNInfo *V);
|
2009-11-03 23:52:08 +00:00
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS, const LiveRange &LR) {
|
|
|
|
LR.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// LiveInterval - This class represents the liveness of a register,
|
|
|
|
/// or stack slot.
|
|
|
|
class LiveInterval : public LiveRange {
|
|
|
|
public:
|
2013-10-10 21:29:05 +00:00
|
|
|
typedef LiveRange super;
|
|
|
|
|
2014-12-10 01:12:10 +00:00
|
|
|
/// A live range for subregisters. The LaneMask specifies which parts of the
|
|
|
|
/// super register are covered by the interval.
|
|
|
|
/// (@sa TargetRegisterInfo::getSubRegIndexLaneMask()).
|
|
|
|
class SubRange : public LiveRange {
|
|
|
|
public:
|
|
|
|
SubRange *Next;
|
|
|
|
unsigned LaneMask;
|
|
|
|
|
|
|
|
/// Constructs a new SubRange object.
|
|
|
|
SubRange(unsigned LaneMask)
|
|
|
|
: Next(nullptr), LaneMask(LaneMask) {
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Constructs a new SubRange object by copying liveness from @p Other.
|
|
|
|
SubRange(unsigned LaneMask, const LiveRange &Other,
|
|
|
|
BumpPtrAllocator &Allocator)
|
|
|
|
: LiveRange(Other, Allocator), Next(nullptr), LaneMask(LaneMask) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
SubRange *SubRanges; ///< Single linked list of subregister live ranges.
|
|
|
|
|
|
|
|
public:
|
2013-10-10 21:28:47 +00:00
|
|
|
const unsigned reg; // the register or stack slot of this interval.
|
|
|
|
float weight; // weight of this interval
|
|
|
|
|
|
|
|
LiveInterval(unsigned Reg, float Weight)
|
2014-12-10 01:12:10 +00:00
|
|
|
: SubRanges(nullptr), reg(Reg), weight(Weight) {}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class SingleLinkedListIterator {
|
|
|
|
T *P;
|
|
|
|
public:
|
|
|
|
SingleLinkedListIterator<T>(T *P) : P(P) {}
|
|
|
|
SingleLinkedListIterator<T> &operator++() {
|
|
|
|
P = P->Next;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
SingleLinkedListIterator<T> &operator++(int) {
|
|
|
|
SingleLinkedListIterator res = *this;
|
|
|
|
++*this;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
bool operator!=(const SingleLinkedListIterator<T> &Other) {
|
|
|
|
return P != Other.operator->();
|
|
|
|
}
|
|
|
|
bool operator==(const SingleLinkedListIterator<T> &Other) {
|
|
|
|
return P == Other.operator->();
|
|
|
|
}
|
|
|
|
T &operator*() const {
|
|
|
|
return *P;
|
|
|
|
}
|
|
|
|
T *operator->() const {
|
|
|
|
return P;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef SingleLinkedListIterator<SubRange> subrange_iterator;
|
|
|
|
subrange_iterator subrange_begin() {
|
|
|
|
return subrange_iterator(SubRanges);
|
|
|
|
}
|
|
|
|
subrange_iterator subrange_end() {
|
|
|
|
return subrange_iterator(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef SingleLinkedListIterator<const SubRange> const_subrange_iterator;
|
|
|
|
const_subrange_iterator subrange_begin() const {
|
|
|
|
return const_subrange_iterator(SubRanges);
|
|
|
|
}
|
|
|
|
const_subrange_iterator subrange_end() const {
|
|
|
|
return const_subrange_iterator(nullptr);
|
|
|
|
}
|
|
|
|
|
2014-12-11 00:59:06 +00:00
|
|
|
iterator_range<subrange_iterator> subranges() {
|
|
|
|
return make_range(subrange_begin(), subrange_end());
|
|
|
|
}
|
|
|
|
|
|
|
|
iterator_range<const_subrange_iterator> subranges() const {
|
|
|
|
return make_range(subrange_begin(), subrange_end());
|
|
|
|
}
|
|
|
|
|
2014-12-10 01:12:10 +00:00
|
|
|
/// Creates a new empty subregister live range. The range is added at the
|
|
|
|
/// beginning of the subrange list; subrange iterators stay valid.
|
|
|
|
SubRange *createSubRange(BumpPtrAllocator &Allocator, unsigned LaneMask) {
|
|
|
|
SubRange *Range = new (Allocator) SubRange(LaneMask);
|
|
|
|
appendSubRange(Range);
|
|
|
|
return Range;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Like createSubRange() but the new range is filled with a copy of the
|
|
|
|
/// liveness information in @p CopyFrom.
|
|
|
|
SubRange *createSubRangeFrom(BumpPtrAllocator &Allocator, unsigned LaneMask,
|
|
|
|
const LiveRange &CopyFrom) {
|
|
|
|
SubRange *Range = new (Allocator) SubRange(LaneMask, CopyFrom, Allocator);
|
|
|
|
appendSubRange(Range);
|
|
|
|
return Range;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if subregister liveness information is available.
|
|
|
|
bool hasSubRanges() const {
|
|
|
|
return SubRanges != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Removes all subregister liveness information.
|
|
|
|
void clearSubRanges() {
|
|
|
|
SubRanges = nullptr;
|
|
|
|
}
|
2013-10-10 21:28:47 +00:00
|
|
|
|
2014-12-10 01:12:40 +00:00
|
|
|
/// Removes all subranges without any segments (subranges without segments
|
|
|
|
/// are not considered valid and should only exist temporarily).
|
|
|
|
void removeEmptySubRanges();
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// getSize - Returns the sum of sizes of all the LiveRange's.
|
|
|
|
///
|
|
|
|
unsigned getSize() const;
|
|
|
|
|
|
|
|
/// isSpillable - Can this interval be spilled?
|
|
|
|
bool isSpillable() const {
|
2013-11-13 00:15:44 +00:00
|
|
|
return weight != llvm::huge_valf;
|
2013-10-10 21:28:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// markNotSpillable - Mark interval as not spillable
|
|
|
|
void markNotSpillable() {
|
2013-11-13 00:15:44 +00:00
|
|
|
weight = llvm::huge_valf;
|
2013-10-10 21:28:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator<(const LiveInterval& other) const {
|
|
|
|
const SlotIndex &thisIndex = beginIndex();
|
|
|
|
const SlotIndex &otherIndex = other.beginIndex();
|
2014-03-03 19:58:30 +00:00
|
|
|
return std::tie(thisIndex, reg) < std::tie(otherIndex, other.reg);
|
2013-10-10 21:28:47 +00:00
|
|
|
}
|
|
|
|
|
2013-10-10 21:29:05 +00:00
|
|
|
void print(raw_ostream &OS) const;
|
|
|
|
void dump() const;
|
|
|
|
|
2014-12-10 01:12:10 +00:00
|
|
|
/// \brief Walks the interval and assert if any invariants fail to hold.
|
|
|
|
///
|
|
|
|
/// Note that this is a no-op when asserts are disabled.
|
|
|
|
#ifdef NDEBUG
|
|
|
|
void verify(const MachineRegisterInfo *MRI = nullptr) const {}
|
|
|
|
#else
|
|
|
|
void verify(const MachineRegisterInfo *MRI = nullptr) const;
|
|
|
|
#endif
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
private:
|
2012-09-17 06:59:23 +00:00
|
|
|
LiveInterval& operator=(const LiveInterval& rhs) LLVM_DELETED_FUNCTION;
|
2009-07-14 02:17:17 +00:00
|
|
|
|
2014-12-10 01:12:10 +00:00
|
|
|
/// Appends @p Range to SubRanges list.
|
|
|
|
void appendSubRange(SubRange *Range) {
|
|
|
|
Range->Next = SubRanges;
|
|
|
|
SubRanges = Range;
|
|
|
|
}
|
2004-07-23 17:49:16 +00:00
|
|
|
};
|
|
|
|
|
2009-07-24 10:36:58 +00:00
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS, const LiveInterval &LI) {
|
|
|
|
LI.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
2004-07-23 17:49:16 +00:00
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const LiveRange::Segment &S);
|
2013-10-10 21:28:43 +00:00
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
inline bool operator<(SlotIndex V, const LiveRange::Segment &S) {
|
2013-10-10 21:28:43 +00:00
|
|
|
return V < S.start;
|
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
inline bool operator<(const LiveRange::Segment &S, SlotIndex V) {
|
2013-10-10 21:28:43 +00:00
|
|
|
return S.start < V;
|
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// Helper class for performant LiveRange bulk updates.
|
2013-02-20 18:18:12 +00:00
|
|
|
///
|
2013-10-10 21:28:47 +00:00
|
|
|
/// Calling LiveRange::addSegment() repeatedly can be expensive on large
|
2013-02-20 18:18:12 +00:00
|
|
|
/// live ranges because segments after the insertion point may need to be
|
|
|
|
/// shifted. The LiveRangeUpdater class can defer the shifting when adding
|
|
|
|
/// many segments in order.
|
|
|
|
///
|
2013-10-10 21:28:47 +00:00
|
|
|
/// The LiveRange will be in an invalid state until flush() is called.
|
2013-02-20 18:18:12 +00:00
|
|
|
class LiveRangeUpdater {
|
2013-10-10 21:28:47 +00:00
|
|
|
LiveRange *LR;
|
2013-02-20 18:18:12 +00:00
|
|
|
SlotIndex LastStart;
|
2013-10-10 21:28:47 +00:00
|
|
|
LiveRange::iterator WriteI;
|
|
|
|
LiveRange::iterator ReadI;
|
|
|
|
SmallVector<LiveRange::Segment, 16> Spills;
|
2013-02-20 18:18:12 +00:00
|
|
|
void mergeSpills();
|
|
|
|
|
|
|
|
public:
|
2013-10-10 21:28:47 +00:00
|
|
|
/// Create a LiveRangeUpdater for adding segments to LR.
|
|
|
|
/// LR will temporarily be in an invalid state until flush() is called.
|
2014-04-14 00:51:57 +00:00
|
|
|
LiveRangeUpdater(LiveRange *lr = nullptr) : LR(lr) {}
|
2013-02-20 18:18:12 +00:00
|
|
|
|
|
|
|
~LiveRangeUpdater() { flush(); }
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// Add a segment to LR and coalesce when possible, just like
|
|
|
|
/// LR.addSegment(). Segments should be added in increasing start order for
|
2013-10-10 21:28:43 +00:00
|
|
|
/// best performance.
|
2013-10-10 21:28:47 +00:00
|
|
|
void add(LiveRange::Segment);
|
2013-02-20 18:18:12 +00:00
|
|
|
|
|
|
|
void add(SlotIndex Start, SlotIndex End, VNInfo *VNI) {
|
2013-10-10 21:28:47 +00:00
|
|
|
add(LiveRange::Segment(Start, End, VNI));
|
2013-02-20 18:18:12 +00:00
|
|
|
}
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// Return true if the LR is currently in an invalid state, and flush()
|
2013-02-20 18:18:12 +00:00
|
|
|
/// needs to be called.
|
|
|
|
bool isDirty() const { return LastStart.isValid(); }
|
|
|
|
|
2013-10-10 21:28:47 +00:00
|
|
|
/// Flush the updater state to LR so it is valid and contains all added
|
2013-02-20 18:18:12 +00:00
|
|
|
/// segments.
|
|
|
|
void flush();
|
|
|
|
|
|
|
|
/// Select a different destination live range.
|
2013-10-10 21:28:47 +00:00
|
|
|
void setDest(LiveRange *lr) {
|
|
|
|
if (LR != lr && isDirty())
|
2013-02-20 18:18:12 +00:00
|
|
|
flush();
|
2013-10-10 21:28:47 +00:00
|
|
|
LR = lr;
|
2013-02-20 18:18:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the current destination live range.
|
2013-10-10 21:28:47 +00:00
|
|
|
LiveRange *getDest() const { return LR; }
|
2013-02-20 18:18:12 +00:00
|
|
|
|
|
|
|
void dump() const;
|
|
|
|
void print(raw_ostream&) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS, const LiveRangeUpdater &X) {
|
|
|
|
X.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
|
|
|
|
2010-10-07 23:34:34 +00:00
|
|
|
/// ConnectedVNInfoEqClasses - Helper class that can divide VNInfos in a
|
|
|
|
/// LiveInterval into equivalence clases of connected components. A
|
|
|
|
/// LiveInterval that has multiple connected components can be broken into
|
|
|
|
/// multiple LiveIntervals.
|
|
|
|
///
|
|
|
|
/// Given a LiveInterval that may have multiple connected components, run:
|
|
|
|
///
|
|
|
|
/// unsigned numComps = ConEQ.Classify(LI);
|
|
|
|
/// if (numComps > 1) {
|
|
|
|
/// // allocate numComps-1 new LiveIntervals into LIS[1..]
|
|
|
|
/// ConEQ.Distribute(LIS);
|
|
|
|
/// }
|
|
|
|
|
|
|
|
class ConnectedVNInfoEqClasses {
|
2011-03-17 00:23:45 +00:00
|
|
|
LiveIntervals &LIS;
|
|
|
|
IntEqClasses EqClass;
|
2010-10-07 23:34:34 +00:00
|
|
|
|
|
|
|
// Note that values a and b are connected.
|
|
|
|
void Connect(unsigned a, unsigned b);
|
|
|
|
|
|
|
|
unsigned Renumber();
|
|
|
|
|
|
|
|
public:
|
2011-03-17 00:23:45 +00:00
|
|
|
explicit ConnectedVNInfoEqClasses(LiveIntervals &lis) : LIS(lis) {}
|
2010-10-07 23:34:34 +00:00
|
|
|
|
|
|
|
/// Classify - Classify the values in LI into connected components.
|
|
|
|
/// Return the number of connected components.
|
|
|
|
unsigned Classify(const LiveInterval *LI);
|
|
|
|
|
2010-10-29 00:40:57 +00:00
|
|
|
/// getEqClass - Classify creates equivalence classes numbered 0..N. Return
|
|
|
|
/// the equivalence class assigned the VNI.
|
2011-03-17 00:23:45 +00:00
|
|
|
unsigned getEqClass(const VNInfo *VNI) const { return EqClass[VNI->id]; }
|
2010-10-29 00:40:57 +00:00
|
|
|
|
|
|
|
/// Distribute - Distribute values in LIV[0] into a separate LiveInterval
|
|
|
|
/// for each connected component. LIV must have a LiveInterval for each
|
|
|
|
/// connected component. The LiveIntervals in Liv[1..] must be empty.
|
2011-03-17 00:23:45 +00:00
|
|
|
/// Instructions using LIV[0] are rewritten.
|
|
|
|
void Distribute(LiveInterval *LIV[], MachineRegisterInfo &MRI);
|
2010-10-29 00:40:57 +00:00
|
|
|
|
2010-10-07 23:34:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2004-07-23 17:49:16 +00:00
|
|
|
#endif
|