blob: bdaedf8c134c66ae3c14f24e9bb20f54916b576c [file] [log] [blame]
Chris Lattnerfeb62c32001-09-07 21:04:20 +00001/* Title: IGNode.h -*- C++ -*-
Ruchira Sasanka4d30f4b2001-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 Sasankaf20079d2002-01-07 19:16:26 +000017 after all modifications to the IG are over (i.e., all neighbors are fixed).
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000018
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000019 The vector representation is the most efficient one for adj list.
Ruchira Sasanka4d30f4b2001-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 Sasanka4d30f4b2001-08-31 20:59:58 +000028#include "llvm/CodeGen/RegAllocCommon.h"
29#include "llvm/CodeGen/LiveRange.h"
Chris Lattnerb0da8b22002-02-04 05:52:08 +000030class LiveRange;
31class RegClass;
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000032
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000033//----------------------------------------------------------------------------
34// Class IGNode
35//
36// Represents a node in an interference graph.
37//----------------------------------------------------------------------------
38
Chris Lattnerb0da8b22002-02-04 05:52:08 +000039class IGNode {
Ruchira Sasanka4d30f4b2001-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 Lattner7f74a562002-01-20 22:54:45 +000044 std::vector<IGNode *> AdjList; // adjacency list for this live range
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000045
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000046 int CurDegree;
47 //
Ruchira Sasanka4d30f4b2001-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 Sasanka4d30f4b2001-08-31 20:59:58 +000052
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000053 LiveRange *const ParentLR; // parent LR (cannot be a const)
Chris Lattnerb0da8b22002-02-04 05:52:08 +000054public:
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000055
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000056 // constructor
57 //
Chris Lattnerf1223ac2002-02-05 03:51:37 +000058 IGNode(LiveRange *LR, unsigned index);
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000059
Chris Lattnerf1223ac2002-02-05 03:51:37 +000060 inline unsigned int getIndex() const { return Index; }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000061
62 // adjLists must be updated only once. However, the CurDegree can be changed
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000063 //
Chris Lattnerf1223ac2002-02-05 03:51:37 +000064 inline void addAdjIGNode(IGNode *AdjNode) { AdjList.push_back(AdjNode); }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000065
Chris Lattnerf1223ac2002-02-05 03:51:37 +000066 inline IGNode *getAdjIGNode(unsigned ind) const
67 { assert ( ind < AdjList.size()); return AdjList[ind]; }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000068
69 // delete a node in AdjList - node must be in the list
70 // should not be called often
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000071 //
Chris Lattnerf1223ac2002-02-05 03:51:37 +000072 void delAdjIGNode(const IGNode *Node);
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000073
Chris Lattnerf1223ac2002-02-05 03:51:37 +000074 inline unsigned getNumOfNeighbors() const { return AdjList.size(); }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000075
Chris Lattnerf1223ac2002-02-05 03:51:37 +000076 inline bool isOnStack() const { return OnStack; }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000077
78 // remove form IG and pushes on to stack (reduce the degree of neighbors)
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000079 //
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000080 void pushOnStack();
81
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
85 // fixed).
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000086 //
Chris Lattnerf1223ac2002-02-05 03:51:37 +000087 inline void setCurDegree() {
88 assert(CurDegree == -1);
89 CurDegree = AdjList.size();
90 }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000091
Chris Lattnerf1223ac2002-02-05 03:51:37 +000092 inline int getCurDegree() const { return CurDegree; }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000093
94 // called when a neigh is pushed on to stack
Ruchira Sasankaf20079d2002-01-07 19:16:26 +000095 //
Chris Lattnerf1223ac2002-02-05 03:51:37 +000096 inline void decCurDegree() { assert(CurDegree > 0); --CurDegree; }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +000097
98
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
103
Chris Lattnerf1223ac2002-02-05 03:51:37 +0000104 inline void setRegClass(RegClass *RC) { ParentLR->setRegClass(RC); }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +0000105
Chris Lattnerf1223ac2002-02-05 03:51:37 +0000106 inline RegClass *getRegClass() const { return ParentLR->getRegClass(); }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +0000107
Chris Lattnerf1223ac2002-02-05 03:51:37 +0000108 inline bool hasColor() const { return ParentLR->hasColor(); }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +0000109
Chris Lattnerf1223ac2002-02-05 03:51:37 +0000110 inline unsigned int getColor() const { return ParentLR->getColor(); }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +0000111
Chris Lattnerf1223ac2002-02-05 03:51:37 +0000112 inline void setColor(unsigned Col) { ParentLR->setColor(Col); }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +0000113
Chris Lattnerf1223ac2002-02-05 03:51:37 +0000114 inline void markForSpill() { ParentLR->markForSpill(); }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +0000115
Chris Lattnerf1223ac2002-02-05 03:51:37 +0000116 inline void markForSaveAcrossCalls() { ParentLR->markForSaveAcrossCalls(); }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +0000117
Ruchira Sasanka6275a042001-10-19 17:21:59 +0000118 inline unsigned int isCallInterference() const
119 { return ParentLR->isCallInterference(); }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +0000120
Chris Lattnerf1223ac2002-02-05 03:51:37 +0000121 inline LiveRange *getParentLR() const { return ParentLR; }
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +0000122};
123
Ruchira Sasanka4d30f4b2001-08-31 20:59:58 +0000124#endif