blob: b89aea32b1d77014c92b1281d755b3c5cad69d9e [file] [log] [blame]
Chris Lattner1b40a1b2001-09-07 21:04:20 +00001/* Title: IGNode.h -*- C++ -*-
Ruchira Sasankaf2a64772001-08-31 20:59:58 +00002 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 Sasanka42bd1772002-01-07 19:16:26 +000017 after all modifications to the IG are over (i.e., all neighbors are fixed).
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000018
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000019 The vector representation is the most efficient one for adj list.
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000020 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"
31
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000032//----------------------------------------------------------------------------
33// Class IGNode
34//
35// Represents a node in an interference graph.
36//----------------------------------------------------------------------------
37
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000038class IGNode
39{
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000040 const int Index; // index within IGNodeList
41
42 bool OnStack; // this has been pushed on to stack for coloring
43
Chris Lattner697954c2002-01-20 22:54:45 +000044 std::vector<IGNode *> AdjList; // adjacency list for this live range
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000045
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000046 int CurDegree;
47 //
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000048 // 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.
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000052
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000053 LiveRange *const ParentLR; // parent LR (cannot be a const)
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000054
55
56 public:
57
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000058 // constructor
59 //
60 IGNode(LiveRange *const LR, unsigned int index);
61
62 // an empty destructor
63 //
64 ~IGNode() { }
65
66
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000067 inline unsigned int getIndex() const
68 { return Index; }
69
70 // adjLists must be updated only once. However, the CurDegree can be changed
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000071 //
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000072 inline void addAdjIGNode( IGNode *const AdjNode)
73 { AdjList.push_back(AdjNode); }
74
75 inline IGNode * getAdjIGNode(unsigned int ind) const
76 { assert ( ind < AdjList.size()); return AdjList[ ind ]; }
77
78 // delete a node in AdjList - node must be in the list
79 // should not be called often
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000080 //
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000081 void delAdjIGNode(const IGNode *const Node);
82
83 inline unsigned int getNumOfNeighbors() const
84 { return AdjList.size() ; }
85
86
87 inline bool isOnStack() const
88 { return OnStack; }
89
90 // remove form IG and pushes on to stack (reduce the degree of neighbors)
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000091 //
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000092 void pushOnStack();
93
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
97 // fixed).
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000098 //
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000099 inline void setCurDegree()
100 { assert( CurDegree == -1); CurDegree = AdjList.size(); }
101
102 inline int getCurDegree() const
103 { return CurDegree; }
104
105 // called when a neigh is pushed on to stack
Ruchira Sasanka42bd1772002-01-07 19:16:26 +0000106 //
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000107 inline void decCurDegree()
108 { assert( CurDegree > 0 ); --CurDegree; }
109
110
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
115
116
117 inline void setRegClass(RegClass *const RC)
118 { ParentLR->setRegClass(RC); }
119
120 inline RegClass *const getRegClass() const
121 { return ParentLR->getRegClass(); }
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 Sasanka36f77072001-10-19 17:21:59 +0000138 inline unsigned int isCallInterference() const
139 { return ParentLR->isCallInterference(); }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000140
141 inline LiveRange *getParentLR() const
142 { return ParentLR; }
143
144 inline Type::PrimitiveID getTypeID() const
145 { return ParentLR->getTypeID(); }
146
147
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000148};
149
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000150#endif