1 //===-- IGNode.h - Represent a node in an interference graph ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file represents a node in an interference graph.
12 // For efficiency, the AdjList is updated only once - ie. we can add but not
13 // remove nodes from AdjList.
15 // The removal of nodes from IG is simulated by decrementing the CurDegree.
16 // If this node is put on stack (that is removed from IG), the CurDegree of all
17 // the neighbors are decremented and this node is marked OnStack. Hence
18 // the effective neighbors in the AdjList are the ones that do not have the
19 // OnStack flag set (therefore, they are in the IG).
21 // The methods that modify/use the CurDegree must be called only
22 // after all modifications to the IG are over (i.e., all neighbors are fixed).
24 // The vector representation is the most efficient one for adj list.
25 // Though nodes are removed when coalescing is done, we access it in sequence
26 // for far many times when coloring (colorNode()).
28 //===----------------------------------------------------------------------===//
33 #include "LiveRange.h"
37 //----------------------------------------------------------------------------
40 // Represents a node in an interference graph.
41 //----------------------------------------------------------------------------
44 const unsigned Index; // index within IGNodeList
45 bool OnStack; // this has been pushed on to stack for coloring
46 std::vector<IGNode *> AdjList;// adjacency list for this live range
50 // set by InterferenceGraph::setCurDegreeOfIGNodes() after calculating
51 // all adjacency lists.
52 // Decremented when a neighbor is pushed on to the stack.
53 // After that, never incremented/set again nor used.
55 LiveRange *const ParentLR;
58 IGNode(LiveRange *LR, unsigned index) : Index(index), ParentLR(LR) {
61 ParentLR->setUserIGNode(this);
64 inline unsigned int getIndex() const { return Index; }
66 // adjLists must be updated only once. However, the CurDegree can be changed
68 inline void addAdjIGNode(IGNode *AdjNode) { AdjList.push_back(AdjNode); }
70 inline IGNode *getAdjIGNode(unsigned ind) const
71 { assert ( ind < AdjList.size()); return AdjList[ind]; }
73 // delete a node in AdjList - node must be in the list
74 // should not be called often
76 void delAdjIGNode(const IGNode *Node);
78 inline unsigned getNumOfNeighbors() const { return AdjList.size(); }
80 // Get the number of unique neighbors if these two nodes are merged
81 unsigned getCombinedDegree(const IGNode* otherNode) const;
83 inline bool isOnStack() const { return OnStack; }
85 // remove form IG and pushes on to stack (reduce the degree of neighbors)
89 // CurDegree is the effective number of neighbors when neighbors are
90 // pushed on to the stack during the coloring phase. Must be called
91 // after all modifications to the IG are over (i.e., all neighbors are
94 inline void setCurDegree() {
95 assert(CurDegree == -1);
96 CurDegree = AdjList.size();
99 inline int getCurDegree() const { return CurDegree; }
101 // called when a neigh is pushed on to stack
103 inline void decCurDegree() { assert(CurDegree > 0); --CurDegree; }
105 // The following methods call the methods in ParentLR
106 // They are added to this class for convenience
107 // If many of these are called within a single scope,
108 // consider calling the methods directly on LR
109 inline bool hasColor() const { return ParentLR->hasColor(); }
111 inline unsigned int getColor() const { return ParentLR->getColor(); }
113 inline void setColor(unsigned Col) { ParentLR->setColor(Col); }
115 inline LiveRange *getParentLR() const { return ParentLR; }