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