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/CodeGen/ValueSet.h"
15 #include "llvm/Value.h"
23 class LiveRange : public ValueSet {
24 RegClass *MyRegClass; // register classs (e.g., int, FP) for this LR
26 // doesSpanAcrossCalls - Does this live range span across calls?
27 // This information is used by graph
28 // coloring algo to avoid allocating volatile colors to live ranges
29 // that span across calls (since they have to be saved/restored)
31 bool doesSpanAcrossCalls;
33 IGNode *UserIGNode; // IGNode which uses this LR
34 int Color; // color assigned to this live range
35 bool mustSpill; // whether this LR must be spilt
37 // mustSaveAcrossCalls - whether this LR must be saved accross calls
38 // ***TODO REMOVE this
40 bool mustSaveAcrossCalls;
42 // SuggestedColor - if this LR has a suggested color, can it be
43 // really alloated? A suggested color cannot be allocated when the
44 // suggested color is volatile and when there are call
47 int SuggestedColor; // The suggested color for this LR
49 // CanUseSuggestedCol - It is possible that a suggested color for
50 // this live range is not available before graph coloring (e.g., it
51 // can be allocated to another live range which interferes with
54 bool CanUseSuggestedCol;
56 // SpilledStackOffsetFromFP - If this LR is spilled, its stack
57 // offset from *FP*. The spilled offsets must always be relative to
60 int SpilledStackOffsetFromFP;
62 // HasSpillOffset 0 Whether this live range has a spill offset
66 // The spill cost of this live range. Calculated using loop depth of
67 // each reference to each Value in the live range
73 Color = SuggestedColor = -1; // not yet colored
74 mustSpill = mustSaveAcrossCalls = false;
77 doesSpanAcrossCalls = false;
78 CanUseSuggestedCol = true;
79 HasSpillOffset = false;
83 void setRegClass(RegClass *RC) { MyRegClass = RC; }
85 RegClass *getRegClass() const { assert(MyRegClass); return MyRegClass; }
86 unsigned getRegClassID() const;
88 bool hasColor() const { return Color != -1; }
90 unsigned getColor() const { assert(Color != -1); return (unsigned)Color; }
92 void setColor(unsigned Col) { Color = (int)Col; }
94 inline void setCallInterference() {
95 doesSpanAcrossCalls = 1;
97 inline void clearCallInterference() {
98 doesSpanAcrossCalls = 0;
101 inline bool isCallInterference() const {
102 return doesSpanAcrossCalls == 1;
105 inline void markForSpill() { mustSpill = true; }
107 inline bool isMarkedForSpill() { return mustSpill; }
109 inline void setSpillOffFromFP(int StackOffset) {
110 assert(mustSpill && "This LR is not spilled");
111 SpilledStackOffsetFromFP = StackOffset;
112 HasSpillOffset = true;
115 inline void modifySpillOffFromFP(int StackOffset) {
116 assert(mustSpill && "This LR is not spilled");
117 SpilledStackOffsetFromFP = StackOffset;
118 HasSpillOffset = true;
121 inline bool hasSpillOffset() const {
122 return HasSpillOffset;
125 inline int getSpillOffFromFP() const {
126 assert(HasSpillOffset && "This LR is not spilled");
127 return SpilledStackOffsetFromFP;
130 inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
132 inline void setUserIGNode(IGNode *IGN) {
133 assert(!UserIGNode); UserIGNode = IGN;
136 // getUserIGNode - NULL if the user is not allocated
137 inline IGNode *getUserIGNode() const { return UserIGNode; }
139 inline const Type *getType() const {
140 return (*begin())->getType(); // set's don't have a front
143 inline void setSuggestedColor(int Col) {
144 if (SuggestedColor == -1)
145 SuggestedColor = Col;
148 inline unsigned getSuggestedColor() const {
149 assert(SuggestedColor != -1); // only a valid color is obtained
150 return (unsigned)SuggestedColor;
153 inline bool hasSuggestedColor() const {
154 return SuggestedColor != -1;
157 inline bool isSuggestedColorUsable() const {
158 assert(hasSuggestedColor() && "No suggested color");
159 return CanUseSuggestedCol;
162 inline void setSuggestedColorUsable(bool val) {
163 assert(hasSuggestedColor() && "No suggested color");
164 CanUseSuggestedCol = val;
167 inline void addSpillCost(unsigned cost) {
171 inline unsigned getSpillCost() const {