Added LLVM project notice to the top of every C++ source file.
[oota-llvm.git] / lib / CodeGen / RegAlloc / IGNode.cpp
1 //===-- IGNode.cpp --------------------------------------------------------===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 // 
8 //===----------------------------------------------------------------------===//
9 // 
10 //  class IGNode for coloring-based register allocation for LLVM.
11 // 
12 //===----------------------------------------------------------------------===//
13
14 #include "IGNode.h"
15 #include <algorithm>
16 #include <iostream>
17
18 //-----------------------------------------------------------------------------
19 // Sets this IGNode on stack and reduce the degree of neighbors  
20 //-----------------------------------------------------------------------------
21
22 void IGNode::pushOnStack() {
23   OnStack = true; 
24   int neighs = AdjList.size();
25
26   if (neighs < 0) {
27     std::cerr << "\nAdj List size = " << neighs;
28     assert(0 && "Invalid adj list size");
29   }
30
31   for(int i=0; i < neighs; i++)
32     AdjList[i]->decCurDegree();
33 }
34  
35 //-----------------------------------------------------------------------------
36 // Deletes an adjacency node. IGNodes are deleted when coalescing merges
37 // two IGNodes together.
38 //-----------------------------------------------------------------------------
39
40 void IGNode::delAdjIGNode(const IGNode *Node) {
41   std::vector<IGNode *>::iterator It=find(AdjList.begin(), AdjList.end(), Node);
42   assert( It != AdjList.end() );      // the node must be there
43   AdjList.erase(It);
44 }
45
46 //-----------------------------------------------------------------------------
47 // Get the number of unique neighbors if these two nodes are merged
48 //-----------------------------------------------------------------------------
49
50 unsigned
51 IGNode::getCombinedDegree(const IGNode* otherNode) const
52 {
53   std::vector<IGNode*> nbrs(AdjList);
54   nbrs.insert(nbrs.end(), otherNode->AdjList.begin(), otherNode->AdjList.end());
55   sort(nbrs.begin(), nbrs.end());
56   std::vector<IGNode*>::iterator new_end = unique(nbrs.begin(), nbrs.end());
57   return new_end - nbrs.begin();
58 }
59
60