2003-06-22 03:08:05 +00:00
|
|
|
//===-- LiveRange.h - Store info about a live range -------------*- C++ -*-===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
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.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2003-10-21 15:17:13 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-02-05 01:43:49 +00:00
|
|
|
//
|
2004-07-29 06:43:06 +00:00
|
|
|
// Implements a live range using a SetVector of Value *s. We keep only
|
2005-06-12 23:52:58 +00:00
|
|
|
// defs in a V9LiveRange.
|
2002-02-05 01:43:49 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
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"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/ADT/SetVector.h"
|
2004-07-29 06:43:06 +00:00
|
|
|
#include <iostream>
|
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;
|
|
|
|
|
2005-06-12 23:52:58 +00:00
|
|
|
class V9LiveRange {
|
2004-07-29 06:43:06 +00:00
|
|
|
public:
|
|
|
|
typedef SetVector<const Value *> ValueContainerType;
|
|
|
|
typedef ValueContainerType::iterator iterator;
|
|
|
|
typedef ValueContainerType::const_iterator const_iterator;
|
|
|
|
|
|
|
|
private:
|
2005-06-12 23:52:58 +00:00
|
|
|
ValueContainerType MyValues; // Values in this V9LiveRange
|
2004-07-29 06:43:06 +00:00
|
|
|
RegClass *MyRegClass; // register class (e.g., int, FP) for this LR
|
2001-09-08 14:10:34 +00:00
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
/// doesSpanAcrossCalls - Does this live range span across calls?
|
2003-10-23 18:03:50 +00:00
|
|
|
/// 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
|
|
|
|
2004-07-29 04:25:43 +00:00
|
|
|
/// SuggestedColor - if this LR has a suggested color, can it
|
|
|
|
/// really be allocated? A suggested color cannot be allocated when the
|
2003-10-23 18:03:50 +00:00
|
|
|
/// 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)
|
2005-04-21 23:30:14 +00:00
|
|
|
///
|
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
|
|
|
|
2004-07-29 04:25:43 +00:00
|
|
|
/// HasSpillOffset - True iff this live range has a spill offset.
|
2003-10-23 18:03:50 +00:00
|
|
|
///
|
2002-02-05 01:43:49 +00:00
|
|
|
bool HasSpillOffset;
|
2002-01-07 19:16:26 +00:00
|
|
|
|
2004-07-29 04:25:43 +00:00
|
|
|
/// SpillCost - The spill cost of this live range. Calculated using loop depth
|
|
|
|
/// of each reference to each Value in the live range.
|
2003-10-23 18:03:50 +00:00
|
|
|
///
|
2002-02-05 01:43:49 +00:00
|
|
|
unsigned SpillCost;
|
|
|
|
|
|
|
|
public:
|
2004-07-29 06:43:06 +00:00
|
|
|
iterator begin() { return MyValues.begin(); }
|
|
|
|
const_iterator begin() const { return MyValues.begin(); }
|
|
|
|
iterator end() { return MyValues.end(); }
|
|
|
|
const_iterator end() const { return MyValues.end(); }
|
|
|
|
bool insert(const Value *&X) { return MyValues.insert (X); }
|
|
|
|
void insert(iterator b, iterator e) { MyValues.insert (b, e); }
|
|
|
|
|
2005-06-12 23:52:58 +00:00
|
|
|
V9LiveRange() {
|
2005-04-21 23:30:14 +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; }
|
2005-04-21 23:30:14 +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
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
inline void setCallInterference() {
|
2001-10-19 21:42:06 +00:00
|
|
|
doesSpanAcrossCalls = 1;
|
2002-03-31 18:58:14 +00:00
|
|
|
}
|
2005-04-21 23:30:14 +00:00
|
|
|
inline void clearCallInterference() {
|
2002-03-31 18:58:14 +00:00
|
|
|
doesSpanAcrossCalls = 0;
|
2001-09-08 14:10:34 +00:00
|
|
|
}
|
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
inline bool isCallInterference() const {
|
|
|
|
return doesSpanAcrossCalls == 1;
|
|
|
|
}
|
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
|
|
|
}
|
2005-04-21 23:30:14 +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
|
|
|
};
|
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
static inline std::ostream &operator << (std::ostream &os,
|
2005-06-12 23:52:58 +00:00
|
|
|
const V9LiveRange &lr) {
|
2004-07-29 06:43:06 +00:00
|
|
|
os << "LiveRange@" << (void *)(&lr);
|
|
|
|
return os;
|
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-09-08 14:10:34 +00:00
|
|
|
#endif
|