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