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 CallInst *const CallI,
124 LiveRangeInfo& LRI, vector<RegClass *> RCL) const = 0;
126 virtual void suggestReg4RetValue(const ReturnInst *const RetI,
127 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 CallInst *const CalI, LiveRangeInfo& LRI,
135 AddedInstrns *const CallAI) const = 0;
137 virtual void colorRetValue(const ReturnInst *const RetI, LiveRangeInfo& LRI,
138 AddedInstrns *const RetAI) const = 0;
142 virtual bool handleSpecialMInstr(const MachineInstr * MInst,
143 LiveRangeInfo& LRI, vector<RegClass *> RCL) const = 0;
145 // returns the reg used for pushing the address when a method is called.
146 // This can be used for other purposes between calls
147 virtual unsigned getCallAddressReg() const = 0;
149 // and when we return from a method. It should be made sure that this
150 // register contains the return value when a return instruction is reached.
151 virtual unsigned getReturnAddressReg() const = 0;
153 virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
155 virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
157 //virtual void printReg(const LiveRange *const LR) const =0;
172 //---------------------------------------------------------------------------
173 // class MachineRegInfo
176 // Interface to register info of target machine
178 //--------------------------------------------------------------------------
182 typedef hash_map<const MachineInstr *, AddedInstrns *> AddedInstrMapType;
184 // A vector of all machine register classes
185 typedef vector<const MachineRegClassInfo *> MachineRegClassArrayType;
188 class MachineRegInfo : public NonCopyableV {
192 MachineRegClassArrayType MachineRegClassArr;
199 // According the definition of a MachineOperand class, a Value in a
200 // machine instruction can go into either a normal register or a
201 // condition code register. If isCCReg is true below, the ID of the condition
202 // code regiter class will be returned. Otherwise, the normal register
203 // class (eg. int, float) must be returned.
204 virtual unsigned getRegClassIDOfValue (const Value *const Val,
205 bool isCCReg = false) const =0;
208 // returns the register that is hardwired to zero if any (-1 if none)
209 virtual inline int getZeroRegNum() const = 0;
211 inline unsigned int getNumOfRegClasses() const {
212 return MachineRegClassArr.size();
215 const MachineRegClassInfo *const getMachineRegClass(unsigned i) const {
216 return MachineRegClassArr[i];
221 //virtual unsigned getRegClassIDOfValue (const Value *const Val) const = 0;
222 // this method must give the exact register class of a machine operand
223 // e.g, Int, Float, Int CC, Float CC
224 //virtual unsigned getRCIDOfMachineOp (const MachineOperand &MO) const = 0;
227 virtual void colorArgs(const Method *const Meth,
228 LiveRangeInfo & LRI) const = 0;
230 virtual void colorCallArgs(vector<const Instruction *> & CallInstrList,
232 AddedInstrMapType& AddedInstrMap ) const = 0 ;
234 virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
236 virtual const string getUnifiedRegName(int UnifiedRegNum) const = 0;
238 //virtual void printReg(const LiveRange *const LR) const =0;