Convert RegClass::IsColorUsedArr from a dynamically allocated array to
[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 Type;
18 class Value;
19 class LiveRangeInfo;
20 class Function;
21 class Instruction;
22 class LiveRange;
23 class AddedInstrns;
24 class MachineInstr;
25 class RegClass;
26 class CallInst;
27 class ReturnInst;
28 class PhyRegAlloc;
29 class BasicBlock;
30
31 //-----------------------------------------------------------------------------
32 // class MachineRegClassInfo
33 // 
34 // Purpose:
35 //   Interface to description of machine register class (e.g., int reg class
36 //   float reg class etc)
37 // 
38 //--------------------------------------------------------------------------
39
40
41 class MachineRegClassInfo {
42 protected:
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   inline unsigned getRegClassID()     const { return RegClassID; }
49   inline unsigned getNumOfAvailRegs() const { return NumOfAvailRegs; }
50   inline unsigned getNumOfAllRegs()   const { return NumOfAllRegs; }
51
52   // This method should find a color which is not used by neighbors
53   // (i.e., a false position in IsColorUsedArr) and 
54   virtual void colorIGNode(IGNode *Node,
55                            std::vector<bool> &IsColorUsedArr) const = 0;
56   virtual bool isRegVolatile(int Reg) const = 0;
57
58   MachineRegClassInfo(unsigned ID, unsigned NVR, unsigned NAR)
59     : RegClassID(ID), NumOfAvailRegs(NVR), NumOfAllRegs(NAR) {}
60 };
61
62
63
64 //---------------------------------------------------------------------------
65 // class MachineRegInfo
66 // 
67 // Purpose:
68 //   Interface to register info of target machine
69 // 
70 //--------------------------------------------------------------------------
71
72 class MachineRegInfo : public NonCopyableV {
73 protected:
74   // A vector of all machine register classes
75   //
76   std::vector<const MachineRegClassInfo *> MachineRegClassArr;    
77   
78 public:
79   const TargetMachine &target;
80
81   MachineRegInfo(const TargetMachine& tgt) : target(tgt) { }
82   ~MachineRegInfo() {
83     for (unsigned i = 0, e = MachineRegClassArr.size(); i != e; ++i)
84       delete MachineRegClassArr[i];
85   }
86
87   // According the definition of a MachineOperand class, a Value in a
88   // machine instruction can go into either a normal register or a 
89   // condition code register. If isCCReg is true below, the ID of the condition
90   // code regiter class will be returned. Otherwise, the normal register
91   // class (eg. int, float) must be returned.
92   virtual unsigned getRegClassIDOfType  (const Type *type,
93                                          bool isCCReg = false) const =0;
94   virtual unsigned getRegClassIDOfValue (const Value *Val,
95                                          bool isCCReg = false) const =0;
96   
97
98   inline unsigned int getNumOfRegClasses() const { 
99     return MachineRegClassArr.size(); 
100   }  
101
102   const MachineRegClassInfo *getMachineRegClass(unsigned i) const { 
103     return MachineRegClassArr[i]; 
104   }
105
106   // returns the register that is hardwired to zero if any (-1 if none)
107   //
108   virtual int getZeroRegNum() const = 0;
109
110   // Number of registers used for passing int args (usually 6: %o0 - %o5)
111   // and float args (usually 32: %f0 - %f31)
112   //
113   virtual unsigned const GetNumOfIntArgRegs() const   = 0;
114   virtual unsigned const GetNumOfFloatArgRegs() const = 0;
115
116   // The following methods are used to color special live ranges (e.g.
117   // method args and return values etc.) with specific hardware registers
118   // as required. See SparcRegInfo.cpp for the implementation for Sparc.
119   //
120   virtual void suggestRegs4MethodArgs(const Function *Func, 
121                          LiveRangeInfo &LRI) const = 0;
122
123   virtual void suggestRegs4CallArgs(const MachineInstr *CallI, 
124                         LiveRangeInfo &LRI, std::vector<RegClass *> RCL) const = 0;
125
126   virtual void suggestReg4RetValue(const MachineInstr *RetI, 
127                                    LiveRangeInfo &LRI) const = 0;
128
129   virtual void colorMethodArgs(const Function *Func,  LiveRangeInfo &LRI,
130                                AddedInstrns *FirstAI) const = 0;
131
132   virtual void colorCallArgs(const MachineInstr *CalI, 
133                              LiveRangeInfo& LRI, AddedInstrns *CallAI, 
134                              PhyRegAlloc &PRA, const BasicBlock *BB) const = 0;
135
136   virtual void colorRetValue(const MachineInstr *RetI, LiveRangeInfo &LRI,
137                              AddedInstrns *RetAI) const = 0;
138
139
140
141   // The following methods are used to generate "copy" machine instructions
142   // for an architecture. Currently they are used in MachineRegClass 
143   // interface. However, they can be moved to MachineInstrInfo interface if
144   // necessary.
145   //
146   virtual void cpReg2RegMI(unsigned SrcReg, unsigned DestReg,
147                            int RegType, vector<MachineInstr*>& mvec) const = 0;
148
149   virtual void cpReg2MemMI(unsigned SrcReg, unsigned DestPtrReg, int Offset,
150                            int RegTypee, vector<MachineInstr*>& mvec) const=0;
151
152   virtual void cpMem2RegMI(unsigned SrcPtrReg, int Offset, unsigned DestReg,
153                            int RegTypee, vector<MachineInstr*>& mvec) const=0;
154
155   virtual void cpValue2Value(Value *Src, Value *Dest,
156                              vector<MachineInstr*>& mvec) const = 0;
157
158   virtual bool isRegVolatile(int RegClassID, int Reg) 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   //
163   virtual unsigned getCallAddressReg() const = 0;
164
165   // Returns the register containing the return address.
166   //It should be made sure that this 
167   // register contains the return value when a return instruction is reached.
168   //
169   virtual unsigned getReturnAddressReg() const = 0; 
170   
171
172   // Each register class has a seperate space for register IDs. To convert
173   // a regId in a register class to a common Id, we use the folloing method(s)
174   //
175   virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
176
177   virtual const std::string getUnifiedRegName(int UnifiedRegNum) const = 0;
178
179
180   // The following 4 methods are used to find the RegType (see enum above)
181   // of a LiveRange, Value and using the unified RegClassID
182   //
183   virtual int getRegType(unsigned regClassID, const Type* type) const = 0;
184   virtual int getRegType(const LiveRange *LR) const = 0;
185   virtual int getRegType(const Value *Val) const = 0;
186   virtual int getRegType(int reg) const = 0;
187
188   
189   // The following methods are used to get the frame/stack pointers
190   // 
191   virtual unsigned getFramePointer() const = 0;
192   virtual unsigned getStackPointer() const = 0;
193
194   // A register can be initialized to an invalid number. That number can
195   // be obtained using this method.
196   //
197   virtual int getInvalidRegNum() const = 0;
198
199
200   // Method for inserting caller saving code. The caller must save all the
201   // volatile registers across a call based on the calling conventions of
202   // an architecture. This must insert code for saving and restoring 
203   // such registers on
204   //
205   virtual void insertCallerSavingCode(const MachineInstr *MInst, 
206                                       const BasicBlock *BB, 
207                                       PhyRegAlloc &PRA) const = 0;
208
209   // This method gives the the number of bytes of stack spaceallocated 
210   // to a register when it is spilled to the stack.
211   //
212   virtual int getSpilledRegSize(int RegType) const = 0;
213 };
214
215 #endif