1 //===- Target/MRegisterInfo.h - Target Register Information -------*-C++-*-===//
3 // This file describes an abstract interface used to get information about a
4 // target machines register file. This information is used for a variety of
5 // purposed, especially register allocation.
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_TARGET_MREGISTERINFO_H
10 #define LLVM_TARGET_MREGISTERINFO_H
12 #include "llvm/CodeGen/MachineBasicBlock.h"
18 /// MRegisterDesc - This record contains all of the information known about a
19 /// particular register.
21 struct MRegisterDesc {
22 const char *Name; // Assembly language name for the register
23 unsigned Flags; // Flags identifying register properties (defined below)
24 unsigned TSFlags; // Target Specific Flags
27 /// MRF namespace - This namespace contains flags that pertain to machine
30 namespace MRF { // MRF = Machine Register Flags
32 INT8 = 1 << 0, // This is an 8 bit integer register
33 INT16 = 1 << 1, // This is a 16 bit integer register
34 INT32 = 1 << 2, // This is a 32 bit integer register
35 INT64 = 1 << 3, // This is a 64 bit integer register
36 INT128 = 1 << 4, // This is a 128 bit integer register
38 FP32 = 1 << 5, // This is a 32 bit floating point register
39 FP64 = 1 << 6, // This is a 64 bit floating point register
40 FP80 = 1 << 7, // This is a 80 bit floating point register
41 FP128 = 1 << 8, // This is a 128 bit floating point register
45 class TargetRegisterClass {
47 TargetRegisterClass() {}
51 typedef unsigned* iterator;
52 typedef unsigned* const_iterator;
56 const_iterator begin() const;
57 const_iterator end() const;
59 virtual unsigned getNumRegs() const { return 0; }
60 virtual unsigned getRegister(unsigned idx) const { return 0; }
62 virtual unsigned getDataSize() const { return 0; }
65 buildReg2RegClassMap(std::map<unsigned,const TargetRegisterClass*>&
66 Reg2RegClassMap) const
68 for (unsigned i=0; i < getNumRegs(); ++i) {
69 Reg2RegClassMap[getRegister(i)] = this;
73 //const std::vector<unsigned> &getRegsInClass(void) { return Regs; }
74 //void getAliases(void);
78 /// MRegisterInfo base class - We assume that the target defines a static array
79 /// of MRegisterDesc objects that represent all of the machine registers that
80 /// the target has. As such, we simply have to track a pointer to this array so
81 /// that we can turn register number into a register descriptor.
84 const MRegisterDesc *Desc; // Pointer to the descriptor array
85 unsigned NumRegs; // Number of entries in the array
87 MRegisterInfo(const MRegisterDesc *D, unsigned NR) : Desc(D), NumRegs(NR) {}
90 enum { // Define some target independant constants
91 /// NoRegister - This 'hard' register is a 'noop' register for all backends.
92 /// This is used as the destination register for instructions that do not
93 /// produce a value. Some frontends may use this as an operand register to
94 /// mean special things, for example, the Sparc backend uses R0 to mean %g0
95 /// which always PRODUCES the value 0. The X86 backend does not use this
96 /// value as an operand register.
100 /// FirstVirtualRegister - This is the first register number that is
101 /// considered to be a 'virtual' register, which is part of the SSA
102 /// namespace. This must be the same for all targets, which means that each
103 /// target is limited to 1024 registers.
105 FirstVirtualRegister = 1024,
108 const MRegisterDesc &operator[](unsigned RegNo) const {
109 assert(RegNo < NumRegs &&
110 "Attempting to access record for invalid register number!");
114 /// Provide a get method, equivalent to [], but more useful if we have a
115 /// pointer to this object.
117 const MRegisterDesc &get(unsigned RegNo) const { return operator[](RegNo); }
120 virtual MachineBasicBlock::iterator
121 storeReg2RegOffset(MachineBasicBlock *MBB,
122 MachineBasicBlock::iterator &MBBI,
123 unsigned SrcReg, unsigned DestReg,
124 unsigned ImmOffset, unsigned dataSize) const = 0;
126 virtual MachineBasicBlock::iterator
127 loadRegOffset2Reg(MachineBasicBlock *MBB,
128 MachineBasicBlock::iterator &MBBI,
129 unsigned DestReg, unsigned SrcReg,
130 unsigned ImmOffset, unsigned dataSize) const = 0;
132 virtual const unsigned* getCalleeSaveRegs() const = 0;
133 virtual const unsigned* getCallerSaveRegs() const = 0;
135 virtual unsigned getFramePointer() const = 0;
136 virtual unsigned getStackPointer() const = 0;
138 /// Register class iterators
139 typedef const TargetRegisterClass* const_iterator;
141 virtual const_iterator const_regclass_begin() const = 0;
142 virtual const_iterator const_regclass_end() const = 0;
144 virtual unsigned getNumRegClasses() const = 0;
145 virtual const TargetRegisterClass* getRegClassForType(const Type* Ty) const=0;
148 buildReg2RegClassMap(std::map<unsigned,const TargetRegisterClass*>&
149 Reg2RegClassMap) const=0;