1 //===-- llvm/Target/RegInfo.h - Target Register Information ------*- C++ -*-==//
3 // This file is used to describe the register system of a target to the
6 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_TARGET_MACHINEREGINFO_H
9 #define LLVM_TARGET_MACHINEREGINFO_H
11 #include "Support/NonCopyable.h"
12 #include <ext/hash_map>
30 //-----------------------------------------------------------------------------
31 // class MachineRegClassInfo
34 // Interface to description of machine register class (e.g., int reg class
35 // float reg class etc)
37 //--------------------------------------------------------------------------
40 class MachineRegClassInfo {
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.
49 inline unsigned getRegClassID() const { return RegClassID; }
50 inline unsigned getNumOfAvailRegs() const { return NumOfAvailRegs; }
51 inline unsigned getNumOfAllRegs() const { return NumOfAllRegs; }
55 // This method should find a color which is not used by neighbors
56 // (i.e., a false position in IsColorUsedArr) and
57 virtual void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const = 0;
58 virtual bool isRegVolatile(const int Reg) const = 0;
60 MachineRegClassInfo(const unsigned ID, const unsigned NVR,
61 const unsigned NAR): RegClassID(ID), NumOfAvailRegs(NVR),
63 { } // empty constructor
69 //---------------------------------------------------------------------------
70 // class MachineRegInfo
73 // Interface to register info of target machine
75 //--------------------------------------------------------------------------
79 typedef std::hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
81 // A vector of all machine register classes
83 typedef std::vector<const MachineRegClassInfo *> MachineRegClassArrayType;
86 class MachineRegInfo : public NonCopyableV {
88 const TargetMachine& target;
92 MachineRegClassArrayType MachineRegClassArr;
98 MachineRegInfo(const TargetMachine& tgt) : target(tgt) { }
101 // According the definition of a MachineOperand class, a Value in a
102 // machine instruction can go into either a normal register or a
103 // condition code register. If isCCReg is true below, the ID of the condition
104 // code regiter class will be returned. Otherwise, the normal register
105 // class (eg. int, float) must be returned.
106 virtual unsigned getRegClassIDOfValue (const Value *const Val,
107 bool isCCReg = false) const =0;
110 inline unsigned int getNumOfRegClasses() const {
111 return MachineRegClassArr.size();
114 const MachineRegClassInfo *const getMachineRegClass(unsigned i) const {
115 return MachineRegClassArr[i];
118 // returns the register that is hardwired to zero if any (-1 if none)
120 virtual inline int getZeroRegNum() const = 0;
123 // The following methods are used to color special live ranges (e.g.
124 // method args and return values etc.) with specific hardware registers
125 // as required. See SparcRegInfo.cpp for the implementation for Sparc.
127 virtual void suggestRegs4MethodArgs(const Method *const Meth,
128 LiveRangeInfo & LRI) const = 0;
130 virtual void suggestRegs4CallArgs(const MachineInstr *const CallI,
131 LiveRangeInfo& LRI, std::vector<RegClass *> RCL) const = 0;
133 virtual void suggestReg4RetValue(const MachineInstr *const RetI,
134 LiveRangeInfo& LRI) const = 0;
136 virtual void colorMethodArgs(const Method *const Meth, LiveRangeInfo& LRI,
137 AddedInstrns *const FirstAI) const = 0;
139 virtual void colorCallArgs(const MachineInstr *const CalI,
140 LiveRangeInfo& LRI, AddedInstrns *const CallAI,
141 PhyRegAlloc &PRA, const BasicBlock *BB) const = 0;
143 virtual void colorRetValue(const MachineInstr *const RetI,LiveRangeInfo& LRI,
144 AddedInstrns *const RetAI) const = 0;
148 // The following methods are used to generate "copy" machine instructions
149 // for an architecture. Currently they are used in MachineRegClass
150 // interface. However, they can be moved to MachineInstrInfo interface if
153 virtual MachineInstr *
154 cpReg2RegMI(const unsigned SrcReg, const unsigned DestReg,
155 const int RegType) const=0;
157 virtual MachineInstr *
158 cpReg2MemMI(const unsigned SrcReg, const unsigned DestPtrReg,
159 const int Offset, const int RegType) const=0;
161 virtual MachineInstr *
162 cpMem2RegMI(const unsigned SrcPtrReg, const int Offset,
163 const unsigned DestReg, const int RegType) const=0;
165 virtual MachineInstr *cpValue2Value( Value *Src, Value *Dest) const=0;
167 virtual bool isRegVolatile(const int RegClassID, const int Reg) const=0;
172 // Returns the reg used for pushing the address when a method is called.
173 // This can be used for other purposes between calls
175 virtual unsigned getCallAddressReg() const = 0;
177 // Returns the register containing the return address.
178 //It should be made sure that this
179 // register contains the return value when a return instruction is reached.
181 virtual unsigned getReturnAddressReg() const = 0;
184 // Each register class has a seperate space for register IDs. To convert
185 // a regId in a register class to a common Id, we use the folloing method(s)
187 virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
189 virtual const std::string getUnifiedRegName(int UnifiedRegNum) const = 0;
192 // Gives the type of a register based on the type of the LR
194 virtual int getRegType(const LiveRange *const LR) const=0;
196 // Gives the return value contained in a CALL machine instruction
198 virtual const Value * getCallInstRetVal(const MachineInstr *CallMI) const=0;
200 // The following methods are used to get the frame/stack pointers
202 inline virtual unsigned getFramePointer() const=0;
203 inline virtual unsigned getStackPointer() const=0;
205 // A register can be initialized to an invalid number. That number can
206 // be obtained using this method.
208 inline virtual int getInvalidRegNum() const=0;
211 // Method for inserting caller saving code. The caller must save all the
212 // volatile registers across a call based on the calling conventions of
213 // an architecture. This must insert code for saving and restoring
216 virtual void insertCallerSavingCode(const MachineInstr *MInst,
217 const BasicBlock *BB,
218 PhyRegAlloc &PRA ) const = 0;
220 // This method gives the the number of bytes of stack spaceallocated
221 // to a register when it is spilled to the stack.
223 virtual inline int getSpilledRegSize(const int RegType) const = 0;