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 /// mustSaveAcrossCalls - whether this LR must be saved accross calls
44 /// ***TODO REMOVE this
46 bool mustSaveAcrossCalls;
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
53 int SuggestedColor; // The suggested color for this LR
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
60 bool CanUseSuggestedCol;
62 /// SpilledStackOffsetFromFP - If this LR is spilled, its stack
63 /// offset from *FP*. The spilled offsets must always be relative to
66 int SpilledStackOffsetFromFP;
68 /// HasSpillOffset 0 Whether this live range has a spill offset
72 /// The spill cost of this live range. Calculated using loop depth of
73 /// each reference to each Value in the live range
79 Color = SuggestedColor = -1; // not yet colored
80 mustSpill = mustSaveAcrossCalls = false;
83 doesSpanAcrossCalls = false;
84 CanUseSuggestedCol = true;
85 HasSpillOffset = false;
89 void setRegClass(RegClass *RC) { MyRegClass = RC; }
91 RegClass *getRegClass() const { assert(MyRegClass); return MyRegClass; }
92 unsigned getRegClassID() const;
94 bool hasColor() const { return Color != -1; }
96 unsigned getColor() const { assert(Color != -1); return (unsigned)Color; }
98 void setColor(unsigned Col) { Color = (int)Col; }
100 inline void setCallInterference() {
101 doesSpanAcrossCalls = 1;
103 inline void clearCallInterference() {
104 doesSpanAcrossCalls = 0;
107 inline bool isCallInterference() const {
108 return doesSpanAcrossCalls == 1;
111 inline void markForSpill() { mustSpill = true; }
113 inline bool isMarkedForSpill() const { return mustSpill; }
115 inline void setSpillOffFromFP(int StackOffset) {
116 assert(mustSpill && "This LR is not spilled");
117 SpilledStackOffsetFromFP = StackOffset;
118 HasSpillOffset = true;
121 inline void modifySpillOffFromFP(int StackOffset) {
122 assert(mustSpill && "This LR is not spilled");
123 SpilledStackOffsetFromFP = StackOffset;
124 HasSpillOffset = true;
127 inline bool hasSpillOffset() const {
128 return HasSpillOffset;
131 inline int getSpillOffFromFP() const {
132 assert(HasSpillOffset && "This LR is not spilled");
133 return SpilledStackOffsetFromFP;
136 inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
138 inline void setUserIGNode(IGNode *IGN) {
139 assert(!UserIGNode); UserIGNode = IGN;
142 // getUserIGNode - NULL if the user is not allocated
143 inline IGNode *getUserIGNode() const { return UserIGNode; }
145 inline const Type *getType() const {
146 return (*begin())->getType(); // set's don't have a front
149 inline void setSuggestedColor(int Col) {
150 if (SuggestedColor == -1)
151 SuggestedColor = Col;
154 inline unsigned getSuggestedColor() const {
155 assert(SuggestedColor != -1); // only a valid color is obtained
156 return (unsigned)SuggestedColor;
159 inline bool hasSuggestedColor() const {
160 return SuggestedColor != -1;
163 inline bool isSuggestedColorUsable() const {
164 assert(hasSuggestedColor() && "No suggested color");
165 return CanUseSuggestedCol;
168 inline void setSuggestedColorUsable(bool val) {
169 assert(hasSuggestedColor() && "No suggested color");
170 CanUseSuggestedCol = val;
173 inline void addSpillCost(unsigned cost) {
177 inline unsigned getSpillCost() const {
182 } // End llvm namespace