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 SetVector of Value *s. We keep only
11 // defs in a LiveRange.
13 //===----------------------------------------------------------------------===//
18 #include "llvm/Value.h"
19 #include "Support/SetVector.h"
29 typedef SetVector<const Value *> ValueContainerType;
30 typedef ValueContainerType::iterator iterator;
31 typedef ValueContainerType::const_iterator const_iterator;
34 ValueContainerType MyValues; // Values in this LiveRange
35 RegClass *MyRegClass; // register class (e.g., int, FP) for this LR
37 /// doesSpanAcrossCalls - Does this live range span across calls?
38 /// This information is used by graph coloring algo to avoid allocating
39 /// volatile colors to live ranges that span across calls (since they have to
40 /// be saved/restored)
42 bool doesSpanAcrossCalls;
44 IGNode *UserIGNode; // IGNode which uses this LR
45 int Color; // color assigned to this live range
46 bool mustSpill; // whether this LR must be spilt
48 /// SuggestedColor - if this LR has a suggested color, can it
49 /// really be allocated? 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 - True iff this live range has a spill offset.
72 /// SpillCost - The spill cost of this live range. Calculated using loop depth
73 /// of each reference to each Value in the live range.
78 iterator begin() { return MyValues.begin(); }
79 const_iterator begin() const { return MyValues.begin(); }
80 iterator end() { return MyValues.end(); }
81 const_iterator end() const { return MyValues.end(); }
82 bool insert(const Value *&X) { return MyValues.insert (X); }
83 void insert(iterator b, iterator e) { MyValues.insert (b, e); }
86 Color = SuggestedColor = -1; // not yet colored
90 doesSpanAcrossCalls = false;
91 CanUseSuggestedCol = true;
92 HasSpillOffset = false;
96 void setRegClass(RegClass *RC) { MyRegClass = RC; }
98 RegClass *getRegClass() const { assert(MyRegClass); return MyRegClass; }
99 unsigned getRegClassID() const;
101 bool hasColor() const { return Color != -1; }
103 unsigned getColor() const { assert(Color != -1); return (unsigned)Color; }
105 void setColor(unsigned Col) { Color = (int)Col; }
107 inline void setCallInterference() {
108 doesSpanAcrossCalls = 1;
110 inline void clearCallInterference() {
111 doesSpanAcrossCalls = 0;
114 inline bool isCallInterference() const {
115 return doesSpanAcrossCalls == 1;
118 inline void markForSpill() { mustSpill = true; }
120 inline bool isMarkedForSpill() const { return mustSpill; }
122 inline void setSpillOffFromFP(int StackOffset) {
123 assert(mustSpill && "This LR is not spilled");
124 SpilledStackOffsetFromFP = StackOffset;
125 HasSpillOffset = true;
128 inline void modifySpillOffFromFP(int StackOffset) {
129 assert(mustSpill && "This LR is not spilled");
130 SpilledStackOffsetFromFP = StackOffset;
131 HasSpillOffset = true;
134 inline bool hasSpillOffset() const {
135 return HasSpillOffset;
138 inline int getSpillOffFromFP() const {
139 assert(HasSpillOffset && "This LR is not spilled");
140 return SpilledStackOffsetFromFP;
143 inline void setUserIGNode(IGNode *IGN) {
144 assert(!UserIGNode); UserIGNode = IGN;
147 // getUserIGNode - NULL if the user is not allocated
148 inline IGNode *getUserIGNode() const { return UserIGNode; }
150 inline const Type *getType() const {
151 return (*begin())->getType(); // set's don't have a front
154 inline void setSuggestedColor(int Col) {
155 if (SuggestedColor == -1)
156 SuggestedColor = Col;
159 inline unsigned getSuggestedColor() const {
160 assert(SuggestedColor != -1); // only a valid color is obtained
161 return (unsigned)SuggestedColor;
164 inline bool hasSuggestedColor() const {
165 return SuggestedColor != -1;
168 inline bool isSuggestedColorUsable() const {
169 assert(hasSuggestedColor() && "No suggested color");
170 return CanUseSuggestedCol;
173 inline void setSuggestedColorUsable(bool val) {
174 assert(hasSuggestedColor() && "No suggested color");
175 CanUseSuggestedCol = val;
178 inline void addSpillCost(unsigned cost) {
182 inline unsigned getSpillCost() const {
187 static inline std::ostream &operator << (std::ostream &os, const LiveRange &lr) {
188 os << "LiveRange@" << (void *)(&lr);
192 } // End llvm namespace