Include SparcV9RegInfo.h instead of TargetRegInfo.h.
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9RegInfo.h
1 //===-- SparcV9RegInfo.h - Define TargetRegInfo for SparcV9 ---------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This class implements the virtual class TargetRegInfo for SparcV9.
11 //
12 //----------------------------------------------------------------------------
13
14 #ifndef SPARCV9REGINFO_H
15 #define SPARCV9REGINFO_H
16
17 #include "llvm/Target/TargetRegInfo.h"
18
19 namespace llvm {
20
21 class SparcV9TargetMachine;
22
23 class SparcV9RegInfo : public TargetRegInfo {
24 private:
25   // Number of registers used for passing int args (usually 6: %o0 - %o5)
26   //
27   unsigned const NumOfIntArgRegs;
28
29   // Number of registers used for passing float args (usually 32: %f0 - %f31)
30   //
31   unsigned const NumOfFloatArgRegs;
32
33   // The following methods are used to color special live ranges (e.g.
34   // function args and return values etc.) with specific hardware registers
35   // as required. See SparcV9RegInfo.cpp for the implementation.
36   //
37   void suggestReg4RetAddr(MachineInstr *RetMI, 
38                           LiveRangeInfo &LRI) const;
39
40   void suggestReg4CallAddr(MachineInstr *CallMI, LiveRangeInfo &LRI) const;
41   
42   // Helper used by the all the getRegType() functions.
43   int getRegTypeForClassAndType(unsigned regClassID, const Type* type) const;
44
45 public:
46   // Type of registers available in SparcV9. There can be several reg types
47   // in the same class. For instace, the float reg class has Single/Double
48   // types
49   //
50   enum RegTypes {
51     IntRegType,
52     FPSingleRegType,
53     FPDoubleRegType,
54     IntCCRegType,
55     FloatCCRegType,
56     SpecialRegType
57   };
58
59   // The actual register classes in the SparcV9
60   //
61   // **** WARNING: If this enum order is changed, also modify 
62   // getRegisterClassOfValue method below since it assumes this particular 
63   // order for efficiency.
64   // 
65   enum RegClassIDs { 
66     IntRegClassID,                      // Integer
67     FloatRegClassID,                    // Float (both single/double)
68     IntCCRegClassID,                    // Int Condition Code
69     FloatCCRegClassID,                  // Float Condition code
70     SpecialRegClassID                   // Special (unallocated) registers
71   };
72
73   SparcV9RegInfo(const SparcV9TargetMachine &tgt);
74
75   // To find the register class used for a specified Type
76   //
77   unsigned getRegClassIDOfType(const Type *type,
78                                bool isCCReg = false) const;
79
80   // To find the register class to which a specified register belongs
81   //
82   unsigned getRegClassIDOfRegType(int regType) const;
83   
84   // getZeroRegNum - returns the register that contains always zero this is the
85   // unified register number
86   //
87   virtual unsigned getZeroRegNum() const;
88
89   // getCallAddressReg - returns the reg used for pushing the address when a
90   // function is called. This can be used for other purposes between calls
91   //
92   unsigned getCallAddressReg() const;
93
94   // Returns the register containing the return address.
95   // It should be made sure that this  register contains the return 
96   // value when a return instruction is reached.
97   //
98   unsigned getReturnAddressReg() const;
99
100   // Number of registers used for passing int args (usually 6: %o0 - %o5)
101   // and float args (usually 32: %f0 - %f31)
102   //
103   unsigned const getNumOfIntArgRegs() const   { return NumOfIntArgRegs; }
104   unsigned const getNumOfFloatArgRegs() const { return NumOfFloatArgRegs; }
105   
106   // Compute which register can be used for an argument, if any
107   // 
108   int regNumForIntArg(bool inCallee, bool isVarArgsCall,
109                       unsigned argNo, unsigned& regClassId) const;
110
111   int regNumForFPArg(unsigned RegType, bool inCallee, bool isVarArgsCall,
112                      unsigned argNo, unsigned& regClassId) const;
113   
114   // The following methods are used to color special live ranges (e.g.
115   // function args and return values etc.) with specific hardware registers
116   // as required. See SparcV9RegInfo.cpp for the implementation for SparcV9.
117   //
118   void suggestRegs4MethodArgs(const Function *Meth, 
119                               LiveRangeInfo& LRI) const;
120
121   void suggestRegs4CallArgs(MachineInstr *CallMI, 
122                             LiveRangeInfo& LRI) const; 
123
124   void suggestReg4RetValue(MachineInstr *RetMI, 
125                            LiveRangeInfo& LRI) const;
126   
127   void colorMethodArgs(const Function *Meth,  LiveRangeInfo& LRI,
128                        std::vector<MachineInstr*>& InstrnsBefore,
129                        std::vector<MachineInstr*>& InstrnsAfter) const;
130
131   // method used for printing a register for debugging purposes
132   //
133   void printReg(const LiveRange *LR) const;
134   
135   // returns the # of bytes of stack space allocated for each register
136   // type. For SparcV9, currently we allocate 8 bytes on stack for all 
137   // register types. We can optimize this later if necessary to save stack
138   // space (However, should make sure that stack alignment is correct)
139   //
140   inline int getSpilledRegSize(int RegType) const {
141     return 8;
142   }
143
144   // To obtain the return value and the indirect call address (if any)
145   // contained in a CALL machine instruction
146   //
147   const Value * getCallInstRetVal(const MachineInstr *CallMI) const;
148   const Value * getCallInstIndirectAddrVal(const MachineInstr *CallMI) const;
149
150   // The following methods are used to generate "copy" machine instructions
151   // for an architecture.
152   //
153   // The function regTypeNeedsScratchReg() can be used to check whether a
154   // scratch register is needed to copy a register of type `regType' to
155   // or from memory.  If so, such a scratch register can be provided by
156   // the caller (e.g., if it knows which regsiters are free); otherwise
157   // an arbitrary one will be chosen and spilled by the copy instructions.
158   //
159   bool regTypeNeedsScratchReg(int RegType,
160                               int& scratchRegClassId) const;
161
162   void cpReg2RegMI(std::vector<MachineInstr*>& mvec,
163                    unsigned SrcReg, unsigned DestReg,
164                    int RegType) const;
165
166   void cpReg2MemMI(std::vector<MachineInstr*>& mvec,
167                    unsigned SrcReg, unsigned DestPtrReg,
168                    int Offset, int RegType, int scratchReg = -1) const;
169
170   void cpMem2RegMI(std::vector<MachineInstr*>& mvec,
171                    unsigned SrcPtrReg, int Offset, unsigned DestReg,
172                    int RegType, int scratchReg = -1) const;
173
174   void cpValue2Value(Value *Src, Value *Dest,
175                      std::vector<MachineInstr*>& mvec) const;
176
177   // Get the register type for a register identified different ways.
178   // Note that getRegTypeForLR(LR) != getRegTypeForDataType(LR->getType())!
179   // The reg class of a LR depends both on the Value types in it and whether
180   // they are CC registers or not (for example).
181   int getRegTypeForDataType(const Type* type) const;
182   int getRegTypeForLR(const LiveRange *LR) const;
183   int getRegType(int unifiedRegNum) const;
184
185   virtual unsigned getFramePointer() const;
186   virtual unsigned getStackPointer() const;
187 };
188
189 } // End llvm namespace
190
191 #endif