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