Chris Lattner | 1b40a1b | 2001-09-07 21:04:20 +0000 | [diff] [blame] | 1 | /* Title: IGNode.h -*- C++ -*- |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 2 | Author: Ruchira Sasanka |
| 3 | Date: July 25, 01 |
| 4 | Purpose: Represents a node in an interference graph. |
| 5 | Notes: |
| 6 | |
| 7 | For efficiency, the AdjList is updated only once - ie. we can add but not |
| 8 | remove nodes from AdjList. |
| 9 | |
| 10 | The removal of nodes from IG is simulated by decrementing the CurDegree. |
| 11 | If this node is put on stack (that is removed from IG), the CurDegree of all |
| 12 | the neighbors are decremented and this node is marked OnSack. Hence |
| 13 | the effective neighbors in the AdjList are the ones that do not have the |
| 14 | OnStack flag set (therefore, they are in the IG). |
| 15 | |
| 16 | The methods that modify/use the CurDegree Must be called only |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 17 | after all modifications to the IG are over (i.e., all neighbors are fixed). |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 18 | |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 19 | The vector representation is the most efficient one for adj list. |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 20 | Though nodes are removed when coalsing is done, we access it in sequence |
| 21 | for far many times when coloring (colorNode()). |
| 22 | |
| 23 | */ |
| 24 | |
| 25 | #ifndef IG_NODE_H |
| 26 | #define IG_NODE_H |
| 27 | |
| 28 | |
| 29 | #include "llvm/CodeGen/RegAllocCommon.h" |
| 30 | #include "llvm/CodeGen/LiveRange.h" |
Chris Lattner | 2182c78 | 2002-02-04 05:52:08 +0000 | [diff] [blame^] | 31 | class LiveRange; |
| 32 | class RegClass; |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 33 | |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 34 | //---------------------------------------------------------------------------- |
| 35 | // Class IGNode |
| 36 | // |
| 37 | // Represents a node in an interference graph. |
| 38 | //---------------------------------------------------------------------------- |
| 39 | |
Chris Lattner | 2182c78 | 2002-02-04 05:52:08 +0000 | [diff] [blame^] | 40 | class IGNode { |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 41 | const int Index; // index within IGNodeList |
| 42 | |
| 43 | bool OnStack; // this has been pushed on to stack for coloring |
| 44 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 45 | std::vector<IGNode *> AdjList; // adjacency list for this live range |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 46 | |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 47 | int CurDegree; |
| 48 | // |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 49 | // set by InterferenceGraph::setCurDegreeOfIGNodes() after calculating |
| 50 | // all adjacency lists. |
| 51 | // Decremented when a neighbor is pushed on to the stack. |
| 52 | // After that, never incremented/set again nor used. |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 53 | |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 54 | LiveRange *const ParentLR; // parent LR (cannot be a const) |
Chris Lattner | 2182c78 | 2002-02-04 05:52:08 +0000 | [diff] [blame^] | 55 | public: |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 56 | |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 57 | // constructor |
| 58 | // |
| 59 | IGNode(LiveRange *const LR, unsigned int index); |
| 60 | |
| 61 | // an empty destructor |
| 62 | // |
| 63 | ~IGNode() { } |
| 64 | |
| 65 | |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 66 | inline unsigned int getIndex() const |
| 67 | { return Index; } |
| 68 | |
| 69 | // adjLists must be updated only once. However, the CurDegree can be changed |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 70 | // |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 71 | inline void addAdjIGNode( IGNode *const AdjNode) |
| 72 | { AdjList.push_back(AdjNode); } |
| 73 | |
| 74 | inline IGNode * getAdjIGNode(unsigned int ind) const |
| 75 | { assert ( ind < AdjList.size()); return AdjList[ ind ]; } |
| 76 | |
| 77 | // delete a node in AdjList - node must be in the list |
| 78 | // should not be called often |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 79 | // |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 80 | void delAdjIGNode(const IGNode *const Node); |
| 81 | |
| 82 | inline unsigned int getNumOfNeighbors() const |
| 83 | { return AdjList.size() ; } |
| 84 | |
| 85 | |
| 86 | inline bool isOnStack() const |
| 87 | { return OnStack; } |
| 88 | |
| 89 | // remove form IG and pushes on to stack (reduce the degree of neighbors) |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 90 | // |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 91 | void pushOnStack(); |
| 92 | |
| 93 | // CurDegree is the effective number of neighbors when neighbors are |
| 94 | // pushed on to the stack during the coloring phase. Must be called |
| 95 | // after all modifications to the IG are over (i.e., all neighbors are |
| 96 | // fixed). |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 97 | // |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 98 | inline void setCurDegree() |
| 99 | { assert( CurDegree == -1); CurDegree = AdjList.size(); } |
| 100 | |
| 101 | inline int getCurDegree() const |
| 102 | { return CurDegree; } |
| 103 | |
| 104 | // called when a neigh is pushed on to stack |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 105 | // |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 106 | inline void decCurDegree() |
| 107 | { assert( CurDegree > 0 ); --CurDegree; } |
| 108 | |
| 109 | |
| 110 | // The following methods call the methods in ParentLR |
| 111 | // They are added to this class for convenience |
| 112 | // If many of these are called within a single scope, |
| 113 | // consider calling the methods directly on LR |
| 114 | |
| 115 | |
| 116 | inline void setRegClass(RegClass *const RC) |
| 117 | { ParentLR->setRegClass(RC); } |
| 118 | |
Chris Lattner | 2182c78 | 2002-02-04 05:52:08 +0000 | [diff] [blame^] | 119 | inline RegClass *const getRegClass() const { |
| 120 | return ParentLR->getRegClass(); |
| 121 | } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 122 | |
| 123 | inline bool hasColor() const |
| 124 | { return ParentLR->hasColor(); } |
| 125 | |
| 126 | inline unsigned int getColor() const |
| 127 | { return ParentLR->getColor(); } |
| 128 | |
| 129 | inline void setColor(unsigned int Col) |
| 130 | { ParentLR->setColor(Col); } |
| 131 | |
| 132 | inline void markForSpill() |
| 133 | { ParentLR->markForSpill(); } |
| 134 | |
| 135 | inline void markForSaveAcrossCalls() |
| 136 | { ParentLR->markForSaveAcrossCalls(); } |
| 137 | |
Ruchira Sasanka | 36f7707 | 2001-10-19 17:21:59 +0000 | [diff] [blame] | 138 | inline unsigned int isCallInterference() const |
| 139 | { return ParentLR->isCallInterference(); } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 140 | |
| 141 | inline LiveRange *getParentLR() const |
| 142 | { return ParentLR; } |
| 143 | |
| 144 | inline Type::PrimitiveID getTypeID() const |
| 145 | { return ParentLR->getTypeID(); } |
| 146 | |
| 147 | |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 150 | #endif |