Changes to build successfully with GCC 3.02
[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 <ext/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 std::hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
80
81 // A vector of all machine register classes
82 //
83 typedef std::vector<const MachineRegClassInfo *> MachineRegClassArrayType;
84
85
86 class MachineRegInfo : public NonCopyableV {
87 public:
88   const TargetMachine& target;
89
90 protected:
91
92   MachineRegClassArrayType MachineRegClassArr;    
93   
94 public:
95
96   // empty constructor
97   //
98   MachineRegInfo(const TargetMachine& tgt) : target(tgt) { }
99
100
101   // According the definition of a MachineOperand class, a Value in a
102   // machine instruction can go into either a normal register or a 
103   // condition code register. If isCCReg is true below, the ID of the condition
104   // code regiter class will be returned. Otherwise, the normal register
105   // class (eg. int, float) must be returned.
106   virtual unsigned getRegClassIDOfValue (const Value *const Val,
107                                          bool isCCReg = false) const =0;
108
109
110   inline unsigned int getNumOfRegClasses() const { 
111     return MachineRegClassArr.size(); 
112   }  
113
114   const MachineRegClassInfo *const getMachineRegClass(unsigned i) const { 
115     return MachineRegClassArr[i]; 
116   }
117
118   // returns the register that is hardwired to zero if any (-1 if none)
119   //
120   virtual inline int  getZeroRegNum()  const = 0;
121
122
123   // The following methods are used to color special live ranges (e.g.
124   // method args and return values etc.) with specific hardware registers
125   // as required. See SparcRegInfo.cpp for the implementation for Sparc.
126   //
127   virtual void suggestRegs4MethodArgs(const Method *const Meth, 
128                          LiveRangeInfo & LRI) const = 0;
129
130   virtual void suggestRegs4CallArgs(const MachineInstr *const CallI, 
131                         LiveRangeInfo& LRI, std::vector<RegClass *> RCL) const = 0;
132
133   virtual void suggestReg4RetValue(const MachineInstr *const RetI, 
134                                    LiveRangeInfo& LRI) const = 0;
135
136   virtual void colorMethodArgs(const Method *const Meth,  LiveRangeInfo& LRI,
137                        AddedInstrns *const FirstAI) const = 0;
138
139   virtual void colorCallArgs(const MachineInstr *const CalI, 
140                              LiveRangeInfo& LRI, AddedInstrns *const CallAI, 
141                              PhyRegAlloc &PRA, const BasicBlock *BB) const = 0;
142
143   virtual void colorRetValue(const MachineInstr *const RetI,LiveRangeInfo& LRI,
144                              AddedInstrns *const RetAI) const = 0;
145
146
147
148   // The following methods are used to generate "copy" machine instructions
149   // for an architecture. Currently they are used in MachineRegClass 
150   // interface. However, they can be moved to MachineInstrInfo interface if
151   // necessary.
152   //
153   virtual MachineInstr * 
154   cpReg2RegMI(const unsigned SrcReg, const unsigned DestReg,
155               const int RegType) const=0;
156
157   virtual MachineInstr * 
158   cpReg2MemMI(const unsigned SrcReg, const unsigned DestPtrReg,
159                const int Offset, const int RegType) const=0;
160
161   virtual MachineInstr *
162    cpMem2RegMI(const unsigned SrcPtrReg, const int Offset,
163                const unsigned DestReg, const int RegType) const=0;
164
165   virtual MachineInstr *cpValue2Value( Value *Src, Value *Dest) const=0;
166
167   virtual bool isRegVolatile(const int RegClassID, const int Reg) const=0;
168
169
170
171  
172   // Returns the reg used for pushing the address when a method is called.
173   // This can be used for other purposes between calls
174   //
175   virtual unsigned getCallAddressReg() const = 0;
176
177   // Returns the register containing the return address.
178   //It should be made sure that this 
179   // register contains the return value when a return instruction is reached.
180   //
181   virtual unsigned getReturnAddressReg() const = 0; 
182   
183
184   // Each register class has a seperate space for register IDs. To convert
185   // a regId in a register class to a common Id, we use the folloing method(s)
186   //
187   virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
188
189   virtual const std::string getUnifiedRegName(int UnifiedRegNum) const = 0;
190
191
192   // Gives the type of a register based on the type of the LR
193   //
194   virtual int getRegType(const LiveRange *const LR) const=0;
195
196   // Gives the return value contained in a CALL machine instruction
197   //
198   virtual const Value * getCallInstRetVal(const MachineInstr *CallMI) const=0;
199
200   // The following methods are used to get the frame/stack pointers
201   // 
202   inline virtual unsigned getFramePointer() const=0;
203   inline virtual unsigned getStackPointer() const=0;
204
205   // A register can be initialized to an invalid number. That number can
206   // be obtained using this method.
207   //
208   inline virtual int getInvalidRegNum() const=0;
209
210
211   // Method for inserting caller saving code. The caller must save all the
212   // volatile registers across a call based on the calling conventions of
213   // an architecture. This must insert code for saving and restoring 
214   // such registers on
215   //
216   virtual void insertCallerSavingCode(const MachineInstr *MInst, 
217                                       const BasicBlock *BB, 
218                                       PhyRegAlloc &PRA ) const = 0;
219
220   // This method gives the the number of bytes of stack spaceallocated 
221   // to a register when it is spilled to the stack.
222   //
223   virtual inline int getSpilledRegSize(const int RegType) const = 0;
224
225
226
227 };
228
229
230
231
232 #endif
233
234
235
236