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