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"
28 //-----------------------------------------------------------------------------
29 // class MachineRegClassInfo
32 // Interface to description of machine register class (e.g., int reg class
33 // float reg class etc)
35 //--------------------------------------------------------------------------
38 class MachineRegClassInfo {
42 const unsigned RegClassID; // integer ID of a reg class
43 const unsigned NumOfAvailRegs; // # of avail for coloring -without SP etc.
44 const unsigned NumOfAllRegs; // # of all registers -including SP,g0 etc.
48 inline unsigned getRegClassID() const { return RegClassID; }
49 inline unsigned getNumOfAvailRegs() const { return NumOfAvailRegs; }
50 inline unsigned getNumOfAllRegs() const { return NumOfAllRegs; }
54 // This method should find a color which is not used by neighbors
55 // (i.e., a false position in IsColorUsedArr) and
56 virtual void colorIGNode(IGNode * Node, bool IsColorUsedArr[] ) const = 0;
59 MachineRegClassInfo(const unsigned ID, const unsigned NVR,
60 const unsigned NAR): RegClassID(ID), NumOfAvailRegs(NVR),
62 { } // empty constructor
68 //---------------------------------------------------------------------------
69 // class MachineRegInfo
72 // Interface to register info of target machine
74 //--------------------------------------------------------------------------
78 typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
80 // A vector of all machine register classes
81 typedef vector<const MachineRegClassInfo *> MachineRegClassArrayType;
84 class MachineRegInfo : public NonCopyableV {
88 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,
134 AddedInstrns *const CallAI) const = 0;
136 virtual void colorRetValue(const MachineInstr *const RetI,LiveRangeInfo& LRI,
137 AddedInstrns *const RetAI) const = 0;
141 //virtual bool handleSpecialMInstr(const MachineInstr * MInst,
142 // LiveRangeInfo& LRI, vector<RegClass *> RCL) const = 0;
144 // returns the reg used for pushing the address when a method is called.
145 // This can be used for other purposes between calls
146 virtual unsigned getCallAddressReg() const = 0;
148 // and when we return from a method. It should be made sure that this
149 // register contains the return value when a return instruction is reached.
150 virtual unsigned getReturnAddressReg() const = 0;
152 virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
154 virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
156 //virtual void printReg(const LiveRange *const LR) const =0;
171 //---------------------------------------------------------------------------
172 // class MachineRegInfo
175 // Interface to register info of target machine
177 //--------------------------------------------------------------------------
181 typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
183 // A vector of all machine register classes
184 typedef vector<const MachineRegClassInfo *> MachineRegClassArrayType;
187 class MachineRegInfo : public NonCopyableV {
191 MachineRegClassArrayType MachineRegClassArr;
198 // According the definition of a MachineOperand class, a Value in a
199 // machine instruction can go into either a normal register or a
200 // condition code register. If isCCReg is true below, the ID of the condition
201 // code regiter class will be returned. Otherwise, the normal register
202 // class (eg. int, float) must be returned.
203 virtual unsigned getRegClassIDOfValue (const Value *const Val,
204 bool isCCReg = false) const =0;
207 // returns the register that is hardwired to zero if any (-1 if none)
208 virtual inline int getZeroRegNum() const = 0;
210 inline unsigned int getNumOfRegClasses() const {
211 return MachineRegClassArr.size();
214 const MachineRegClassInfo *const getMachineRegClass(unsigned i) const {
215 return MachineRegClassArr[i];
220 //virtual unsigned getRegClassIDOfValue (const Value *const Val) const = 0;
221 // this method must give the exact register class of a machine operand
222 // e.g, Int, Float, Int CC, Float CC
223 //virtual unsigned getRCIDOfMachineOp (const MachineOperand &MO) const = 0;
226 virtual void colorArgs(const Method *const Meth,
227 LiveRangeInfo & LRI) const = 0;
229 virtual void colorCallArgs(vector<const Instruction *> & CallInstrList,
231 AddedInstrMapType& AddedInstrMap ) const = 0 ;
233 virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
235 virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
237 //virtual void printReg(const LiveRange *const LR) const =0;