More renamings of Target/Machine*Info to Target/Target*Info
[oota-llvm.git] / include / llvm / CodeGen / 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/TargetRegInfo.h"
13 #include <stack>
14 class TargetRegClassInfo;
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 (TargetRegInfo 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 TargetRegClassInfo *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   // ReservedColorList - for passing registers that are pre-allocated and cannot
46   // be used by the register allocator for this function.
47   //
48   const ReservedColorListType *const ReservedColorList;
49   
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.
53   //
54   std::vector<bool> IsColorUsedArr;
55
56
57
58   //--------------------------- private methods ------------------------------
59
60   void pushAllIGNodes();
61
62   bool  pushUnconstrainedIGNodes();
63
64   IGNode * getIGNodeWithMinSpillCost();
65
66   void colorIGNode(IGNode *const Node);
67
68
69  public:
70
71   RegClass(const Function *M,
72            const TargetRegClassInfo *MRC,
73            const ReservedColorListType *RCL = 0);
74
75   inline void createInterferenceGraph() { IG.createGraph(); }
76
77   inline InterferenceGraph &getIG() { return IG; }
78
79   inline const unsigned getID() const { return RegClassID; }
80
81   // main method called for coloring regs
82   //
83   void colorAllRegs();                 
84
85   inline unsigned getNumOfAvailRegs() const 
86     { return MRC->getNumOfAvailRegs(); }
87
88
89   // --- following methods are provided to access the IG contained within this
90   // ---- RegClass easilly.
91
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
108   inline std::vector<bool> &getIsColorUsedArr() { return IsColorUsedArr; }
109
110
111   void printIGNodeList() const;
112   void printIG();
113 };
114
115 #endif