2001-09-07 23:04:20 +02:00
|
|
|
/* Title: IGNode.h -*- C++ -*-
|
2001-08-31 22:59:58 +02:00
|
|
|
Author: Ruchira Sasanka
|
|
|
|
Date: July 25, 01
|
|
|
|
Purpose: Represents a node in an interference graph.
|
|
|
|
Notes:
|
|
|
|
|
|
|
|
For efficiency, the AdjList is updated only once - ie. we can add but not
|
|
|
|
remove nodes from AdjList.
|
|
|
|
|
|
|
|
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 OnSack. 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
|
2002-01-07 20:16:26 +01:00
|
|
|
after all modifications to the IG are over (i.e., all neighbors are fixed).
|
2001-08-31 22:59:58 +02:00
|
|
|
|
2002-01-07 20:16:26 +01:00
|
|
|
The vector representation is the most efficient one for adj list.
|
2001-08-31 22:59:58 +02:00
|
|
|
Though nodes are removed when coalsing is done, we access it in sequence
|
|
|
|
for far many times when coloring (colorNode()).
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef IG_NODE_H
|
|
|
|
#define IG_NODE_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "llvm/CodeGen/RegAllocCommon.h"
|
|
|
|
#include "llvm/CodeGen/LiveRange.h"
|
2002-02-04 06:52:08 +01:00
|
|
|
class LiveRange;
|
|
|
|
class RegClass;
|
2001-08-31 22:59:58 +02:00
|
|
|
|
2002-01-07 20:16:26 +01:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// Class IGNode
|
|
|
|
//
|
|
|
|
// Represents a node in an interference graph.
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2002-02-04 06:52:08 +01:00
|
|
|
class IGNode {
|
2001-08-31 22:59:58 +02:00
|
|
|
const int Index; // index within IGNodeList
|
|
|
|
|
|
|
|
bool OnStack; // this has been pushed on to stack for coloring
|
|
|
|
|
2002-01-20 23:54:45 +01:00
|
|
|
std::vector<IGNode *> AdjList; // adjacency list for this live range
|
2001-08-31 22:59:58 +02:00
|
|
|
|
2002-01-07 20:16:26 +01:00
|
|
|
int CurDegree;
|
|
|
|
//
|
2001-08-31 22:59:58 +02:00
|
|
|
// set by InterferenceGraph::setCurDegreeOfIGNodes() after calculating
|
|
|
|
// all adjacency lists.
|
|
|
|
// Decremented when a neighbor is pushed on to the stack.
|
|
|
|
// After that, never incremented/set again nor used.
|
|
|
|
|
2002-01-07 20:16:26 +01:00
|
|
|
LiveRange *const ParentLR; // parent LR (cannot be a const)
|
2002-02-04 06:52:08 +01:00
|
|
|
public:
|
2001-08-31 22:59:58 +02:00
|
|
|
|
2002-01-07 20:16:26 +01:00
|
|
|
// constructor
|
|
|
|
//
|
|
|
|
IGNode(LiveRange *const LR, unsigned int index);
|
|
|
|
|
|
|
|
// an empty destructor
|
|
|
|
//
|
|
|
|
~IGNode() { }
|
|
|
|
|
|
|
|
|
2001-08-31 22:59:58 +02:00
|
|
|
inline unsigned int getIndex() const
|
|
|
|
{ return Index; }
|
|
|
|
|
|
|
|
// adjLists must be updated only once. However, the CurDegree can be changed
|
2002-01-07 20:16:26 +01:00
|
|
|
//
|
2001-08-31 22:59:58 +02:00
|
|
|
inline void addAdjIGNode( IGNode *const AdjNode)
|
|
|
|
{ AdjList.push_back(AdjNode); }
|
|
|
|
|
|
|
|
inline IGNode * getAdjIGNode(unsigned int ind) const
|
|
|
|
{ assert ( ind < AdjList.size()); return AdjList[ ind ]; }
|
|
|
|
|
|
|
|
// delete a node in AdjList - node must be in the list
|
|
|
|
// should not be called often
|
2002-01-07 20:16:26 +01:00
|
|
|
//
|
2001-08-31 22:59:58 +02:00
|
|
|
void delAdjIGNode(const IGNode *const Node);
|
|
|
|
|
|
|
|
inline unsigned int getNumOfNeighbors() const
|
|
|
|
{ return AdjList.size() ; }
|
|
|
|
|
|
|
|
|
|
|
|
inline bool isOnStack() const
|
|
|
|
{ return OnStack; }
|
|
|
|
|
|
|
|
// remove form IG and pushes on to stack (reduce the degree of neighbors)
|
2002-01-07 20:16:26 +01:00
|
|
|
//
|
2001-08-31 22:59:58 +02:00
|
|
|
void pushOnStack();
|
|
|
|
|
|
|
|
// 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 20:16:26 +01:00
|
|
|
//
|
2001-08-31 22:59:58 +02:00
|
|
|
inline void setCurDegree()
|
|
|
|
{ assert( CurDegree == -1); CurDegree = AdjList.size(); }
|
|
|
|
|
|
|
|
inline int getCurDegree() const
|
|
|
|
{ return CurDegree; }
|
|
|
|
|
|
|
|
// called when a neigh is pushed on to stack
|
2002-01-07 20:16:26 +01:00
|
|
|
//
|
2001-08-31 22:59:58 +02:00
|
|
|
inline void decCurDegree()
|
|
|
|
{ assert( CurDegree > 0 ); --CurDegree; }
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
|
|
inline void setRegClass(RegClass *const RC)
|
|
|
|
{ ParentLR->setRegClass(RC); }
|
|
|
|
|
2002-02-04 06:52:08 +01:00
|
|
|
inline RegClass *const getRegClass() const {
|
|
|
|
return ParentLR->getRegClass();
|
|
|
|
}
|
2001-08-31 22:59:58 +02:00
|
|
|
|
|
|
|
inline bool hasColor() const
|
|
|
|
{ return ParentLR->hasColor(); }
|
|
|
|
|
|
|
|
inline unsigned int getColor() const
|
|
|
|
{ return ParentLR->getColor(); }
|
|
|
|
|
|
|
|
inline void setColor(unsigned int Col)
|
|
|
|
{ ParentLR->setColor(Col); }
|
|
|
|
|
|
|
|
inline void markForSpill()
|
|
|
|
{ ParentLR->markForSpill(); }
|
|
|
|
|
|
|
|
inline void markForSaveAcrossCalls()
|
|
|
|
{ ParentLR->markForSaveAcrossCalls(); }
|
|
|
|
|
2001-10-19 19:21:59 +02:00
|
|
|
inline unsigned int isCallInterference() const
|
|
|
|
{ return ParentLR->isCallInterference(); }
|
2001-08-31 22:59:58 +02:00
|
|
|
|
|
|
|
inline LiveRange *getParentLR() const
|
|
|
|
{ return ParentLR; }
|
|
|
|
|
|
|
|
inline Type::PrimitiveID getTypeID() const
|
|
|
|
{ return ParentLR->getTypeID(); }
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|