2003-06-22 03:08:05 +00:00
|
|
|
//===-- LiveRange.h - Store info about a live range -------------*- C++ -*-===//
|
2003-10-21 15:17:13 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2002-02-05 01:43:49 +00:00
|
|
|
//
|
|
|
|
// Implements a live range using a ValueSet. A LiveRange is a simple set
|
|
|
|
// of Values.
|
|
|
|
//
|
|
|
|
// Since the Value pointed by a use is the same as of its def, it is sufficient
|
|
|
|
// to keep only defs in a LiveRange.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-08 14:10:34 +00:00
|
|
|
|
2003-09-21 02:31:37 +00:00
|
|
|
#ifndef LIVERANGE_H
|
|
|
|
#define LIVERANGE_H
|
2001-09-08 14:10:34 +00:00
|
|
|
|
2002-02-05 03:51:37 +00:00
|
|
|
#include "llvm/Value.h"
|
2003-10-23 18:03:50 +00:00
|
|
|
#include "llvm/CodeGen/ValueSet.h"
|
2001-09-08 14:10:34 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2001-09-08 14:10:34 +00:00
|
|
|
class RegClass;
|
|
|
|
class IGNode;
|
|
|
|
|
2002-02-04 05:52:08 +00:00
|
|
|
class LiveRange : public ValueSet {
|
2003-10-23 18:03:50 +00:00
|
|
|
RegClass *MyRegClass; // register class (e.g., int, FP) for this LR
|
2001-09-08 14:10:34 +00:00
|
|
|
|
2003-10-23 18:03:50 +00:00
|
|
|
/// doesSpanAcrossCalls - Does this live range span across calls?
|
|
|
|
/// This information is used by graph coloring algo to avoid allocating
|
|
|
|
/// volatile colors to live ranges that span across calls (since they have to
|
|
|
|
/// be saved/restored)
|
|
|
|
///
|
2002-02-05 01:43:49 +00:00
|
|
|
bool doesSpanAcrossCalls;
|
2001-09-08 14:10:34 +00:00
|
|
|
|
|
|
|
IGNode *UserIGNode; // IGNode which uses this LR
|
2002-01-07 19:16:26 +00:00
|
|
|
int Color; // color assigned to this live range
|
|
|
|
bool mustSpill; // whether this LR must be spilt
|
2001-09-08 14:10:34 +00:00
|
|
|
|
2003-10-23 18:03:50 +00:00
|
|
|
/// SuggestedColor - if this LR has a suggested color, can it be
|
|
|
|
/// really alloated? A suggested color cannot be allocated when the
|
|
|
|
/// suggested color is volatile and when there are call
|
|
|
|
/// interferences.
|
|
|
|
///
|
2002-02-05 01:43:49 +00:00
|
|
|
int SuggestedColor; // The suggested color for this LR
|
2001-10-19 21:42:06 +00:00
|
|
|
|
2003-10-23 18:03:50 +00:00
|
|
|
/// CanUseSuggestedCol - It is possible that a suggested color for
|
|
|
|
/// this live range is not available before graph coloring (e.g., it
|
|
|
|
/// can be allocated to another live range which interferes with
|
|
|
|
/// this)
|
|
|
|
///
|
2002-02-05 01:43:49 +00:00
|
|
|
bool CanUseSuggestedCol;
|
2001-10-19 21:42:06 +00:00
|
|
|
|
2003-10-23 18:03:50 +00:00
|
|
|
/// SpilledStackOffsetFromFP - If this LR is spilled, its stack
|
|
|
|
/// offset from *FP*. The spilled offsets must always be relative to
|
|
|
|
/// the FP.
|
|
|
|
///
|
2002-02-05 01:43:49 +00:00
|
|
|
int SpilledStackOffsetFromFP;
|
2002-01-07 19:16:26 +00:00
|
|
|
|
2003-10-23 18:03:50 +00:00
|
|
|
/// HasSpillOffset 0 Whether this live range has a spill offset
|
|
|
|
///
|
2002-02-05 01:43:49 +00:00
|
|
|
bool HasSpillOffset;
|
2002-01-07 19:16:26 +00:00
|
|
|
|
2003-10-23 18:03:50 +00:00
|
|
|
/// The spill cost of this live range. Calculated using loop depth of
|
|
|
|
/// each reference to each Value in the live range
|
|
|
|
///
|
2002-02-05 01:43:49 +00:00
|
|
|
unsigned SpillCost;
|
|
|
|
|
|
|
|
public:
|
|
|
|
LiveRange() {
|
2002-01-07 19:16:26 +00:00
|
|
|
Color = SuggestedColor = -1; // not yet colored
|
2004-07-29 04:15:36 +00:00
|
|
|
mustSpill = false;
|
2002-02-05 01:43:49 +00:00
|
|
|
MyRegClass = 0;
|
|
|
|
UserIGNode = 0;
|
2002-01-07 19:16:26 +00:00
|
|
|
doesSpanAcrossCalls = false;
|
|
|
|
CanUseSuggestedCol = true;
|
2002-02-05 01:43:49 +00:00
|
|
|
HasSpillOffset = false;
|
2002-01-07 19:16:26 +00:00
|
|
|
SpillCost = 0;
|
|
|
|
}
|
|
|
|
|
2002-02-05 01:43:49 +00:00
|
|
|
void setRegClass(RegClass *RC) { MyRegClass = RC; }
|
2001-09-08 14:10:34 +00:00
|
|
|
|
2002-02-05 01:43:49 +00:00
|
|
|
RegClass *getRegClass() const { assert(MyRegClass); return MyRegClass; }
|
2003-01-15 20:28:36 +00:00
|
|
|
unsigned getRegClassID() const;
|
2001-09-08 14:10:34 +00:00
|
|
|
|
2002-02-05 01:43:49 +00:00
|
|
|
bool hasColor() const { return Color != -1; }
|
2001-10-19 17:21:59 +00:00
|
|
|
|
2002-02-05 01:43:49 +00:00
|
|
|
unsigned getColor() const { assert(Color != -1); return (unsigned)Color; }
|
2001-09-08 14:10:34 +00:00
|
|
|
|
2002-02-05 01:43:49 +00:00
|
|
|
void setColor(unsigned Col) { Color = (int)Col; }
|
2001-09-08 14:10:34 +00:00
|
|
|
|
2001-10-19 21:42:06 +00:00
|
|
|
inline void setCallInterference() {
|
|
|
|
doesSpanAcrossCalls = 1;
|
2002-03-31 18:58:14 +00:00
|
|
|
}
|
|
|
|
inline void clearCallInterference() {
|
|
|
|
doesSpanAcrossCalls = 0;
|
2001-09-08 14:10:34 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 21:42:06 +00:00
|
|
|
inline bool isCallInterference() const {
|
2002-02-05 01:43:49 +00:00
|
|
|
return doesSpanAcrossCalls == 1;
|
2001-10-19 21:42:06 +00:00
|
|
|
}
|
2001-09-08 14:10:34 +00:00
|
|
|
|
|
|
|
inline void markForSpill() { mustSpill = true; }
|
|
|
|
|
2003-07-10 19:45:28 +00:00
|
|
|
inline bool isMarkedForSpill() const { return mustSpill; }
|
2001-10-28 18:15:12 +00:00
|
|
|
|
|
|
|
inline void setSpillOffFromFP(int StackOffset) {
|
2002-02-05 01:43:49 +00:00
|
|
|
assert(mustSpill && "This LR is not spilled");
|
2001-10-28 18:15:12 +00:00
|
|
|
SpilledStackOffsetFromFP = StackOffset;
|
|
|
|
HasSpillOffset = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void modifySpillOffFromFP(int StackOffset) {
|
2002-02-05 01:43:49 +00:00
|
|
|
assert(mustSpill && "This LR is not spilled");
|
2001-10-28 18:15:12 +00:00
|
|
|
SpilledStackOffsetFromFP = StackOffset;
|
|
|
|
HasSpillOffset = true;
|
|
|
|
}
|
|
|
|
|
2001-11-15 20:22:37 +00:00
|
|
|
inline bool hasSpillOffset() const {
|
2002-02-05 01:43:49 +00:00
|
|
|
return HasSpillOffset;
|
2001-10-28 18:15:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int getSpillOffFromFP() const {
|
2002-02-05 01:43:49 +00:00
|
|
|
assert(HasSpillOffset && "This LR is not spilled");
|
2001-10-28 18:15:12 +00:00
|
|
|
return SpilledStackOffsetFromFP;
|
|
|
|
}
|
|
|
|
|
2002-02-05 01:43:49 +00:00
|
|
|
inline void setUserIGNode(IGNode *IGN) {
|
|
|
|
assert(!UserIGNode); UserIGNode = IGN;
|
|
|
|
}
|
2001-09-08 14:10:34 +00:00
|
|
|
|
2002-02-05 01:43:49 +00:00
|
|
|
// getUserIGNode - NULL if the user is not allocated
|
|
|
|
inline IGNode *getUserIGNode() const { return UserIGNode; }
|
2001-09-08 14:10:34 +00:00
|
|
|
|
2002-02-05 01:43:49 +00:00
|
|
|
inline const Type *getType() const {
|
|
|
|
return (*begin())->getType(); // set's don't have a front
|
2001-11-08 04:49:52 +00:00
|
|
|
}
|
|
|
|
|
2001-09-30 23:19:57 +00:00
|
|
|
inline void setSuggestedColor(int Col) {
|
2002-02-05 01:43:49 +00:00
|
|
|
if (SuggestedColor == -1)
|
2001-09-30 23:19:57 +00:00
|
|
|
SuggestedColor = Col;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline unsigned getSuggestedColor() const {
|
2002-02-05 01:43:49 +00:00
|
|
|
assert(SuggestedColor != -1); // only a valid color is obtained
|
|
|
|
return (unsigned)SuggestedColor;
|
2001-09-30 23:19:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool hasSuggestedColor() const {
|
2002-02-05 01:43:49 +00:00
|
|
|
return SuggestedColor != -1;
|
2001-09-30 23:19:57 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 21:42:06 +00:00
|
|
|
inline bool isSuggestedColorUsable() const {
|
2002-02-05 01:43:49 +00:00
|
|
|
assert(hasSuggestedColor() && "No suggested color");
|
2001-10-19 21:42:06 +00:00
|
|
|
return CanUseSuggestedCol;
|
|
|
|
}
|
|
|
|
|
2002-02-05 01:43:49 +00:00
|
|
|
inline void setSuggestedColorUsable(bool val) {
|
|
|
|
assert(hasSuggestedColor() && "No suggested color");
|
2001-10-19 21:42:06 +00:00
|
|
|
CanUseSuggestedCol = val;
|
|
|
|
}
|
|
|
|
|
2002-01-07 19:16:26 +00:00
|
|
|
inline void addSpillCost(unsigned cost) {
|
|
|
|
SpillCost += cost;
|
|
|
|
}
|
2001-10-19 21:42:06 +00:00
|
|
|
|
2002-01-07 19:16:26 +00:00
|
|
|
inline unsigned getSpillCost() const {
|
|
|
|
return SpillCost;
|
|
|
|
}
|
2001-09-08 14:10:34 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-09-08 14:10:34 +00:00
|
|
|
#endif
|