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()).
28 #include "llvm/CodeGen/RegAllocCommon.h"
29 #include "llvm/CodeGen/LiveRange.h"
33 //----------------------------------------------------------------------------
36 // Represents a node in an interference graph.
37 //----------------------------------------------------------------------------
40 const unsigned Index; // index within IGNodeList
41 bool OnStack; // this has been pushed on to stack for coloring
42 std::vector<IGNode *> AdjList;// adjacency list for this live range
46 // set by InterferenceGraph::setCurDegreeOfIGNodes() after calculating
47 // all adjacency lists.
48 // Decremented when a neighbor is pushed on to the stack.
49 // After that, never incremented/set again nor used.
51 LiveRange *const ParentLR;
54 IGNode(LiveRange *LR, unsigned index) : Index(index), ParentLR(LR) {
57 ParentLR->setUserIGNode(this);
60 inline unsigned int getIndex() const { return Index; }
62 // adjLists must be updated only once. However, the CurDegree can be changed
64 inline void addAdjIGNode(IGNode *AdjNode) { AdjList.push_back(AdjNode); }
66 inline IGNode *getAdjIGNode(unsigned ind) const
67 { assert ( ind < AdjList.size()); return AdjList[ind]; }
69 // delete a node in AdjList - node must be in the list
70 // should not be called often
72 void delAdjIGNode(const IGNode *Node);
74 inline unsigned getNumOfNeighbors() const { return AdjList.size(); }
76 inline bool isOnStack() const { return OnStack; }
78 // remove form IG and pushes on to stack (reduce the degree of neighbors)
82 // CurDegree is the effective number of neighbors when neighbors are
83 // pushed on to the stack during the coloring phase. Must be called
84 // after all modifications to the IG are over (i.e., all neighbors are
87 inline void setCurDegree() {
88 assert(CurDegree == -1);
89 CurDegree = AdjList.size();
92 inline int getCurDegree() const { return CurDegree; }
94 // called when a neigh is pushed on to stack
96 inline void decCurDegree() { assert(CurDegree > 0); --CurDegree; }
99 // The following methods call the methods in ParentLR
100 // They are added to this class for convenience
101 // If many of these are called within a single scope,
102 // consider calling the methods directly on LR
104 inline void setRegClass(RegClass *RC) { ParentLR->setRegClass(RC); }
106 inline RegClass *getRegClass() const { return ParentLR->getRegClass(); }
108 inline bool hasColor() const { return ParentLR->hasColor(); }
110 inline unsigned int getColor() const { return ParentLR->getColor(); }
112 inline void setColor(unsigned Col) { ParentLR->setColor(Col); }
114 inline void markForSpill() { ParentLR->markForSpill(); }
116 inline void markForSaveAcrossCalls() { ParentLR->markForSaveAcrossCalls(); }
118 inline unsigned int isCallInterference() const
119 { return ParentLR->isCallInterference(); }
121 inline LiveRange *getParentLR() const { return ParentLR; }