1 //===-- SparcV9RegInfo.h - Define TargetRegInfo for SparcV9 ---------*- 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 SparcV9.
12 //----------------------------------------------------------------------------
14 #ifndef SPARCV9REGINFO_H
15 #define SPARCV9REGINFO_H
17 #include "llvm/Target/TargetRegInfo.h"
21 class SparcV9TargetMachine;
23 class SparcV9RegInfo : public TargetRegInfo {
25 // Number of registers used for passing int args (usually 6: %o0 - %o5)
27 unsigned const NumOfIntArgRegs;
29 // Number of registers used for passing float args (usually 32: %f0 - %f31)
31 unsigned const NumOfFloatArgRegs;
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.
37 void suggestReg4RetAddr(MachineInstr *RetMI,
38 LiveRangeInfo &LRI) const;
40 void suggestReg4CallAddr(MachineInstr *CallMI, LiveRangeInfo &LRI) const;
42 // Helper used by the all the getRegType() functions.
43 int getRegTypeForClassAndType(unsigned regClassID, const Type* type) const;
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
59 // The actual register classes in the SparcV9
61 // **** WARNING: If this enum order is changed, also modify
62 // getRegisterClassOfValue method below since it assumes this particular
63 // order for efficiency.
66 IntRegClassID, // Integer
67 FloatRegClassID, // Float (both single/double)
68 IntCCRegClassID, // Int Condition Code
69 FloatCCRegClassID, // Float Condition code
70 SpecialRegClassID // Special (unallocated) registers
73 SparcV9RegInfo(const SparcV9TargetMachine &tgt);
75 // To find the register class used for a specified Type
77 unsigned getRegClassIDOfType(const Type *type,
78 bool isCCReg = false) const;
80 // To find the register class to which a specified register belongs
82 unsigned getRegClassIDOfRegType(int regType) const;
84 // getZeroRegNum - returns the register that contains always zero this is the
85 // unified register number
87 virtual unsigned getZeroRegNum() const;
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
92 unsigned getCallAddressReg() const;
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.
98 unsigned getReturnAddressReg() const;
100 // Number of registers used for passing int args (usually 6: %o0 - %o5)
101 // and float args (usually 32: %f0 - %f31)
103 unsigned const getNumOfIntArgRegs() const { return NumOfIntArgRegs; }
104 unsigned const getNumOfFloatArgRegs() const { return NumOfFloatArgRegs; }
106 // Compute which register can be used for an argument, if any
108 int regNumForIntArg(bool inCallee, bool isVarArgsCall,
109 unsigned argNo, unsigned& regClassId) const;
111 int regNumForFPArg(unsigned RegType, bool inCallee, bool isVarArgsCall,
112 unsigned argNo, unsigned& regClassId) const;
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.
118 void suggestRegs4MethodArgs(const Function *Meth,
119 LiveRangeInfo& LRI) const;
121 void suggestRegs4CallArgs(MachineInstr *CallMI,
122 LiveRangeInfo& LRI) const;
124 void suggestReg4RetValue(MachineInstr *RetMI,
125 LiveRangeInfo& LRI) const;
127 void colorMethodArgs(const Function *Meth, LiveRangeInfo& LRI,
128 std::vector<MachineInstr*>& InstrnsBefore,
129 std::vector<MachineInstr*>& InstrnsAfter) const;
131 // method used for printing a register for debugging purposes
133 void printReg(const LiveRange *LR) const;
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)
140 inline int getSpilledRegSize(int RegType) const {
144 // To obtain the return value and the indirect call address (if any)
145 // contained in a CALL machine instruction
147 const Value * getCallInstRetVal(const MachineInstr *CallMI) const;
148 const Value * getCallInstIndirectAddrVal(const MachineInstr *CallMI) const;
150 // The following methods are used to generate "copy" machine instructions
151 // for an architecture.
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.
159 bool regTypeNeedsScratchReg(int RegType,
160 int& scratchRegClassId) const;
162 void cpReg2RegMI(std::vector<MachineInstr*>& mvec,
163 unsigned SrcReg, unsigned DestReg,
166 void cpReg2MemMI(std::vector<MachineInstr*>& mvec,
167 unsigned SrcReg, unsigned DestPtrReg,
168 int Offset, int RegType, int scratchReg = -1) const;
170 void cpMem2RegMI(std::vector<MachineInstr*>& mvec,
171 unsigned SrcPtrReg, int Offset, unsigned DestReg,
172 int RegType, int scratchReg = -1) const;
174 void cpValue2Value(Value *Src, Value *Dest,
175 std::vector<MachineInstr*>& mvec) const;
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;
185 virtual unsigned getFramePointer() const;
186 virtual unsigned getStackPointer() const;
189 } // End llvm namespace