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>
31 //-----------------------------------------------------------------------------
32 // class MachineRegClassInfo
35 // Interface to description of machine register class (e.g., int reg class
36 // float reg class etc)
38 //--------------------------------------------------------------------------
41 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.
48 inline unsigned getRegClassID() const { return RegClassID; }
49 inline unsigned getNumOfAvailRegs() const { return NumOfAvailRegs; }
50 inline unsigned getNumOfAllRegs() const { return NumOfAllRegs; }
52 // This method should find a color which is not used by neighbors
53 // (i.e., a false position in IsColorUsedArr) and
54 virtual void colorIGNode(IGNode *Node, bool IsColorUsedArr[]) const = 0;
55 virtual bool isRegVolatile(int Reg) const = 0;
57 MachineRegClassInfo(unsigned ID, unsigned NVR, unsigned NAR)
58 : RegClassID(ID), NumOfAvailRegs(NVR), NumOfAllRegs(NAR) {}
63 //---------------------------------------------------------------------------
64 // class MachineRegInfo
67 // Interface to register info of target machine
69 //--------------------------------------------------------------------------
71 class MachineRegInfo : public NonCopyableV {
73 // A vector of all machine register classes
75 std::vector<const MachineRegClassInfo *> MachineRegClassArr;
78 const TargetMachine ⌖
80 MachineRegInfo(const TargetMachine& tgt) : target(tgt) { }
83 // According the definition of a MachineOperand class, a Value in a
84 // machine instruction can go into either a normal register or a
85 // condition code register. If isCCReg is true below, the ID of the condition
86 // code regiter class will be returned. Otherwise, the normal register
87 // class (eg. int, float) must be returned.
88 virtual unsigned getRegClassIDOfType (const Type *type,
89 bool isCCReg = false) const =0;
90 virtual unsigned getRegClassIDOfValue (const Value *Val,
91 bool isCCReg = false) const =0;
94 inline unsigned int getNumOfRegClasses() const {
95 return MachineRegClassArr.size();
98 const MachineRegClassInfo *getMachineRegClass(unsigned i) const {
99 return MachineRegClassArr[i];
102 // returns the register that is hardwired to zero if any (-1 if none)
104 virtual int getZeroRegNum() const = 0;
107 // The following methods are used to color special live ranges (e.g.
108 // method args and return values etc.) with specific hardware registers
109 // as required. See SparcRegInfo.cpp for the implementation for Sparc.
111 virtual void suggestRegs4MethodArgs(const Function *Func,
112 LiveRangeInfo &LRI) const = 0;
114 virtual void suggestRegs4CallArgs(const MachineInstr *CallI,
115 LiveRangeInfo &LRI, std::vector<RegClass *> RCL) const = 0;
117 virtual void suggestReg4RetValue(const MachineInstr *RetI,
118 LiveRangeInfo &LRI) const = 0;
120 virtual void colorMethodArgs(const Function *Func, LiveRangeInfo &LRI,
121 AddedInstrns *FirstAI) const = 0;
123 virtual void colorCallArgs(const MachineInstr *CalI,
124 LiveRangeInfo& LRI, AddedInstrns *CallAI,
125 PhyRegAlloc &PRA, const BasicBlock *BB) const = 0;
127 virtual void colorRetValue(const MachineInstr *RetI, LiveRangeInfo &LRI,
128 AddedInstrns *RetAI) const = 0;
132 // The following methods are used to generate "copy" machine instructions
133 // for an architecture. Currently they are used in MachineRegClass
134 // interface. However, they can be moved to MachineInstrInfo interface if
137 virtual MachineInstr *cpReg2RegMI(unsigned SrcReg, unsigned DestReg,
138 int RegType) const = 0;
140 virtual MachineInstr *cpReg2MemMI(unsigned SrcReg, unsigned DestPtrReg,
141 int Offset, int RegType) const = 0;
143 virtual MachineInstr *cpMem2RegMI(unsigned SrcPtrReg, int Offset,
144 unsigned DestReg, int RegType) const = 0;
146 virtual MachineInstr *cpValue2Value(Value *Src, Value *Dest) const = 0;
148 virtual bool isRegVolatile(int RegClassID, int Reg) const = 0;
153 // Returns the reg used for pushing the address when a method is called.
154 // This can be used for other purposes between calls
156 virtual unsigned getCallAddressReg() const = 0;
158 // Returns the register containing the return address.
159 //It should be made sure that this
160 // register contains the return value when a return instruction is reached.
162 virtual unsigned getReturnAddressReg() const = 0;
165 // Each register class has a seperate space for register IDs. To convert
166 // a regId in a register class to a common Id, we use the folloing method(s)
168 virtual int getUnifiedRegNum(int RegClassID, int reg) const = 0;
170 virtual const std::string getUnifiedRegName(int UnifiedRegNum) const = 0;
173 // Gives the type of a register based on the type of the LR
175 virtual int getRegType(const LiveRange *LR) const = 0;
177 // To obtain the return value and the indirect call address (if any)
178 // contained in a CALL machine instruction
180 virtual const Value *getCallInstRetVal(const MachineInstr *CallMI) const = 0;
181 virtual const Value *getCallInstIndirectAddrVal(const MachineInstr *CallMI) const = 0;
183 // The following methods are used to get the frame/stack pointers
185 virtual unsigned getFramePointer() const = 0;
186 virtual unsigned getStackPointer() const = 0;
188 // A register can be initialized to an invalid number. That number can
189 // be obtained using this method.
191 virtual int getInvalidRegNum() const = 0;
194 // Method for inserting caller saving code. The caller must save all the
195 // volatile registers across a call based on the calling conventions of
196 // an architecture. This must insert code for saving and restoring
199 virtual void insertCallerSavingCode(const MachineInstr *MInst,
200 const BasicBlock *BB,
201 PhyRegAlloc &PRA) const = 0;
203 // This method gives the the number of bytes of stack spaceallocated
204 // to a register when it is spilled to the stack.
206 virtual int getSpilledRegSize(int RegType) const = 0;