blob: 5b7b7ca2d4973574c603828a4a6eda11ee1f8dab [file] [log] [blame]
Ruchira Sasankac7136d22001-09-08 14:10:34 +00001/* Title: LiveRange.h
2 Author: Ruchira Sasanka
3 Date: July 25, 01
4 Purpose: To keep info about a live range.
5 Asuumptions:
6
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.
9*/
10
11#ifndef LIVE_RANGE_H
12#define LIVE_RANGE_H
13
14#include "llvm/Analysis/LiveVar/ValueSet.h"
15#include "llvm/Type.h"
16
17
18
19
20class RegClass;
21class IGNode;
22
23
24class LiveRange : public ValueSet
25{
26 private:
27
28 RegClass *MyRegClass; // register classs (e.g., int, FP) for this LR
29
30 // a list of call instructions that interferes with this live range
Ruchira Sasanka36f77072001-10-19 17:21:59 +000031 //vector<const Instruction *> CallInterferenceList;
32
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)
37
38 bool doesSpanAcrossCalls;
Ruchira Sasankac7136d22001-09-08 14:10:34 +000039
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
43
Ruchira Sasanka36f77072001-10-19 17:21:59 +000044 // whether this LR must be saved accross calls ***TODO REMOVE this
Ruchira Sasankac7136d22001-09-08 14:10:34 +000045 bool mustSaveAcrossCalls;
46
47 // bool mustLoadFromStack; // must load from stack at start of method
48
Ruchira Sasankaab304c42001-09-30 23:19:57 +000049
50 int SuggestedColor; // The suggested color for this LR
51
Ruchira Sasanka44d2b942001-10-19 21:42:06 +000052 // 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.
55
56 bool CanUseSuggestedCol;
57
Ruchira Sasanka20c82b12001-10-28 18:15:12 +000058 // if this LR is spilled, its stack offset from *FP*. The spilled offsets
59 // must always be relative to the FP.
60 int SpilledStackOffsetFromFP;
61 bool HasSpillOffset;
62
Ruchira Sasankac7136d22001-09-08 14:10:34 +000063 public:
64
65
66 ~LiveRange() {} // empty destructor
67
68 void setRegClass(RegClass *const RC)
69 { MyRegClass = RC; }
70
71 inline RegClass *const getRegClass() const
72 { assert(MyRegClass); return MyRegClass; }
73
74 inline bool hasColor() const
75 { return Color != -1; }
Ruchira Sasanka36f77072001-10-19 17:21:59 +000076
Ruchira Sasankac7136d22001-09-08 14:10:34 +000077 inline unsigned int getColor() const
78 { assert( Color != -1); return (unsigned) Color ; }
79
80 inline void setColor(unsigned int Col)
81 { Color = (int) Col ; }
82
83
Ruchira Sasanka44d2b942001-10-19 21:42:06 +000084 inline void setCallInterference() {
85 doesSpanAcrossCalls = 1;
Ruchira Sasankac7136d22001-09-08 14:10:34 +000086 }
87
Ruchira Sasanka44d2b942001-10-19 21:42:06 +000088
89 inline bool isCallInterference() const {
90 return (doesSpanAcrossCalls == 1);
91 }
Ruchira Sasankac7136d22001-09-08 14:10:34 +000092
93
94 inline void markForSpill() { mustSpill = true; }
95
Ruchira Sasanka20c82b12001-10-28 18:15:12 +000096 inline bool isMarkedForSpill() { return mustSpill; }
97
98 inline void setSpillOffFromFP(int StackOffset) {
99 assert( mustSpill && "This LR is not spilled");
100 SpilledStackOffsetFromFP = StackOffset;
101 HasSpillOffset = true;
102 }
103
104 inline void modifySpillOffFromFP(int StackOffset) {
105 assert( mustSpill && "This LR is not spilled");
106 SpilledStackOffsetFromFP = StackOffset;
107 HasSpillOffset = true;
108 }
109
110
111
112 inline bool hasSpillOffset() {
113 return HasSpillOffset;
114 }
115
116
117 inline int getSpillOffFromFP() const {
118 assert( HasSpillOffset && "This LR is not spilled");
119 return SpilledStackOffsetFromFP;
120 }
121
122
Ruchira Sasankac7136d22001-09-08 14:10:34 +0000123 inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
124
125 // inline void markForLoadFromStack() { mustLoadFromStack = true;
126
127
128 inline void setUserIGNode( IGNode *const IGN)
129 { assert( !UserIGNode); UserIGNode = IGN; }
130
131 inline IGNode * getUserIGNode() const
132 { return UserIGNode; } // NULL if the user is not allocated
133
Vikram S. Adve38f5d462001-11-08 04:49:52 +0000134 inline const Type* getType() const {
Ruchira Sasankac7136d22001-09-08 14:10:34 +0000135 const Value *val = *begin();
136 assert(val && "Can't find type - Live range is empty" );
Vikram S. Adve38f5d462001-11-08 04:49:52 +0000137 return val->getType();
Ruchira Sasankac7136d22001-09-08 14:10:34 +0000138 }
Vikram S. Adve38f5d462001-11-08 04:49:52 +0000139
140 inline Type::PrimitiveID getTypeID() const {
141 return this->getType()->getPrimitiveID();
142 }
Ruchira Sasankac7136d22001-09-08 14:10:34 +0000143
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000144 inline void setSuggestedColor(int Col) {
145 //assert( (SuggestedColor == -1) && "Changing an already suggested color");
146
147 if(SuggestedColor == -1 )
148 SuggestedColor = Col;
149 else if (DEBUG_RA)
Chris Lattner634b3522001-10-15 18:30:06 +0000150 cerr << "Already has a suggested color " << Col << endl;
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000151 }
152
153 inline unsigned getSuggestedColor() const {
154 assert( SuggestedColor != -1); // only a valid color is obtained
155 return (unsigned) SuggestedColor;
156 }
157
158 inline bool hasSuggestedColor() const {
159 return ( SuggestedColor > -1);
160 }
161
Ruchira Sasanka44d2b942001-10-19 21:42:06 +0000162 inline bool isSuggestedColorUsable() const {
163 assert( hasSuggestedColor() && "No suggested color");
164 return CanUseSuggestedCol;
165 }
166
167 inline void setSuggestedColorUsable(const bool val) {
168 assert( hasSuggestedColor() && "No suggested color");
169 CanUseSuggestedCol = val;
170 }
171
172
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000173
174
175
176
177
Ruchira Sasanka36f77072001-10-19 17:21:59 +0000178 inline LiveRange() : ValueSet() /* , CallInterferenceList() */
Ruchira Sasankac7136d22001-09-08 14:10:34 +0000179 {
Ruchira Sasankaab304c42001-09-30 23:19:57 +0000180 Color = SuggestedColor = -1; // not yet colored
Ruchira Sasankac7136d22001-09-08 14:10:34 +0000181 mustSpill = mustSaveAcrossCalls = false;
182 MyRegClass = NULL;
183 UserIGNode = NULL;
Ruchira Sasanka36f77072001-10-19 17:21:59 +0000184 doesSpanAcrossCalls = false;
Ruchira Sasanka44d2b942001-10-19 21:42:06 +0000185 CanUseSuggestedCol = true;
Ruchira Sasanka20c82b12001-10-28 18:15:12 +0000186 HasSpillOffset = false;
Ruchira Sasankac7136d22001-09-08 14:10:34 +0000187 }
188
189};
190
191
192
193
194
195#endif
196