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 {
30 RegClass *MyRegClass; // register classs (e.g., int, FP) for this LR
32 bool doesSpanAcrossCalls;
34 // Does this live range span across calls?
35 // This information is used by graph
36 // coloring algo to avoid allocating volatile colors to live ranges
37 // that span across calls (since they have to be saved/restored)
40 IGNode *UserIGNode; // IGNode which uses this LR
42 int Color; // color assigned to this live range
44 bool mustSpill; // whether this LR must be spilt
47 bool mustSaveAcrossCalls;
49 // whether this LR must be saved accross calls ***TODO REMOVE this
51 int SuggestedColor; // The suggested color for this LR
53 // if this LR has a suggested color, can it be really alloated?
54 // A suggested color cannot be allocated when the suggested color is
55 // volatile and when there are call interferences.
57 bool CanUseSuggestedCol;
59 // It is possible that a suggested color for this live range is not
60 // available before graph coloring (e.g., it can be allocated to another
61 // live range which interferes with this)
63 int SpilledStackOffsetFromFP;
65 // if this LR is spilled, its stack offset from *FP*. The spilled offsets
66 // must always be relative to the FP.
70 // Whether this live range has a spill offset
74 // The spill cost of this live range. Calculated using loop depth of
75 // each reference to each Value in the live range
81 LiveRange() : ValueSet() {
82 Color = SuggestedColor = -1; // not yet colored
83 mustSpill = mustSaveAcrossCalls = false;
86 doesSpanAcrossCalls = false;
87 CanUseSuggestedCol = true;
88 HasSpillOffset = false;
92 // empty destructor since there are nothing to be deleted
97 void setRegClass(RegClass *const RC)
100 inline RegClass *const getRegClass() const
101 { assert(MyRegClass); return MyRegClass; }
103 inline bool hasColor() const
104 { return Color != -1; }
106 inline unsigned int getColor() const
107 { assert( Color != -1); return (unsigned) Color ; }
109 inline void setColor(unsigned int Col)
110 { Color = (int) Col ; }
113 inline void setCallInterference() {
114 doesSpanAcrossCalls = 1;
118 inline bool isCallInterference() const {
119 return (doesSpanAcrossCalls == 1);
122 inline void markForSpill() { mustSpill = true; }
124 inline bool isMarkedForSpill() { return mustSpill; }
126 inline void setSpillOffFromFP(int StackOffset) {
127 assert( mustSpill && "This LR is not spilled");
128 SpilledStackOffsetFromFP = StackOffset;
129 HasSpillOffset = true;
132 inline void modifySpillOffFromFP(int StackOffset) {
133 assert( mustSpill && "This LR is not spilled");
134 SpilledStackOffsetFromFP = StackOffset;
135 HasSpillOffset = true;
140 inline bool hasSpillOffset() const {
141 return HasSpillOffset;
145 inline int getSpillOffFromFP() const {
146 assert( HasSpillOffset && "This LR is not spilled");
147 return SpilledStackOffsetFromFP;
151 inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
154 inline void setUserIGNode( IGNode *const IGN)
155 { assert( !UserIGNode); UserIGNode = IGN; }
157 inline IGNode * getUserIGNode() const
158 { return UserIGNode; } // NULL if the user is not allocated
160 inline const Type* getType() const {
161 const Value *val = *begin();
162 assert(val && "Can't find type - Live range is empty" );
163 return val->getType();
166 inline Type::PrimitiveID getTypeID() const {
167 return getType()->getPrimitiveID();
170 inline void setSuggestedColor(int Col) {
171 //assert( (SuggestedColor == -1) && "Changing an already suggested color");
173 if(SuggestedColor == -1 )
174 SuggestedColor = Col;
177 std::cerr << "Already has a suggested color " << Col << "\n";
181 inline unsigned getSuggestedColor() const {
182 assert( SuggestedColor != -1); // only a valid color is obtained
183 return (unsigned) SuggestedColor;
186 inline bool hasSuggestedColor() const {
187 return ( SuggestedColor > -1);
190 inline bool isSuggestedColorUsable() const {
191 assert( hasSuggestedColor() && "No suggested color");
192 return CanUseSuggestedCol;
195 inline void setSuggestedColorUsable(const bool val) {
196 assert( hasSuggestedColor() && "No suggested color");
197 CanUseSuggestedCol = val;
200 inline void addSpillCost(unsigned cost) {
204 inline unsigned getSpillCost() const {