PhyRegAlloc.cpp: Added temp area resetting before every call
[oota-llvm.git] / lib / Target / SparcV9 / 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/IGNode.h"
12 #include "llvm/CodeGen/InterferenceGraph.h"
13 #include "llvm/Target/TargetMachine.h"
14 #include "llvm/Target/MachineRegInfo.h"
15 #include <stack>
16
17 typedef vector<unsigned int> ReservedColorListType;
18
19
20 //-----------------------------------------------------------------------------
21 // Class RegClass
22 //
23 //   Implements a machine independant register class. 
24 //
25 //   This is the class that contains all data structures and common algos
26 //   for coloring a particular register class (e.g., int class, fp class).  
27 //   This class is hardware independent. This class accepts a hardware 
28 //   dependent description of machine registers (MachineRegInfo class) to 
29 //   get hardware specific info and to color an individual IG node.
30 //
31 //   This class contains the InterferenceGraph (IG).
32 //   Also it contains an IGNode stack that can be used for coloring. 
33 //   The class provides some easy access methods to the IG methods, since these
34 //   methods are called thru a register class.
35 //
36 //-----------------------------------------------------------------------------
37 class RegClass
38 {
39
40  private:
41   const Method *const Meth;             // Method we are working on
42
43   const MachineRegClassInfo *const MRC; // corresponding MRC
44
45   const unsigned RegClassID;            // my int ID
46
47   InterferenceGraph IG;                 // Interference graph - constructed by
48                                         // buildInterferenceGraph
49   stack <IGNode *> IGNodeStack;         // the stack used for coloring
50
51   const ReservedColorListType *const ReservedColorList;
52   //
53   // for passing registers that are pre-allocated and cannot be used by the
54   // register allocator for this method.
55   
56   bool *IsColorUsedArr;
57   //
58   // An array used for coloring each node. This array must be of size 
59   // MRC->getNumOfAllRegs(). Allocated once in the constructor
60   // for efficiency.
61
62
63   //--------------------------- private methods ------------------------------
64
65   void pushAllIGNodes();
66
67   bool  pushUnconstrainedIGNodes();
68
69   IGNode * getIGNodeWithMinSpillCost();
70
71   void colorIGNode(IGNode *const Node);
72
73
74  public:
75
76   RegClass(const Method *const M, 
77            const MachineRegClassInfo *const MRC, 
78            const ReservedColorListType *const RCL = NULL);
79
80   ~RegClass() { delete[] IsColorUsedArr; };
81
82   inline void createInterferenceGraph() 
83     { IG.createGraph(); }
84
85   inline InterferenceGraph &getIG() { return IG; }
86
87   inline const unsigned getID() const { return RegClassID; }
88
89   // main method called for coloring regs
90   //
91   void colorAllRegs();                 
92
93   inline unsigned getNumOfAvailRegs() const 
94     { return MRC->getNumOfAvailRegs(); }
95
96
97   // --- following methods are provided to access the IG contained within this
98   // ---- RegClass easilly.
99
100   inline void addLRToIG(LiveRange *const LR) 
101     { IG.addLRToIG(LR); }
102
103   inline void setInterference(const LiveRange *const LR1,
104                               const LiveRange *const LR2)  
105     { IG.setInterference(LR1, LR2); }
106
107   inline unsigned getInterference(const LiveRange *const LR1,
108                               const LiveRange *const LR2) const 
109     { return IG.getInterference(LR1, LR2); }
110
111   inline void mergeIGNodesOfLRs(const LiveRange *const LR1,
112                                 LiveRange *const LR2) 
113     { IG.mergeIGNodesOfLRs(LR1, LR2); }
114
115
116   inline bool * getIsColorUsedArr() { return IsColorUsedArr; }
117
118
119   inline void printIGNodeList() const {
120     cerr << "IG Nodes for Register Class " << RegClassID << ":" << endl;
121     IG.printIGNodeList(); 
122   }
123
124   inline void printIG() {  
125     cerr << "IG for Register Class " << RegClassID << ":" << endl;
126     IG.printIG(); 
127   }
128
129 };
130
131
132
133
134
135
136
137 #endif