1 //===-- LiveRange.h - Store info about a live range --------------*- C++ -*--=//
3 // Implements a live range using a ValueSet. A LiveRange is a simple set
6 // Since the Value pointed by a use is the same as of its def, it is sufficient
7 // to keep only defs in a LiveRange.
9 //===----------------------------------------------------------------------===//
14 #include "llvm/Analysis/LiveVar/ValueSet.h"
15 #include "llvm/Value.h"
22 class LiveRange : public ValueSet {
23 RegClass *MyRegClass; // register classs (e.g., int, FP) for this LR
25 // doesSpanAcrossCalls - Does this live range span across calls?
26 // This information is used by graph
27 // coloring algo to avoid allocating volatile colors to live ranges
28 // that span across calls (since they have to be saved/restored)
30 bool doesSpanAcrossCalls;
32 IGNode *UserIGNode; // IGNode which uses this LR
33 int Color; // color assigned to this live range
34 bool mustSpill; // whether this LR must be spilt
36 // mustSaveAcrossCalls - whether this LR must be saved accross calls
37 // ***TODO REMOVE this
39 bool mustSaveAcrossCalls;
41 // SuggestedColor - if this LR has a suggested color, can it be
42 // really alloated? A suggested color cannot be allocated when the
43 // suggested color is volatile and when there are call
46 int SuggestedColor; // The suggested color for this LR
48 // CanUseSuggestedCol - It is possible that a suggested color for
49 // this live range is not available before graph coloring (e.g., it
50 // can be allocated to another live range which interferes with
53 bool CanUseSuggestedCol;
55 // SpilledStackOffsetFromFP - If this LR is spilled, its stack
56 // offset from *FP*. The spilled offsets must always be relative to
59 int SpilledStackOffsetFromFP;
61 // HasSpillOffset 0 Whether this live range has a spill offset
65 // The spill cost of this live range. Calculated using loop depth of
66 // each reference to each Value in the live range
72 Color = SuggestedColor = -1; // not yet colored
73 mustSpill = mustSaveAcrossCalls = false;
76 doesSpanAcrossCalls = false;
77 CanUseSuggestedCol = true;
78 HasSpillOffset = false;
82 void setRegClass(RegClass *RC) { MyRegClass = RC; }
84 RegClass *getRegClass() const { assert(MyRegClass); return MyRegClass; }
86 bool hasColor() const { return Color != -1; }
88 unsigned getColor() const { assert(Color != -1); return (unsigned)Color; }
90 void setColor(unsigned Col) { Color = (int)Col; }
92 inline void setCallInterference() {
93 doesSpanAcrossCalls = 1;
95 inline void clearCallInterference() {
96 doesSpanAcrossCalls = 0;
99 inline bool isCallInterference() const {
100 return doesSpanAcrossCalls == 1;
103 inline void markForSpill() { mustSpill = true; }
105 inline bool isMarkedForSpill() { return mustSpill; }
107 inline void setSpillOffFromFP(int StackOffset) {
108 assert(mustSpill && "This LR is not spilled");
109 SpilledStackOffsetFromFP = StackOffset;
110 HasSpillOffset = true;
113 inline void modifySpillOffFromFP(int StackOffset) {
114 assert(mustSpill && "This LR is not spilled");
115 SpilledStackOffsetFromFP = StackOffset;
116 HasSpillOffset = true;
119 inline bool hasSpillOffset() const {
120 return HasSpillOffset;
123 inline int getSpillOffFromFP() const {
124 assert(HasSpillOffset && "This LR is not spilled");
125 return SpilledStackOffsetFromFP;
128 inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
130 inline void setUserIGNode(IGNode *IGN) {
131 assert(!UserIGNode); UserIGNode = IGN;
134 // getUserIGNode - NULL if the user is not allocated
135 inline IGNode *getUserIGNode() const { return UserIGNode; }
137 inline const Type *getType() const {
138 return (*begin())->getType(); // set's don't have a front
141 inline void setSuggestedColor(int Col) {
142 if (SuggestedColor == -1)
143 SuggestedColor = Col;
146 std::cerr << "Already has a suggested color " << Col << "\n";
150 inline unsigned getSuggestedColor() const {
151 assert(SuggestedColor != -1); // only a valid color is obtained
152 return (unsigned)SuggestedColor;
155 inline bool hasSuggestedColor() const {
156 return SuggestedColor != -1;
159 inline bool isSuggestedColorUsable() const {
160 assert(hasSuggestedColor() && "No suggested color");
161 return CanUseSuggestedCol;
164 inline void setSuggestedColorUsable(bool val) {
165 assert(hasSuggestedColor() && "No suggested color");
166 CanUseSuggestedCol = val;
169 inline void addSpillCost(unsigned cost) {
173 inline unsigned getSpillCost() const {