Make a new llvm/Target #include directory.
[oota-llvm.git] / lib / CodeGen / RegAlloc / RegClass.h
1 /* Title:   RegClass.h
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
19 #ifndef REG_CLASS_H
20 #define REG_CLASS_H
21
22 #include "llvm/CodeGen/IGNode.h"
23 #include "llvm/CodeGen/InterferenceGraph.h"
24 #include "llvm/Target/Machine.h"
25 #include <stack>
26
27 typedef vector<unsigned int> ReservedColorListType;
28
29
30 class RegClass
31 {
32
33  private:
34   const Method *const Meth;             // Method we are working on
35
36   const MachineRegClassInfo *const MRC; // corresponding MRC
37
38   const unsigned RegClassID;            // my int ID
39
40   InterferenceGraph IG;                 // Interference graph - constructed by
41                                         // buildInterferenceGraph
42   stack <IGNode *> IGNodeStack;         // the stack used for coloring
43
44   // for passing registered that are pre-allocated (e.g., %g's)
45   const ReservedColorListType *const ReservedColorList;
46
47   // An array used for coloring each node. This array must be of size 
48   // MRC->getNumOfAllRegs(). Allocated once in the constructor
49   // for efficiency.
50   bool *IsColorUsedArr;
51
52
53   //------------ private methods ------------------
54
55   void pushAllIGNodes();
56   bool  pushUnconstrainedIGNodes();
57   IGNode * getIGNodeWithMinSpillCost();
58   void colorIGNode(IGNode *const Node);
59
60  public:
61
62   RegClass(const Method *const M, 
63            const MachineRegClassInfo *const MRC, 
64            const ReservedColorListType *const RCL = NULL);
65
66   inline void createInterferenceGraph() 
67     { IG.createGraph(); }
68
69   inline InterferenceGraph &getIG() { return IG; }
70
71   inline const unsigned getID() const { return RegClassID; }
72
73   void colorAllRegs();                  // main method called for coloring regs
74
75   inline unsigned getNumOfAvailRegs() const 
76     { return MRC->getNumOfAvailRegs(); }
77
78   ~RegClass() { delete[] IsColorUsedArr; };
79
80
81
82   // --- following methods are provided to access the IG contained within this
83   // ---- RegClass easilly.
84
85
86   inline void addLRToIG(LiveRange *const LR) 
87     { IG.addLRToIG(LR); }
88
89   inline void setInterference(const LiveRange *const LR1,
90                               const LiveRange *const LR2)  
91     { IG.setInterference(LR1, LR2); }
92
93   inline unsigned getInterference(const LiveRange *const LR1,
94                               const LiveRange *const LR2) const 
95     { return IG.getInterference(LR1, LR2); }
96
97   inline void mergeIGNodesOfLRs(const LiveRange *const LR1,
98                                 LiveRange *const LR2) 
99     { IG.mergeIGNodesOfLRs(LR1, LR2); }
100
101
102   inline void printIGNodeList() const {
103     cout << "IG Nodes for Register Class " << RegClassID << ":" << endl;
104     IG.printIGNodeList(); 
105   }
106
107   inline void printIG() {  
108     cout << "IG for Register Class " << RegClassID << ":" << endl;
109     IG.printIG(); 
110   }
111
112 };
113
114
115
116
117
118
119
120 #endif