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"
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 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 {
87 const TargetMachine& target;
91 MachineRegClassArrayType MachineRegClassArr;
96 // According the definition of a MachineOperand class, a Value in a
97 // machine instruction can go into either a normal register or a
98 // condition code register. If isCCReg is true below, the ID of the condition
99 // code regiter class will be returned. Otherwise, the normal register
100 // class (eg. int, float) must be returned.
101 virtual unsigned getRegClassIDOfValue (const Value *const Val,
102 bool isCCReg = false) const =0;
105 inline unsigned int getNumOfRegClasses() const {
106 return MachineRegClassArr.size();
109 const MachineRegClassInfo *const getMachineRegClass(unsigned i) const {
110 return MachineRegClassArr[i];
113 // returns the register that is hardwired to zero if any (-1 if none)
114 virtual inline int getZeroRegNum() const = 0;
116 //virtual unsigned getRegClassIDOfValue (const Value *const Val) const = 0;
117 // this method must give the exact register class of a machine operand
118 // e.g, Int, Float, Int CC, Float CC
119 //virtual unsigned getRCIDOfMachineOp (const MachineOperand &MO) const = 0;
122 virtual void suggestRegs4MethodArgs(const Method *const Meth,
123 LiveRangeInfo & LRI) const = 0;
125 virtual void suggestRegs4CallArgs(const MachineInstr *const CallI,
126 LiveRangeInfo& LRI, vector<RegClass *> RCL) const = 0;
128 virtual void suggestReg4RetValue(const MachineInstr *const RetI,
129 LiveRangeInfo& LRI) const = 0;
131 virtual void colorMethodArgs(const Method *const Meth, LiveRangeInfo& LRI,
132 AddedInstrns *const FirstAI) const = 0;
134 virtual void colorCallArgs(const MachineInstr *const CalI,
135 LiveRangeInfo& LRI, AddedInstrns *const CallAI,
136 PhyRegAlloc &PRA) const = 0;
138 virtual void colorRetValue(const MachineInstr *const RetI,LiveRangeInfo& LRI,
139 AddedInstrns *const RetAI) const = 0;
143 virtual MachineInstr *
144 cpReg2RegMI(const unsigned SrcReg, const unsigned DestReg,
145 const int RegType) const=0;
147 virtual MachineInstr *
148 cpReg2MemMI(const unsigned SrcReg, const unsigned DestPtrReg,
149 const int Offset, const int RegType) const=0;
151 virtual MachineInstr *
152 cpMem2RegMI(const unsigned SrcPtrReg, const int Offset,
153 const unsigned DestReg, const int RegType) const=0;
155 virtual MachineInstr *cpValue2Value( Value *Src, Value *Dest) const=0;
158 virtual bool isRegVolatile(const int RegClassID, const int Reg) const=0;
162 //virtual bool handleSpecialMInstr(const MachineInstr * MInst,
163 // LiveRangeInfo& LRI, vector<RegClass *> RCL) const = 0;
165 // returns the reg used for pushing the address when a method is called.
166 // This can be used for other purposes between calls
167 virtual unsigned getCallAddressReg() const = 0;
169 // and when we return from a method. It should be made sure that this
170 // register contains the return value when a return instruction is reached.
171 virtual unsigned getReturnAddressReg() const = 0;
173 virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
175 virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
177 virtual int getRegType(const LiveRange *const LR) const=0;
179 virtual const Value * getCallInstRetVal(const MachineInstr *CallMI) const=0;
181 inline virtual unsigned getFramePointer() const=0;
183 inline virtual unsigned getStackPointer() const=0;
185 inline virtual int getInvalidRegNum() const=0;
188 virtual void insertCallerSavingCode(const MachineInstr *MInst,
189 const BasicBlock *BB,
190 PhyRegAlloc &PRA ) const = 0;
193 //virtual void printReg(const LiveRange *const LR) const =0;
195 MachineRegInfo(const TargetMachine& tgt) : target(tgt) { }
208 //---------------------------------------------------------------------------
209 // class MachineRegInfo
212 // Interface to register info of target machine
214 //--------------------------------------------------------------------------
218 typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
220 // A vector of all machine register classes
221 typedef vector<const MachineRegClassInfo *> MachineRegClassArrayType;
224 class MachineRegInfo : public NonCopyableV {
228 MachineRegClassArrayType MachineRegClassArr;
235 // According the definition of a MachineOperand class, a Value in a
236 // machine instruction can go into either a normal register or a
237 // condition code register. If isCCReg is true below, the ID of the condition
238 // code regiter class will be returned. Otherwise, the normal register
239 // class (eg. int, float) must be returned.
240 virtual unsigned getRegClassIDOfValue (const Value *const Val,
241 bool isCCReg = false) const =0;
244 // returns the register that is hardwired to zero if any (-1 if none)
245 virtual inline int getZeroRegNum() const = 0;
247 inline unsigned int getNumOfRegClasses() const {
248 return MachineRegClassArr.size();
251 const MachineRegClassInfo *const getMachineRegClass(unsigned i) const {
252 return MachineRegClassArr[i];
257 //virtual unsigned getRegClassIDOfValue (const Value *const Val) const = 0;
258 // this method must give the exact register class of a machine operand
259 // e.g, Int, Float, Int CC, Float CC
260 //virtual unsigned getRCIDOfMachineOp (const MachineOperand &MO) const = 0;
263 virtual void colorArgs(const Method *const Meth,
264 LiveRangeInfo & LRI) const = 0;
266 virtual void colorCallArgs(vector<const Instruction *> & CallInstrList,
268 AddedInstrMapType& AddedInstrMap ) const = 0 ;
270 virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
272 virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
274 //virtual void printReg(const LiveRange *const LR) const =0;