LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

IGNode.cpp

Go to the documentation of this file.
00001 //===-- IGNode.cpp --------------------------------------------------------===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 // 
00010 // This file implements an Interference graph node for coloring-based register
00011 // allocation.
00012 // 
00013 //===----------------------------------------------------------------------===//
00014 
00015 #include "IGNode.h"
00016 #include <algorithm>
00017 #include <iostream>
00018 
00019 namespace llvm {
00020 
00021 //-----------------------------------------------------------------------------
00022 // Sets this IGNode on stack and reduce the degree of neighbors  
00023 //-----------------------------------------------------------------------------
00024 
00025 void IGNode::pushOnStack() {
00026   OnStack = true; 
00027   int neighs = AdjList.size();
00028 
00029   if (neighs < 0) {
00030     std::cerr << "\nAdj List size = " << neighs;
00031     assert(0 && "Invalid adj list size");
00032   }
00033 
00034   for (int i=0; i < neighs; i++)
00035     AdjList[i]->decCurDegree();
00036 }
00037  
00038 //-----------------------------------------------------------------------------
00039 // Deletes an adjacency node. IGNodes are deleted when coalescing merges
00040 // two IGNodes together.
00041 //-----------------------------------------------------------------------------
00042 
00043 void IGNode::delAdjIGNode(const IGNode *Node) {
00044   std::vector<IGNode *>::iterator It=find(AdjList.begin(), AdjList.end(), Node);
00045   assert(It != AdjList.end() && "The node must be there!");
00046   AdjList.erase(It);
00047 }
00048 
00049 //-----------------------------------------------------------------------------
00050 // Get the number of unique neighbors if these two nodes are merged
00051 //-----------------------------------------------------------------------------
00052 
00053 unsigned
00054 IGNode::getCombinedDegree(const IGNode* otherNode) const {
00055   std::vector<IGNode*> nbrs(AdjList);
00056   nbrs.insert(nbrs.end(), otherNode->AdjList.begin(), otherNode->AdjList.end());
00057   sort(nbrs.begin(), nbrs.end());
00058   std::vector<IGNode*>::iterator new_end = unique(nbrs.begin(), nbrs.end());
00059   return new_end - nbrs.begin();
00060 }
00061 
00062 } // End llvm namespace