2003-10-21 15:29:18 +00:00
|
|
|
//===-- IGNode.h - Represent a node in an interference graph ----*- C++ -*-===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2003-10-21 15:29:18 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2003-10-21 15:29:18 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2003-10-23 18:02:47 +00:00
|
|
|
//
|
2005-04-21 23:30:14 +00:00
|
|
|
// This file represents a node in an interference graph.
|
2003-10-23 18:02:47 +00:00
|
|
|
//
|
|
|
|
// For efficiency, the AdjList is updated only once - ie. we can add but not
|
2005-04-21 23:30:14 +00:00
|
|
|
// remove nodes from AdjList.
|
2003-10-23 18:02:47 +00:00
|
|
|
//
|
|
|
|
// The removal of nodes from IG is simulated by decrementing the CurDegree.
|
|
|
|
// If this node is put on stack (that is removed from IG), the CurDegree of all
|
|
|
|
// the neighbors are decremented and this node is marked OnStack. Hence
|
|
|
|
// the effective neighbors in the AdjList are the ones that do not have the
|
|
|
|
// OnStack flag set (therefore, they are in the IG).
|
|
|
|
//
|
|
|
|
// The methods that modify/use the CurDegree must be called only
|
|
|
|
// after all modifications to the IG are over (i.e., all neighbors are fixed).
|
|
|
|
//
|
|
|
|
// The vector representation is the most efficient one for adj list.
|
|
|
|
// Though nodes are removed when coalescing is done, we access it in sequence
|
|
|
|
// for far many times when coloring (colorNode()).
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-08-31 20:59:58 +00:00
|
|
|
|
2003-09-21 02:31:15 +00:00
|
|
|
#ifndef IGNODE_H
|
|
|
|
#define IGNODE_H
|
2001-08-31 20:59:58 +00:00
|
|
|
|
2003-09-01 20:17:13 +00:00
|
|
|
#include "LiveRange.h"
|
2003-10-15 22:09:32 +00:00
|
|
|
#include <vector>
|
2003-11-11 22:41:34 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2002-02-04 05:52:08 +00:00
|
|
|
class RegClass;
|
2001-08-31 20:59:58 +00:00
|
|
|
|
2002-01-07 19:16:26 +00:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Class IGNode
|
|
|
|
//
|
|
|
|
// Represents a node in an interference graph.
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2002-02-04 05:52:08 +00:00
|
|
|
class IGNode {
|
2005-04-21 23:30:14 +00:00
|
|
|
const unsigned Index; // index within IGNodeList
|
2002-02-05 04:20:12 +00:00
|
|
|
bool OnStack; // this has been pushed on to stack for coloring
|
|
|
|
std::vector<IGNode *> AdjList;// adjacency list for this live range
|
2001-08-31 20:59:58 +00:00
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
int CurDegree;
|
2002-01-07 19:16:26 +00:00
|
|
|
//
|
2001-08-31 20:59:58 +00:00
|
|
|
// set by InterferenceGraph::setCurDegreeOfIGNodes() after calculating
|
|
|
|
// all adjacency lists.
|
2005-04-21 23:30:14 +00:00
|
|
|
// Decremented when a neighbor is pushed on to the stack.
|
2001-08-31 20:59:58 +00:00
|
|
|
// After that, never incremented/set again nor used.
|
|
|
|
|
2005-06-12 23:52:58 +00:00
|
|
|
V9LiveRange *const ParentLR;
|
2002-02-04 05:52:08 +00:00
|
|
|
public:
|
2001-08-31 20:59:58 +00:00
|
|
|
|
2005-06-12 23:52:58 +00:00
|
|
|
IGNode(V9LiveRange *LR, unsigned index) : Index(index), ParentLR(LR) {
|
2002-02-05 04:20:12 +00:00
|
|
|
OnStack = false;
|
|
|
|
CurDegree = -1;
|
|
|
|
ParentLR->setUserIGNode(this);
|
|
|
|
}
|
2002-01-07 19:16:26 +00:00
|
|
|
|
2002-02-05 03:51:37 +00:00
|
|
|
inline unsigned int getIndex() const { return Index; }
|
2001-08-31 20:59:58 +00:00
|
|
|
|
|
|
|
// adjLists must be updated only once. However, the CurDegree can be changed
|
2002-01-07 19:16:26 +00:00
|
|
|
//
|
2005-04-21 23:30:14 +00:00
|
|
|
inline void addAdjIGNode(IGNode *AdjNode) { AdjList.push_back(AdjNode); }
|
2001-08-31 20:59:58 +00:00
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
inline IGNode *getAdjIGNode(unsigned ind) const
|
2002-02-05 03:51:37 +00:00
|
|
|
{ assert ( ind < AdjList.size()); return AdjList[ind]; }
|
2001-08-31 20:59:58 +00:00
|
|
|
|
|
|
|
// delete a node in AdjList - node must be in the list
|
|
|
|
// should not be called often
|
2002-01-07 19:16:26 +00:00
|
|
|
//
|
2005-04-21 23:30:14 +00:00
|
|
|
void delAdjIGNode(const IGNode *Node);
|
2001-08-31 20:59:58 +00:00
|
|
|
|
2002-02-05 03:51:37 +00:00
|
|
|
inline unsigned getNumOfNeighbors() const { return AdjList.size(); }
|
2001-08-31 20:59:58 +00:00
|
|
|
|
2002-09-20 00:55:04 +00:00
|
|
|
// Get the number of unique neighbors if these two nodes are merged
|
|
|
|
unsigned getCombinedDegree(const IGNode* otherNode) const;
|
|
|
|
|
2002-02-05 03:51:37 +00:00
|
|
|
inline bool isOnStack() const { return OnStack; }
|
2001-08-31 20:59:58 +00:00
|
|
|
|
|
|
|
// remove form IG and pushes on to stack (reduce the degree of neighbors)
|
2002-01-07 19:16:26 +00:00
|
|
|
//
|
2005-04-21 23:30:14 +00:00
|
|
|
void pushOnStack();
|
2001-08-31 20:59:58 +00:00
|
|
|
|
|
|
|
// CurDegree is the effective number of neighbors when neighbors are
|
|
|
|
// pushed on to the stack during the coloring phase. Must be called
|
|
|
|
// after all modifications to the IG are over (i.e., all neighbors are
|
|
|
|
// fixed).
|
2002-01-07 19:16:26 +00:00
|
|
|
//
|
2002-02-05 03:51:37 +00:00
|
|
|
inline void setCurDegree() {
|
|
|
|
assert(CurDegree == -1);
|
|
|
|
CurDegree = AdjList.size();
|
|
|
|
}
|
2001-08-31 20:59:58 +00:00
|
|
|
|
2002-02-05 03:51:37 +00:00
|
|
|
inline int getCurDegree() const { return CurDegree; }
|
2001-08-31 20:59:58 +00:00
|
|
|
|
|
|
|
// called when a neigh is pushed on to stack
|
2002-01-07 19:16:26 +00:00
|
|
|
//
|
2002-02-05 03:51:37 +00:00
|
|
|
inline void decCurDegree() { assert(CurDegree > 0); --CurDegree; }
|
2001-08-31 20:59:58 +00:00
|
|
|
|
|
|
|
// The following methods call the methods in ParentLR
|
|
|
|
// They are added to this class for convenience
|
|
|
|
// If many of these are called within a single scope,
|
|
|
|
// consider calling the methods directly on LR
|
2002-02-05 03:51:37 +00:00
|
|
|
inline bool hasColor() const { return ParentLR->hasColor(); }
|
2001-08-31 20:59:58 +00:00
|
|
|
|
2002-02-05 03:51:37 +00:00
|
|
|
inline unsigned int getColor() const { return ParentLR->getColor(); }
|
2001-08-31 20:59:58 +00:00
|
|
|
|
2002-02-05 03:51:37 +00:00
|
|
|
inline void setColor(unsigned Col) { ParentLR->setColor(Col); }
|
2001-08-31 20:59:58 +00:00
|
|
|
|
2005-06-12 23:52:58 +00:00
|
|
|
inline V9LiveRange *getParentLR() const { return ParentLR; }
|
2001-08-31 20:59:58 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-08-31 20:59:58 +00:00
|
|
|
#endif
|