--changed Sugesting colors for method calls/return values etc.
[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 MachineInstr *const CallI, 
124                         LiveRangeInfo& LRI, vector<RegClass *> RCL) const = 0;
125
126   virtual void suggestReg4RetValue(const MachineInstr *const RetI, 
127                                    LiveRangeInfo& LRI) const = 0;
128
129   virtual void colorMethodArgs(const Method *const Meth,  LiveRangeInfo& LRI,
130                        AddedInstrns *const FirstAI) const = 0;
131
132   virtual void colorCallArgs(const MachineInstr *const CalI, 
133                              LiveRangeInfo& LRI,
134                              AddedInstrns *const CallAI) const = 0;
135
136   virtual void colorRetValue(const MachineInstr *const RetI,LiveRangeInfo& LRI,
137                              AddedInstrns *const RetAI) const = 0;
138
139
140
141   //virtual bool handleSpecialMInstr(const MachineInstr * MInst, 
142   //                   LiveRangeInfo& LRI,  vector<RegClass *> RCL) const  = 0;
143  
144   // returns the reg used for pushing the address when a method is called.
145   // This can be used for other purposes between calls
146   virtual unsigned getCallAddressReg() const = 0;
147
148   // and when we return from a method. It should be made sure that this 
149   // register contains the return value when a return instruction is reached.
150   virtual unsigned getReturnAddressReg() const = 0; 
151   
152   virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
153
154   virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
155
156   //virtual void printReg(const LiveRange *const LR) const =0;
157
158   MachineRegInfo() { }
159
160 };
161
162
163
164
165 #endif
166
167
168
169 #if 0
170
171 //---------------------------------------------------------------------------
172 // class MachineRegInfo
173 // 
174 // Purpose:
175 //   Interface to register info of target machine
176 // 
177 //--------------------------------------------------------------------------
178
179
180
181 typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
182
183 // A vector of all machine register classes
184 typedef vector<const MachineRegClassInfo *> MachineRegClassArrayType;
185
186
187 class MachineRegInfo : public NonCopyableV {
188
189 protected:
190
191   MachineRegClassArrayType MachineRegClassArr;
192
193
194 public:
195
196  MachineRegInfo() {}
197   
198   // According the definition of a MachineOperand class, a Value in a
199   // machine instruction can go into either a normal register or a 
200   // condition code register. If isCCReg is true below, the ID of the condition
201   // code regiter class will be returned. Otherwise, the normal register
202   // class (eg. int, float) must be returned.
203   virtual unsigned getRegClassIDOfValue (const Value *const Val,
204                                          bool isCCReg = false) const =0;
205
206
207   // returns the register that is hardwired to zero if any (-1 if none)
208   virtual inline int      getZeroRegNum()     const = 0;
209   
210   inline unsigned int getNumOfRegClasses() const { 
211     return MachineRegClassArr.size(); 
212   }  
213
214   const MachineRegClassInfo *const getMachineRegClass(unsigned i) const { 
215     return MachineRegClassArr[i]; 
216   }
217
218
219
220   //virtual unsigned getRegClassIDOfValue (const Value *const Val) const = 0;
221   // this method must give the exact register class of a machine operand
222   // e.g, Int, Float, Int CC, Float CC 
223   //virtual unsigned getRCIDOfMachineOp (const MachineOperand &MO) const = 0;
224
225
226   virtual void colorArgs(const Method *const Meth, 
227                          LiveRangeInfo & LRI) const = 0;
228
229   virtual void colorCallArgs(vector<const Instruction *> & CallInstrList, 
230                              LiveRangeInfo& LRI, 
231                              AddedInstrMapType& AddedInstrMap ) const = 0 ;
232
233   virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
234
235   virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
236
237   //virtual void printReg(const LiveRange *const LR) const =0;
238 };
239
240
241 #endif
242
243
244
245
246
247