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 "llvm/Support/NonCopyable.h"
29 //-----------------------------------------------------------------------------
30 // class MachineRegClassInfo
33 // Interface to description of machine register class (e.g., int reg class
34 // float reg class etc)
36 //--------------------------------------------------------------------------
39 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 hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
81 // A vector of all machine register classes
82 typedef vector<const MachineRegClassInfo *> MachineRegClassArrayType;
85 class MachineRegInfo : public NonCopyableV {
89 MachineRegClassArrayType MachineRegClassArr;
94 // According the definition of a MachineOperand class, a Value in a
95 // machine instruction can go into either a normal register or a
96 // condition code register. If isCCReg is true below, the ID of the condition
97 // code regiter class will be returned. Otherwise, the normal register
98 // class (eg. int, float) must be returned.
99 virtual unsigned getRegClassIDOfValue (const Value *const Val,
100 bool isCCReg = false) const =0;
103 inline unsigned int getNumOfRegClasses() const {
104 return MachineRegClassArr.size();
107 const MachineRegClassInfo *const getMachineRegClass(unsigned i) const {
108 return MachineRegClassArr[i];
111 // returns the register that is hardwired to zero if any (-1 if none)
112 virtual inline int getZeroRegNum() const = 0;
114 //virtual unsigned getRegClassIDOfValue (const Value *const Val) const = 0;
115 // this method must give the exact register class of a machine operand
116 // e.g, Int, Float, Int CC, Float CC
117 //virtual unsigned getRCIDOfMachineOp (const MachineOperand &MO) const = 0;
120 virtual void suggestRegs4MethodArgs(const Method *const Meth,
121 LiveRangeInfo & LRI) const = 0;
123 virtual void suggestRegs4CallArgs(const MachineInstr *const CallI,
124 LiveRangeInfo& LRI, vector<RegClass *> RCL) const = 0;
126 virtual void suggestReg4RetValue(const MachineInstr *const RetI,
127 LiveRangeInfo& LRI) const = 0;
129 virtual void colorMethodArgs(const Method *const Meth, LiveRangeInfo& LRI,
130 AddedInstrns *const FirstAI) const = 0;
132 virtual void colorCallArgs(const MachineInstr *const CalI,
133 LiveRangeInfo& LRI, AddedInstrns *const CallAI,
134 PhyRegAlloc &PRA) const = 0;
136 virtual void colorRetValue(const MachineInstr *const RetI,LiveRangeInfo& LRI,
137 AddedInstrns *const RetAI) const = 0;
141 virtual MachineInstr *
142 cpReg2RegMI(const unsigned SrcReg, const unsigned DestReg,
143 const int RegType) const=0;
145 virtual MachineInstr *
146 cpReg2MemMI(const unsigned SrcReg, const unsigned DestPtrReg,
147 const int Offset, const int RegType) const=0;
149 virtual MachineInstr *
150 cpMem2RegMI(const unsigned SrcPtrReg, const int Offset,
151 const unsigned DestReg, const int RegType) const=0;
153 virtual bool isRegVolatile(const int RegClassID, const int Reg) const=0;
157 //virtual bool handleSpecialMInstr(const MachineInstr * MInst,
158 // LiveRangeInfo& LRI, vector<RegClass *> RCL) const = 0;
160 // returns the reg used for pushing the address when a method is called.
161 // This can be used for other purposes between calls
162 virtual unsigned getCallAddressReg() const = 0;
164 // and when we return from a method. It should be made sure that this
165 // register contains the return value when a return instruction is reached.
166 virtual unsigned getReturnAddressReg() const = 0;
168 virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
170 virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
172 virtual int getRegType(const LiveRange *const LR) const=0;
174 virtual const Value * getCallInstRetVal(const MachineInstr *CallMI) const=0;
176 inline virtual unsigned getFramePointer() const=0;
178 inline virtual unsigned getStackPointer() const=0;
180 inline virtual int getInvalidRegNum() const=0;
183 virtual void insertCallerSavingCode(const MachineInstr *MInst,
184 const BasicBlock *BB,
185 PhyRegAlloc &PRA ) const = 0;
188 //virtual void printReg(const LiveRange *const LR) const =0;
203 //---------------------------------------------------------------------------
204 // class MachineRegInfo
207 // Interface to register info of target machine
209 //--------------------------------------------------------------------------
213 typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
215 // A vector of all machine register classes
216 typedef vector<const MachineRegClassInfo *> MachineRegClassArrayType;
219 class MachineRegInfo : public NonCopyableV {
223 MachineRegClassArrayType MachineRegClassArr;
230 // According the definition of a MachineOperand class, a Value in a
231 // machine instruction can go into either a normal register or a
232 // condition code register. If isCCReg is true below, the ID of the condition
233 // code regiter class will be returned. Otherwise, the normal register
234 // class (eg. int, float) must be returned.
235 virtual unsigned getRegClassIDOfValue (const Value *const Val,
236 bool isCCReg = false) const =0;
239 // returns the register that is hardwired to zero if any (-1 if none)
240 virtual inline int getZeroRegNum() const = 0;
242 inline unsigned int getNumOfRegClasses() const {
243 return MachineRegClassArr.size();
246 const MachineRegClassInfo *const getMachineRegClass(unsigned i) const {
247 return MachineRegClassArr[i];
252 //virtual unsigned getRegClassIDOfValue (const Value *const Val) const = 0;
253 // this method must give the exact register class of a machine operand
254 // e.g, Int, Float, Int CC, Float CC
255 //virtual unsigned getRCIDOfMachineOp (const MachineOperand &MO) const = 0;
258 virtual void colorArgs(const Method *const Meth,
259 LiveRangeInfo & LRI) const = 0;
261 virtual void colorCallArgs(vector<const Instruction *> & CallInstrList,
263 AddedInstrMapType& AddedInstrMap ) const = 0 ;
265 virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
267 virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
269 //virtual void printReg(const LiveRange *const LR) const =0;