2003-09-01 22:05:47 +02:00
|
|
|
//===-- IGNode.cpp --------------------------------------------------------===//
|
2002-09-15 01:05:33 +02:00
|
|
|
//
|
|
|
|
// class IGNode for coloring-based register allocation for LLVM.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2003-09-01 22:05:47 +02:00
|
|
|
#include "IGNode.h"
|
2002-01-20 23:54:45 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <iostream>
|
2001-09-14 23:18:34 +02:00
|
|
|
|
2002-01-07 20:19:18 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Sets this IGNode on stack and reduce the degree of neighbors
|
|
|
|
//-----------------------------------------------------------------------------
|
2002-02-05 05:20:12 +01:00
|
|
|
|
|
|
|
void IGNode::pushOnStack() {
|
2001-09-14 23:18:34 +02:00
|
|
|
OnStack = true;
|
2001-11-03 23:01:09 +01:00
|
|
|
int neighs = AdjList.size();
|
2001-09-14 23:18:34 +02:00
|
|
|
|
2002-02-05 05:20:12 +01:00
|
|
|
if (neighs < 0) {
|
2003-09-01 22:05:47 +02:00
|
|
|
std::cerr << "\nAdj List size = " << neighs;
|
2001-11-03 23:01:09 +01:00
|
|
|
assert(0 && "Invalid adj list size");
|
|
|
|
}
|
|
|
|
|
2002-01-20 23:54:45 +01:00
|
|
|
for(int i=0; i < neighs; i++)
|
|
|
|
AdjList[i]->decCurDegree();
|
2001-09-14 23:18:34 +02:00
|
|
|
}
|
|
|
|
|
2002-01-07 20:19:18 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Deletes an adjacency node. IGNodes are deleted when coalescing merges
|
|
|
|
// two IGNodes together.
|
|
|
|
//-----------------------------------------------------------------------------
|
2002-02-05 05:20:12 +01:00
|
|
|
|
|
|
|
void IGNode::delAdjIGNode(const IGNode *Node) {
|
|
|
|
std::vector<IGNode *>::iterator It=find(AdjList.begin(), AdjList.end(), Node);
|
2001-09-14 23:18:34 +02:00
|
|
|
assert( It != AdjList.end() ); // the node must be there
|
2002-01-20 23:54:45 +01:00
|
|
|
AdjList.erase(It);
|
2001-09-14 23:18:34 +02:00
|
|
|
}
|
2002-09-20 02:45:47 +02:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Get the number of unique neighbors if these two nodes are merged
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
IGNode::getCombinedDegree(const IGNode* otherNode) const
|
|
|
|
{
|
|
|
|
std::vector<IGNode*> nbrs(AdjList);
|
|
|
|
nbrs.insert(nbrs.end(), otherNode->AdjList.begin(), otherNode->AdjList.end());
|
|
|
|
sort(nbrs.begin(), nbrs.end());
|
|
|
|
std::vector<IGNode*>::iterator new_end = unique(nbrs.begin(), nbrs.end());
|
|
|
|
return new_end - nbrs.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|