* Use C++ style comments instead of C-style
[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 // This file implements an Interference graph node for coloring-based register
11 // allocation.
12 // 
13 //===----------------------------------------------------------------------===//
14
15 #include "IGNode.h"
16 #include <algorithm>
17 #include <iostream>
18
19 //-----------------------------------------------------------------------------
20 // Sets this IGNode on stack and reduce the degree of neighbors  
21 //-----------------------------------------------------------------------------
22
23 void IGNode::pushOnStack() {
24   OnStack = true; 
25   int neighs = AdjList.size();
26
27   if (neighs < 0) {
28     std::cerr << "\nAdj List size = " << neighs;
29     assert(0 && "Invalid adj list size");
30   }
31
32   for (int i=0; i < neighs; i++)
33     AdjList[i]->decCurDegree();
34 }
35  
36 //-----------------------------------------------------------------------------
37 // Deletes an adjacency node. IGNodes are deleted when coalescing merges
38 // two IGNodes together.
39 //-----------------------------------------------------------------------------
40
41 void IGNode::delAdjIGNode(const IGNode *Node) {
42   std::vector<IGNode *>::iterator It=find(AdjList.begin(), AdjList.end(), Node);
43   assert(It != AdjList.end() && "The node must be there!");
44   AdjList.erase(It);
45 }
46
47 //-----------------------------------------------------------------------------
48 // Get the number of unique neighbors if these two nodes are merged
49 //-----------------------------------------------------------------------------
50
51 unsigned
52 IGNode::getCombinedDegree(const IGNode* otherNode) const {
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 }