Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 1 | /* Title: InterferenceGraph.h -*- C++ -*- |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 2 | 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 Lattner | 97d6885 | 2002-10-29 16:50:06 +0000 | [diff] [blame] | 21 | #ifndef INTERFERENCE_GRAPH_H |
| 22 | #define INTERFERENCE_GRAPH_H |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 23 | |
Chris Lattner | 97d6885 | 2002-10-29 16:50:06 +0000 | [diff] [blame] | 24 | #include <vector> |
| 25 | class LiveRange; |
| 26 | class RegClass; |
| 27 | class IGNode; |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 28 | |
Chris Lattner | 28760f4 | 2002-10-29 16:42:34 +0000 | [diff] [blame] | 29 | class InterferenceGraph { |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 30 | 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 Lattner | 97d6885 | 2002-10-29 16:50:06 +0000 | [diff] [blame] | 33 | std::vector<IGNode *> IGNodeList; // a list of all IGNodes in a reg class |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 34 | |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 35 | public: |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 36 | // the matrix is not yet created by the constructor. Call createGraph() |
| 37 | // to create it after adding all IGNodes to the IGNodeList |
Chris Lattner | 28760f4 | 2002-10-29 16:42:34 +0000 | [diff] [blame] | 38 | InterferenceGraph(RegClass *RC); |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 39 | ~InterferenceGraph(); |
| 40 | |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 41 | void createGraph(); |
| 42 | |
Chris Lattner | 28760f4 | 2002-10-29 16:42:34 +0000 | [diff] [blame] | 43 | void addLRToIG(LiveRange *LR); |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 44 | |
Chris Lattner | 28760f4 | 2002-10-29 16:42:34 +0000 | [diff] [blame] | 45 | void setInterference(const LiveRange *LR1, |
| 46 | const LiveRange *LR2); |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 47 | |
Chris Lattner | 28760f4 | 2002-10-29 16:42:34 +0000 | [diff] [blame] | 48 | unsigned getInterference(const LiveRange *LR1, |
| 49 | const LiveRange *LR2) const ; |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 50 | |
Chris Lattner | 28760f4 | 2002-10-29 16:42:34 +0000 | [diff] [blame] | 51 | void mergeIGNodesOfLRs(const LiveRange *LR1, LiveRange *LR2); |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 52 | |
Chris Lattner | 97d6885 | 2002-10-29 16:50:06 +0000 | [diff] [blame] | 53 | std::vector<IGNode *> &getIGNodeList() { return IGNodeList; } |
| 54 | const std::vector<IGNode *> &getIGNodeList() const { return IGNodeList; } |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 55 | |
| 56 | void setCurDegreeOfIGNodes(); |
| 57 | |
| 58 | void printIG() const; |
| 59 | void printIGNodeList() const; |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 62 | #endif |