blob: 5af8149a329d94f4ef5da49ae9191773c5357f89 [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
21#ifndef INTERFERENCE_GRAPH_H
22#define INTERFERENCE_GRAPH_H
23
24
25#include "llvm/CodeGen/IGNode.h"
26
Chris Lattner697954c2002-01-20 22:54:45 +000027typedef std::vector <IGNode *> IGNodeListType;
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000028
29
Chris Lattner28760f42002-10-29 16:42:34 +000030class InterferenceGraph {
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000031 char **IG; // a poiner to the interference graph
32 unsigned int Size; // size of a side of the IG
33 RegClass *const RegCl; // RegCl contains this IG
34 IGNodeListType IGNodeList; // a list of all IGNodes in a reg class
35
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000036 public:
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000037 // the matrix is not yet created by the constructor. Call createGraph()
38 // to create it after adding all IGNodes to the IGNodeList
Chris Lattner28760f42002-10-29 16:42:34 +000039 InterferenceGraph(RegClass *RC);
Chris Lattner697954c2002-01-20 22:54:45 +000040 ~InterferenceGraph();
41
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000042 void createGraph();
43
Chris Lattner28760f42002-10-29 16:42:34 +000044 void addLRToIG(LiveRange *LR);
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000045
Chris Lattner28760f42002-10-29 16:42:34 +000046 void setInterference(const LiveRange *LR1,
47 const LiveRange *LR2);
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000048
Chris Lattner28760f42002-10-29 16:42:34 +000049 unsigned getInterference(const LiveRange *LR1,
50 const LiveRange *LR2) const ;
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000051
Chris Lattner28760f42002-10-29 16:42:34 +000052 void mergeIGNodesOfLRs(const LiveRange *LR1, LiveRange *LR2);
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000053
Chris Lattner28760f42002-10-29 16:42:34 +000054 IGNodeListType &getIGNodeList() { return IGNodeList; }
55 const IGNodeListType &getIGNodeList() const { return IGNodeList; }
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000056
57 void setCurDegreeOfIGNodes();
58
59 void printIG() const;
60 void printIGNodeList() const;
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000061};
62
Ruchira Sasanka7cd2ca12001-09-08 14:22:50 +000063#endif