Included assert.h so that the code compiles under newer versions of GCC.
[oota-llvm.git] / lib / CodeGen / RegAlloc / LiveRange.h
1 //===-- LiveRange.h - Store info about a live range --------------*- C++ -*--=//
2 //
3 // Implements a live range using a ValueSet. A LiveRange is a simple set
4 // of Values. 
5 //
6 // Since the Value pointed by a use is the same as of its def, it is sufficient
7 // to keep only defs in a LiveRange.
8 //
9 //===----------------------------------------------------------------------===//
10
11 #ifndef LIVE_RANGE_H
12 #define LIVE_RANGE_H
13
14 #include "llvm/CodeGen/ValueSet.h"
15 #include "llvm/Value.h"
16
17 #include <assert.h>
18
19 class RegClass;
20 class IGNode;
21 class Type;
22
23 class LiveRange : public ValueSet {
24   RegClass *MyRegClass;       // register classs (e.g., int, FP) for this LR
25
26   // doesSpanAcrossCalls - Does this live range span across calls? 
27   // This information is used by graph
28   // coloring algo to avoid allocating volatile colors to live ranges
29   // that span across calls (since they have to be saved/restored)
30   //
31   bool doesSpanAcrossCalls;
32
33   IGNode *UserIGNode;         // IGNode which uses this LR
34   int Color;                  // color assigned to this live range
35   bool mustSpill;             // whether this LR must be spilt
36
37   // mustSaveAcrossCalls - whether this LR must be saved accross calls
38   // ***TODO REMOVE this
39   //
40   bool mustSaveAcrossCalls;        
41   
42   // SuggestedColor - if this LR has a suggested color, can it be
43   // really alloated?  A suggested color cannot be allocated when the
44   // suggested color is volatile and when there are call
45   // interferences.
46   //
47   int SuggestedColor;        // The suggested color for this LR
48
49   // CanUseSuggestedCol - It is possible that a suggested color for
50   // this live range is not available before graph coloring (e.g., it
51   // can be allocated to another live range which interferes with
52   // this)
53   // 
54   bool CanUseSuggestedCol;
55
56   // SpilledStackOffsetFromFP - If this LR is spilled, its stack
57   // offset from *FP*. The spilled offsets must always be relative to
58   // the FP.
59   //
60   int SpilledStackOffsetFromFP;
61
62   // HasSpillOffset 0 Whether this live range has a spill offset
63   //
64   bool HasSpillOffset;
65
66   // The spill cost of this live range. Calculated using loop depth of
67   // each reference to each Value in the live range
68   //
69   unsigned SpillCost;
70
71 public:
72   LiveRange() {
73     Color = SuggestedColor = -1;        // not yet colored 
74     mustSpill = mustSaveAcrossCalls = false;
75     MyRegClass = 0;
76     UserIGNode = 0;
77     doesSpanAcrossCalls = false;
78     CanUseSuggestedCol = true;
79     HasSpillOffset = false;
80     SpillCost = 0;
81   }
82
83   void setRegClass(RegClass *RC) { MyRegClass = RC; }
84
85   RegClass *getRegClass() const { assert(MyRegClass); return MyRegClass; }
86   unsigned getRegClassID() const;
87
88   bool hasColor() const { return Color != -1; }
89   
90   unsigned getColor() const { assert(Color != -1); return (unsigned)Color; }
91
92   void setColor(unsigned Col) { Color = (int)Col; }
93
94   inline void setCallInterference() { 
95     doesSpanAcrossCalls = 1;
96   }
97   inline void clearCallInterference() { 
98     doesSpanAcrossCalls = 0;
99   }
100
101   inline bool isCallInterference() const { 
102     return doesSpanAcrossCalls == 1; 
103   } 
104
105   inline void markForSpill() { mustSpill = true; }
106
107   inline bool isMarkedForSpill() { return mustSpill; }
108
109   inline void setSpillOffFromFP(int StackOffset) {
110     assert(mustSpill && "This LR is not spilled");
111     SpilledStackOffsetFromFP = StackOffset;
112     HasSpillOffset = true;
113   }
114
115   inline void modifySpillOffFromFP(int StackOffset) {
116     assert(mustSpill && "This LR is not spilled");
117     SpilledStackOffsetFromFP = StackOffset;
118     HasSpillOffset = true;
119   }
120
121   inline bool hasSpillOffset() const {
122     return HasSpillOffset;
123   }
124
125   inline int getSpillOffFromFP() const {
126     assert(HasSpillOffset && "This LR is not spilled");
127     return SpilledStackOffsetFromFP;
128   }
129
130   inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
131   
132   inline void setUserIGNode(IGNode *IGN) {
133     assert(!UserIGNode); UserIGNode = IGN;
134   }
135
136   // getUserIGNode - NULL if the user is not allocated
137   inline IGNode *getUserIGNode() const { return UserIGNode; }
138
139   inline const Type *getType() const {
140     return (*begin())->getType();  // set's don't have a front
141   }
142   
143   inline void setSuggestedColor(int Col) {
144     if (SuggestedColor == -1)
145       SuggestedColor = Col;
146   }
147
148   inline unsigned getSuggestedColor() const {
149     assert(SuggestedColor != -1);      // only a valid color is obtained
150     return (unsigned)SuggestedColor;
151   }
152
153   inline bool hasSuggestedColor() const {
154     return SuggestedColor != -1;
155   }
156
157   inline bool isSuggestedColorUsable() const {
158     assert(hasSuggestedColor() && "No suggested color");
159     return CanUseSuggestedCol;
160   }
161
162   inline void setSuggestedColorUsable(bool val) {
163     assert(hasSuggestedColor() && "No suggested color");
164     CanUseSuggestedCol = val;
165   }
166
167   inline void addSpillCost(unsigned cost) {
168     SpillCost += cost;
169   }
170
171   inline unsigned getSpillCost() const {
172     return SpillCost;
173   }
174 };
175
176 #endif