Added prototypes for emitting prologue and epilogue for function code
[oota-llvm.git] / include / llvm / Target / MRegisterInfo.h
1 //===- Target/MRegisterInfo.h - Target Register Information -------*-C++-*-===//
2 //
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.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_TARGET_MREGISTERINFO_H
10 #define LLVM_TARGET_MREGISTERINFO_H
11
12 #include "llvm/CodeGen/MachineBasicBlock.h"
13 #include <map>
14 #include <assert.h>
15
16 class Type;
17
18 /// MRegisterDesc - This record contains all of the information known about a
19 /// particular register.
20 ///
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
25 };
26
27 /// MRF namespace - This namespace contains flags that pertain to machine
28 /// registers
29 ///
30 namespace MRF {  // MRF = Machine Register Flags
31   enum {
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
37
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
42   };
43 };
44
45 class TargetRegisterClass {
46 protected:
47   TargetRegisterClass() {}
48
49 public:
50
51   typedef unsigned* iterator;
52   typedef unsigned* const_iterator;
53
54   iterator       begin();
55   iterator         end();
56   const_iterator begin() const;
57   const_iterator   end() const;
58
59   virtual unsigned getNumRegs() const { return 0; }
60   virtual unsigned getRegister(unsigned idx) const { return 0; }
61
62   virtual unsigned getDataSize() const { return 0; }
63
64   void
65   buildReg2RegClassMap(std::map<unsigned,const TargetRegisterClass*>&
66                        Reg2RegClassMap) const
67   {
68     for (unsigned i=0; i < getNumRegs(); ++i) {
69       Reg2RegClassMap[getRegister(i)] = this;
70     }
71   }
72
73   //const std::vector<unsigned> &getRegsInClass(void) { return Regs; }
74   //void getAliases(void);
75 };
76
77
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.
82 ///
83 class MRegisterInfo {
84   const MRegisterDesc *Desc;    // Pointer to the descriptor array
85   unsigned NumRegs;             // Number of entries in the array
86 protected:
87   MRegisterInfo(const MRegisterDesc *D, unsigned NR) : Desc(D), NumRegs(NR) {}
88 public:
89
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.
97     ///
98     NoRegister = 0,
99
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.
104     ///
105     FirstVirtualRegister = 1024,
106   };
107
108   const MRegisterDesc &operator[](unsigned RegNo) const {
109     assert(RegNo < NumRegs &&
110            "Attempting to access record for invalid register number!");
111     return Desc[RegNo];
112   }
113
114   /// Provide a get method, equivalent to [], but more useful if we have a
115   /// pointer to this object.
116   ///
117   const MRegisterDesc &get(unsigned RegNo) const { return operator[](RegNo); }
118
119
120   virtual MachineBasicBlock::iterator
121   storeReg2RegOffset(MachineBasicBlock *MBB,
122                      MachineBasicBlock::iterator MBBI,
123                      unsigned SrcReg, unsigned DestReg,
124                      unsigned ImmOffset, unsigned dataSize) const = 0;
125
126   virtual MachineBasicBlock::iterator
127   loadRegOffset2Reg(MachineBasicBlock *MBB,
128                     MachineBasicBlock::iterator MBBI,
129                     unsigned DestReg, unsigned SrcReg,
130                     unsigned ImmOffset, unsigned dataSize) const = 0;
131
132   virtual MachineBasicBlock::iterator
133   emitPrologue(MachineBasicBlock *MBB,
134                MachineBasicBlock::iterator MBBI,
135                unsigned numBytes) const = 0;
136
137   virtual MachineBasicBlock::iterator
138   emitEpilogue(MachineBasicBlock *MBB,
139                MachineBasicBlock::iterator MBBI,
140                unsigned numBytes) const = 0;
141
142   virtual const unsigned* getCalleeSaveRegs() const = 0;
143   virtual const unsigned* getCallerSaveRegs() const = 0;
144
145   virtual unsigned getFramePointer() const = 0;
146   virtual unsigned getStackPointer() const = 0;
147
148   /// Register class iterators
149   typedef const TargetRegisterClass* const_iterator;
150
151   virtual const_iterator const_regclass_begin() const = 0;
152   virtual const_iterator const_regclass_end() const = 0;
153
154   virtual unsigned getNumRegClasses() const = 0;
155   virtual const TargetRegisterClass* getRegClassForType(const Type* Ty) const=0;
156
157   virtual void
158   buildReg2RegClassMap(std::map<unsigned,const TargetRegisterClass*>&
159                        Reg2RegClassMap) const {
160     for (MRegisterInfo::const_iterator I = const_regclass_begin(),
161            E = const_regclass_end(); I != E; ++I) {
162       I->buildReg2RegClassMap(Reg2RegClassMap);
163     }
164   }
165
166 };
167
168 #endif