1 //===-- LiveRange.h - Store info about a live range -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // Implements a live range using a ValueSet. A LiveRange is a simple set
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.
16 //===----------------------------------------------------------------------===//
21 #include "llvm/Value.h"
22 #include "llvm/CodeGen/ValueSet.h"
29 class LiveRange : public ValueSet {
30 RegClass *MyRegClass; // register class (e.g., int, FP) for this LR
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)
37 bool doesSpanAcrossCalls;
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
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
48 int SuggestedColor; // The suggested color for this LR
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
55 bool CanUseSuggestedCol;
57 /// SpilledStackOffsetFromFP - If this LR is spilled, its stack
58 /// offset from *FP*. The spilled offsets must always be relative to
61 int SpilledStackOffsetFromFP;
63 /// HasSpillOffset - True iff this live range has a spill offset.
67 /// SpillCost - The spill cost of this live range. Calculated using loop depth
68 /// of each reference to each Value in the live range.
74 Color = SuggestedColor = -1; // not yet colored
78 doesSpanAcrossCalls = false;
79 CanUseSuggestedCol = true;
80 HasSpillOffset = false;
84 void setRegClass(RegClass *RC) { MyRegClass = RC; }
86 RegClass *getRegClass() const { assert(MyRegClass); return MyRegClass; }
87 unsigned getRegClassID() const;
89 bool hasColor() const { return Color != -1; }
91 unsigned getColor() const { assert(Color != -1); return (unsigned)Color; }
93 void setColor(unsigned Col) { Color = (int)Col; }
95 inline void setCallInterference() {
96 doesSpanAcrossCalls = 1;
98 inline void clearCallInterference() {
99 doesSpanAcrossCalls = 0;
102 inline bool isCallInterference() const {
103 return doesSpanAcrossCalls == 1;
106 inline void markForSpill() { mustSpill = true; }
108 inline bool isMarkedForSpill() const { return mustSpill; }
110 inline void setSpillOffFromFP(int StackOffset) {
111 assert(mustSpill && "This LR is not spilled");
112 SpilledStackOffsetFromFP = StackOffset;
113 HasSpillOffset = true;
116 inline void modifySpillOffFromFP(int StackOffset) {
117 assert(mustSpill && "This LR is not spilled");
118 SpilledStackOffsetFromFP = StackOffset;
119 HasSpillOffset = true;
122 inline bool hasSpillOffset() const {
123 return HasSpillOffset;
126 inline int getSpillOffFromFP() const {
127 assert(HasSpillOffset && "This LR is not spilled");
128 return SpilledStackOffsetFromFP;
131 inline void setUserIGNode(IGNode *IGN) {
132 assert(!UserIGNode); UserIGNode = IGN;
135 // getUserIGNode - NULL if the user is not allocated
136 inline IGNode *getUserIGNode() const { return UserIGNode; }
138 inline const Type *getType() const {
139 return (*begin())->getType(); // set's don't have a front
142 inline void setSuggestedColor(int Col) {
143 if (SuggestedColor == -1)
144 SuggestedColor = Col;
147 inline unsigned getSuggestedColor() const {
148 assert(SuggestedColor != -1); // only a valid color is obtained
149 return (unsigned)SuggestedColor;
152 inline bool hasSuggestedColor() const {
153 return SuggestedColor != -1;
156 inline bool isSuggestedColorUsable() const {
157 assert(hasSuggestedColor() && "No suggested color");
158 return CanUseSuggestedCol;
161 inline void setSuggestedColorUsable(bool val) {
162 assert(hasSuggestedColor() && "No suggested color");
163 CanUseSuggestedCol = val;
166 inline void addSpillCost(unsigned cost) {
170 inline unsigned getSpillCost() const {
175 } // End llvm namespace