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/CodeGen/ValueSet.h"
22 #include "llvm/Value.h"
27 class LiveRange : public ValueSet {
28 RegClass *MyRegClass; // register classs (e.g., int, FP) for this LR
30 // doesSpanAcrossCalls - Does this live range span across calls?
31 // This information is used by graph
32 // coloring algo to avoid allocating volatile colors to live ranges
33 // that span across calls (since they have to be saved/restored)
35 bool doesSpanAcrossCalls;
37 IGNode *UserIGNode; // IGNode which uses this LR
38 int Color; // color assigned to this live range
39 bool mustSpill; // whether this LR must be spilt
41 // mustSaveAcrossCalls - whether this LR must be saved accross calls
42 // ***TODO REMOVE this
44 bool mustSaveAcrossCalls;
46 // SuggestedColor - if this LR has a suggested color, can it be
47 // really alloated? A suggested color cannot be allocated when the
48 // suggested color is volatile and when there are call
51 int SuggestedColor; // The suggested color for this LR
53 // CanUseSuggestedCol - It is possible that a suggested color for
54 // this live range is not available before graph coloring (e.g., it
55 // can be allocated to another live range which interferes with
58 bool CanUseSuggestedCol;
60 // SpilledStackOffsetFromFP - If this LR is spilled, its stack
61 // offset from *FP*. The spilled offsets must always be relative to
64 int SpilledStackOffsetFromFP;
66 // HasSpillOffset 0 Whether this live range has a spill offset
70 // The spill cost of this live range. Calculated using loop depth of
71 // each reference to each Value in the live range
77 Color = SuggestedColor = -1; // not yet colored
78 mustSpill = mustSaveAcrossCalls = false;
81 doesSpanAcrossCalls = false;
82 CanUseSuggestedCol = true;
83 HasSpillOffset = false;
87 void setRegClass(RegClass *RC) { MyRegClass = RC; }
89 RegClass *getRegClass() const { assert(MyRegClass); return MyRegClass; }
90 unsigned getRegClassID() const;
92 bool hasColor() const { return Color != -1; }
94 unsigned getColor() const { assert(Color != -1); return (unsigned)Color; }
96 void setColor(unsigned Col) { Color = (int)Col; }
98 inline void setCallInterference() {
99 doesSpanAcrossCalls = 1;
101 inline void clearCallInterference() {
102 doesSpanAcrossCalls = 0;
105 inline bool isCallInterference() const {
106 return doesSpanAcrossCalls == 1;
109 inline void markForSpill() { mustSpill = true; }
111 inline bool isMarkedForSpill() const { return mustSpill; }
113 inline void setSpillOffFromFP(int StackOffset) {
114 assert(mustSpill && "This LR is not spilled");
115 SpilledStackOffsetFromFP = StackOffset;
116 HasSpillOffset = true;
119 inline void modifySpillOffFromFP(int StackOffset) {
120 assert(mustSpill && "This LR is not spilled");
121 SpilledStackOffsetFromFP = StackOffset;
122 HasSpillOffset = true;
125 inline bool hasSpillOffset() const {
126 return HasSpillOffset;
129 inline int getSpillOffFromFP() const {
130 assert(HasSpillOffset && "This LR is not spilled");
131 return SpilledStackOffsetFromFP;
134 inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; }
136 inline void setUserIGNode(IGNode *IGN) {
137 assert(!UserIGNode); UserIGNode = IGN;
140 // getUserIGNode - NULL if the user is not allocated
141 inline IGNode *getUserIGNode() const { return UserIGNode; }
143 inline const Type *getType() const {
144 return (*begin())->getType(); // set's don't have a front
147 inline void setSuggestedColor(int Col) {
148 if (SuggestedColor == -1)
149 SuggestedColor = Col;
152 inline unsigned getSuggestedColor() const {
153 assert(SuggestedColor != -1); // only a valid color is obtained
154 return (unsigned)SuggestedColor;
157 inline bool hasSuggestedColor() const {
158 return SuggestedColor != -1;
161 inline bool isSuggestedColorUsable() const {
162 assert(hasSuggestedColor() && "No suggested color");
163 return CanUseSuggestedCol;
166 inline void setSuggestedColorUsable(bool val) {
167 assert(hasSuggestedColor() && "No suggested color");
168 CanUseSuggestedCol = val;
171 inline void addSpillCost(unsigned cost) {
175 inline unsigned getSpillCost() const {