Remove a ton of extraneous #includes
[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
14 class Type;
15 class MachineFunction;
16
17 /// MRegisterDesc - This record contains all of the information known about a
18 /// particular register.  The AliasSet field (if not null) contains a pointer to
19 /// a Zero terminated array of registers that this register aliases.  This is
20 /// needed for architectures like X86 which have AL alias AX alias EAX.
21 /// Registers that this does not apply to simply should set this to null.
22 ///
23 struct MRegisterDesc {
24   const char     *Name;       // Assembly language name for the register
25   const unsigned *AliasSet;   // Register Alias Set, described above
26   unsigned        Flags;      // Flags identifying register properties (below)
27   unsigned        TSFlags;    // Target Specific Flags
28 };
29
30 /// MRF namespace - This namespace contains flags that pertain to machine
31 /// registers
32 ///
33 namespace MRF {  // MRF = Machine Register Flags
34   enum {
35     Other            =   0 << 0,   // This is a non-standard register
36     INT8             =   1 << 0,   // This is an 8 bit integer register
37     INT16            =   1 << 1,   // This is a 16 bit integer register
38     INT32            =   1 << 2,   // This is a 32 bit integer register
39     INT64            =   1 << 3,   // This is a 64 bit integer register
40     INT128           =   1 << 4,   // This is a 128 bit integer register
41
42     FP32             =   1 << 5,   // This is a 32 bit floating point register
43     FP64             =   1 << 6,   // This is a 64 bit floating point register
44     FP80             =   1 << 7,   // This is a 80 bit floating point register
45     FP128            =   1 << 8,   // This is a 128 bit floating point register
46   };
47 };
48
49 class TargetRegisterClass {
50 public:
51   typedef const unsigned* iterator;
52   typedef const unsigned* const_iterator;
53
54 private:
55   const unsigned RegSize, Alignment;    // Size & Alignment of register in bytes
56   const iterator RegsBegin, RegsEnd;
57 public:
58   TargetRegisterClass(unsigned RS, unsigned Al, iterator RB, iterator RE)
59     : RegSize(RS), Alignment(Al), RegsBegin(RB), RegsEnd(RE) {}
60   virtual ~TargetRegisterClass() {}     // Allow subclasses
61
62   // begin/end - Return all of the registers in this class.
63   iterator       begin() const { return RegsBegin; }
64   iterator         end() const { return RegsEnd; }
65
66   // getNumRegs - Return the number of registers in this class
67   unsigned getNumRegs() const { return RegsEnd-RegsBegin; }
68
69   // getRegister - Return the specified register in the class
70   unsigned getRegister(unsigned i) const {
71     assert(i < getNumRegs() && "Register number out of range!");
72     return RegsBegin[i];
73   }
74
75   /// allocation_order_begin/end - These methods define a range of registers
76   /// which specify the registers in this class that are valid to register
77   /// allocate, and the preferred order to allocate them in.  For example,
78   /// callee saved registers should be at the end of the list, because it is
79   /// cheaper to allocate caller saved registers.
80   ///
81   /// These methods take a MachineFunction argument, which can be used to tune
82   /// the allocatable registers based on the characteristics of the function.
83   /// One simple example is that the frame pointer register can be used if
84   /// frame-pointer-elimination is performed.
85   ///
86   /// By default, these methods return all registers in the class.
87   ///
88   virtual iterator allocation_order_begin(MachineFunction &MF) const {
89     return begin();
90   }
91   virtual iterator allocation_order_end(MachineFunction &MF)   const {
92     return end();
93   }
94   
95
96
97   /// getSize - Return the size of the register in bytes, which is also the size
98   /// of a stack slot allocated to hold a spilled copy of this register.
99   unsigned getSize() const { return RegSize; }
100
101   /// getAlignment - Return the minimum required alignment for a register of
102   /// this class.
103   unsigned getAlignment() const { return Alignment; }
104 };
105
106
107 /// MRegisterInfo base class - We assume that the target defines a static array
108 /// of MRegisterDesc objects that represent all of the machine registers that
109 /// the target has.  As such, we simply have to track a pointer to this array so
110 /// that we can turn register number into a register descriptor.
111 ///
112 class MRegisterInfo {
113 public:
114   typedef const TargetRegisterClass * const * regclass_iterator;
115 private:
116   const MRegisterDesc *Desc;                  // Pointer to the descriptor array
117   unsigned NumRegs;                           // Number of entries in the array
118
119   regclass_iterator RegClassBegin, RegClassEnd;   // List of regclasses
120
121   const TargetRegisterClass **PhysRegClasses; // Reg class for each register
122   int CallFrameSetupOpcode, CallFrameDestroyOpcode;
123 protected:
124   MRegisterInfo(const MRegisterDesc *D, unsigned NR,
125                 regclass_iterator RegClassBegin, regclass_iterator RegClassEnd,
126                 int CallFrameSetupOpcode = -1, int CallFrameDestroyOpcode = -1);
127   virtual ~MRegisterInfo();
128 public:
129
130   enum {                        // Define some target independant constants
131     /// NoRegister - This 'hard' register is a 'noop' register for all backends.
132     /// This is used as the destination register for instructions that do not
133     /// produce a value.  Some frontends may use this as an operand register to
134     /// mean special things, for example, the Sparc backend uses R0 to mean %g0
135     /// which always PRODUCES the value 0.  The X86 backend does not use this
136     /// value as an operand register, except for memory references.
137     ///
138     NoRegister = 0,
139
140     /// FirstVirtualRegister - This is the first register number that is
141     /// considered to be a 'virtual' register, which is part of the SSA
142     /// namespace.  This must be the same for all targets, which means that each
143     /// target is limited to 1024 registers.
144     ///
145     FirstVirtualRegister = 1024,
146   };
147
148   const MRegisterDesc &operator[](unsigned RegNo) const {
149     assert(RegNo < NumRegs &&
150            "Attempting to access record for invalid register number!");
151     return Desc[RegNo];
152   }
153
154   /// Provide a get method, equivalent to [], but more useful if we have a
155   /// pointer to this object.
156   ///
157   const MRegisterDesc &get(unsigned RegNo) const { return operator[](RegNo); }
158
159   /// getRegClass - Return the register class for the specified physical
160   /// register.
161   ///
162   const TargetRegisterClass *getRegClass(unsigned RegNo) const {
163     assert(RegNo < NumRegs && "Register number out of range!");
164     assert(PhysRegClasses[RegNo] && "Register is not in a class!");
165     return PhysRegClasses[RegNo];
166   }
167
168   /// getAliasSet - Return the set of registers aliased by the specified
169   /// register, or a null list of there are none.  The list returned is zero
170   /// terminated.
171   ///
172   const unsigned *getAliasSet(unsigned RegNo) const {
173     return get(RegNo).AliasSet;
174   }
175
176   /// getName - Return the symbolic target specific name for the specified
177   /// physical register.
178   const char *getName(unsigned RegNo) const {
179     return get(RegNo).Name;
180   }
181
182   virtual const unsigned* getCalleeSaveRegs() const = 0;
183
184
185   //===--------------------------------------------------------------------===//
186   // Register Class Information
187   //
188
189   /// Register class iterators
190   regclass_iterator regclass_begin() const { return RegClassBegin; }
191   regclass_iterator regclass_end() const { return RegClassEnd; }
192
193   unsigned getNumRegClasses() const {
194     return regclass_end()-regclass_begin();
195   }
196   virtual const TargetRegisterClass* getRegClassForType(const Type* Ty) const=0;
197
198
199   //===--------------------------------------------------------------------===//
200   // Interfaces used by the register allocator and stack frame manipulation
201   // passes to move data around between registers, immediates and memory.
202   //
203
204   virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
205                                    MachineBasicBlock::iterator &MBBI,
206                                    unsigned SrcReg, int FrameIndex,
207                                    const TargetRegisterClass *RC) const = 0;
208
209   virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
210                                     MachineBasicBlock::iterator &MBBI,
211                                     unsigned DestReg, int FrameIndex,
212                                     const TargetRegisterClass *RC) const = 0;
213
214   virtual void copyRegToReg(MachineBasicBlock &MBB,
215                             MachineBasicBlock::iterator &MBBI,
216                             unsigned DestReg, unsigned SrcReg,
217                             const TargetRegisterClass *RC) const = 0;
218
219
220   /// getCallFrameSetup/DestroyOpcode - These methods return the opcode of the
221   /// frame setup/destroy instructions if they exist (-1 otherwise).  Some
222   /// targets use pseudo instructions in order to abstract away the difference
223   /// between operating with a frame pointer and operating without, through the
224   /// use of these two instructions.
225   ///
226   int getCallFrameSetupOpcode() const { return CallFrameSetupOpcode; }
227   int getCallFrameDestroyOpcode() const { return CallFrameDestroyOpcode; }
228
229
230   /// eliminateCallFramePseudoInstr - This method is called during prolog/epilog
231   /// code insertion to eliminate call frame setup and destroy pseudo
232   /// instructions (but only if the Target is using them).  It is responsible
233   /// for eliminating these instructions, replacing them with concrete
234   /// instructions.  This method need only be implemented if using call frame
235   /// setup/destroy pseudo instructions.
236   ///
237   virtual void eliminateCallFramePseudoInstr(MachineFunction &MF,
238                                              MachineBasicBlock &MBB,
239                                          MachineBasicBlock::iterator &I) const {
240     assert(getCallFrameSetupOpcode()== -1 && getCallFrameDestroyOpcode()== -1 &&
241            "eliminateCallFramePseudoInstr must be implemented if using"
242            " call frame setup/destroy pseudo instructions!");
243     assert(0 && "Call Frame Pseudo Instructions do not exist on this target!");
244   }
245
246   /// processFunctionBeforeFrameFinalized - This method is called immediately
247   /// before the specified functions frame layout (MF.getFrameInfo()) is
248   /// finalized.  Once the frame is finalized, MO_FrameIndex operands are
249   /// replaced with direct constants.  This method is optional.
250   ///
251   virtual void processFunctionBeforeFrameFinalized(MachineFunction &MF) const {}
252
253   /// eliminateFrameIndex - This method must be overriden to eliminate abstract
254   /// frame indices from instructions which may use them.  The instruction
255   /// referenced by the iterator contains an MO_FrameIndex operand which must be
256   /// eliminated by this method.  This method may modify or replace the
257   /// specified instruction, as long as it keeps the iterator pointing the the
258   /// finished product.
259   ///
260   virtual void eliminateFrameIndex(MachineFunction &MF,
261                                    MachineBasicBlock::iterator &II) const = 0;
262
263   /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
264   /// the function.
265   virtual void emitPrologue(MachineFunction &MF) const = 0;
266   virtual void emitEpilogue(MachineFunction &MF,
267                             MachineBasicBlock &MBB) const = 0;
268 };
269
270 #endif