added suggesting color suppor
[oota-llvm.git] / include / llvm / Target / TargetRegInfo.h
1 //===-- llvm/Target/RegInfo.h - Target Register Information ------*- C++ -*-==//
2 //
3 // This file is used to describe the register system of a target to the
4 // register allocator.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LLVM_TARGET_MACHINEREGINFO_H
9 #define LLVM_TARGET_MACHINEREGINFO_H
10
11 #include "llvm/Support/NonCopyable.h"
12 #include <hash_map>
13 #include <string>
14
15 class IGNode;
16 class Value;
17 class LiveRangeInfo;
18 class Method;
19 class Instruction;
20 class LiveRange;
21 class AddedInstrns;
22 class MachineInstr;
23 class RegClass;
24 class CallInst;
25 class ReturnInst;
26
27
28 //-----------------------------------------------------------------------------
29 // class MachineRegClassInfo
30 // 
31 // Purpose:
32 //   Interface to description of machine register class (e.g., int reg class
33 //   float reg class etc)
34 // 
35 //--------------------------------------------------------------------------
36
37
38 class MachineRegClassInfo {
39
40 protected:
41   
42   const unsigned RegClassID;        // integer ID of a reg class
43   const unsigned NumOfAvailRegs;    // # of avail for coloring -without SP etc.
44   const unsigned NumOfAllRegs;      // # of all registers -including SP,g0 etc.
45   
46 public:
47   
48   inline unsigned getRegClassID()     const { return RegClassID; }
49   inline unsigned getNumOfAvailRegs() const { return NumOfAvailRegs; }
50   inline unsigned getNumOfAllRegs()   const { return NumOfAllRegs; }
51
52
53
54   // This method should find a color which is not used by neighbors
55   // (i.e., a false position in IsColorUsedArr) and 
56   virtual void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const = 0;
57
58
59   MachineRegClassInfo(const unsigned ID, const unsigned NVR, 
60                       const unsigned NAR): RegClassID(ID), NumOfAvailRegs(NVR),
61                                              NumOfAllRegs(NAR)
62   { }                         // empty constructor
63
64 };
65
66
67
68 //---------------------------------------------------------------------------
69 // class MachineRegInfo
70 // 
71 // Purpose:
72 //   Interface to register info of target machine
73 // 
74 //--------------------------------------------------------------------------
75
76
77
78 typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
79
80 // A vector of all machine register classes
81 typedef vector<const MachineRegClassInfo *> MachineRegClassArrayType;
82
83
84 class MachineRegInfo : public NonCopyableV {
85
86 protected:
87
88   MachineRegClassArrayType MachineRegClassArr;    
89
90   
91 public:
92
93
94   // According the definition of a MachineOperand class, a Value in a
95   // machine instruction can go into either a normal register or a 
96   // condition code register. If isCCReg is true below, the ID of the condition
97   // code regiter class will be returned. Otherwise, the normal register
98   // class (eg. int, float) must be returned.
99   virtual unsigned getRegClassIDOfValue (const Value *const Val,
100                                          bool isCCReg = false) const =0;
101
102
103   inline unsigned int getNumOfRegClasses() const { 
104     return MachineRegClassArr.size(); 
105   }  
106
107   const MachineRegClassInfo *const getMachineRegClass(unsigned i) const { 
108     return MachineRegClassArr[i]; 
109   }
110
111   // returns the register that is hardwired to zero if any (-1 if none)
112   virtual inline int      getZeroRegNum()     const = 0;
113
114   //virtual unsigned getRegClassIDOfValue (const Value *const Val) const = 0;
115   // this method must give the exact register class of a machine operand
116   // e.g, Int, Float, Int CC, Float CC 
117   //virtual unsigned getRCIDOfMachineOp (const MachineOperand &MO) const = 0;
118
119
120   virtual void suggestRegs4MethodArgs(const Method *const Meth, 
121                          LiveRangeInfo & LRI) const = 0;
122
123   virtual void suggestRegs4CallArgs(const CallInst *const CallI, 
124                         LiveRangeInfo& LRI, vector<RegClass *> RCL) const = 0;
125
126   virtual void suggestReg4RetValue(const ReturnInst *const RetI, 
127                                    LiveRangeInfo& LRI) const = 0;
128
129
130
131   virtual void colorMethodArgs(const Method *const Meth,  LiveRangeInfo& LRI,
132                        AddedInstrns *const FirstAI) const = 0;
133
134   virtual void colorCallArgs(const CallInst *const CalI, LiveRangeInfo& LRI,
135                      AddedInstrns *const CallAI) const = 0;
136
137   virtual void colorRetValue(const ReturnInst *const RetI, LiveRangeInfo& LRI,
138                      AddedInstrns *const RetAI) const = 0;
139
140
141
142   virtual bool handleSpecialMInstr(const MachineInstr * MInst, 
143                        LiveRangeInfo& LRI,  vector<RegClass *> RCL) const  = 0;
144  
145   // returns the reg used for pushing the address when a method is called.
146   // This can be used for other purposes between calls
147   virtual unsigned getCallAddressReg() const = 0;
148
149   // and when we return from a method. It should be made sure that this 
150   // register contains the return value when a return instruction is reached.
151   virtual unsigned getReturnAddressReg() const = 0; 
152   
153   virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
154
155   virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
156
157   //virtual void printReg(const LiveRange *const LR) const =0;
158
159   MachineRegInfo() { }
160
161 };
162
163
164
165
166 #endif
167
168
169
170 #if 0
171
172 //---------------------------------------------------------------------------
173 // class MachineRegInfo
174 // 
175 // Purpose:
176 //   Interface to register info of target machine
177 // 
178 //--------------------------------------------------------------------------
179
180
181
182 typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
183
184 // A vector of all machine register classes
185 typedef vector<const MachineRegClassInfo *> MachineRegClassArrayType;
186
187
188 class MachineRegInfo : public NonCopyableV {
189
190 protected:
191
192   MachineRegClassArrayType MachineRegClassArr;
193
194
195 public:
196
197  MachineRegInfo() {}
198   
199   // According the definition of a MachineOperand class, a Value in a
200   // machine instruction can go into either a normal register or a 
201   // condition code register. If isCCReg is true below, the ID of the condition
202   // code regiter class will be returned. Otherwise, the normal register
203   // class (eg. int, float) must be returned.
204   virtual unsigned getRegClassIDOfValue (const Value *const Val,
205                                          bool isCCReg = false) const =0;
206
207
208   // returns the register that is hardwired to zero if any (-1 if none)
209   virtual inline int      getZeroRegNum()     const = 0;
210   
211   inline unsigned int getNumOfRegClasses() const { 
212     return MachineRegClassArr.size(); 
213   }  
214
215   const MachineRegClassInfo *const getMachineRegClass(unsigned i) const { 
216     return MachineRegClassArr[i]; 
217   }
218
219
220
221   //virtual unsigned getRegClassIDOfValue (const Value *const Val) const = 0;
222   // this method must give the exact register class of a machine operand
223   // e.g, Int, Float, Int CC, Float CC 
224   //virtual unsigned getRCIDOfMachineOp (const MachineOperand &MO) const = 0;
225
226
227   virtual void colorArgs(const Method *const Meth, 
228                          LiveRangeInfo & LRI) const = 0;
229
230   virtual void colorCallArgs(vector<const Instruction *> & CallInstrList, 
231                              LiveRangeInfo& LRI, 
232                              AddedInstrMapType& AddedInstrMap ) const = 0 ;
233
234   virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
235
236   virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
237
238   //virtual void printReg(const LiveRange *const LR) const =0;
239 };
240
241
242 #endif
243
244
245
246
247
248