Add #includes neccesary since they were removed from .h files
[oota-llvm.git] / lib / Target / SparcV9 / RegAlloc / LiveRange.h
1 /* Title:   LiveRange.h   -*- C++ -*-
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 #include <iostream>
17
18 class RegClass;
19 class IGNode;
20
21
22 //----------------------------------------------------------------------------
23 // Class LiveRange
24 //
25 // Implements a live range using a ValueSet. A LiveRange is a simple set
26 // of Values. 
27 //----------------------------------------------------------------------------
28
29 class LiveRange : public ValueSet {
30   RegClass *MyRegClass;       // register classs (e.g., int, FP) for this LR
31
32   bool doesSpanAcrossCalls;
33   //
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)
38   
39
40   IGNode *UserIGNode;         // IGNode which uses this LR
41
42   int Color;                  // color assigned to this live range
43
44   bool mustSpill;             // whether this LR must be spilt
45
46
47   bool mustSaveAcrossCalls;        
48   //
49   // whether this LR must be saved accross calls ***TODO REMOVE this
50   
51   int SuggestedColor;        // The suggested color for this LR
52   //
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.
56
57   bool CanUseSuggestedCol;
58   // 
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)
62
63   int SpilledStackOffsetFromFP;
64   //
65   // if this LR is spilled, its stack offset from *FP*. The spilled offsets
66   // must always be relative to the FP.
67
68   bool HasSpillOffset;
69   //
70   // Whether this live range has a spill offset
71
72   unsigned SpillCost;
73   //
74   // The spill cost of this live range. Calculated using loop depth of
75   // each reference to each Value in the live range
76
77  public:
78
79   // constructor
80   //
81   LiveRange() : ValueSet() {
82     Color = SuggestedColor = -1;        // not yet colored 
83     mustSpill = mustSaveAcrossCalls = false;
84     MyRegClass = NULL;
85     UserIGNode = NULL;
86     doesSpanAcrossCalls = false;
87     CanUseSuggestedCol = true;
88     HasSpillOffset  = false;
89     SpillCost = 0;
90   }
91
92   // empty destructor since there are nothing to be deleted
93   //
94   ~LiveRange() {}          
95
96
97   void setRegClass(RegClass *const RC) 
98     { MyRegClass = RC; }
99
100   inline RegClass *const getRegClass() const 
101     { assert(MyRegClass); return MyRegClass; } 
102
103   inline bool hasColor() const 
104     { return Color != -1; }
105   
106   inline unsigned int getColor() const 
107     { assert( Color != -1); return (unsigned) Color ; }
108
109   inline void setColor(unsigned int Col) 
110     { Color = (int) Col ; }
111
112   
113   inline void setCallInterference() { 
114     doesSpanAcrossCalls = 1;
115   }
116
117
118   inline bool isCallInterference() const { 
119     return (doesSpanAcrossCalls == 1); 
120   } 
121
122   inline void markForSpill() { mustSpill = true; }
123
124   inline bool isMarkedForSpill() { return  mustSpill; }
125
126   inline void setSpillOffFromFP(int StackOffset) {
127     assert( mustSpill && "This LR is not spilled");
128     SpilledStackOffsetFromFP = StackOffset;
129     HasSpillOffset = true;
130   }
131
132   inline void modifySpillOffFromFP(int StackOffset) {
133     assert( mustSpill && "This LR is not spilled");
134     SpilledStackOffsetFromFP = StackOffset;
135     HasSpillOffset = true;
136   }
137
138
139
140   inline bool hasSpillOffset() const {
141     return  HasSpillOffset;
142   }
143
144
145   inline int getSpillOffFromFP() const {
146     assert( HasSpillOffset && "This LR is not spilled");
147     return SpilledStackOffsetFromFP;
148   }
149
150
151   inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
152
153   
154   inline void setUserIGNode( IGNode *const IGN) 
155     { assert( !UserIGNode); UserIGNode = IGN; }
156
157   inline IGNode * getUserIGNode() const 
158     { return UserIGNode; }    // NULL if the user is not allocated
159
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();
164   }
165   
166   inline Type::PrimitiveID getTypeID() const {
167     return getType()->getPrimitiveID();
168   }
169
170   inline void setSuggestedColor(int Col) {
171     //assert( (SuggestedColor == -1) && "Changing an already suggested color");
172
173     if(SuggestedColor == -1 )
174       SuggestedColor = Col;
175 #if 0
176     else if (DEBUG_RA) 
177       std::cerr << "Already has a suggested color " << Col << "\n";
178 #endif
179   }
180
181   inline unsigned getSuggestedColor() const {
182     assert( SuggestedColor != -1);      // only a valid color is obtained
183     return (unsigned) SuggestedColor;
184   }
185
186   inline bool hasSuggestedColor() const {
187     return ( SuggestedColor > -1);
188   }
189
190   inline bool isSuggestedColorUsable() const {
191     assert( hasSuggestedColor() && "No suggested color");
192     return CanUseSuggestedCol;
193   }
194
195   inline void setSuggestedColorUsable(const bool val) {
196     assert( hasSuggestedColor() && "No suggested color");
197     CanUseSuggestedCol = val;
198   }
199
200   inline void addSpillCost(unsigned cost) {
201     SpillCost += cost;
202   }
203
204   inline unsigned getSpillCost() const {
205     return SpillCost;
206   }
207 };
208
209 #endif