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"
21 class LiveRange : public ValueSet {
22 RegClass *MyRegClass; // register classs (e.g., int, FP) for this LR
24 // doesSpanAcrossCalls - Does this live range span across calls?
25 // This information is used by graph
26 // coloring algo to avoid allocating volatile colors to live ranges
27 // that span across calls (since they have to be saved/restored)
29 bool doesSpanAcrossCalls;
31 IGNode *UserIGNode; // IGNode which uses this LR
32 int Color; // color assigned to this live range
33 bool mustSpill; // whether this LR must be spilt
35 // mustSaveAcrossCalls - whether this LR must be saved accross calls
36 // ***TODO REMOVE this
38 bool mustSaveAcrossCalls;
40 // SuggestedColor - if this LR has a suggested color, can it be
41 // really alloated? A suggested color cannot be allocated when the
42 // suggested color is volatile and when there are call
45 int SuggestedColor; // The suggested color for this LR
47 // CanUseSuggestedCol - It is possible that a suggested color for
48 // this live range is not available before graph coloring (e.g., it
49 // can be allocated to another live range which interferes with
52 bool CanUseSuggestedCol;
54 // SpilledStackOffsetFromFP - If this LR is spilled, its stack
55 // offset from *FP*. The spilled offsets must always be relative to
58 int SpilledStackOffsetFromFP;
60 // HasSpillOffset 0 Whether this live range has a spill offset
64 // The spill cost of this live range. Calculated using loop depth of
65 // each reference to each Value in the live range
71 Color = SuggestedColor = -1; // not yet colored
72 mustSpill = mustSaveAcrossCalls = false;
75 doesSpanAcrossCalls = false;
76 CanUseSuggestedCol = true;
77 HasSpillOffset = false;
81 void setRegClass(RegClass *RC) { MyRegClass = RC; }
83 RegClass *getRegClass() const { assert(MyRegClass); return MyRegClass; }
85 bool hasColor() const { return Color != -1; }
87 unsigned getColor() const { assert(Color != -1); return (unsigned)Color; }
89 void setColor(unsigned Col) { Color = (int)Col; }
91 inline void setCallInterference() {
92 doesSpanAcrossCalls = 1;
94 inline void clearCallInterference() {
95 doesSpanAcrossCalls = 0;
98 inline bool isCallInterference() const {
99 return doesSpanAcrossCalls == 1;
102 inline void markForSpill() { mustSpill = true; }
104 inline bool isMarkedForSpill() { return mustSpill; }
106 inline void setSpillOffFromFP(int StackOffset) {
107 assert(mustSpill && "This LR is not spilled");
108 SpilledStackOffsetFromFP = StackOffset;
109 HasSpillOffset = true;
112 inline void modifySpillOffFromFP(int StackOffset) {
113 assert(mustSpill && "This LR is not spilled");
114 SpilledStackOffsetFromFP = StackOffset;
115 HasSpillOffset = true;
118 inline bool hasSpillOffset() const {
119 return HasSpillOffset;
122 inline int getSpillOffFromFP() const {
123 assert(HasSpillOffset && "This LR is not spilled");
124 return SpilledStackOffsetFromFP;
127 inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
129 inline void setUserIGNode(IGNode *IGN) {
130 assert(!UserIGNode); UserIGNode = IGN;
133 // getUserIGNode - NULL if the user is not allocated
134 inline IGNode *getUserIGNode() const { return UserIGNode; }
136 inline const Type *getType() const {
137 return (*begin())->getType(); // set's don't have a front
140 inline void setSuggestedColor(int Col) {
141 if (SuggestedColor == -1)
142 SuggestedColor = Col;
145 inline unsigned getSuggestedColor() const {
146 assert(SuggestedColor != -1); // only a valid color is obtained
147 return (unsigned)SuggestedColor;
150 inline bool hasSuggestedColor() const {
151 return SuggestedColor != -1;
154 inline bool isSuggestedColorUsable() const {
155 assert(hasSuggestedColor() && "No suggested color");
156 return CanUseSuggestedCol;
159 inline void setSuggestedColorUsable(bool val) {
160 assert(hasSuggestedColor() && "No suggested color");
161 CanUseSuggestedCol = val;
164 inline void addSpillCost(unsigned cost) {
168 inline unsigned getSpillCost() const {