Create a new #include "Support/..." directory structure to move things
[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 "Support/NonCopyable.h"
12 #include <hash_map>
13 #include <string>
14
15 class TargetMachine;
16 class IGNode;
17 class Value;
18 class LiveRangeInfo;
19 class Method;
20 class Instruction;
21 class LiveRange;
22 class AddedInstrns;
23 class MachineInstr;
24 class RegClass;
25 class CallInst;
26 class ReturnInst;
27 class PhyRegAlloc;
28 class BasicBlock;
29
30 //-----------------------------------------------------------------------------
31 // class MachineRegClassInfo
32 // 
33 // Purpose:
34 //   Interface to description of machine register class (e.g., int reg class
35 //   float reg class etc)
36 // 
37 //--------------------------------------------------------------------------
38
39
40 class MachineRegClassInfo {
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 public:
87   const TargetMachine& target;
88
89 protected:
90
91   MachineRegClassArrayType MachineRegClassArr;    
92   
93 public:
94
95
96   // According the definition of a MachineOperand class, a Value in a
97   // machine instruction can go into either a normal register or a 
98   // condition code register. If isCCReg is true below, the ID of the condition
99   // code regiter class will be returned. Otherwise, the normal register
100   // class (eg. int, float) must be returned.
101   virtual unsigned getRegClassIDOfValue (const Value *const Val,
102                                          bool isCCReg = false) const =0;
103
104
105   inline unsigned int getNumOfRegClasses() const { 
106     return MachineRegClassArr.size(); 
107   }  
108
109   const MachineRegClassInfo *const getMachineRegClass(unsigned i) const { 
110     return MachineRegClassArr[i]; 
111   }
112
113   // returns the register that is hardwired to zero if any (-1 if none)
114   virtual inline int      getZeroRegNum()     const = 0;
115
116   //virtual unsigned getRegClassIDOfValue (const Value *const Val) const = 0;
117   // this method must give the exact register class of a machine operand
118   // e.g, Int, Float, Int CC, Float CC 
119   //virtual unsigned getRCIDOfMachineOp (const MachineOperand &MO) const = 0;
120
121
122   virtual void suggestRegs4MethodArgs(const Method *const Meth, 
123                          LiveRangeInfo & LRI) const = 0;
124
125   virtual void suggestRegs4CallArgs(const MachineInstr *const CallI, 
126                         LiveRangeInfo& LRI, vector<RegClass *> RCL) const = 0;
127
128   virtual void suggestReg4RetValue(const MachineInstr *const RetI, 
129                                    LiveRangeInfo& LRI) const = 0;
130
131   virtual void colorMethodArgs(const Method *const Meth,  LiveRangeInfo& LRI,
132                        AddedInstrns *const FirstAI) const = 0;
133
134   virtual void colorCallArgs(const MachineInstr *const CalI, 
135                              LiveRangeInfo& LRI, AddedInstrns *const CallAI, 
136                              PhyRegAlloc &PRA) const = 0;
137
138   virtual void colorRetValue(const MachineInstr *const RetI,LiveRangeInfo& LRI,
139                              AddedInstrns *const RetAI) const = 0;
140
141
142
143   virtual MachineInstr * 
144   cpReg2RegMI(const unsigned SrcReg, const unsigned DestReg,
145               const int RegType) const=0;
146
147   virtual MachineInstr * 
148   cpReg2MemMI(const unsigned SrcReg, const unsigned DestPtrReg,
149                const int Offset, const int RegType) const=0;
150
151   virtual MachineInstr *
152    cpMem2RegMI(const unsigned SrcPtrReg, const int Offset,
153                const unsigned DestReg, const int RegType) const=0;
154
155   virtual MachineInstr *cpValue2Value( Value *Src, Value *Dest) const=0;
156
157
158   virtual bool isRegVolatile(const int RegClassID, const int Reg) const=0;
159
160
161
162   //virtual bool handleSpecialMInstr(const MachineInstr * MInst, 
163   //                   LiveRangeInfo& LRI,  vector<RegClass *> RCL) const  = 0;
164  
165   // returns the reg used for pushing the address when a method is called.
166   // This can be used for other purposes between calls
167   virtual unsigned getCallAddressReg() const = 0;
168
169   // and when we return from a method. It should be made sure that this 
170   // register contains the return value when a return instruction is reached.
171   virtual unsigned getReturnAddressReg() const = 0; 
172   
173   virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
174
175   virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
176
177   virtual int getRegType(const LiveRange *const LR) const=0;
178
179   virtual const Value * getCallInstRetVal(const MachineInstr *CallMI) const=0;
180
181   inline virtual unsigned getFramePointer() const=0;
182
183   inline virtual unsigned getStackPointer() const=0;
184
185   inline virtual int getInvalidRegNum() const=0;
186
187
188   virtual void insertCallerSavingCode(const MachineInstr *MInst, 
189                                       const BasicBlock *BB, 
190                                       PhyRegAlloc &PRA ) const = 0;
191
192
193   //virtual void printReg(const LiveRange *const LR) const =0;
194
195   MachineRegInfo(const TargetMachine& tgt) : target(tgt) { }
196
197 };
198
199
200
201
202 #endif
203
204
205
206 #if 0
207
208 //---------------------------------------------------------------------------
209 // class MachineRegInfo
210 // 
211 // Purpose:
212 //   Interface to register info of target machine
213 // 
214 //--------------------------------------------------------------------------
215
216
217
218 typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
219
220 // A vector of all machine register classes
221 typedef vector<const MachineRegClassInfo *> MachineRegClassArrayType;
222
223
224 class MachineRegInfo : public NonCopyableV {
225
226 protected:
227
228   MachineRegClassArrayType MachineRegClassArr;
229
230
231 public:
232
233  MachineRegInfo() {}
234   
235   // According the definition of a MachineOperand class, a Value in a
236   // machine instruction can go into either a normal register or a 
237   // condition code register. If isCCReg is true below, the ID of the condition
238   // code regiter class will be returned. Otherwise, the normal register
239   // class (eg. int, float) must be returned.
240   virtual unsigned getRegClassIDOfValue (const Value *const Val,
241                                          bool isCCReg = false) const =0;
242
243
244   // returns the register that is hardwired to zero if any (-1 if none)
245   virtual inline int      getZeroRegNum()     const = 0;
246   
247   inline unsigned int getNumOfRegClasses() const { 
248     return MachineRegClassArr.size(); 
249   }  
250
251   const MachineRegClassInfo *const getMachineRegClass(unsigned i) const { 
252     return MachineRegClassArr[i]; 
253   }
254
255
256
257   //virtual unsigned getRegClassIDOfValue (const Value *const Val) const = 0;
258   // this method must give the exact register class of a machine operand
259   // e.g, Int, Float, Int CC, Float CC 
260   //virtual unsigned getRCIDOfMachineOp (const MachineOperand &MO) const = 0;
261
262
263   virtual void colorArgs(const Method *const Meth, 
264                          LiveRangeInfo & LRI) const = 0;
265
266   virtual void colorCallArgs(vector<const Instruction *> & CallInstrList, 
267                              LiveRangeInfo& LRI, 
268                              AddedInstrMapType& AddedInstrMap ) const = 0 ;
269
270   virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
271
272   virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
273
274   //virtual void printReg(const LiveRange *const LR) const =0;
275 };
276
277
278 #endif
279
280
281
282
283
284