2 Author: Ruchira Sasanka
4 Purpose: To keep info about a live range.
7 Since the Value pointed by a use is the same as of its def, it is sufficient
8 to keep only defs in a LiveRange.
14 #include "llvm/Analysis/LiveVar/ValueSet.h"
15 #include "llvm/Type.h"
21 //----------------------------------------------------------------------------
24 // Implements a live range using a ValueSet. A LiveRange is a simple set
26 //----------------------------------------------------------------------------
28 class LiveRange : public ValueSet
32 RegClass *MyRegClass; // register classs (e.g., int, FP) for this LR
35 bool doesSpanAcrossCalls;
37 // Does this live range span across calls?
38 // This information is used by graph
39 // coloring algo to avoid allocating volatile colors to live ranges
40 // that span across calls (since they have to be saved/restored)
43 IGNode *UserIGNode; // IGNode which uses this LR
45 int Color; // color assigned to this live range
47 bool mustSpill; // whether this LR must be spilt
50 bool mustSaveAcrossCalls;
52 // whether this LR must be saved accross calls ***TODO REMOVE this
54 int SuggestedColor; // The suggested color for this LR
56 // if this LR has a suggested color, can it be really alloated?
57 // A suggested color cannot be allocated when the suggested color is
58 // volatile and when there are call interferences.
60 bool CanUseSuggestedCol;
62 // It is possible that a suggested color for this live range is not
63 // available before graph coloring (e.g., it can be allocated to another
64 // live range which interferes with this)
66 int SpilledStackOffsetFromFP;
68 // if this LR is spilled, its stack offset from *FP*. The spilled offsets
69 // must always be relative to the FP.
73 // Whether this live range has a spill offset
77 // The spill cost of this live range. Calculated using loop depth of
78 // each reference to each Value in the live range
84 LiveRange() : ValueSet() {
85 Color = SuggestedColor = -1; // not yet colored
86 mustSpill = mustSaveAcrossCalls = false;
89 doesSpanAcrossCalls = false;
90 CanUseSuggestedCol = true;
91 HasSpillOffset = false;
95 // empty destructor since there are nothing to be deleted
100 void setRegClass(RegClass *const RC)
103 inline RegClass *const getRegClass() const
104 { assert(MyRegClass); return MyRegClass; }
106 inline bool hasColor() const
107 { return Color != -1; }
109 inline unsigned int getColor() const
110 { assert( Color != -1); return (unsigned) Color ; }
112 inline void setColor(unsigned int Col)
113 { Color = (int) Col ; }
116 inline void setCallInterference() {
117 doesSpanAcrossCalls = 1;
121 inline bool isCallInterference() const {
122 return (doesSpanAcrossCalls == 1);
125 inline void markForSpill() { mustSpill = true; }
127 inline bool isMarkedForSpill() { return mustSpill; }
129 inline void setSpillOffFromFP(int StackOffset) {
130 assert( mustSpill && "This LR is not spilled");
131 SpilledStackOffsetFromFP = StackOffset;
132 HasSpillOffset = true;
135 inline void modifySpillOffFromFP(int StackOffset) {
136 assert( mustSpill && "This LR is not spilled");
137 SpilledStackOffsetFromFP = StackOffset;
138 HasSpillOffset = true;
143 inline bool hasSpillOffset() const {
144 return HasSpillOffset;
148 inline int getSpillOffFromFP() const {
149 assert( HasSpillOffset && "This LR is not spilled");
150 return SpilledStackOffsetFromFP;
154 inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
157 inline void setUserIGNode( IGNode *const IGN)
158 { assert( !UserIGNode); UserIGNode = IGN; }
160 inline IGNode * getUserIGNode() const
161 { return UserIGNode; } // NULL if the user is not allocated
163 inline const Type* getType() const {
164 const Value *val = *begin();
165 assert(val && "Can't find type - Live range is empty" );
166 return val->getType();
169 inline Type::PrimitiveID getTypeID() const {
170 return this->getType()->getPrimitiveID();
173 inline void setSuggestedColor(int Col) {
174 //assert( (SuggestedColor == -1) && "Changing an already suggested color");
176 if(SuggestedColor == -1 )
177 SuggestedColor = Col;
179 cerr << "Already has a suggested color " << Col << endl;
182 inline unsigned getSuggestedColor() const {
183 assert( SuggestedColor != -1); // only a valid color is obtained
184 return (unsigned) SuggestedColor;
187 inline bool hasSuggestedColor() const {
188 return ( SuggestedColor > -1);
191 inline bool isSuggestedColorUsable() const {
192 assert( hasSuggestedColor() && "No suggested color");
193 return CanUseSuggestedCol;
196 inline void setSuggestedColorUsable(const bool val) {
197 assert( hasSuggestedColor() && "No suggested color");
198 CanUseSuggestedCol = val;
201 inline void addSpillCost(unsigned cost) {
205 inline unsigned getSpillCost() const {