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"
24 class LiveRange : public ValueSet
28 RegClass *MyRegClass; // register classs (e.g., int, FP) for this LR
30 // a list of call instructions that interferes with this live range
31 //vector<const Instruction *> CallInterferenceList;
33 // does this live range span across calls?
34 // This information is used by graph
35 // coloring algo to avoid allocating volatile colors to live ranges
36 // that span across calls (since they have to be saved/restored)
38 bool doesSpanAcrossCalls;
40 IGNode *UserIGNode; // IGNode which uses this LR
41 int Color; // color assigned to this live range
42 bool mustSpill; // whether this LR must be spilt
44 // whether this LR must be saved accross calls ***TODO REMOVE this
45 bool mustSaveAcrossCalls;
47 // bool mustLoadFromStack; // must load from stack at start of method
50 int SuggestedColor; // The suggested color for this LR
52 // if this LR has a suggested color, can it be really alloated?
53 // A suggested color cannot be allocated when the suggested color is
54 // volatile and when there are call interferences.
56 bool CanUseSuggestedCol;
58 // if this LR is spilled, its stack offset from *FP*. The spilled offsets
59 // must always be relative to the FP.
60 int SpilledStackOffsetFromFP;
66 ~LiveRange() {} // empty destructor
68 void setRegClass(RegClass *const RC)
71 inline RegClass *const getRegClass() const
72 { assert(MyRegClass); return MyRegClass; }
74 inline bool hasColor() const
75 { return Color != -1; }
77 inline unsigned int getColor() const
78 { assert( Color != -1); return (unsigned) Color ; }
80 inline void setColor(unsigned int Col)
81 { Color = (int) Col ; }
84 inline void setCallInterference() {
85 doesSpanAcrossCalls = 1;
89 inline bool isCallInterference() const {
90 return (doesSpanAcrossCalls == 1);
94 inline void markForSpill() { mustSpill = true; }
96 inline bool isMarkedForSpill() { return mustSpill; }
98 inline void setSpillOffFromFP(int StackOffset) {
99 assert( mustSpill && "This LR is not spilled");
100 SpilledStackOffsetFromFP = StackOffset;
101 HasSpillOffset = true;
104 inline void modifySpillOffFromFP(int StackOffset) {
105 assert( mustSpill && "This LR is not spilled");
106 SpilledStackOffsetFromFP = StackOffset;
107 HasSpillOffset = true;
112 inline bool hasSpillOffset() {
113 return HasSpillOffset;
117 inline int getSpillOffFromFP() const {
118 assert( HasSpillOffset && "This LR is not spilled");
119 return SpilledStackOffsetFromFP;
123 inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
125 // inline void markForLoadFromStack() { mustLoadFromStack = true;
128 inline void setUserIGNode( IGNode *const IGN)
129 { assert( !UserIGNode); UserIGNode = IGN; }
131 inline IGNode * getUserIGNode() const
132 { return UserIGNode; } // NULL if the user is not allocated
134 inline Type::PrimitiveID getTypeID() const {
135 const Value *val = *begin();
136 assert(val && "Can't find type - Live range is empty" );
137 return (val->getType())->getPrimitiveID();
141 inline void setSuggestedColor(int Col) {
142 //assert( (SuggestedColor == -1) && "Changing an already suggested color");
144 if(SuggestedColor == -1 )
145 SuggestedColor = Col;
147 cerr << "Already has a suggested color " << Col << endl;
150 inline unsigned getSuggestedColor() const {
151 assert( SuggestedColor != -1); // only a valid color is obtained
152 return (unsigned) SuggestedColor;
155 inline bool hasSuggestedColor() const {
156 return ( SuggestedColor > -1);
159 inline bool isSuggestedColorUsable() const {
160 assert( hasSuggestedColor() && "No suggested color");
161 return CanUseSuggestedCol;
164 inline void setSuggestedColorUsable(const bool val) {
165 assert( hasSuggestedColor() && "No suggested color");
166 CanUseSuggestedCol = val;
175 inline LiveRange() : ValueSet() /* , CallInterferenceList() */
177 Color = SuggestedColor = -1; // not yet colored
178 mustSpill = mustSaveAcrossCalls = false;
181 doesSpanAcrossCalls = false;
182 CanUseSuggestedCol = true;
183 HasSpillOffset = false;