1 /* Title: LiveRange.h -*- C++ -*-
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"
22 //----------------------------------------------------------------------------
25 // Implements a live range using a ValueSet. A LiveRange is a simple set
27 //----------------------------------------------------------------------------
29 class LiveRange : public ValueSet
33 RegClass *MyRegClass; // register classs (e.g., int, FP) for this LR
36 bool doesSpanAcrossCalls;
38 // Does this live range span across calls?
39 // This information is used by graph
40 // coloring algo to avoid allocating volatile colors to live ranges
41 // that span across calls (since they have to be saved/restored)
44 IGNode *UserIGNode; // IGNode which uses this LR
46 int Color; // color assigned to this live range
48 bool mustSpill; // whether this LR must be spilt
51 bool mustSaveAcrossCalls;
53 // whether this LR must be saved accross calls ***TODO REMOVE this
55 int SuggestedColor; // The suggested color for this LR
57 // if this LR has a suggested color, can it be really alloated?
58 // A suggested color cannot be allocated when the suggested color is
59 // volatile and when there are call interferences.
61 bool CanUseSuggestedCol;
63 // It is possible that a suggested color for this live range is not
64 // available before graph coloring (e.g., it can be allocated to another
65 // live range which interferes with this)
67 int SpilledStackOffsetFromFP;
69 // if this LR is spilled, its stack offset from *FP*. The spilled offsets
70 // must always be relative to the FP.
74 // Whether this live range has a spill offset
78 // The spill cost of this live range. Calculated using loop depth of
79 // each reference to each Value in the live range
85 LiveRange() : ValueSet() {
86 Color = SuggestedColor = -1; // not yet colored
87 mustSpill = mustSaveAcrossCalls = false;
90 doesSpanAcrossCalls = false;
91 CanUseSuggestedCol = true;
92 HasSpillOffset = false;
96 // empty destructor since there are nothing to be deleted
101 void setRegClass(RegClass *const RC)
104 inline RegClass *const getRegClass() const
105 { assert(MyRegClass); return MyRegClass; }
107 inline bool hasColor() const
108 { return Color != -1; }
110 inline unsigned int getColor() const
111 { assert( Color != -1); return (unsigned) Color ; }
113 inline void setColor(unsigned int Col)
114 { Color = (int) Col ; }
117 inline void setCallInterference() {
118 doesSpanAcrossCalls = 1;
122 inline bool isCallInterference() const {
123 return (doesSpanAcrossCalls == 1);
126 inline void markForSpill() { mustSpill = true; }
128 inline bool isMarkedForSpill() { return mustSpill; }
130 inline void setSpillOffFromFP(int StackOffset) {
131 assert( mustSpill && "This LR is not spilled");
132 SpilledStackOffsetFromFP = StackOffset;
133 HasSpillOffset = true;
136 inline void modifySpillOffFromFP(int StackOffset) {
137 assert( mustSpill && "This LR is not spilled");
138 SpilledStackOffsetFromFP = StackOffset;
139 HasSpillOffset = true;
144 inline bool hasSpillOffset() const {
145 return HasSpillOffset;
149 inline int getSpillOffFromFP() const {
150 assert( HasSpillOffset && "This LR is not spilled");
151 return SpilledStackOffsetFromFP;
155 inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
158 inline void setUserIGNode( IGNode *const IGN)
159 { assert( !UserIGNode); UserIGNode = IGN; }
161 inline IGNode * getUserIGNode() const
162 { return UserIGNode; } // NULL if the user is not allocated
164 inline const Type* getType() const {
165 const Value *val = *begin();
166 assert(val && "Can't find type - Live range is empty" );
167 return val->getType();
170 inline Type::PrimitiveID getTypeID() const {
171 return this->getType()->getPrimitiveID();
174 inline void setSuggestedColor(int Col) {
175 //assert( (SuggestedColor == -1) && "Changing an already suggested color");
177 if(SuggestedColor == -1 )
178 SuggestedColor = Col;
180 std::cerr << "Already has a suggested color " << Col << "\n";
183 inline unsigned getSuggestedColor() const {
184 assert( SuggestedColor != -1); // only a valid color is obtained
185 return (unsigned) SuggestedColor;
188 inline bool hasSuggestedColor() const {
189 return ( SuggestedColor > -1);
192 inline bool isSuggestedColorUsable() const {
193 assert( hasSuggestedColor() && "No suggested color");
194 return CanUseSuggestedCol;
197 inline void setSuggestedColorUsable(const bool val) {
198 assert( hasSuggestedColor() && "No suggested color");
199 CanUseSuggestedCol = val;
202 inline void addSpillCost(unsigned cost) {
206 inline unsigned getSpillCost() const {