Fix a few typoes and grammaroes in comments.
[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   /// SuggestedColor - if this LR has a suggested color, can it
44   /// really be allocated?  A suggested color cannot be allocated when the
45   /// suggested color is volatile and when there are call
46   /// interferences.
47   ///
48   int SuggestedColor;        // The suggested color for this LR
49
50   /// CanUseSuggestedCol - It is possible that a suggested color for
51   /// this live range is not available before graph coloring (e.g., it
52   /// can be allocated to another live range which interferes with
53   /// this)
54   /// 
55   bool CanUseSuggestedCol;
56
57   /// SpilledStackOffsetFromFP - If this LR is spilled, its stack
58   /// offset from *FP*. The spilled offsets must always be relative to
59   /// the FP.
60   ///
61   int SpilledStackOffsetFromFP;
62
63   /// HasSpillOffset - True iff this live range has a spill offset.
64   ///
65   bool HasSpillOffset;
66
67   /// SpillCost - The spill cost of this live range. Calculated using loop depth
68   /// of each reference to each Value in the live range.
69   ///
70   unsigned SpillCost;
71
72 public:
73   LiveRange() {
74     Color = SuggestedColor = -1;        // not yet colored 
75     mustSpill = false;
76     MyRegClass = 0;
77     UserIGNode = 0;
78     doesSpanAcrossCalls = false;
79     CanUseSuggestedCol = true;
80     HasSpillOffset = false;
81     SpillCost = 0;
82   }
83
84   void setRegClass(RegClass *RC) { MyRegClass = RC; }
85
86   RegClass *getRegClass() const { assert(MyRegClass); return MyRegClass; }
87   unsigned getRegClassID() const;
88
89   bool hasColor() const { return Color != -1; }
90   
91   unsigned getColor() const { assert(Color != -1); return (unsigned)Color; }
92
93   void setColor(unsigned Col) { Color = (int)Col; }
94
95   inline void setCallInterference() { 
96     doesSpanAcrossCalls = 1;
97   }
98   inline void clearCallInterference() { 
99     doesSpanAcrossCalls = 0;
100   }
101
102   inline bool isCallInterference() const { 
103     return doesSpanAcrossCalls == 1; 
104   } 
105
106   inline void markForSpill() { mustSpill = true; }
107
108   inline bool isMarkedForSpill() const { return mustSpill; }
109
110   inline void setSpillOffFromFP(int StackOffset) {
111     assert(mustSpill && "This LR is not spilled");
112     SpilledStackOffsetFromFP = StackOffset;
113     HasSpillOffset = true;
114   }
115
116   inline void modifySpillOffFromFP(int StackOffset) {
117     assert(mustSpill && "This LR is not spilled");
118     SpilledStackOffsetFromFP = StackOffset;
119     HasSpillOffset = true;
120   }
121
122   inline bool hasSpillOffset() const {
123     return HasSpillOffset;
124   }
125
126   inline int getSpillOffFromFP() const {
127     assert(HasSpillOffset && "This LR is not spilled");
128     return SpilledStackOffsetFromFP;
129   }
130
131   inline void setUserIGNode(IGNode *IGN) {
132     assert(!UserIGNode); UserIGNode = IGN;
133   }
134
135   // getUserIGNode - NULL if the user is not allocated
136   inline IGNode *getUserIGNode() const { return UserIGNode; }
137
138   inline const Type *getType() const {
139     return (*begin())->getType();  // set's don't have a front
140   }
141   
142   inline void setSuggestedColor(int Col) {
143     if (SuggestedColor == -1)
144       SuggestedColor = Col;
145   }
146
147   inline unsigned getSuggestedColor() const {
148     assert(SuggestedColor != -1);      // only a valid color is obtained
149     return (unsigned)SuggestedColor;
150   }
151
152   inline bool hasSuggestedColor() const {
153     return SuggestedColor != -1;
154   }
155
156   inline bool isSuggestedColorUsable() const {
157     assert(hasSuggestedColor() && "No suggested color");
158     return CanUseSuggestedCol;
159   }
160
161   inline void setSuggestedColorUsable(bool val) {
162     assert(hasSuggestedColor() && "No suggested color");
163     CanUseSuggestedCol = val;
164   }
165
166   inline void addSpillCost(unsigned cost) {
167     SpillCost += cost;
168   }
169
170   inline unsigned getSpillCost() const {
171     return SpillCost;
172   }
173 };
174
175 } // End llvm namespace
176
177 #endif