Eliminate duplicate or unneccesary #include's
[oota-llvm.git] / lib / CodeGen / RegAlloc / RegClass.h
1 /* Title:   RegClass.h   -*- C++ -*-
2    Author:  Ruchira Sasanka
3    Date:    Aug 20, 01
4    Purpose: Contains machine independent methods for register coloring.
5
6 */
7
8 #ifndef REG_CLASS_H
9 #define REG_CLASS_H
10
11 #include "llvm/CodeGen/InterferenceGraph.h"
12 #include "llvm/Target/MachineRegInfo.h"
13 #include <stack>
14 class MachineRegClassInfo;
15
16 typedef std::vector<unsigned> ReservedColorListType;
17
18
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 
27 //   dependent description of machine registers (MachineRegInfo class) to 
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 //-----------------------------------------------------------------------------
36 class RegClass {
37   const Function *const Meth;           // Function we are working on
38   const MachineRegClassInfo *const MRC; // corresponding MRC
39   const unsigned RegClassID;            // my int ID
40
41   InterferenceGraph IG;                 // Interference graph - constructed by
42                                         // buildInterferenceGraph
43   std::stack<IGNode *> IGNodeStack;     // the stack used for coloring
44
45   const ReservedColorListType *const ReservedColorList;
46   //
47   // for passing registers that are pre-allocated and cannot be used by the
48   // register allocator for this function.
49   
50   bool *IsColorUsedArr;
51   //
52   // An array used for coloring each node. This array must be of size 
53   // MRC->getNumOfAllRegs(). Allocated once in the constructor
54   // for efficiency.
55
56
57   //--------------------------- private methods ------------------------------
58
59   void pushAllIGNodes();
60
61   bool  pushUnconstrainedIGNodes();
62
63   IGNode * getIGNodeWithMinSpillCost();
64
65   void colorIGNode(IGNode *const Node);
66
67
68  public:
69
70   RegClass(const Function *M,
71            const MachineRegClassInfo *MRC,
72            const ReservedColorListType *RCL = 0);
73
74   ~RegClass() { delete[] IsColorUsedArr; }
75
76   inline void createInterferenceGraph() { IG.createGraph(); }
77
78   inline InterferenceGraph &getIG() { return IG; }
79
80   inline const unsigned getID() const { return RegClassID; }
81
82   // main method called for coloring regs
83   //
84   void colorAllRegs();                 
85
86   inline unsigned getNumOfAvailRegs() const 
87     { return MRC->getNumOfAvailRegs(); }
88
89
90   // --- following methods are provided to access the IG contained within this
91   // ---- RegClass easilly.
92
93   inline void addLRToIG(LiveRange *const LR) 
94     { IG.addLRToIG(LR); }
95
96   inline void setInterference(const LiveRange *const LR1,
97                               const LiveRange *const LR2)  
98     { IG.setInterference(LR1, LR2); }
99
100   inline unsigned getInterference(const LiveRange *const LR1,
101                               const LiveRange *const LR2) const 
102     { return IG.getInterference(LR1, LR2); }
103
104   inline void mergeIGNodesOfLRs(const LiveRange *const LR1,
105                                 LiveRange *const LR2) 
106     { IG.mergeIGNodesOfLRs(LR1, LR2); }
107
108
109   inline bool * getIsColorUsedArr() { return IsColorUsedArr; }
110
111
112   inline void printIGNodeList() const {
113     std::cerr << "IG Nodes for Register Class " << RegClassID << ":" << "\n";
114     IG.printIGNodeList(); 
115   }
116
117   inline void printIG() {  
118     std::cerr << "IG for Register Class " << RegClassID << ":" << "\n";
119     IG.printIG(); 
120   }
121 };
122
123 #endif