Moved callerSaving code to machine specific classes since we have to handle
[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 class PhyRegAlloc;
27 class BasicBlock;
28
29 //-----------------------------------------------------------------------------
30 // class MachineRegClassInfo
31 // 
32 // Purpose:
33 //   Interface to description of machine register class (e.g., int reg class
34 //   float reg class etc)
35 // 
36 //--------------------------------------------------------------------------
37
38
39 class MachineRegClassInfo {
40
41 protected:
42   
43   const unsigned RegClassID;        // integer ID of a reg class
44   const unsigned NumOfAvailRegs;    // # of avail for coloring -without SP etc.
45   const unsigned NumOfAllRegs;      // # of all registers -including SP,g0 etc.
46   
47 public:
48   
49   inline unsigned getRegClassID()     const { return RegClassID; }
50   inline unsigned getNumOfAvailRegs() const { return NumOfAvailRegs; }
51   inline unsigned getNumOfAllRegs()   const { return NumOfAllRegs; }
52
53
54
55   // This method should find a color which is not used by neighbors
56   // (i.e., a false position in IsColorUsedArr) and 
57   virtual void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const = 0;
58   virtual bool isRegVolatile(const int Reg) const = 0;
59
60   MachineRegClassInfo(const unsigned ID, const unsigned NVR, 
61                       const unsigned NAR): RegClassID(ID), NumOfAvailRegs(NVR),
62                                              NumOfAllRegs(NAR)
63   { }                         // empty constructor
64
65 };
66
67
68
69 //---------------------------------------------------------------------------
70 // class MachineRegInfo
71 // 
72 // Purpose:
73 //   Interface to register info of target machine
74 // 
75 //--------------------------------------------------------------------------
76
77
78
79 typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
80
81 // A vector of all machine register classes
82 typedef vector<const MachineRegClassInfo *> MachineRegClassArrayType;
83
84
85 class MachineRegInfo : public NonCopyableV {
86
87 protected:
88
89   MachineRegClassArrayType MachineRegClassArr;    
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, AddedInstrns *const CallAI, 
134                              PhyRegAlloc &PRA) const = 0;
135
136   virtual void colorRetValue(const MachineInstr *const RetI,LiveRangeInfo& LRI,
137                              AddedInstrns *const RetAI) const = 0;
138
139
140
141   virtual MachineInstr * 
142   cpReg2RegMI(const unsigned SrcReg, const unsigned DestReg,
143               const int RegType) const=0;
144
145    virtual MachineInstr * 
146    cpReg2MemMI(const unsigned SrcReg, const unsigned DestPtrReg,
147                const int Offset, const int RegType) const=0;
148
149    virtual MachineInstr *
150    cpMem2RegMI(const unsigned SrcPtrReg, const int Offset,
151                const unsigned DestReg, const int RegType) const=0;
152
153   virtual bool isRegVolatile(const int RegClassID, const int Reg) const=0;
154
155
156
157   //virtual bool handleSpecialMInstr(const MachineInstr * MInst, 
158   //                   LiveRangeInfo& LRI,  vector<RegClass *> RCL) const  = 0;
159  
160   // returns the reg used for pushing the address when a method is called.
161   // This can be used for other purposes between calls
162   virtual unsigned getCallAddressReg() const = 0;
163
164   // and when we return from a method. It should be made sure that this 
165   // register contains the return value when a return instruction is reached.
166   virtual unsigned getReturnAddressReg() const = 0; 
167   
168   virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
169
170   virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
171
172   virtual int getRegType(const LiveRange *const LR) const=0;
173
174   virtual const Value * getCallInstRetVal(const MachineInstr *CallMI) const=0;
175
176   inline virtual unsigned getFramePointer() const=0;
177
178   inline virtual unsigned getStackPointer() const=0;
179
180   inline virtual int getInvalidRegNum() const=0;
181
182
183   virtual void insertCallerSavingCode(const MachineInstr *MInst, 
184                                       const BasicBlock *BB, 
185                                       PhyRegAlloc &PRA ) const = 0;
186
187
188   //virtual void printReg(const LiveRange *const LR) const =0;
189
190   MachineRegInfo() { }
191
192 };
193
194
195
196
197 #endif
198
199
200
201 #if 0
202
203 //---------------------------------------------------------------------------
204 // class MachineRegInfo
205 // 
206 // Purpose:
207 //   Interface to register info of target machine
208 // 
209 //--------------------------------------------------------------------------
210
211
212
213 typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
214
215 // A vector of all machine register classes
216 typedef vector<const MachineRegClassInfo *> MachineRegClassArrayType;
217
218
219 class MachineRegInfo : public NonCopyableV {
220
221 protected:
222
223   MachineRegClassArrayType MachineRegClassArr;
224
225
226 public:
227
228  MachineRegInfo() {}
229   
230   // According the definition of a MachineOperand class, a Value in a
231   // machine instruction can go into either a normal register or a 
232   // condition code register. If isCCReg is true below, the ID of the condition
233   // code regiter class will be returned. Otherwise, the normal register
234   // class (eg. int, float) must be returned.
235   virtual unsigned getRegClassIDOfValue (const Value *const Val,
236                                          bool isCCReg = false) const =0;
237
238
239   // returns the register that is hardwired to zero if any (-1 if none)
240   virtual inline int      getZeroRegNum()     const = 0;
241   
242   inline unsigned int getNumOfRegClasses() const { 
243     return MachineRegClassArr.size(); 
244   }  
245
246   const MachineRegClassInfo *const getMachineRegClass(unsigned i) const { 
247     return MachineRegClassArr[i]; 
248   }
249
250
251
252   //virtual unsigned getRegClassIDOfValue (const Value *const Val) const = 0;
253   // this method must give the exact register class of a machine operand
254   // e.g, Int, Float, Int CC, Float CC 
255   //virtual unsigned getRCIDOfMachineOp (const MachineOperand &MO) const = 0;
256
257
258   virtual void colorArgs(const Method *const Meth, 
259                          LiveRangeInfo & LRI) const = 0;
260
261   virtual void colorCallArgs(vector<const Instruction *> & CallInstrList, 
262                              LiveRangeInfo& LRI, 
263                              AddedInstrMapType& AddedInstrMap ) const = 0 ;
264
265   virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
266
267   virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
268
269   //virtual void printReg(const LiveRange *const LR) const =0;
270 };
271
272
273 #endif
274
275
276
277
278
279