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