blob: e9cb610787770d13b79b0ee4bfdf79ce458fd1bf [file] [log] [blame]
Chris Lattner697954c2002-01-20 22:54:45 +00001/* Title: InterferenceGraph.h -*- C++ -*-
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +00002 Author: Ruchira Sasanka
3 Date: July 20, 01
4 Purpose: Interference Graph used for register coloring.
5
6 Notes:
7 Adj Info is stored in the lower trangular matrix (i.e., row > col )
8
9 This class must be used in the following way:
10
11 * Construct class
12 * call addLRToIG as many times to add ALL LRs to this IG
13 * call createGraph to create the actual matrix
14 * Then setInterference, getInterference, mergeIGNodesOfLRs can be
15 called as desired to modify the graph.
16 * Once the modifications to the graph are over, call
17 setCurDegreeOfIGNodes() before pushing IGNodes on to stack for coloring.
18*/
19
20
Chris Lattner97d68852002-10-29 16:50:06 +000021#ifndef INTERFERENCE_GRAPH_H
22#define INTERFERENCE_GRAPH_H
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000023
Chris Lattner97d68852002-10-29 16:50:06 +000024#include <vector>
25class LiveRange;
26class RegClass;
27class IGNode;
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000028
Chris Lattner28760f42002-10-29 16:42:34 +000029class InterferenceGraph {
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000030 char **IG; // a poiner to the interference graph
31 unsigned int Size; // size of a side of the IG
32 RegClass *const RegCl; // RegCl contains this IG
Chris Lattner97d68852002-10-29 16:50:06 +000033 std::vector<IGNode *> IGNodeList; // a list of all IGNodes in a reg class
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000034
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000035 public:
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000036 // the matrix is not yet created by the constructor. Call createGraph()
37 // to create it after adding all IGNodes to the IGNodeList
Chris Lattner28760f42002-10-29 16:42:34 +000038 InterferenceGraph(RegClass *RC);
Chris Lattner697954c2002-01-20 22:54:45 +000039 ~InterferenceGraph();
40
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000041 void createGraph();
42
Chris Lattner28760f42002-10-29 16:42:34 +000043 void addLRToIG(LiveRange *LR);
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000044
Chris Lattner28760f42002-10-29 16:42:34 +000045 void setInterference(const LiveRange *LR1,
46 const LiveRange *LR2);
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000047
Chris Lattner28760f42002-10-29 16:42:34 +000048 unsigned getInterference(const LiveRange *LR1,
49 const LiveRange *LR2) const ;
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000050
Chris Lattner28760f42002-10-29 16:42:34 +000051 void mergeIGNodesOfLRs(const LiveRange *LR1, LiveRange *LR2);
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000052
Chris Lattner97d68852002-10-29 16:50:06 +000053 std::vector<IGNode *> &getIGNodeList() { return IGNodeList; }
54 const std::vector<IGNode *> &getIGNodeList() const { return IGNodeList; }
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000055
56 void setCurDegreeOfIGNodes();
57
58 void printIG() const;
59 void printIGNodeList() const;
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000060};
61
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000062#endif