Chris Lattner | e5bc8b0 | 2001-09-14 06:08:03 +0000 | [diff] [blame] | 1 | /* Title: RegClass.h -*- C++ -*- |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 2 | Author: Ruchira Sasanka |
| 3 | Date: Aug 20, 01 |
| 4 | Purpose: Contains machine independent methods for register coloring. |
| 5 | |
| 6 | This is the class that contains all data structures and common algos |
| 7 | for coloring a particular register class (e.g., int class, fp class). |
| 8 | This class is hardware independent. This class accepts a hardware |
| 9 | dependent description of machine registers (MachineRegInfo class) to |
| 10 | get hardware specific info and color and indidual IG node. |
| 11 | |
| 12 | This class contains the InterferenceGraph (IG). |
| 13 | Also it contains an IGNode stack that can be used for coloring. |
| 14 | The class provides some easy access methods to the IG methods, since these |
| 15 | methods are called thru a register class. |
| 16 | |
| 17 | */ |
| 18 | |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 19 | #ifndef REG_CLASS_H |
| 20 | #define REG_CLASS_H |
| 21 | |
| 22 | #include "llvm/CodeGen/IGNode.h" |
| 23 | #include "llvm/CodeGen/InterferenceGraph.h" |
Chris Lattner | b26bcc5 | 2001-09-14 05:34:53 +0000 | [diff] [blame] | 24 | #include "llvm/Target/Machine.h" |
Ruchira Sasanka | 1bf6d64 | 2001-09-15 00:33:26 +0000 | [diff] [blame^] | 25 | #include "llvm/Target/RegInfo.h" |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 26 | #include <stack> |
| 27 | |
Ruchira Sasanka | 7cd2ca1 | 2001-09-08 14:22:50 +0000 | [diff] [blame] | 28 | typedef vector<unsigned int> ReservedColorListType; |
| 29 | |
| 30 | |
| 31 | class RegClass |
| 32 | { |
| 33 | |
| 34 | private: |
| 35 | const Method *const Meth; // Method we are working on |
| 36 | |
| 37 | const MachineRegClassInfo *const MRC; // corresponding MRC |
| 38 | |
| 39 | const unsigned RegClassID; // my int ID |
| 40 | |
| 41 | InterferenceGraph IG; // Interference graph - constructed by |
| 42 | // buildInterferenceGraph |
| 43 | stack <IGNode *> IGNodeStack; // the stack used for coloring |
| 44 | |
| 45 | // for passing registered that are pre-allocated (e.g., %g's) |
| 46 | const ReservedColorListType *const ReservedColorList; |
| 47 | |
| 48 | // An array used for coloring each node. This array must be of size |
| 49 | // MRC->getNumOfAllRegs(). Allocated once in the constructor |
| 50 | // for efficiency. |
| 51 | bool *IsColorUsedArr; |
| 52 | |
| 53 | |
| 54 | //------------ private methods ------------------ |
| 55 | |
| 56 | void pushAllIGNodes(); |
| 57 | bool pushUnconstrainedIGNodes(); |
| 58 | IGNode * getIGNodeWithMinSpillCost(); |
| 59 | void colorIGNode(IGNode *const Node); |
| 60 | |
| 61 | public: |
| 62 | |
| 63 | RegClass(const Method *const M, |
| 64 | const MachineRegClassInfo *const MRC, |
| 65 | const ReservedColorListType *const RCL = NULL); |
| 66 | |
| 67 | inline void createInterferenceGraph() |
| 68 | { IG.createGraph(); } |
| 69 | |
| 70 | inline InterferenceGraph &getIG() { return IG; } |
| 71 | |
| 72 | inline const unsigned getID() const { return RegClassID; } |
| 73 | |
| 74 | void colorAllRegs(); // main method called for coloring regs |
| 75 | |
| 76 | inline unsigned getNumOfAvailRegs() const |
| 77 | { return MRC->getNumOfAvailRegs(); } |
| 78 | |
| 79 | ~RegClass() { delete[] IsColorUsedArr; }; |
| 80 | |
| 81 | |
| 82 | |
| 83 | // --- following methods are provided to access the IG contained within this |
| 84 | // ---- RegClass easilly. |
| 85 | |
| 86 | |
| 87 | inline void addLRToIG(LiveRange *const LR) |
| 88 | { IG.addLRToIG(LR); } |
| 89 | |
| 90 | inline void setInterference(const LiveRange *const LR1, |
| 91 | const LiveRange *const LR2) |
| 92 | { IG.setInterference(LR1, LR2); } |
| 93 | |
| 94 | inline unsigned getInterference(const LiveRange *const LR1, |
| 95 | const LiveRange *const LR2) const |
| 96 | { return IG.getInterference(LR1, LR2); } |
| 97 | |
| 98 | inline void mergeIGNodesOfLRs(const LiveRange *const LR1, |
| 99 | LiveRange *const LR2) |
| 100 | { IG.mergeIGNodesOfLRs(LR1, LR2); } |
| 101 | |
| 102 | |
| 103 | inline void printIGNodeList() const { |
| 104 | cout << "IG Nodes for Register Class " << RegClassID << ":" << endl; |
| 105 | IG.printIGNodeList(); |
| 106 | } |
| 107 | |
| 108 | inline void printIG() { |
| 109 | cout << "IG for Register Class " << RegClassID << ":" << endl; |
| 110 | IG.printIG(); |
| 111 | } |
| 112 | |
| 113 | }; |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | #endif |