1 //===-- SparcRegInfo.h - Define TargetRegInfo for Sparc ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This class implements the virtual class TargetRegInfo for Sparc.
12 //----------------------------------------------------------------------------
14 #ifndef SPARC_REGINFO_H
15 #define SPARC_REGINFO_H
17 #include "llvm/Target/TargetRegInfo.h"
21 class SparcTargetMachine;
23 class SparcRegInfo : public TargetRegInfo {
27 // Number of registers used for passing int args (usually 6: %o0 - %o5)
29 unsigned const NumOfIntArgRegs;
31 // Number of registers used for passing float args (usually 32: %f0 - %f31)
33 unsigned const NumOfFloatArgRegs;
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.
39 void suggestReg4RetAddr(MachineInstr *RetMI,
40 LiveRangeInfo &LRI) const;
42 void suggestReg4CallAddr(MachineInstr *CallMI, LiveRangeInfo &LRI) const;
44 // Helper used by the all the getRegType() functions.
45 int getRegTypeForClassAndType(unsigned regClassID, const Type* type) const;
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
61 // The actual register classes in the Sparc
63 // **** WARNING: If this enum order is changed, also modify
64 // getRegisterClassOfValue method below since it assumes this particular
65 // order for efficiency.
68 IntRegClassID, // Integer
69 FloatRegClassID, // Float (both single/double)
70 IntCCRegClassID, // Int Condition Code
71 FloatCCRegClassID, // Float Condition code
72 SpecialRegClassID // Special (unallocated) registers
75 SparcRegInfo(const SparcTargetMachine &tgt);
77 // To find the register class used for a specified Type
79 unsigned getRegClassIDOfType(const Type *type,
80 bool isCCReg = false) const;
82 // To find the register class to which a specified register belongs
84 unsigned getRegClassIDOfRegType(int regType) const;
86 // getZeroRegNum - returns the register that contains always zero this is the
87 // unified register number
89 virtual int getZeroRegNum() const;
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
94 unsigned getCallAddressReg() const;
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.
100 unsigned getReturnAddressReg() const;
102 // Number of registers used for passing int args (usually 6: %o0 - %o5)
103 // and float args (usually 32: %f0 - %f31)
105 unsigned const getNumOfIntArgRegs() const { return NumOfIntArgRegs; }
106 unsigned const getNumOfFloatArgRegs() const { return NumOfFloatArgRegs; }
108 // Compute which register can be used for an argument, if any
110 int regNumForIntArg(bool inCallee, bool isVarArgsCall,
111 unsigned argNo, unsigned& regClassId) const;
113 int regNumForFPArg(unsigned RegType, bool inCallee, bool isVarArgsCall,
114 unsigned argNo, unsigned& regClassId) const;
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.
120 void suggestRegs4MethodArgs(const Function *Meth,
121 LiveRangeInfo& LRI) const;
123 void suggestRegs4CallArgs(MachineInstr *CallMI,
124 LiveRangeInfo& LRI) const;
126 void suggestReg4RetValue(MachineInstr *RetMI,
127 LiveRangeInfo& LRI) const;
129 void colorMethodArgs(const Function *Meth, LiveRangeInfo& LRI,
130 std::vector<MachineInstr*>& InstrnsBefore,
131 std::vector<MachineInstr*>& InstrnsAfter) const;
133 // method used for printing a register for debugging purposes
135 void printReg(const LiveRange *LR) const;
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)
142 inline int getSpilledRegSize(int RegType) const {
146 // To obtain the return value and the indirect call address (if any)
147 // contained in a CALL machine instruction
149 const Value * getCallInstRetVal(const MachineInstr *CallMI) const;
150 const Value * getCallInstIndirectAddrVal(const MachineInstr *CallMI) const;
152 // The following methods are used to generate "copy" machine instructions
153 // for an architecture.
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.
161 bool regTypeNeedsScratchReg(int RegType,
162 int& scratchRegClassId) const;
164 void cpReg2RegMI(std::vector<MachineInstr*>& mvec,
165 unsigned SrcReg, unsigned DestReg,
168 void cpReg2MemMI(std::vector<MachineInstr*>& mvec,
169 unsigned SrcReg, unsigned DestPtrReg,
170 int Offset, int RegType, int scratchReg = -1) const;
172 void cpMem2RegMI(std::vector<MachineInstr*>& mvec,
173 unsigned SrcPtrReg, int Offset, unsigned DestReg,
174 int RegType, int scratchReg = -1) const;
176 void cpValue2Value(Value *Src, Value *Dest,
177 std::vector<MachineInstr*>& mvec) const;
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;
187 virtual unsigned getFramePointer() const;
188 virtual unsigned getStackPointer() const;
191 } // End llvm namespace