Ruchira Sasanka | c7136d2 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 1 | /* Title: LiveRange.h |
| 2 | Author: Ruchira Sasanka |
| 3 | Date: July 25, 01 |
| 4 | Purpose: To keep info about a live range. |
| 5 | Asuumptions: |
| 6 | |
| 7 | Since the Value pointed by a use is the same as of its def, it is sufficient |
| 8 | to keep only defs in a LiveRange. |
| 9 | */ |
| 10 | |
| 11 | #ifndef LIVE_RANGE_H |
| 12 | #define LIVE_RANGE_H |
| 13 | |
| 14 | #include "llvm/Analysis/LiveVar/ValueSet.h" |
| 15 | #include "llvm/Type.h" |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | class RegClass; |
| 21 | class IGNode; |
| 22 | |
| 23 | |
| 24 | class LiveRange : public ValueSet |
| 25 | { |
| 26 | private: |
| 27 | |
| 28 | RegClass *MyRegClass; // register classs (e.g., int, FP) for this LR |
| 29 | |
| 30 | // a list of call instructions that interferes with this live range |
Ruchira Sasanka | 36f7707 | 2001-10-19 17:21:59 +0000 | [diff] [blame] | 31 | //vector<const Instruction *> CallInterferenceList; |
| 32 | |
| 33 | // does this live range span across calls? |
| 34 | // This information is used by graph |
| 35 | // coloring algo to avoid allocating volatile colors to live ranges |
| 36 | // that span across calls (since they have to be saved/restored) |
| 37 | |
| 38 | bool doesSpanAcrossCalls; |
Ruchira Sasanka | c7136d2 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 39 | |
| 40 | IGNode *UserIGNode; // IGNode which uses this LR |
| 41 | int Color; // color assigned to this live range |
| 42 | bool mustSpill; // whether this LR must be spilt |
| 43 | |
Ruchira Sasanka | 36f7707 | 2001-10-19 17:21:59 +0000 | [diff] [blame] | 44 | // whether this LR must be saved accross calls ***TODO REMOVE this |
Ruchira Sasanka | c7136d2 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 45 | bool mustSaveAcrossCalls; |
| 46 | |
| 47 | // bool mustLoadFromStack; // must load from stack at start of method |
| 48 | |
Ruchira Sasanka | ab304c4 | 2001-09-30 23:19:57 +0000 | [diff] [blame] | 49 | |
| 50 | int SuggestedColor; // The suggested color for this LR |
| 51 | |
Ruchira Sasanka | 44d2b94 | 2001-10-19 21:42:06 +0000 | [diff] [blame^] | 52 | // if this LR has a suggested color, can it be really alloated? |
| 53 | // A suggested color cannot be allocated when the suggested color is |
| 54 | // volatile and when there are call interferences. |
| 55 | |
| 56 | bool CanUseSuggestedCol; |
| 57 | |
Ruchira Sasanka | c7136d2 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 58 | public: |
| 59 | |
| 60 | |
| 61 | ~LiveRange() {} // empty destructor |
| 62 | |
| 63 | void setRegClass(RegClass *const RC) |
| 64 | { MyRegClass = RC; } |
| 65 | |
| 66 | inline RegClass *const getRegClass() const |
| 67 | { assert(MyRegClass); return MyRegClass; } |
| 68 | |
| 69 | inline bool hasColor() const |
| 70 | { return Color != -1; } |
Ruchira Sasanka | 36f7707 | 2001-10-19 17:21:59 +0000 | [diff] [blame] | 71 | |
Ruchira Sasanka | c7136d2 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 72 | inline unsigned int getColor() const |
| 73 | { assert( Color != -1); return (unsigned) Color ; } |
| 74 | |
| 75 | inline void setColor(unsigned int Col) |
| 76 | { Color = (int) Col ; } |
| 77 | |
| 78 | |
Ruchira Sasanka | 44d2b94 | 2001-10-19 21:42:06 +0000 | [diff] [blame^] | 79 | inline void setCallInterference() { |
| 80 | doesSpanAcrossCalls = 1; |
Ruchira Sasanka | c7136d2 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Ruchira Sasanka | 44d2b94 | 2001-10-19 21:42:06 +0000 | [diff] [blame^] | 83 | |
| 84 | inline bool isCallInterference() const { |
| 85 | return (doesSpanAcrossCalls == 1); |
| 86 | } |
Ruchira Sasanka | c7136d2 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 87 | |
| 88 | |
| 89 | inline void markForSpill() { mustSpill = true; } |
| 90 | |
| 91 | inline void markForSaveAcrossCalls() { mustSaveAcrossCalls = true; } |
| 92 | |
| 93 | // inline void markForLoadFromStack() { mustLoadFromStack = true; |
| 94 | |
| 95 | |
| 96 | inline void setUserIGNode( IGNode *const IGN) |
| 97 | { assert( !UserIGNode); UserIGNode = IGN; } |
| 98 | |
| 99 | inline IGNode * getUserIGNode() const |
| 100 | { return UserIGNode; } // NULL if the user is not allocated |
| 101 | |
| 102 | inline Type::PrimitiveID getTypeID() const { |
| 103 | const Value *val = *begin(); |
| 104 | assert(val && "Can't find type - Live range is empty" ); |
| 105 | return (val->getType())->getPrimitiveID(); |
| 106 | } |
| 107 | |
| 108 | |
Ruchira Sasanka | ab304c4 | 2001-09-30 23:19:57 +0000 | [diff] [blame] | 109 | inline void setSuggestedColor(int Col) { |
| 110 | //assert( (SuggestedColor == -1) && "Changing an already suggested color"); |
| 111 | |
| 112 | if(SuggestedColor == -1 ) |
| 113 | SuggestedColor = Col; |
| 114 | else if (DEBUG_RA) |
Chris Lattner | 634b352 | 2001-10-15 18:30:06 +0000 | [diff] [blame] | 115 | cerr << "Already has a suggested color " << Col << endl; |
Ruchira Sasanka | ab304c4 | 2001-09-30 23:19:57 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | inline unsigned getSuggestedColor() const { |
| 119 | assert( SuggestedColor != -1); // only a valid color is obtained |
| 120 | return (unsigned) SuggestedColor; |
| 121 | } |
| 122 | |
| 123 | inline bool hasSuggestedColor() const { |
| 124 | return ( SuggestedColor > -1); |
| 125 | } |
| 126 | |
Ruchira Sasanka | 44d2b94 | 2001-10-19 21:42:06 +0000 | [diff] [blame^] | 127 | inline bool isSuggestedColorUsable() const { |
| 128 | assert( hasSuggestedColor() && "No suggested color"); |
| 129 | return CanUseSuggestedCol; |
| 130 | } |
| 131 | |
| 132 | inline void setSuggestedColorUsable(const bool val) { |
| 133 | assert( hasSuggestedColor() && "No suggested color"); |
| 134 | CanUseSuggestedCol = val; |
| 135 | } |
| 136 | |
| 137 | |
Ruchira Sasanka | 36f7707 | 2001-10-19 17:21:59 +0000 | [diff] [blame] | 138 | inline LiveRange() : ValueSet() /* , CallInterferenceList() */ |
Ruchira Sasanka | c7136d2 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 139 | { |
Ruchira Sasanka | ab304c4 | 2001-09-30 23:19:57 +0000 | [diff] [blame] | 140 | Color = SuggestedColor = -1; // not yet colored |
Ruchira Sasanka | c7136d2 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 141 | mustSpill = mustSaveAcrossCalls = false; |
| 142 | MyRegClass = NULL; |
| 143 | UserIGNode = NULL; |
Ruchira Sasanka | 36f7707 | 2001-10-19 17:21:59 +0000 | [diff] [blame] | 144 | doesSpanAcrossCalls = false; |
Ruchira Sasanka | 44d2b94 | 2001-10-19 21:42:06 +0000 | [diff] [blame^] | 145 | CanUseSuggestedCol = true; |
Ruchira Sasanka | c7136d2 | 2001-09-08 14:10:34 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | }; |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | #endif |
| 155 | |