blob: bcf850f68b321da4ab84333b3c16d63592f4f162 [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
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000028#include "llvm/CodeGen/LiveRange.h"
Chris Lattner2182c782002-02-04 05:52:08 +000029class LiveRange;
30class RegClass;
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000031
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000032//----------------------------------------------------------------------------
33// Class IGNode
34//
35// Represents a node in an interference graph.
36//----------------------------------------------------------------------------
37
Chris Lattner2182c782002-02-04 05:52:08 +000038class IGNode {
Chris Lattner748697d2002-02-05 04:20:12 +000039 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 Sasankaf2a64772001-08-31 20:59:58 +000042
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000043 int CurDegree;
44 //
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000045 // 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 Sasankaf2a64772001-08-31 20:59:58 +000049
Chris Lattner748697d2002-02-05 04:20:12 +000050 LiveRange *const ParentLR;
Chris Lattner2182c782002-02-04 05:52:08 +000051public:
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000052
Chris Lattner748697d2002-02-05 04:20:12 +000053 IGNode(LiveRange *LR, unsigned index) : Index(index), ParentLR(LR) {
54 OnStack = false;
55 CurDegree = -1;
56 ParentLR->setUserIGNode(this);
57 }
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000058
Chris Lattner569ea232002-02-05 03:51:37 +000059 inline unsigned int getIndex() const { return Index; }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000060
61 // adjLists must be updated only once. However, the CurDegree can be changed
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000062 //
Chris Lattner569ea232002-02-05 03:51:37 +000063 inline void addAdjIGNode(IGNode *AdjNode) { AdjList.push_back(AdjNode); }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000064
Chris Lattner569ea232002-02-05 03:51:37 +000065 inline IGNode *getAdjIGNode(unsigned ind) const
66 { assert ( ind < AdjList.size()); return AdjList[ind]; }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000067
68 // delete a node in AdjList - node must be in the list
69 // should not be called often
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000070 //
Chris Lattner569ea232002-02-05 03:51:37 +000071 void delAdjIGNode(const IGNode *Node);
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000072
Chris Lattner569ea232002-02-05 03:51:37 +000073 inline unsigned getNumOfNeighbors() const { return AdjList.size(); }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000074
Chris Lattner569ea232002-02-05 03:51:37 +000075 inline bool isOnStack() const { return OnStack; }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000076
77 // remove form IG and pushes on to stack (reduce the degree of neighbors)
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000078 //
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000079 void pushOnStack();
80
81 // CurDegree is the effective number of neighbors when neighbors are
82 // pushed on to the stack during the coloring phase. Must be called
83 // after all modifications to the IG are over (i.e., all neighbors are
84 // fixed).
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000085 //
Chris Lattner569ea232002-02-05 03:51:37 +000086 inline void setCurDegree() {
87 assert(CurDegree == -1);
88 CurDegree = AdjList.size();
89 }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000090
Chris Lattner569ea232002-02-05 03:51:37 +000091 inline int getCurDegree() const { return CurDegree; }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000092
93 // called when a neigh is pushed on to stack
Ruchira Sasanka42bd1772002-01-07 19:16:26 +000094 //
Chris Lattner569ea232002-02-05 03:51:37 +000095 inline void decCurDegree() { assert(CurDegree > 0); --CurDegree; }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +000096
97
98 // The following methods call the methods in ParentLR
99 // They are added to this class for convenience
100 // If many of these are called within a single scope,
101 // consider calling the methods directly on LR
102
Chris Lattner569ea232002-02-05 03:51:37 +0000103 inline void setRegClass(RegClass *RC) { ParentLR->setRegClass(RC); }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000104
Chris Lattner569ea232002-02-05 03:51:37 +0000105 inline RegClass *getRegClass() const { return ParentLR->getRegClass(); }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000106
Chris Lattner569ea232002-02-05 03:51:37 +0000107 inline bool hasColor() const { return ParentLR->hasColor(); }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000108
Chris Lattner569ea232002-02-05 03:51:37 +0000109 inline unsigned int getColor() const { return ParentLR->getColor(); }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000110
Chris Lattner569ea232002-02-05 03:51:37 +0000111 inline void setColor(unsigned Col) { ParentLR->setColor(Col); }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000112
Chris Lattner569ea232002-02-05 03:51:37 +0000113 inline void markForSpill() { ParentLR->markForSpill(); }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000114
Chris Lattner569ea232002-02-05 03:51:37 +0000115 inline void markForSaveAcrossCalls() { ParentLR->markForSaveAcrossCalls(); }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000116
Ruchira Sasanka36f77072001-10-19 17:21:59 +0000117 inline unsigned int isCallInterference() const
118 { return ParentLR->isCallInterference(); }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000119
Chris Lattner569ea232002-02-05 03:51:37 +0000120 inline LiveRange *getParentLR() const { return ParentLR; }
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000121};
122
Ruchira Sasankaf2a64772001-08-31 20:59:58 +0000123#endif