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 | |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/LiveRange.h" |
Chris Lattner | 2182c78 | 2002-02-04 05:52:08 +0000 | [diff] [blame] | 29 | class LiveRange; |
| 30 | class RegClass; |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 31 | |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 32 | //---------------------------------------------------------------------------- |
| 33 | // Class IGNode |
| 34 | // |
| 35 | // Represents a node in an interference graph. |
| 36 | //---------------------------------------------------------------------------- |
| 37 | |
Chris Lattner | 2182c78 | 2002-02-04 05:52:08 +0000 | [diff] [blame] | 38 | class IGNode { |
Chris Lattner | 748697d | 2002-02-05 04:20:12 +0000 | [diff] [blame] | 39 | const unsigned Index; // index within IGNodeList |
| 40 | bool OnStack; // this has been pushed on to stack for coloring |
| 41 | std::vector<IGNode *> AdjList;// adjacency list for this live range |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 42 | |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 43 | int CurDegree; |
| 44 | // |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 45 | // set by InterferenceGraph::setCurDegreeOfIGNodes() after calculating |
| 46 | // all adjacency lists. |
| 47 | // Decremented when a neighbor is pushed on to the stack. |
| 48 | // After that, never incremented/set again nor used. |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 49 | |
Chris Lattner | 748697d | 2002-02-05 04:20:12 +0000 | [diff] [blame] | 50 | LiveRange *const ParentLR; |
Chris Lattner | 2182c78 | 2002-02-04 05:52:08 +0000 | [diff] [blame] | 51 | public: |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 52 | |
Chris Lattner | 748697d | 2002-02-05 04:20:12 +0000 | [diff] [blame] | 53 | IGNode(LiveRange *LR, unsigned index) : Index(index), ParentLR(LR) { |
| 54 | OnStack = false; |
| 55 | CurDegree = -1; |
| 56 | ParentLR->setUserIGNode(this); |
| 57 | } |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 58 | |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 59 | inline unsigned int getIndex() const { return Index; } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 60 | |
| 61 | // adjLists must be updated only once. However, the CurDegree can be changed |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 62 | // |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 63 | inline void addAdjIGNode(IGNode *AdjNode) { AdjList.push_back(AdjNode); } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 64 | |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 65 | inline IGNode *getAdjIGNode(unsigned ind) const |
| 66 | { assert ( ind < AdjList.size()); return AdjList[ind]; } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 67 | |
| 68 | // delete a node in AdjList - node must be in the list |
| 69 | // should not be called often |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 70 | // |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 71 | void delAdjIGNode(const IGNode *Node); |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 72 | |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 73 | inline unsigned getNumOfNeighbors() const { return AdjList.size(); } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 74 | |
Vikram S. Adve | 0efb507 | 2002-09-20 00:55:04 +0000 | [diff] [blame] | 75 | // Get the number of unique neighbors if these two nodes are merged |
| 76 | unsigned getCombinedDegree(const IGNode* otherNode) const; |
| 77 | |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 78 | inline bool isOnStack() const { return OnStack; } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 79 | |
| 80 | // 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] | 81 | // |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 82 | void pushOnStack(); |
| 83 | |
| 84 | // CurDegree is the effective number of neighbors when neighbors are |
| 85 | // pushed on to the stack during the coloring phase. Must be called |
| 86 | // after all modifications to the IG are over (i.e., all neighbors are |
| 87 | // fixed). |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 88 | // |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 89 | inline void setCurDegree() { |
| 90 | assert(CurDegree == -1); |
| 91 | CurDegree = AdjList.size(); |
| 92 | } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 93 | |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 94 | inline int getCurDegree() const { return CurDegree; } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 95 | |
| 96 | // called when a neigh is pushed on to stack |
Ruchira Sasanka | 42bd177 | 2002-01-07 19:16:26 +0000 | [diff] [blame] | 97 | // |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 98 | inline void decCurDegree() { assert(CurDegree > 0); --CurDegree; } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 99 | |
| 100 | |
| 101 | // The following methods call the methods in ParentLR |
| 102 | // They are added to this class for convenience |
| 103 | // If many of these are called within a single scope, |
| 104 | // consider calling the methods directly on LR |
| 105 | |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 106 | inline void setRegClass(RegClass *RC) { ParentLR->setRegClass(RC); } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 107 | |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 108 | inline RegClass *getRegClass() const { return ParentLR->getRegClass(); } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 109 | |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 110 | inline bool hasColor() const { return ParentLR->hasColor(); } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 111 | |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 112 | inline unsigned int getColor() const { return ParentLR->getColor(); } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 113 | |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 114 | inline void setColor(unsigned Col) { ParentLR->setColor(Col); } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 115 | |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 116 | inline void markForSpill() { ParentLR->markForSpill(); } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 117 | |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 118 | inline void markForSaveAcrossCalls() { ParentLR->markForSaveAcrossCalls(); } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 119 | |
Ruchira Sasanka | 36f7707 | 2001-10-19 17:21:59 +0000 | [diff] [blame] | 120 | inline unsigned int isCallInterference() const |
| 121 | { return ParentLR->isCallInterference(); } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 122 | |
Chris Lattner | 569ea23 | 2002-02-05 03:51:37 +0000 | [diff] [blame] | 123 | inline LiveRange *getParentLR() const { return ParentLR; } |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
Ruchira Sasanka | f2a6477 | 2001-08-31 20:59:58 +0000 | [diff] [blame] | 126 | #endif |