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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// 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 05:50:31 +00:00
|
|
|
// live interval 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
|
2004-07-23 17:49:16 +00: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
|
|
|
|
|
2006-08-22 06:32:56 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2007-09-05 21:46:51 +00:00
|
|
|
#include "llvm/Support/Allocator.h"
|
2009-07-14 05:46:55 +00:00
|
|
|
#include "llvm/Support/AlignOf.h"
|
2009-11-03 23:52:08 +00:00
|
|
|
#include "llvm/CodeGen/SlotIndexes.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 {
|
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;
|
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.
|
|
|
|
///
|
|
|
|
/// Care must be taken in interpreting the def index of the value. The
|
|
|
|
/// following rules apply:
|
|
|
|
///
|
2009-06-19 02:17:53 +00:00
|
|
|
/// If the isDefAccurate() method returns false then def does not contain the
|
|
|
|
/// index of the defining MachineInstr, or even (necessarily) to a
|
|
|
|
/// MachineInstr at all. In general such a def index is not meaningful
|
|
|
|
/// and should not be used. The exception is that, for values originally
|
|
|
|
/// defined by PHI instructions, after PHI elimination def will contain the
|
|
|
|
/// index of the MBB in which the PHI originally existed. This can be used
|
|
|
|
/// to insert code (spills or copies) which deals with the value, which will
|
|
|
|
/// be live in to the block.
|
2009-06-17 21:01:20 +00:00
|
|
|
class VNInfo {
|
|
|
|
private:
|
2009-06-18 04:56:53 +00:00
|
|
|
enum {
|
2010-06-25 22:53:05 +00:00
|
|
|
HAS_PHI_KILL = 1,
|
2009-06-18 04:56:53 +00:00
|
|
|
REDEF_BY_EC = 1 << 1,
|
|
|
|
IS_PHI_DEF = 1 << 2,
|
|
|
|
IS_UNUSED = 1 << 3,
|
|
|
|
IS_DEF_ACCURATE = 1 << 4
|
|
|
|
};
|
2009-06-17 21:01:20 +00:00
|
|
|
|
2009-06-18 04:56:53 +00:00
|
|
|
unsigned char flags;
|
2009-08-10 23:43:28 +00:00
|
|
|
union {
|
|
|
|
MachineInstr *copy;
|
|
|
|
unsigned reg;
|
|
|
|
} cr;
|
2009-06-17 21:01:20 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2009-06-17 21:01:20 +00:00
|
|
|
/// The index of the defining instruction (if isDefAccurate() returns true).
|
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.
|
|
|
|
/// d is presumed to point to the actual defining instr. If it doesn't
|
|
|
|
/// setIsDefAccurate(false) should be called after construction.
|
2009-11-03 23:52:08 +00:00
|
|
|
VNInfo(unsigned i, SlotIndex d, MachineInstr *c)
|
2009-08-10 23:43:28 +00:00
|
|
|
: flags(IS_DEF_ACCURATE), id(i), def(d) { cr.copy = c; }
|
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)
|
2010-06-25 22:53:05 +00:00
|
|
|
: flags(orig.flags), cr(orig.cr), id(i), def(orig.def)
|
2009-08-10 23:43:28 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
/// Copy from the parameter into this VNInfo.
|
|
|
|
void copyFrom(VNInfo &src) {
|
|
|
|
flags = src.flags;
|
|
|
|
cr = src.cr;
|
|
|
|
def = src.def;
|
|
|
|
}
|
2009-06-17 21:01:20 +00:00
|
|
|
|
|
|
|
/// Used for copying value number info.
|
|
|
|
unsigned getFlags() const { return flags; }
|
|
|
|
void setFlags(unsigned flags) { this->flags = flags; }
|
|
|
|
|
2009-08-10 23:43:28 +00: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.
|
|
|
|
MachineInstr* getCopy() const { return cr.copy; }
|
|
|
|
/// For a register interval, set the copy member.
|
|
|
|
/// This method should not be called on stack intervals as it may lead to
|
|
|
|
/// undefined behavior.
|
|
|
|
void setCopy(MachineInstr *c) { cr.copy = c; }
|
2010-06-25 22:53:05 +00:00
|
|
|
|
2009-08-10 23:43:28 +00:00
|
|
|
/// For a stack interval, returns the reg which this stack interval was
|
|
|
|
/// defined from.
|
|
|
|
/// For a register interval the behaviour of this method is undefined.
|
|
|
|
unsigned getReg() const { return cr.reg; }
|
|
|
|
/// For a stack interval, set the defining register.
|
|
|
|
/// This method should not be called on register intervals as it may lead
|
|
|
|
/// to undefined behaviour.
|
|
|
|
void setReg(unsigned reg) { cr.reg = reg; }
|
|
|
|
|
2009-06-17 21:01:20 +00:00
|
|
|
/// Returns true if one or more kills are PHI nodes.
|
|
|
|
bool hasPHIKill() const { return flags & HAS_PHI_KILL; }
|
2009-09-04 20:41:11 +00:00
|
|
|
/// Set the PHI kill flag on this value.
|
2009-06-17 21:01:20 +00: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 20:41:11 +00:00
|
|
|
/// Set the "redef by early clobber" flag on this value.
|
2009-06-17 21:01:20 +00:00
|
|
|
void setHasRedefByEC(bool hasRedef) {
|
|
|
|
if (hasRedef)
|
|
|
|
flags |= REDEF_BY_EC;
|
|
|
|
else
|
|
|
|
flags &= ~REDEF_BY_EC;
|
|
|
|
}
|
2010-06-25 22:53:05 +00:00
|
|
|
|
2009-06-17 21:01:20 +00: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 20:41:11 +00:00
|
|
|
/// Set the "phi def" flag on this value.
|
2009-06-17 21:01:20 +00: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 20:41:11 +00:00
|
|
|
/// Set the "is unused" flag on this value.
|
2009-06-17 21:01:20 +00:00
|
|
|
void setIsUnused(bool unused) {
|
|
|
|
if (unused)
|
|
|
|
flags |= IS_UNUSED;
|
|
|
|
else
|
|
|
|
flags &= ~IS_UNUSED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns true if the def is accurate.
|
|
|
|
bool isDefAccurate() const { return flags & IS_DEF_ACCURATE; }
|
2009-09-04 20:41:11 +00:00
|
|
|
/// Set the "is def accurate" flag on this value.
|
2009-06-17 21:01:20 +00:00
|
|
|
void setIsDefAccurate(bool defAccurate) {
|
|
|
|
if (defAccurate)
|
|
|
|
flags |= IS_DEF_ACCURATE;
|
2010-06-25 22:53:05 +00:00
|
|
|
else
|
2009-06-17 21:01:20 +00:00
|
|
|
flags &= ~IS_DEF_ACCURATE;
|
|
|
|
}
|
2009-09-04 20:41:11 +00:00
|
|
|
};
|
2009-07-09 03:57:02 +00:00
|
|
|
|
2004-07-23 17:49:16 +00: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-03 23:52:08 +00:00
|
|
|
SlotIndex start; // Start point of the interval (inclusive)
|
|
|
|
SlotIndex end; // End point of the interval (exclusive)
|
2007-08-29 20:45:00 +00:00
|
|
|
VNInfo *valno; // identifier for the value contained in this interval.
|
2004-07-24 02:52:23 +00:00
|
|
|
|
2009-11-03 23:52:08 +00:00
|
|
|
LiveRange(SlotIndex S, SlotIndex E, VNInfo *V)
|
2009-09-04 20:41:11 +00:00
|
|
|
: start(S), end(E), valno(V) {
|
|
|
|
|
2004-07-23 17:49:16 +00:00
|
|
|
assert(S < E && "Cannot create empty or backwards range");
|
|
|
|
}
|
|
|
|
|
2004-07-23 18:39:12 +00:00
|
|
|
/// contains - Return true if the index is covered by this range.
|
|
|
|
///
|
2009-11-03 23:52:08 +00:00
|
|
|
bool contains(SlotIndex I) const {
|
2004-07-23 18:39:12 +00:00
|
|
|
return start <= I && I < end;
|
|
|
|
}
|
|
|
|
|
2009-09-04 20:41:11 +00:00
|
|
|
/// containsRange - Return true if the given range, [S, E), is covered by
|
|
|
|
/// this range.
|
2009-11-03 23:52:08 +00:00
|
|
|
bool containsRange(SlotIndex S, SlotIndex E) const {
|
2009-09-04 20:41:11 +00:00
|
|
|
assert((S < E) && "Backwards interval?");
|
|
|
|
return (start <= S && S < end) && (start < E && E <= end);
|
|
|
|
}
|
|
|
|
|
2004-07-23 17:49:16 +00: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 02:52:23 +00:00
|
|
|
|
|
|
|
void dump() const;
|
2009-07-24 10:36:58 +00:00
|
|
|
void print(raw_ostream &os) const;
|
2004-07-24 02:52:23 +00:00
|
|
|
|
2004-07-23 18:39:12 +00:00
|
|
|
private:
|
2004-07-23 17:49:16 +00:00
|
|
|
LiveRange(); // DO NOT IMPLEMENT
|
|
|
|
};
|
2006-11-28 22:21:29 +00:00
|
|
|
|
2010-06-13 12:52:38 +00:00
|
|
|
template <> struct isPodLike<LiveRange> { static const bool value = true; };
|
|
|
|
|
2009-07-24 10:36:58 +00:00
|
|
|
raw_ostream& operator<<(raw_ostream& os, const LiveRange &LR);
|
2006-12-16 02:15:42 +00:00
|
|
|
|
2004-07-23 17:49:16 +00:00
|
|
|
|
2009-11-03 23:52:08 +00:00
|
|
|
inline bool operator<(SlotIndex V, const LiveRange &LR) {
|
2004-07-23 18:13:24 +00:00
|
|
|
return V < LR.start;
|
|
|
|
}
|
|
|
|
|
2009-11-03 23:52:08 +00:00
|
|
|
inline bool operator<(const LiveRange &LR, SlotIndex V) {
|
2006-01-26 20:41:32 +00:00
|
|
|
return LR.start < V;
|
|
|
|
}
|
2004-07-23 18:13:24 +00:00
|
|
|
|
2004-07-23 17:49:16 +00: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 02:05:37 +00:00
|
|
|
class LiveInterval {
|
|
|
|
public:
|
|
|
|
|
2006-08-22 06:32:56 +00:00
|
|
|
typedef SmallVector<LiveRange,4> Ranges;
|
2007-08-29 20:45:00 +00:00
|
|
|
typedef SmallVector<VNInfo*,4> VNInfoList;
|
|
|
|
|
2008-06-04 09:18:41 +00:00
|
|
|
unsigned reg; // the register or stack slot of this interval
|
2008-06-23 21:03:19 +00:00
|
|
|
// if the top bits is set, it represents a stack slot.
|
2004-07-23 17:49:16 +00:00
|
|
|
float weight; // weight of this interval
|
|
|
|
Ranges ranges; // the ranges in which this register is live
|
2007-08-29 20:45:00 +00:00
|
|
|
VNInfoList valnos; // value#'s
|
2009-06-02 16:53:25 +00:00
|
|
|
|
|
|
|
struct InstrSlots {
|
|
|
|
enum {
|
|
|
|
LOAD = 0,
|
|
|
|
USE = 1,
|
|
|
|
DEF = 2,
|
|
|
|
STORE = 3,
|
|
|
|
NUM = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2008-09-24 01:07:17 +00:00
|
|
|
LiveInterval(unsigned Reg, float Weight, bool IsSS = false)
|
2009-06-14 20:22:55 +00:00
|
|
|
: reg(Reg), weight(Weight) {
|
2008-06-23 21:03:19 +00:00
|
|
|
if (IsSS)
|
2009-04-01 18:45:54 +00:00
|
|
|
reg = reg | (1U << (sizeof(unsigned)*CHAR_BIT-1));
|
2007-08-28 08:28:51 +00:00
|
|
|
}
|
|
|
|
|
2004-11-18 01:29:39 +00:00
|
|
|
typedef Ranges::iterator iterator;
|
|
|
|
iterator begin() { return ranges.begin(); }
|
|
|
|
iterator end() { return ranges.end(); }
|
|
|
|
|
2004-11-18 03:47:34 +00:00
|
|
|
typedef Ranges::const_iterator const_iterator;
|
|
|
|
const_iterator begin() const { return ranges.begin(); }
|
|
|
|
const_iterator end() const { return ranges.end(); }
|
|
|
|
|
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(); }
|
|
|
|
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(); }
|
|
|
|
const_vni_iterator vni_end() const { return valnos.end(); }
|
|
|
|
|
2004-11-18 02:37:31 +00: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 20:04:19 +00:00
|
|
|
/// position is in a hole, this method returns an iterator pointing to the
|
2004-11-18 04:31:10 +00:00
|
|
|
/// LiveRange immediately after the hole.
|
2009-11-03 23:52:08 +00:00
|
|
|
iterator advanceTo(iterator I, SlotIndex Pos) {
|
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;
|
|
|
|
}
|
2008-12-28 21:57:02 +00:00
|
|
|
|
|
|
|
void clear() {
|
2010-03-30 11:17:48 +00:00
|
|
|
valnos.clear();
|
2008-12-28 21:57:02 +00:00
|
|
|
ranges.clear();
|
|
|
|
}
|
2004-11-18 02:37:31 +00:00
|
|
|
|
2008-06-04 09:18:41 +00:00
|
|
|
/// isStackSlot - Return true if this is a stack slot interval.
|
|
|
|
///
|
2008-06-23 21:03:19 +00:00
|
|
|
bool isStackSlot() const {
|
2009-04-01 18:45:54 +00:00
|
|
|
return reg & (1U << (sizeof(unsigned)*CHAR_BIT-1));
|
2008-06-23 21:03:19 +00:00
|
|
|
}
|
2008-06-04 09:18:41 +00:00
|
|
|
|
|
|
|
/// getStackSlotIndex - Return stack slot index if this is a stack slot
|
|
|
|
/// interval.
|
|
|
|
int getStackSlotIndex() const {
|
|
|
|
assert(isStackSlot() && "Interval is not a stack slot interval!");
|
2009-04-01 18:45:54 +00:00
|
|
|
return reg & ~(1U << (sizeof(unsigned)*CHAR_BIT-1));
|
2008-06-04 09:18:41 +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(); }
|
2006-08-24 22:43:55 +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
|
|
|
}
|
|
|
|
|
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.
|
2009-11-03 23:52:08 +00:00
|
|
|
VNInfo *getNextValue(SlotIndex def, MachineInstr *CopyMI,
|
2010-03-30 20:16:45 +00:00
|
|
|
bool isDefAccurate, VNInfo::Allocator &VNInfoAllocator) {
|
2010-06-26 11:30:59 +00:00
|
|
|
VNInfo *VNI =
|
|
|
|
new (VNInfoAllocator) VNInfo((unsigned)valnos.size(), def, CopyMI);
|
2009-06-17 21:01:20 +00:00
|
|
|
VNI->setIsDefAccurate(isDefAccurate);
|
|
|
|
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 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
|
|
|
|
2009-02-08 08:24:28 +00:00
|
|
|
/// isOnlyLROfValNo - Return true if the specified live range is the only
|
|
|
|
/// one defined by the its val#.
|
2009-07-09 03:57:02 +00:00
|
|
|
bool isOnlyLROfValNo(const LiveRange *LR) {
|
2009-02-08 08:24:28 +00: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 07:48:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-02-08 08:24:28 +00:00
|
|
|
return true;
|
2009-02-08 07:48:37 +00:00
|
|
|
}
|
2006-08-31 05:54:43 +00:00
|
|
|
|
2006-08-24 22:43:55 +00: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 22:42:01 +00:00
|
|
|
VNInfo* MergeValueNumberInto(VNInfo *V1, VNInfo *V2);
|
2006-08-22 18:19:46 +00:00
|
|
|
|
2006-08-25 23:41:24 +00:00
|
|
|
/// MergeInClobberRanges - For any live ranges that are not defined in the
|
|
|
|
/// current interval, but are defined in the Clobbers interval, mark them
|
2007-09-05 21:46:51 +00:00
|
|
|
/// used with an unknown definition value. Caller must pass in reference to
|
|
|
|
/// VNInfoAllocator since it will create a new val#.
|
2009-11-03 23:52:08 +00:00
|
|
|
void MergeInClobberRanges(LiveIntervals &li_,
|
|
|
|
const LiveInterval &Clobbers,
|
2010-03-30 20:16:45 +00:00
|
|
|
VNInfo::Allocator &VNInfoAllocator);
|
2004-07-23 17:49:16 +00:00
|
|
|
|
2009-03-11 00:03:21 +00:00
|
|
|
/// MergeInClobberRange - Same as MergeInClobberRanges except it merge in a
|
|
|
|
/// single LiveRange only.
|
2009-11-03 23:52:08 +00:00
|
|
|
void MergeInClobberRange(LiveIntervals &li_,
|
|
|
|
SlotIndex Start,
|
|
|
|
SlotIndex End,
|
2010-03-30 20:16:45 +00:00
|
|
|
VNInfo::Allocator &VNInfoAllocator);
|
2009-03-11 00:03:21 +00:00
|
|
|
|
2007-10-17 02:16:40 +00: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 20:45:00 +00:00
|
|
|
void MergeRangesInAsValue(const LiveInterval &RHS, VNInfo *LHSValNo);
|
2007-10-12 08:50:34 +00: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 10:08:34 +00:00
|
|
|
const VNInfo *RHSValNo, VNInfo *LHSValNo);
|
2007-10-12 08:50:34 +00:00
|
|
|
|
|
|
|
/// Copy - Copy the specified live interval. This copies all the fields
|
|
|
|
/// except for the register of the interval.
|
2009-06-14 20:22:55 +00:00
|
|
|
void Copy(const LiveInterval &RHS, MachineRegisterInfo *MRI,
|
2010-03-30 20:16:45 +00:00
|
|
|
VNInfo::Allocator &VNInfoAllocator);
|
2006-09-02 05:37:53 +00:00
|
|
|
|
2004-07-23 17:49:16 +00:00
|
|
|
bool empty() const { return ranges.empty(); }
|
|
|
|
|
2009-09-04 20:41:11 +00:00
|
|
|
/// beginIndex - Return the lowest numbered slot covered by interval.
|
2009-11-03 23:52:08 +00:00
|
|
|
SlotIndex beginIndex() const {
|
|
|
|
assert(!empty() && "Call to beginIndex() on empty interval.");
|
2004-07-23 17:49:16 +00:00
|
|
|
return ranges.front().start;
|
|
|
|
}
|
|
|
|
|
2004-11-18 01:29:39 +00:00
|
|
|
/// endNumber - return the maximum point of the interval of the whole,
|
2004-07-23 17:49:16 +00:00
|
|
|
/// exclusive.
|
2009-11-03 23:52:08 +00:00
|
|
|
SlotIndex endIndex() const {
|
|
|
|
assert(!empty() && "Call to endIndex() on empty interval.");
|
2004-07-23 17:49:16 +00:00
|
|
|
return ranges.back().end;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-11-03 23:52:08 +00:00
|
|
|
bool liveAt(SlotIndex index) const;
|
2004-07-23 17:49:16 +00:00
|
|
|
|
2008-02-15 18:24:29 +00:00
|
|
|
// liveBeforeAndAt - Check if the interval is live at the index and the
|
|
|
|
// index just before it. If index is liveAt, check if it starts a new live
|
|
|
|
// range.If it does, then check if the previous live range ends at index-1.
|
2009-11-03 23:52:08 +00:00
|
|
|
bool liveBeforeAndAt(SlotIndex index) const;
|
2008-02-15 18:24:29 +00:00
|
|
|
|
2010-06-25 22:53:05 +00: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.
|
|
|
|
bool killedAt(SlotIndex index) const;
|
|
|
|
|
|
|
|
/// 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 02:52:23 +00:00
|
|
|
/// getLiveRangeContaining - Return the live range that contains the
|
|
|
|
/// specified index, or null if there is none.
|
2009-11-03 23:52:08 +00:00
|
|
|
const LiveRange *getLiveRangeContaining(SlotIndex Idx) const {
|
2006-08-24 22:43:55 +00:00
|
|
|
const_iterator I = FindLiveRangeContaining(Idx);
|
|
|
|
return I == end() ? 0 : &*I;
|
|
|
|
}
|
2004-07-24 02:52:23 +00:00
|
|
|
|
2009-07-09 03:57:02 +00:00
|
|
|
/// getLiveRangeContaining - Return the live range that contains the
|
|
|
|
/// specified index, or null if there is none.
|
2009-11-03 23:52:08 +00:00
|
|
|
LiveRange *getLiveRangeContaining(SlotIndex Idx) {
|
2009-07-09 03:57:02 +00:00
|
|
|
iterator I = FindLiveRangeContaining(Idx);
|
|
|
|
return I == end() ? 0 : &*I;
|
|
|
|
}
|
|
|
|
|
2010-07-02 17:44:57 +00: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;
|
|
|
|
}
|
|
|
|
|
2006-08-24 22:43:55 +00:00
|
|
|
/// FindLiveRangeContaining - Return an iterator to the live range that
|
|
|
|
/// contains the specified index, or end() if there is none.
|
2009-11-03 23:52:08 +00:00
|
|
|
const_iterator FindLiveRangeContaining(SlotIndex Idx) const;
|
2004-07-24 02:52:23 +00:00
|
|
|
|
2006-08-24 22:43:55 +00:00
|
|
|
/// FindLiveRangeContaining - Return an iterator to the live range that
|
|
|
|
/// contains the specified index, or end() if there is none.
|
2009-11-03 23:52:08 +00:00
|
|
|
iterator FindLiveRangeContaining(SlotIndex Idx);
|
2009-09-04 20:41:11 +00:00
|
|
|
|
|
|
|
/// findDefinedVNInfo - Find the by the specified
|
|
|
|
/// index (register interval) or defined
|
2009-11-03 23:52:08 +00:00
|
|
|
VNInfo *findDefinedVNInfoForRegInt(SlotIndex Idx) const;
|
2009-09-04 20:41:11 +00:00
|
|
|
|
|
|
|
/// findDefinedVNInfo - Find the VNInfo that's defined by the specified
|
|
|
|
/// register (stack inteval only).
|
|
|
|
VNInfo *findDefinedVNInfoForStackInt(unsigned Reg) const;
|
2008-06-04 09:18:41 +00:00
|
|
|
|
2006-08-24 22:43:55 +00:00
|
|
|
|
2004-11-18 03:47:34 +00:00
|
|
|
/// overlaps - Return true if the intersection of the two live intervals is
|
|
|
|
/// not empty.
|
|
|
|
bool overlaps(const LiveInterval& 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());
|
|
|
|
}
|
|
|
|
|
2009-04-18 08:52:15 +00:00
|
|
|
/// overlaps - Return true if the live interval overlaps a range 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
|
|
|
|
2004-11-18 03:47:34 +00: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 17:49:16 +00:00
|
|
|
|
2004-07-23 19:38:44 +00: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 17:49:16 +00:00
|
|
|
|
2006-08-29 23:18:15 +00: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-03 23:52:08 +00:00
|
|
|
void join(LiveInterval &Other,
|
|
|
|
const int *ValNoAssignments,
|
2007-09-06 19:46:46 +00:00
|
|
|
const int *RHSValNoAssignments,
|
2009-06-14 20:22:55 +00:00
|
|
|
SmallVector<VNInfo*, 16> &NewVNInfo,
|
|
|
|
MachineRegisterInfo *MRI);
|
2004-07-24 02:52:23 +00:00
|
|
|
|
2009-01-29 02:20:59 +00:00
|
|
|
/// isInOneLiveRange - Return true if the range specified is entirely in the
|
|
|
|
/// a single LiveRange of the live interval.
|
2009-11-03 23:52:08 +00:00
|
|
|
bool isInOneLiveRange(SlotIndex Start, SlotIndex End);
|
2009-01-29 02:20:59 +00:00
|
|
|
|
2004-07-24 02:52:23 +00:00
|
|
|
/// removeRange - Remove the specified range from this interval. Note that
|
2009-01-29 00:06:09 +00:00
|
|
|
/// the range must be a single LiveRange in its entirety.
|
2009-11-03 23:52:08 +00:00
|
|
|
void removeRange(SlotIndex Start, SlotIndex End,
|
2009-09-04 20:41:11 +00:00
|
|
|
bool RemoveDeadValNo = false);
|
2004-07-23 17:49:16 +00:00
|
|
|
|
2008-02-13 02:48:26 +00:00
|
|
|
void removeRange(LiveRange LR, bool RemoveDeadValNo = false) {
|
|
|
|
removeRange(LR.start, LR.end, RemoveDeadValNo);
|
2006-11-16 02:43:32 +00:00
|
|
|
}
|
|
|
|
|
2008-02-13 02:48:26 +00: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 20:25:11 +00:00
|
|
|
/// getSize - Returns the sum of sizes of all the LiveRange's.
|
|
|
|
///
|
|
|
|
unsigned getSize() const;
|
|
|
|
|
2010-03-01 20:59:38 +00: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 20:08:25 +00:00
|
|
|
/// ComputeJoinedWeight - Set the weight of a live interval after
|
|
|
|
/// Other has been merged into it.
|
|
|
|
void ComputeJoinedWeight(const LiveInterval &Other);
|
|
|
|
|
2004-07-23 17:49:16 +00:00
|
|
|
bool operator<(const LiveInterval& other) const {
|
2009-11-03 23:52:08 +00:00
|
|
|
const SlotIndex &thisIndex = beginIndex();
|
|
|
|
const SlotIndex &otherIndex = other.beginIndex();
|
2009-09-05 01:19:16 +00:00
|
|
|
return (thisIndex < otherIndex ||
|
|
|
|
(thisIndex == otherIndex && reg < other.reg));
|
2004-07-23 17:49:16 +00:00
|
|
|
}
|
|
|
|
|
2009-07-24 10:36:58 +00:00
|
|
|
void print(raw_ostream &OS, const TargetRegisterInfo *TRI = 0) const;
|
2004-07-24 02:52:23 +00:00
|
|
|
void dump() const;
|
2004-07-23 17:49:16 +00:00
|
|
|
|
2009-07-14 02:17:17 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
Ranges::iterator addRangeFrom(LiveRange LR, Ranges::iterator From);
|
2009-11-03 23:52:08 +00:00
|
|
|
void extendIntervalEndTo(Ranges::iterator I, SlotIndex NewEnd);
|
|
|
|
Ranges::iterator extendIntervalStartTo(Ranges::iterator I, SlotIndex NewStr);
|
2010-07-26 01:49:41 +00:00
|
|
|
void markValNoForDeletion(VNInfo *V);
|
2009-11-03 23:52:08 +00:00
|
|
|
|
2009-07-14 02:17:17 +00:00
|
|
|
LiveInterval& operator=(const LiveInterval& rhs); // DO NOT IMPLEMENT
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|