2004-07-23 19:49:16 +02:00
|
|
|
//===-- llvm/CodeGen/LiveInterval.h - Interval representation ---*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2004-07-23 19:49:16 +02: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
|
2008-11-26 06:50:31 +01:00
|
|
|
// live interval for register v if there is no instruction with number j' >= j
|
2004-07-24 04:52:23 +02:00
|
|
|
// such that v is live at j' and there is no instruction with number i' < i such
|
2004-07-23 19:49:16 +02:00
|
|
|
// that v is live at i'. In this implementation intervals can have holes,
|
|
|
|
// i.e. an interval might look like [1,20), [50,65), [1000,1001). Each
|
|
|
|
// individual range is represented as an instance of LiveRange, and the whole
|
|
|
|
// interval is represented as an instance of LiveInterval.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_LIVEINTERVAL_H
|
|
|
|
#define LLVM_CODEGEN_LIVEINTERVAL_H
|
|
|
|
|
2010-12-21 01:48:17 +01:00
|
|
|
#include "llvm/ADT/IntEqClasses.h"
|
2007-09-05 23:46:51 +02:00
|
|
|
#include "llvm/Support/Allocator.h"
|
2009-07-14 07:46:55 +02:00
|
|
|
#include "llvm/Support/AlignOf.h"
|
2009-11-04 00:52:08 +01:00
|
|
|
#include "llvm/CodeGen/SlotIndexes.h"
|
2004-07-23 19:49:16 +02:00
|
|
|
#include <cassert>
|
2009-04-01 20:45:54 +02:00
|
|
|
#include <climits>
|
2004-07-23 19:49:16 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
2009-11-04 00:52:08 +01:00
|
|
|
class LiveIntervals;
|
2007-03-20 09:13:50 +01:00
|
|
|
class MachineInstr;
|
2009-06-14 22:22:55 +02:00
|
|
|
class MachineRegisterInfo;
|
2008-02-10 19:45:23 +01:00
|
|
|
class TargetRegisterInfo;
|
2009-07-24 12:36:58 +02:00
|
|
|
class raw_ostream;
|
2007-08-29 22:45:00 +02:00
|
|
|
|
2009-06-17 23:01:20 +02:00
|
|
|
/// VNInfo - Value Number Information.
|
|
|
|
/// This class holds information about a machine level values, including
|
|
|
|
/// definition and use points.
|
|
|
|
///
|
|
|
|
class VNInfo {
|
|
|
|
private:
|
2009-06-18 06:56:53 +02:00
|
|
|
enum {
|
2010-06-26 00:53:05 +02:00
|
|
|
HAS_PHI_KILL = 1,
|
2009-06-18 06:56:53 +02:00
|
|
|
REDEF_BY_EC = 1 << 1,
|
|
|
|
IS_PHI_DEF = 1 << 2,
|
2010-09-25 14:04:16 +02:00
|
|
|
IS_UNUSED = 1 << 3
|
2009-06-18 06:56:53 +02:00
|
|
|
};
|
2009-06-17 23:01:20 +02:00
|
|
|
|
2010-09-08 23:21:28 +02:00
|
|
|
MachineInstr *copy;
|
2010-09-09 01:54:00 +02:00
|
|
|
unsigned char flags;
|
2009-06-17 23:01:20 +02:00
|
|
|
|
|
|
|
public:
|
2010-06-26 13:30:59 +02:00
|
|
|
typedef BumpPtrAllocator Allocator;
|
2009-07-09 05:57:02 +02:00
|
|
|
|
2009-06-17 23:01:20 +02:00
|
|
|
/// The ID number of this value.
|
2007-08-29 22:45:00 +02:00
|
|
|
unsigned id;
|
2010-06-26 00:53:05 +02:00
|
|
|
|
2009-06-17 23:01:20 +02:00
|
|
|
/// The index of the defining instruction (if isDefAccurate() returns true).
|
2009-11-04 00:52:08 +01:00
|
|
|
SlotIndex def;
|
2009-08-11 01:43:28 +02:00
|
|
|
|
2009-06-17 23:01:20 +02:00
|
|
|
/// VNInfo constructor.
|
2009-11-04 00:52:08 +01:00
|
|
|
VNInfo(unsigned i, SlotIndex d, MachineInstr *c)
|
2010-09-25 14:04:16 +02:00
|
|
|
: copy(c), flags(0), id(i), def(d)
|
2010-09-09 01:54:00 +02:00
|
|
|
{ }
|
2009-06-17 23:01:20 +02:00
|
|
|
|
|
|
|
/// VNInfo construtor, copies values from orig, except for the value number.
|
|
|
|
VNInfo(unsigned i, const VNInfo &orig)
|
2010-09-09 01:54:00 +02:00
|
|
|
: copy(orig.copy), flags(orig.flags), id(i), def(orig.def)
|
2009-08-11 01:43:28 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
/// Copy from the parameter into this VNInfo.
|
|
|
|
void copyFrom(VNInfo &src) {
|
|
|
|
flags = src.flags;
|
2010-09-08 23:21:28 +02:00
|
|
|
copy = src.copy;
|
2009-08-11 01:43:28 +02:00
|
|
|
def = src.def;
|
|
|
|
}
|
2009-06-17 23:01:20 +02:00
|
|
|
|
|
|
|
/// Used for copying value number info.
|
|
|
|
unsigned getFlags() const { return flags; }
|
|
|
|
void setFlags(unsigned flags) { this->flags = flags; }
|
|
|
|
|
2010-10-02 01:52:25 +02:00
|
|
|
/// Merge flags from another VNInfo
|
|
|
|
void mergeFlags(const VNInfo *VNI) {
|
|
|
|
flags = (flags | VNI->flags) & ~IS_UNUSED;
|
|
|
|
}
|
|
|
|
|
2009-08-11 01:43:28 +02:00
|
|
|
/// For a register interval, if this VN was definied by a copy instr
|
|
|
|
/// getCopy() returns a pointer to it, otherwise returns 0.
|
|
|
|
/// For a stack interval the behaviour of this method is undefined.
|
2010-09-08 23:21:28 +02:00
|
|
|
MachineInstr* getCopy() const { return copy; }
|
2009-08-11 01:43:28 +02:00
|
|
|
/// For a register interval, set the copy member.
|
|
|
|
/// This method should not be called on stack intervals as it may lead to
|
|
|
|
/// undefined behavior.
|
2010-09-08 23:21:28 +02:00
|
|
|
void setCopy(MachineInstr *c) { copy = c; }
|
2009-08-11 01:43:28 +02:00
|
|
|
|
2010-09-25 20:10:38 +02:00
|
|
|
/// isDefByCopy - Return true when this value was defined by a copy-like
|
|
|
|
/// instruction as determined by MachineInstr::isCopyLike.
|
|
|
|
bool isDefByCopy() const { return copy != 0; }
|
|
|
|
|
2009-06-17 23:01:20 +02:00
|
|
|
/// Returns true if one or more kills are PHI nodes.
|
|
|
|
bool hasPHIKill() const { return flags & HAS_PHI_KILL; }
|
2009-09-04 22:41:11 +02:00
|
|
|
/// Set the PHI kill flag on this value.
|
2009-06-17 23:01:20 +02:00
|
|
|
void setHasPHIKill(bool hasKill) {
|
|
|
|
if (hasKill)
|
|
|
|
flags |= HAS_PHI_KILL;
|
|
|
|
else
|
|
|
|
flags &= ~HAS_PHI_KILL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if this value is re-defined by an early clobber somewhere
|
|
|
|
/// during the live range.
|
|
|
|
bool hasRedefByEC() const { return flags & REDEF_BY_EC; }
|
2009-09-04 22:41:11 +02:00
|
|
|
/// Set the "redef by early clobber" flag on this value.
|
2009-06-17 23:01:20 +02:00
|
|
|
void setHasRedefByEC(bool hasRedef) {
|
|
|
|
if (hasRedef)
|
|
|
|
flags |= REDEF_BY_EC;
|
|
|
|
else
|
|
|
|
flags &= ~REDEF_BY_EC;
|
|
|
|
}
|
2010-06-26 00:53:05 +02:00
|
|
|
|
2009-06-17 23:01:20 +02:00
|
|
|
/// Returns true if this value is defined by a PHI instruction (or was,
|
|
|
|
/// PHI instrucions may have been eliminated).
|
|
|
|
bool isPHIDef() const { return flags & IS_PHI_DEF; }
|
2009-09-04 22:41:11 +02:00
|
|
|
/// Set the "phi def" flag on this value.
|
2009-06-17 23:01:20 +02:00
|
|
|
void setIsPHIDef(bool phiDef) {
|
|
|
|
if (phiDef)
|
|
|
|
flags |= IS_PHI_DEF;
|
|
|
|
else
|
|
|
|
flags &= ~IS_PHI_DEF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if this value is unused.
|
|
|
|
bool isUnused() const { return flags & IS_UNUSED; }
|
2009-09-04 22:41:11 +02:00
|
|
|
/// Set the "is unused" flag on this value.
|
2009-06-17 23:01:20 +02:00
|
|
|
void setIsUnused(bool unused) {
|
|
|
|
if (unused)
|
|
|
|
flags |= IS_UNUSED;
|
|
|
|
else
|
|
|
|
flags &= ~IS_UNUSED;
|
|
|
|
}
|
2009-09-04 22:41:11 +02:00
|
|
|
};
|
2009-07-09 05:57:02 +02:00
|
|
|
|
2004-07-23 19:49:16 +02:00
|
|
|
/// LiveRange structure - This represents a simple register range in the
|
|
|
|
/// program, with an inclusive start point and an exclusive end point.
|
|
|
|
/// These ranges are rendered as [start,end).
|
|
|
|
struct LiveRange {
|
2009-11-04 00:52:08 +01:00
|
|
|
SlotIndex start; // Start point of the interval (inclusive)
|
|
|
|
SlotIndex end; // End point of the interval (exclusive)
|
2007-08-29 22:45:00 +02:00
|
|
|
VNInfo *valno; // identifier for the value contained in this interval.
|
2004-07-24 04:52:23 +02:00
|
|
|
|
2009-11-04 00:52:08 +01:00
|
|
|
LiveRange(SlotIndex S, SlotIndex E, VNInfo *V)
|
2009-09-04 22:41:11 +02:00
|
|
|
: start(S), end(E), valno(V) {
|
|
|
|
|
2004-07-23 19:49:16 +02:00
|
|
|
assert(S < E && "Cannot create empty or backwards range");
|
|
|
|
}
|
|
|
|
|
2004-07-23 20:39:12 +02:00
|
|
|
/// contains - Return true if the index is covered by this range.
|
|
|
|
///
|
2009-11-04 00:52:08 +01:00
|
|
|
bool contains(SlotIndex I) const {
|
2004-07-23 20:39:12 +02:00
|
|
|
return start <= I && I < end;
|
|
|
|
}
|
|
|
|
|
2009-09-04 22:41:11 +02:00
|
|
|
/// containsRange - Return true if the given range, [S, E), is covered by
|
2010-08-12 22:01:23 +02:00
|
|
|
/// this range.
|
2009-11-04 00:52:08 +01:00
|
|
|
bool containsRange(SlotIndex S, SlotIndex E) const {
|
2009-09-04 22:41:11 +02:00
|
|
|
assert((S < E) && "Backwards interval?");
|
|
|
|
return (start <= S && S < end) && (start < E && E <= end);
|
|
|
|
}
|
|
|
|
|
2004-07-23 19:49:16 +02:00
|
|
|
bool operator<(const LiveRange &LR) const {
|
|
|
|
return start < LR.start || (start == LR.start && end < LR.end);
|
|
|
|
}
|
|
|
|
bool operator==(const LiveRange &LR) const {
|
|
|
|
return start == LR.start && end == LR.end;
|
|
|
|
}
|
2004-07-24 04:52:23 +02:00
|
|
|
|
|
|
|
void dump() const;
|
2009-07-24 12:36:58 +02:00
|
|
|
void print(raw_ostream &os) const;
|
2004-07-24 04:52:23 +02:00
|
|
|
|
2004-07-23 20:39:12 +02:00
|
|
|
private:
|
2004-07-23 19:49:16 +02:00
|
|
|
LiveRange(); // DO NOT IMPLEMENT
|
|
|
|
};
|
2006-11-28 23:21:29 +01:00
|
|
|
|
2010-06-13 14:52:38 +02:00
|
|
|
template <> struct isPodLike<LiveRange> { static const bool value = true; };
|
|
|
|
|
2009-07-24 12:36:58 +02:00
|
|
|
raw_ostream& operator<<(raw_ostream& os, const LiveRange &LR);
|
2006-12-16 03:15:42 +01:00
|
|
|
|
2004-07-23 19:49:16 +02:00
|
|
|
|
2009-11-04 00:52:08 +01:00
|
|
|
inline bool operator<(SlotIndex V, const LiveRange &LR) {
|
2004-07-23 20:13:24 +02:00
|
|
|
return V < LR.start;
|
|
|
|
}
|
|
|
|
|
2009-11-04 00:52:08 +01:00
|
|
|
inline bool operator<(const LiveRange &LR, SlotIndex V) {
|
2006-01-26 21:41:32 +01:00
|
|
|
return LR.start < V;
|
|
|
|
}
|
2004-07-23 20:13:24 +02:00
|
|
|
|
2004-07-23 19:49:16 +02:00
|
|
|
/// LiveInterval - This class represents some number of live ranges for a
|
|
|
|
/// register or value. This class also contains a bit of register allocator
|
|
|
|
/// state.
|
2009-07-14 04:05:37 +02:00
|
|
|
class LiveInterval {
|
|
|
|
public:
|
|
|
|
|
2006-08-22 08:32:56 +02:00
|
|
|
typedef SmallVector<LiveRange,4> Ranges;
|
2007-08-29 22:45:00 +02:00
|
|
|
typedef SmallVector<VNInfo*,4> VNInfoList;
|
|
|
|
|
2011-01-09 22:17:37 +01:00
|
|
|
const unsigned reg; // the register or stack slot of this interval.
|
2004-07-23 19:49:16 +02:00
|
|
|
float weight; // weight of this interval
|
|
|
|
Ranges ranges; // the ranges in which this register is live
|
2007-08-29 22:45:00 +02:00
|
|
|
VNInfoList valnos; // value#'s
|
2010-08-12 22:01:23 +02:00
|
|
|
|
2009-06-02 18:53:25 +02:00
|
|
|
struct InstrSlots {
|
|
|
|
enum {
|
|
|
|
LOAD = 0,
|
|
|
|
USE = 1,
|
|
|
|
DEF = 2,
|
|
|
|
STORE = 3,
|
|
|
|
NUM = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-01-09 22:17:37 +01:00
|
|
|
LiveInterval(unsigned Reg, float Weight)
|
|
|
|
: reg(Reg), weight(Weight) {}
|
2007-08-28 10:28:51 +02:00
|
|
|
|
2004-11-18 02:29:39 +01:00
|
|
|
typedef Ranges::iterator iterator;
|
|
|
|
iterator begin() { return ranges.begin(); }
|
|
|
|
iterator end() { return ranges.end(); }
|
|
|
|
|
2004-11-18 04:47:34 +01:00
|
|
|
typedef Ranges::const_iterator const_iterator;
|
|
|
|
const_iterator begin() const { return ranges.begin(); }
|
|
|
|
const_iterator end() const { return ranges.end(); }
|
|
|
|
|
2007-08-28 10:28:51 +02:00
|
|
|
typedef VNInfoList::iterator vni_iterator;
|
2007-08-29 22:45:00 +02:00
|
|
|
vni_iterator vni_begin() { return valnos.begin(); }
|
|
|
|
vni_iterator vni_end() { return valnos.end(); }
|
2007-08-28 10:28:51 +02:00
|
|
|
|
|
|
|
typedef VNInfoList::const_iterator const_vni_iterator;
|
2007-08-29 22:45:00 +02:00
|
|
|
const_vni_iterator vni_begin() const { return valnos.begin(); }
|
|
|
|
const_vni_iterator vni_end() const { return valnos.end(); }
|
|
|
|
|
2004-11-18 03:37:31 +01:00
|
|
|
/// advanceTo - Advance the specified iterator to point to the LiveRange
|
|
|
|
/// containing the specified position, or end() if the position is past the
|
|
|
|
/// end of the interval. If no LiveRange contains this position, but the
|
2010-02-10 21:04:19 +01:00
|
|
|
/// position is in a hole, this method returns an iterator pointing to the
|
2004-11-18 05:31:10 +01:00
|
|
|
/// LiveRange immediately after the hole.
|
2009-11-04 00:52:08 +01:00
|
|
|
iterator advanceTo(iterator I, SlotIndex Pos) {
|
2010-12-18 00:16:38 +01:00
|
|
|
assert(I != end());
|
2009-09-04 22:41:11 +02:00
|
|
|
if (Pos >= endIndex())
|
2004-11-18 03:37:31 +01:00
|
|
|
return end();
|
|
|
|
while (I->end <= Pos) ++I;
|
|
|
|
return I;
|
|
|
|
}
|
2010-08-12 22:01:23 +02:00
|
|
|
|
2010-09-21 19:12:18 +02:00
|
|
|
/// find - Return an iterator pointing to the first range that ends after
|
|
|
|
/// Pos, or end(). This is the same as advanceTo(begin(), Pos), but faster
|
|
|
|
/// when searching large intervals.
|
|
|
|
///
|
|
|
|
/// If Pos is contained in a LiveRange, that range is returned.
|
|
|
|
/// If Pos is in a hole, the following LiveRange is returned.
|
|
|
|
/// If Pos is beyond endIndex, end() is returned.
|
|
|
|
iterator find(SlotIndex Pos);
|
|
|
|
|
|
|
|
const_iterator find(SlotIndex Pos) const {
|
|
|
|
return const_cast<LiveInterval*>(this)->find(Pos);
|
|
|
|
}
|
|
|
|
|
2008-12-28 22:57:02 +01:00
|
|
|
void clear() {
|
2010-03-30 13:17:48 +02:00
|
|
|
valnos.clear();
|
2008-12-28 22:57:02 +01:00
|
|
|
ranges.clear();
|
|
|
|
}
|
2004-11-18 03:37:31 +01:00
|
|
|
|
2008-10-29 09:39:34 +01:00
|
|
|
bool hasAtLeastOneValue() const { return !valnos.empty(); }
|
|
|
|
|
2007-08-31 10:26:44 +02:00
|
|
|
bool containsOneValue() const { return valnos.size() == 1; }
|
2004-07-24 04:52:23 +02:00
|
|
|
|
2008-05-05 20:30:58 +02:00
|
|
|
unsigned getNumValNums() const { return (unsigned)valnos.size(); }
|
2010-08-12 22:01:23 +02:00
|
|
|
|
2007-09-05 23:46:51 +02:00
|
|
|
/// getValNumInfo - Returns pointer to the specified val#.
|
2007-08-28 10:28:51 +02:00
|
|
|
///
|
2007-09-05 23:46:51 +02:00
|
|
|
inline VNInfo *getValNumInfo(unsigned ValNo) {
|
|
|
|
return valnos[ValNo];
|
2007-08-28 10:28:51 +02:00
|
|
|
}
|
2007-09-05 23:46:51 +02:00
|
|
|
inline const VNInfo *getValNumInfo(unsigned ValNo) const {
|
|
|
|
return valnos[ValNo];
|
2007-08-28 10:28:51 +02:00
|
|
|
}
|
|
|
|
|
2011-04-30 08:42:21 +02:00
|
|
|
/// containsValue - Returns true if VNI belongs to this interval.
|
|
|
|
bool containsValue(const VNInfo *VNI) const {
|
|
|
|
return VNI && VNI->id < getNumValNums() && VNI == getValNumInfo(VNI->id);
|
|
|
|
}
|
|
|
|
|
2006-08-22 20:19:46 +02:00
|
|
|
/// getNextValue - Create a new value number and return it. MIIdx specifies
|
|
|
|
/// the instruction that defines the value number.
|
2009-11-04 00:52:08 +01:00
|
|
|
VNInfo *getNextValue(SlotIndex def, MachineInstr *CopyMI,
|
2010-09-25 14:04:16 +02:00
|
|
|
VNInfo::Allocator &VNInfoAllocator) {
|
2010-06-26 13:30:59 +02:00
|
|
|
VNInfo *VNI =
|
|
|
|
new (VNInfoAllocator) VNInfo((unsigned)valnos.size(), def, CopyMI);
|
2009-06-17 23:01:20 +02:00
|
|
|
valnos.push_back(VNI);
|
|
|
|
return VNI;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a copy of the given value. The new value will be identical except
|
|
|
|
/// for the Value number.
|
2009-08-23 05:47:42 +02:00
|
|
|
VNInfo *createValueCopy(const VNInfo *orig,
|
2010-03-30 22:16:45 +02:00
|
|
|
VNInfo::Allocator &VNInfoAllocator) {
|
2010-06-26 13:30:59 +02:00
|
|
|
VNInfo *VNI =
|
|
|
|
new (VNInfoAllocator) VNInfo((unsigned)valnos.size(), *orig);
|
2007-08-29 22:45:00 +02:00
|
|
|
valnos.push_back(VNI);
|
|
|
|
return VNI;
|
2007-08-08 05:00:28 +02:00
|
|
|
}
|
2007-08-11 02:59:19 +02:00
|
|
|
|
2010-08-06 20:46:59 +02:00
|
|
|
/// RenumberValues - Renumber all values in order of appearance and remove
|
|
|
|
/// unused values.
|
2010-08-12 22:38:03 +02:00
|
|
|
void RenumberValues(LiveIntervals &lis);
|
2010-08-06 20:46:59 +02:00
|
|
|
|
2009-02-08 09:24:28 +01:00
|
|
|
/// isOnlyLROfValNo - Return true if the specified live range is the only
|
|
|
|
/// one defined by the its val#.
|
2009-07-09 05:57:02 +02:00
|
|
|
bool isOnlyLROfValNo(const LiveRange *LR) {
|
2009-02-08 09:24:28 +01:00
|
|
|
for (const_iterator I = begin(), E = end(); I != E; ++I) {
|
|
|
|
const LiveRange *Tmp = I;
|
|
|
|
if (Tmp != LR && Tmp->valno == LR->valno)
|
2009-02-08 08:48:37 +01:00
|
|
|
return false;
|
|
|
|
}
|
2009-02-08 09:24:28 +01:00
|
|
|
return true;
|
2009-02-08 08:48:37 +01:00
|
|
|
}
|
2010-08-12 22:01:23 +02:00
|
|
|
|
2006-08-25 00:43:55 +02:00
|
|
|
/// MergeValueNumberInto - This method is called when two value nubmers
|
|
|
|
/// are found to be equivalent. This eliminates V1, replacing all
|
|
|
|
/// LiveRanges with the V1 value number with the V2 value number. This can
|
|
|
|
/// cause merging of V1/V2 values numbers and compaction of the value space.
|
2009-02-02 23:42:01 +01:00
|
|
|
VNInfo* MergeValueNumberInto(VNInfo *V1, VNInfo *V2);
|
2006-08-22 20:19:46 +02:00
|
|
|
|
2007-10-17 04:16:40 +02:00
|
|
|
/// MergeValueInAsValue - Merge all of the live ranges of a specific val#
|
|
|
|
/// in RHS into this live interval as the specified value number.
|
|
|
|
/// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
|
|
|
|
/// current interval, it will replace the value numbers of the overlaped
|
|
|
|
/// live ranges with the specified value number.
|
2007-08-29 22:45:00 +02:00
|
|
|
void MergeRangesInAsValue(const LiveInterval &RHS, VNInfo *LHSValNo);
|
2007-10-12 10:50:34 +02:00
|
|
|
|
|
|
|
/// MergeValueInAsValue - Merge all of the live ranges of a specific val#
|
|
|
|
/// in RHS into this live interval as the specified value number.
|
|
|
|
/// The LiveRanges in RHS are allowed to overlap with LiveRanges in the
|
|
|
|
/// current interval, but only if the overlapping LiveRanges have the
|
|
|
|
/// specified value number.
|
|
|
|
void MergeValueInAsValue(const LiveInterval &RHS,
|
2007-10-14 12:08:34 +02:00
|
|
|
const VNInfo *RHSValNo, VNInfo *LHSValNo);
|
2007-10-12 10:50:34 +02:00
|
|
|
|
|
|
|
/// Copy - Copy the specified live interval. This copies all the fields
|
|
|
|
/// except for the register of the interval.
|
2009-06-14 22:22:55 +02:00
|
|
|
void Copy(const LiveInterval &RHS, MachineRegisterInfo *MRI,
|
2010-03-30 22:16:45 +02:00
|
|
|
VNInfo::Allocator &VNInfoAllocator);
|
2010-08-12 22:01:23 +02:00
|
|
|
|
2004-07-23 19:49:16 +02:00
|
|
|
bool empty() const { return ranges.empty(); }
|
|
|
|
|
2009-09-04 22:41:11 +02:00
|
|
|
/// beginIndex - Return the lowest numbered slot covered by interval.
|
2009-11-04 00:52:08 +01:00
|
|
|
SlotIndex beginIndex() const {
|
|
|
|
assert(!empty() && "Call to beginIndex() on empty interval.");
|
2004-07-23 19:49:16 +02:00
|
|
|
return ranges.front().start;
|
|
|
|
}
|
|
|
|
|
2004-11-18 02:29:39 +01:00
|
|
|
/// endNumber - return the maximum point of the interval of the whole,
|
2004-07-23 19:49:16 +02:00
|
|
|
/// exclusive.
|
2009-11-04 00:52:08 +01:00
|
|
|
SlotIndex endIndex() const {
|
|
|
|
assert(!empty() && "Call to endIndex() on empty interval.");
|
2004-07-23 19:49:16 +02:00
|
|
|
return ranges.back().end;
|
|
|
|
}
|
|
|
|
|
2009-11-04 00:52:08 +01:00
|
|
|
bool expiredAt(SlotIndex index) const {
|
2009-09-04 22:41:11 +02:00
|
|
|
return index >= endIndex();
|
2004-07-23 19:49:16 +02:00
|
|
|
}
|
|
|
|
|
2010-09-21 19:12:18 +02:00
|
|
|
bool liveAt(SlotIndex index) const {
|
|
|
|
const_iterator r = find(index);
|
|
|
|
return r != end() && r->start <= index;
|
|
|
|
}
|
2004-07-23 19:49:16 +02:00
|
|
|
|
2010-06-26 00:53:05 +02:00
|
|
|
/// killedAt - Return true if a live range ends at index. Note that the kill
|
|
|
|
/// point is not contained in the half-open live range. It is usually the
|
|
|
|
/// getDefIndex() slot following its last use.
|
2010-09-21 19:12:18 +02:00
|
|
|
bool killedAt(SlotIndex index) const {
|
|
|
|
const_iterator r = find(index.getUseIndex());
|
|
|
|
return r != end() && r->end == index;
|
|
|
|
}
|
2010-06-26 00:53:05 +02:00
|
|
|
|
|
|
|
/// killedInRange - Return true if the interval has kills in [Start,End).
|
|
|
|
/// Note that the kill point is considered the end of a live range, so it is
|
|
|
|
/// not contained in the live range. If a live range ends at End, it won't
|
|
|
|
/// be counted as a kill by this method.
|
|
|
|
bool killedInRange(SlotIndex Start, SlotIndex End) const;
|
|
|
|
|
2004-07-24 04:52:23 +02:00
|
|
|
/// getLiveRangeContaining - Return the live range that contains the
|
|
|
|
/// specified index, or null if there is none.
|
2009-11-04 00:52:08 +01:00
|
|
|
const LiveRange *getLiveRangeContaining(SlotIndex Idx) const {
|
2006-08-25 00:43:55 +02:00
|
|
|
const_iterator I = FindLiveRangeContaining(Idx);
|
|
|
|
return I == end() ? 0 : &*I;
|
|
|
|
}
|
2004-07-24 04:52:23 +02:00
|
|
|
|
2009-07-09 05:57:02 +02:00
|
|
|
/// getLiveRangeContaining - Return the live range that contains the
|
|
|
|
/// specified index, or null if there is none.
|
2009-11-04 00:52:08 +01:00
|
|
|
LiveRange *getLiveRangeContaining(SlotIndex Idx) {
|
2009-07-09 05:57:02 +02:00
|
|
|
iterator I = FindLiveRangeContaining(Idx);
|
|
|
|
return I == end() ? 0 : &*I;
|
|
|
|
}
|
|
|
|
|
2010-07-02 19:44:57 +02:00
|
|
|
/// getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
|
|
|
|
VNInfo *getVNInfoAt(SlotIndex Idx) const {
|
|
|
|
const_iterator I = FindLiveRangeContaining(Idx);
|
|
|
|
return I == end() ? 0 : I->valno;
|
|
|
|
}
|
|
|
|
|
2011-09-15 03:09:33 +02: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 {
|
|
|
|
const_iterator I = FindLiveRangeContaining(Idx.getPrevIndex());
|
|
|
|
return I == end() ? 0 : I->valno;
|
|
|
|
}
|
|
|
|
|
2006-08-25 00:43:55 +02:00
|
|
|
/// FindLiveRangeContaining - Return an iterator to the live range that
|
|
|
|
/// contains the specified index, or end() if there is none.
|
2010-09-21 19:12:18 +02:00
|
|
|
iterator FindLiveRangeContaining(SlotIndex Idx) {
|
|
|
|
iterator I = find(Idx);
|
|
|
|
return I != end() && I->start <= Idx ? I : end();
|
|
|
|
}
|
2004-07-24 04:52:23 +02:00
|
|
|
|
2010-09-21 19:12:18 +02:00
|
|
|
const_iterator FindLiveRangeContaining(SlotIndex Idx) const {
|
|
|
|
const_iterator I = find(Idx);
|
|
|
|
return I != end() && I->start <= Idx ? I : end();
|
|
|
|
}
|
2009-09-04 22:41:11 +02:00
|
|
|
|
|
|
|
/// findDefinedVNInfo - Find the by the specified
|
2010-08-12 22:01:23 +02:00
|
|
|
/// index (register interval) or defined
|
2009-11-04 00:52:08 +01:00
|
|
|
VNInfo *findDefinedVNInfoForRegInt(SlotIndex Idx) const;
|
2009-09-04 22:41:11 +02:00
|
|
|
|
2010-08-12 22:01:23 +02:00
|
|
|
|
2004-11-18 04:47:34 +01:00
|
|
|
/// overlaps - Return true if the intersection of the two live intervals is
|
|
|
|
/// not empty.
|
|
|
|
bool overlaps(const LiveInterval& other) const {
|
2010-07-22 04:05:10 +02:00
|
|
|
if (other.empty())
|
|
|
|
return false;
|
2004-11-18 04:47:34 +01:00
|
|
|
return overlapsFrom(other, other.begin());
|
|
|
|
}
|
|
|
|
|
2009-04-18 10:52:15 +02:00
|
|
|
/// overlaps - Return true if the live interval overlaps a range specified
|
|
|
|
/// by [Start, End).
|
2009-11-04 00:52:08 +01:00
|
|
|
bool overlaps(SlotIndex Start, SlotIndex End) const;
|
2009-04-18 10:52:15 +02:00
|
|
|
|
2004-11-18 04:47:34 +01:00
|
|
|
/// overlapsFrom - Return true if the intersection of the two live intervals
|
|
|
|
/// is not empty. The specified iterator is a hint that we can begin
|
|
|
|
/// scanning the Other interval starting at I.
|
|
|
|
bool overlapsFrom(const LiveInterval& other, const_iterator I) const;
|
2004-07-23 19:49:16 +02:00
|
|
|
|
2004-07-23 21:38:44 +02:00
|
|
|
/// addRange - Add the specified LiveRange to this interval, merging
|
|
|
|
/// intervals as appropriate. This returns an iterator to the inserted live
|
|
|
|
/// range (which may have grown since it was inserted.
|
|
|
|
void addRange(LiveRange LR) {
|
|
|
|
addRangeFrom(LR, ranges.begin());
|
|
|
|
}
|
2004-07-23 19:49:16 +02:00
|
|
|
|
2011-09-13 18:47:56 +02:00
|
|
|
/// extendInBlock - If this interval is live before Kill in the basic block
|
|
|
|
/// that starts at StartIdx, extend it to be live up to Kill, and return
|
|
|
|
/// the value. If there is no live range before Kill, return NULL.
|
|
|
|
VNInfo *extendInBlock(SlotIndex StartIdx, SlotIndex Kill);
|
2011-03-02 01:06:15 +01:00
|
|
|
|
2006-08-30 01:18:15 +02:00
|
|
|
/// join - Join two live intervals (this, and other) together. This applies
|
|
|
|
/// mappings to the value numbers in the LHS/RHS intervals as specified. If
|
|
|
|
/// the intervals are not joinable, this aborts.
|
2009-11-04 00:52:08 +01:00
|
|
|
void join(LiveInterval &Other,
|
|
|
|
const int *ValNoAssignments,
|
2007-09-06 21:46:46 +02:00
|
|
|
const int *RHSValNoAssignments,
|
2009-06-14 22:22:55 +02:00
|
|
|
SmallVector<VNInfo*, 16> &NewVNInfo,
|
|
|
|
MachineRegisterInfo *MRI);
|
2004-07-24 04:52:23 +02:00
|
|
|
|
2009-01-29 03:20:59 +01:00
|
|
|
/// isInOneLiveRange - Return true if the range specified is entirely in the
|
|
|
|
/// a single LiveRange of the live interval.
|
2010-09-21 19:12:18 +02:00
|
|
|
bool isInOneLiveRange(SlotIndex Start, SlotIndex End) const {
|
|
|
|
const_iterator r = find(Start);
|
|
|
|
return r != end() && r->containsRange(Start, End);
|
|
|
|
}
|
2009-01-29 03:20:59 +01:00
|
|
|
|
2004-07-24 04:52:23 +02:00
|
|
|
/// removeRange - Remove the specified range from this interval. Note that
|
2009-01-29 01:06:09 +01:00
|
|
|
/// the range must be a single LiveRange in its entirety.
|
2009-11-04 00:52:08 +01:00
|
|
|
void removeRange(SlotIndex Start, SlotIndex End,
|
2009-09-04 22:41:11 +02:00
|
|
|
bool RemoveDeadValNo = false);
|
2004-07-23 19:49:16 +02:00
|
|
|
|
2008-02-13 03:48:26 +01:00
|
|
|
void removeRange(LiveRange LR, bool RemoveDeadValNo = false) {
|
|
|
|
removeRange(LR.start, LR.end, RemoveDeadValNo);
|
2006-11-16 03:43:32 +01:00
|
|
|
}
|
|
|
|
|
2008-02-13 03:48:26 +01:00
|
|
|
/// removeValNo - Remove all the ranges defined by the specified value#.
|
|
|
|
/// Also remove the value# from value# list.
|
|
|
|
void removeValNo(VNInfo *ValNo);
|
|
|
|
|
2007-04-17 22:25:11 +02:00
|
|
|
/// getSize - Returns the sum of sizes of all the LiveRange's.
|
|
|
|
///
|
|
|
|
unsigned getSize() const;
|
|
|
|
|
2010-08-10 02:02:26 +02:00
|
|
|
/// Returns true if the live interval is zero length, i.e. no live ranges
|
|
|
|
/// span instructions. It doesn't pay to spill such an interval.
|
2011-05-17 01:50:05 +02:00
|
|
|
bool isZeroLength(SlotIndexes *Indexes) const {
|
2010-08-10 02:02:26 +02:00
|
|
|
for (const_iterator i = begin(), e = end(); i != e; ++i)
|
2011-05-17 01:50:05 +02:00
|
|
|
if (Indexes->getNextNonNullIndex(i->start).getBaseIndex() <
|
|
|
|
i->end.getBaseIndex())
|
2010-08-10 02:02:26 +02:00
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-01 21:59:38 +01:00
|
|
|
/// isSpillable - Can this interval be spilled?
|
|
|
|
bool isSpillable() const {
|
|
|
|
return weight != HUGE_VALF;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// markNotSpillable - Mark interval as not spillable
|
|
|
|
void markNotSpillable() {
|
|
|
|
weight = HUGE_VALF;
|
|
|
|
}
|
|
|
|
|
2009-07-22 22:08:25 +02:00
|
|
|
/// ComputeJoinedWeight - Set the weight of a live interval after
|
|
|
|
/// Other has been merged into it.
|
|
|
|
void ComputeJoinedWeight(const LiveInterval &Other);
|
|
|
|
|
2004-07-23 19:49:16 +02:00
|
|
|
bool operator<(const LiveInterval& other) const {
|
2009-11-04 00:52:08 +01:00
|
|
|
const SlotIndex &thisIndex = beginIndex();
|
|
|
|
const SlotIndex &otherIndex = other.beginIndex();
|
2009-09-05 03:19:16 +02:00
|
|
|
return (thisIndex < otherIndex ||
|
|
|
|
(thisIndex == otherIndex && reg < other.reg));
|
2004-07-23 19:49:16 +02:00
|
|
|
}
|
|
|
|
|
2009-07-24 12:36:58 +02:00
|
|
|
void print(raw_ostream &OS, const TargetRegisterInfo *TRI = 0) const;
|
2004-07-24 04:52:23 +02:00
|
|
|
void dump() const;
|
2004-07-23 19:49:16 +02:00
|
|
|
|
2009-07-14 04:17:17 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
Ranges::iterator addRangeFrom(LiveRange LR, Ranges::iterator From);
|
2009-11-04 00:52:08 +01:00
|
|
|
void extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd);
|
|
|
|
Ranges::iterator extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStr);
|
2010-07-26 03:49:41 +02:00
|
|
|
void markValNoForDeletion(VNInfo *V);
|
2009-11-04 00:52:08 +01:00
|
|
|
|
2009-07-14 04:17:17 +02:00
|
|
|
LiveInterval& operator=(const LiveInterval& rhs); // DO NOT IMPLEMENT
|
|
|
|
|
2004-07-23 19:49:16 +02:00
|
|
|
};
|
|
|
|
|
2009-07-24 12:36:58 +02:00
|
|
|
inline raw_ostream &operator<<(raw_ostream &OS, const LiveInterval &LI) {
|
|
|
|
LI.print(OS);
|
|
|
|
return OS;
|
|
|
|
}
|
2004-07-23 19:49:16 +02:00
|
|
|
|
2010-10-08 01:34:34 +02: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 01:23:45 +01:00
|
|
|
LiveIntervals &LIS;
|
|
|
|
IntEqClasses EqClass;
|
2010-10-08 01:34:34 +02:00
|
|
|
|
|
|
|
// Note that values a and b are connected.
|
|
|
|
void Connect(unsigned a, unsigned b);
|
|
|
|
|
|
|
|
unsigned Renumber();
|
|
|
|
|
|
|
|
public:
|
2011-03-17 01:23:45 +01:00
|
|
|
explicit ConnectedVNInfoEqClasses(LiveIntervals &lis) : LIS(lis) {}
|
2010-10-08 01:34:34 +02:00
|
|
|
|
|
|
|
/// Classify - Classify the values in LI into connected components.
|
|
|
|
/// Return the number of connected components.
|
|
|
|
unsigned Classify(const LiveInterval *LI);
|
|
|
|
|
2010-10-29 02:40:57 +02:00
|
|
|
/// getEqClass - Classify creates equivalence classes numbered 0..N. Return
|
|
|
|
/// the equivalence class assigned the VNI.
|
2011-03-17 01:23:45 +01:00
|
|
|
unsigned getEqClass(const VNInfo *VNI) const { return EqClass[VNI->id]; }
|
2010-10-29 02:40:57 +02: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 01:23:45 +01:00
|
|
|
/// Instructions using LIV[0] are rewritten.
|
|
|
|
void Distribute(LiveInterval *LIV[], MachineRegisterInfo &MRI);
|
2010-10-29 02:40:57 +02:00
|
|
|
|
2010-10-08 01:34:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2004-07-23 19:49:16 +02:00
|
|
|
#endif
|