1 /* Title: IGNode.h -*- C++ -*-
2 Author: Ruchira Sasanka
4 Purpose: Represents a node in an interference graph.
7 For efficiency, the AdjList is updated only once - ie. we can add but not
8 remove nodes from AdjList.
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).
16 The methods that modify/use the CurDegree Must be called only
17 after all modifications to the IG are over (i.e., all neighbors are fixed).
19 The vector representation is the most efficient one for adj list.
20 Though nodes are removed when coalsing is done, we access it in sequence
21 for far many times when coloring (colorNode()).
29 #include "llvm/CodeGen/RegAllocCommon.h"
30 #include "llvm/CodeGen/LiveRange.h"
32 //----------------------------------------------------------------------------
35 // Represents a node in an interference graph.
36 //----------------------------------------------------------------------------
40 const int Index; // index within IGNodeList
42 bool OnStack; // this has been pushed on to stack for coloring
44 std::vector<IGNode *> AdjList; // adjacency list for this live range
48 // set by InterferenceGraph::setCurDegreeOfIGNodes() after calculating
49 // all adjacency lists.
50 // Decremented when a neighbor is pushed on to the stack.
51 // After that, never incremented/set again nor used.
53 LiveRange *const ParentLR; // parent LR (cannot be a const)
60 IGNode(LiveRange *const LR, unsigned int index);
62 // an empty destructor
67 inline unsigned int getIndex() const
70 // adjLists must be updated only once. However, the CurDegree can be changed
72 inline void addAdjIGNode( IGNode *const AdjNode)
73 { AdjList.push_back(AdjNode); }
75 inline IGNode * getAdjIGNode(unsigned int ind) const
76 { assert ( ind < AdjList.size()); return AdjList[ ind ]; }
78 // delete a node in AdjList - node must be in the list
79 // should not be called often
81 void delAdjIGNode(const IGNode *const Node);
83 inline unsigned int getNumOfNeighbors() const
84 { return AdjList.size() ; }
87 inline bool isOnStack() const
90 // remove form IG and pushes on to stack (reduce the degree of neighbors)
94 // CurDegree is the effective number of neighbors when neighbors are
95 // pushed on to the stack during the coloring phase. Must be called
96 // after all modifications to the IG are over (i.e., all neighbors are
99 inline void setCurDegree()
100 { assert( CurDegree == -1); CurDegree = AdjList.size(); }
102 inline int getCurDegree() const
103 { return CurDegree; }
105 // called when a neigh is pushed on to stack
107 inline void decCurDegree()
108 { assert( CurDegree > 0 ); --CurDegree; }
111 // The following methods call the methods in ParentLR
112 // They are added to this class for convenience
113 // If many of these are called within a single scope,
114 // consider calling the methods directly on LR
117 inline void setRegClass(RegClass *const RC)
118 { ParentLR->setRegClass(RC); }
120 inline RegClass *const getRegClass() const
121 { return ParentLR->getRegClass(); }
123 inline bool hasColor() const
124 { return ParentLR->hasColor(); }
126 inline unsigned int getColor() const
127 { return ParentLR->getColor(); }
129 inline void setColor(unsigned int Col)
130 { ParentLR->setColor(Col); }
132 inline void markForSpill()
133 { ParentLR->markForSpill(); }
135 inline void markForSaveAcrossCalls()
136 { ParentLR->markForSaveAcrossCalls(); }
138 inline unsigned int isCallInterference() const
139 { return ParentLR->isCallInterference(); }
141 inline LiveRange *getParentLR() const
144 inline Type::PrimitiveID getTypeID() const
145 { return ParentLR->getTypeID(); }