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