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