LLVM API Documentation
00001 //===-- LiveRange.h - Store info about a live range -------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Implements a live range using a SetVector of Value *s. We keep only 00011 // defs in a LiveRange. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LIVERANGE_H 00016 #define LIVERANGE_H 00017 00018 #include "llvm/Value.h" 00019 #include "llvm/ADT/SetVector.h" 00020 #include <iostream> 00021 00022 namespace llvm { 00023 00024 class RegClass; 00025 class IGNode; 00026 00027 class LiveRange { 00028 public: 00029 typedef SetVector<const Value *> ValueContainerType; 00030 typedef ValueContainerType::iterator iterator; 00031 typedef ValueContainerType::const_iterator const_iterator; 00032 00033 private: 00034 ValueContainerType MyValues; // Values in this LiveRange 00035 RegClass *MyRegClass; // register class (e.g., int, FP) for this LR 00036 00037 /// doesSpanAcrossCalls - Does this live range span across calls? 00038 /// This information is used by graph coloring algo to avoid allocating 00039 /// volatile colors to live ranges that span across calls (since they have to 00040 /// be saved/restored) 00041 /// 00042 bool doesSpanAcrossCalls; 00043 00044 IGNode *UserIGNode; // IGNode which uses this LR 00045 int Color; // color assigned to this live range 00046 bool mustSpill; // whether this LR must be spilt 00047 00048 /// SuggestedColor - if this LR has a suggested color, can it 00049 /// really be allocated? A suggested color cannot be allocated when the 00050 /// suggested color is volatile and when there are call 00051 /// interferences. 00052 /// 00053 int SuggestedColor; // The suggested color for this LR 00054 00055 /// CanUseSuggestedCol - It is possible that a suggested color for 00056 /// this live range is not available before graph coloring (e.g., it 00057 /// can be allocated to another live range which interferes with 00058 /// this) 00059 /// 00060 bool CanUseSuggestedCol; 00061 00062 /// SpilledStackOffsetFromFP - If this LR is spilled, its stack 00063 /// offset from *FP*. The spilled offsets must always be relative to 00064 /// the FP. 00065 /// 00066 int SpilledStackOffsetFromFP; 00067 00068 /// HasSpillOffset - True iff this live range has a spill offset. 00069 /// 00070 bool HasSpillOffset; 00071 00072 /// SpillCost - The spill cost of this live range. Calculated using loop depth 00073 /// of each reference to each Value in the live range. 00074 /// 00075 unsigned SpillCost; 00076 00077 public: 00078 iterator begin() { return MyValues.begin(); } 00079 const_iterator begin() const { return MyValues.begin(); } 00080 iterator end() { return MyValues.end(); } 00081 const_iterator end() const { return MyValues.end(); } 00082 bool insert(const Value *&X) { return MyValues.insert (X); } 00083 void insert(iterator b, iterator e) { MyValues.insert (b, e); } 00084 00085 LiveRange() { 00086 Color = SuggestedColor = -1; // not yet colored 00087 mustSpill = false; 00088 MyRegClass = 0; 00089 UserIGNode = 0; 00090 doesSpanAcrossCalls = false; 00091 CanUseSuggestedCol = true; 00092 HasSpillOffset = false; 00093 SpillCost = 0; 00094 } 00095 00096 void setRegClass(RegClass *RC) { MyRegClass = RC; } 00097 00098 RegClass *getRegClass() const { assert(MyRegClass); return MyRegClass; } 00099 unsigned getRegClassID() const; 00100 00101 bool hasColor() const { return Color != -1; } 00102 00103 unsigned getColor() const { assert(Color != -1); return (unsigned)Color; } 00104 00105 void setColor(unsigned Col) { Color = (int)Col; } 00106 00107 inline void setCallInterference() { 00108 doesSpanAcrossCalls = 1; 00109 } 00110 inline void clearCallInterference() { 00111 doesSpanAcrossCalls = 0; 00112 } 00113 00114 inline bool isCallInterference() const { 00115 return doesSpanAcrossCalls == 1; 00116 } 00117 00118 inline void markForSpill() { mustSpill = true; } 00119 00120 inline bool isMarkedForSpill() const { return mustSpill; } 00121 00122 inline void setSpillOffFromFP(int StackOffset) { 00123 assert(mustSpill && "This LR is not spilled"); 00124 SpilledStackOffsetFromFP = StackOffset; 00125 HasSpillOffset = true; 00126 } 00127 00128 inline void modifySpillOffFromFP(int StackOffset) { 00129 assert(mustSpill && "This LR is not spilled"); 00130 SpilledStackOffsetFromFP = StackOffset; 00131 HasSpillOffset = true; 00132 } 00133 00134 inline bool hasSpillOffset() const { 00135 return HasSpillOffset; 00136 } 00137 00138 inline int getSpillOffFromFP() const { 00139 assert(HasSpillOffset && "This LR is not spilled"); 00140 return SpilledStackOffsetFromFP; 00141 } 00142 00143 inline void setUserIGNode(IGNode *IGN) { 00144 assert(!UserIGNode); UserIGNode = IGN; 00145 } 00146 00147 // getUserIGNode - NULL if the user is not allocated 00148 inline IGNode *getUserIGNode() const { return UserIGNode; } 00149 00150 inline const Type *getType() const { 00151 return (*begin())->getType(); // set's don't have a front 00152 } 00153 00154 inline void setSuggestedColor(int Col) { 00155 if (SuggestedColor == -1) 00156 SuggestedColor = Col; 00157 } 00158 00159 inline unsigned getSuggestedColor() const { 00160 assert(SuggestedColor != -1); // only a valid color is obtained 00161 return (unsigned)SuggestedColor; 00162 } 00163 00164 inline bool hasSuggestedColor() const { 00165 return SuggestedColor != -1; 00166 } 00167 00168 inline bool isSuggestedColorUsable() const { 00169 assert(hasSuggestedColor() && "No suggested color"); 00170 return CanUseSuggestedCol; 00171 } 00172 00173 inline void setSuggestedColorUsable(bool val) { 00174 assert(hasSuggestedColor() && "No suggested color"); 00175 CanUseSuggestedCol = val; 00176 } 00177 00178 inline void addSpillCost(unsigned cost) { 00179 SpillCost += cost; 00180 } 00181 00182 inline unsigned getSpillCost() const { 00183 return SpillCost; 00184 } 00185 }; 00186 00187 static inline std::ostream &operator << (std::ostream &os, const LiveRange &lr) { 00188 os << "LiveRange@" << (void *)(&lr); 00189 return os; 00190 }; 00191 00192 } // End llvm namespace 00193 00194 #endif