Vikram S. Adve | 39c94e1 | 2002-09-14 23:05:33 +0000 | [diff] [blame^] | 1 | //===-- IGNode.cpp -------------------------------------------------------===// |
| 2 | // |
| 3 | // class IGNode for coloring-based register allocation for LLVM. |
| 4 | // |
| 5 | //===----------------------------------------------------------------------===// |
| 6 | |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 7 | #include "llvm/CodeGen/IGNode.h" |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 8 | #include <algorithm> |
| 9 | #include <iostream> |
| 10 | using std::cerr; |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 11 | |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 12 | //----------------------------------------------------------------------------- |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 13 | // Sets this IGNode on stack and reduce the degree of neighbors |
| 14 | //----------------------------------------------------------------------------- |
Chris Lattner | 748697d | 2002-02-05 04:20:12 +0000 | [diff] [blame] | 15 | |
| 16 | void IGNode::pushOnStack() { |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 17 | OnStack = true; |
Ruchira Sasanka | a9e45c8 | 2001-11-03 22:01:09 +0000 | [diff] [blame] | 18 | int neighs = AdjList.size(); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 19 | |
Chris Lattner | 748697d | 2002-02-05 04:20:12 +0000 | [diff] [blame] | 20 | if (neighs < 0) { |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 21 | cerr << "\nAdj List size = " << neighs; |
Ruchira Sasanka | a9e45c8 | 2001-11-03 22:01:09 +0000 | [diff] [blame] | 22 | assert(0 && "Invalid adj list size"); |
| 23 | } |
| 24 | |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 25 | for(int i=0; i < neighs; i++) |
| 26 | AdjList[i]->decCurDegree(); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 27 | } |
| 28 | |
Ruchira Sasanka | 4f3eb22 | 2002-01-07 19:19:18 +0000 | [diff] [blame] | 29 | //----------------------------------------------------------------------------- |
| 30 | // Deletes an adjacency node. IGNodes are deleted when coalescing merges |
| 31 | // two IGNodes together. |
| 32 | //----------------------------------------------------------------------------- |
Chris Lattner | 748697d | 2002-02-05 04:20:12 +0000 | [diff] [blame] | 33 | |
| 34 | void IGNode::delAdjIGNode(const IGNode *Node) { |
| 35 | std::vector<IGNode *>::iterator It=find(AdjList.begin(), AdjList.end(), Node); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 36 | assert( It != AdjList.end() ); // the node must be there |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 37 | AdjList.erase(It); |
Ruchira Sasanka | 8e60479 | 2001-09-14 21:18:34 +0000 | [diff] [blame] | 38 | } |