Rewrite stack callee saved spills and restores to use push/pop instructions.
[oota-llvm.git] / lib / Target / ARM / ARMBaseRegisterInfo.h
1 //===- ARMBaseRegisterInfo.h - ARM Register Information Impl ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the base ARM implementation of TargetRegisterInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef ARMBASEREGISTERINFO_H
15 #define ARMBASEREGISTERINFO_H
16
17 #include "ARM.h"
18 #include "llvm/Target/TargetRegisterInfo.h"
19 #include "ARMGenRegisterInfo.h.inc"
20
21 namespace llvm {
22   class ARMSubtarget;
23   class ARMBaseInstrInfo;
24   class Type;
25
26 /// Register allocation hints.
27 namespace ARMRI {
28   enum {
29     RegPairOdd  = 1,
30     RegPairEven = 2
31   };
32 }
33
34 /// isARMLowRegister - Returns true if the register is low register r0-r7.
35 ///
36 static inline bool isARMLowRegister(unsigned Reg) {
37   using namespace ARM;
38   switch (Reg) {
39   case R0:  case R1:  case R2:  case R3:
40   case R4:  case R5:  case R6:  case R7:
41     return true;
42   default:
43     return false;
44   }
45 }
46
47 /// isARMArea1Register - Returns true if the register is a low register (r0-r7)
48 /// or a stack/pc register that we should push/pop.
49 static inline bool isARMArea1Register(unsigned Reg, bool isDarwin) {
50   using namespace ARM;
51   switch (Reg) {
52     case R0:  case R1:  case R2:  case R3:
53     case R4:  case R5:  case R6:  case R7:
54     case LR:  case SP:  case PC:
55       return true;
56     case R8:  case R9:  case R10: case R11:
57       // For darwin we want r7 and lr to be next to each other.
58       return !isDarwin;
59     default:
60       return false;
61   }
62 }
63
64 static inline bool isARMArea2Register(unsigned Reg, bool isDarwin) {
65   using namespace ARM;
66   switch (Reg) {
67     case R8: case R9: case R10: case R11:
68       // Darwin has this second area.
69       return isDarwin;
70     default:
71       return false;
72   }
73 }
74
75 static inline bool isARMArea3Register(unsigned Reg, bool isDarwin) {
76   using namespace ARM;
77   switch (Reg) {
78     case D15: case D14: case D13: case D12:
79     case D11: case D10: case D9:  case D8:
80       return true;
81     default:
82       return false;
83   }
84 }
85
86 class ARMBaseRegisterInfo : public ARMGenRegisterInfo {
87 protected:
88   const ARMBaseInstrInfo &TII;
89   const ARMSubtarget &STI;
90
91   /// FramePtr - ARM physical register used as frame ptr.
92   unsigned FramePtr;
93
94   /// BasePtr - ARM physical register used as a base ptr in complex stack
95   /// frames. I.e., when we need a 3rd base, not just SP and FP, due to
96   /// variable size stack objects.
97   unsigned BasePtr;
98
99   // Can be only subclassed.
100   explicit ARMBaseRegisterInfo(const ARMBaseInstrInfo &tii,
101                                const ARMSubtarget &STI);
102
103   // Return the opcode that implements 'Op', or 0 if no opcode
104   unsigned getOpcode(int Op) const;
105
106 public:
107   /// Code Generation virtual methods...
108   const unsigned *getCalleeSavedRegs(const MachineFunction *MF = 0) const;
109
110   BitVector getReservedRegs(const MachineFunction &MF) const;
111
112   /// getMatchingSuperRegClass - Return a subclass of the specified register
113   /// class A so that each register in it has a sub-register of the
114   /// specified sub-register index which is in the specified register class B.
115   virtual const TargetRegisterClass *
116   getMatchingSuperRegClass(const TargetRegisterClass *A,
117                            const TargetRegisterClass *B, unsigned Idx) const;
118
119   /// canCombineSubRegIndices - Given a register class and a list of
120   /// subregister indices, return true if it's possible to combine the
121   /// subregister indices into one that corresponds to a larger
122   /// subregister. Return the new subregister index by reference. Note the
123   /// new index may be zero if the given subregisters can be combined to
124   /// form the whole register.
125   virtual bool canCombineSubRegIndices(const TargetRegisterClass *RC,
126                                        SmallVectorImpl<unsigned> &SubIndices,
127                                        unsigned &NewSubIdx) const;
128
129   const TargetRegisterClass *getPointerRegClass(unsigned Kind = 0) const;
130
131   std::pair<TargetRegisterClass::iterator,TargetRegisterClass::iterator>
132   getAllocationOrder(const TargetRegisterClass *RC,
133                      unsigned HintType, unsigned HintReg,
134                      const MachineFunction &MF) const;
135
136   unsigned ResolveRegAllocHint(unsigned Type, unsigned Reg,
137                                const MachineFunction &MF) const;
138
139   void UpdateRegAllocHint(unsigned Reg, unsigned NewReg,
140                           MachineFunction &MF) const;
141
142   bool hasFP(const MachineFunction &MF) const;
143   bool hasBasePointer(const MachineFunction &MF) const;
144
145   bool canRealignStack(const MachineFunction &MF) const;
146   bool needsStackRealignment(const MachineFunction &MF) const;
147   int64_t getFrameIndexInstrOffset(const MachineInstr *MI, int Idx) const;
148   bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const;
149   void materializeFrameBaseRegister(MachineBasicBlock::iterator I,
150                                     unsigned BaseReg, int FrameIdx,
151                                     int64_t Offset) const;
152   void resolveFrameIndex(MachineBasicBlock::iterator I,
153                          unsigned BaseReg, int64_t Offset) const;
154   bool isFrameOffsetLegal(const MachineInstr *MI, int64_t Offset) const;
155
156   bool cannotEliminateFrame(const MachineFunction &MF) const;
157
158   void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
159                                             RegScavenger *RS = NULL) const;
160
161   // Debug information queries.
162   unsigned getRARegister() const;
163   unsigned getFrameRegister(const MachineFunction &MF) const;
164   unsigned getBaseRegister() const { return BasePtr; }
165   int getFrameIndexReference(const MachineFunction &MF, int FI,
166                              unsigned &FrameReg) const;
167   int ResolveFrameIndexReference(const MachineFunction &MF, int FI,
168                                  unsigned &FrameReg, int SPAdj) const;
169   int getFrameIndexOffset(const MachineFunction &MF, int FI) const;
170
171   // Exception handling queries.
172   unsigned getEHExceptionRegister() const;
173   unsigned getEHHandlerRegister() const;
174
175   int getDwarfRegNum(unsigned RegNum, bool isEH) const;
176
177   bool isLowRegister(unsigned Reg) const;
178
179
180   /// emitLoadConstPool - Emits a load from constpool to materialize the
181   /// specified immediate.
182   virtual void emitLoadConstPool(MachineBasicBlock &MBB,
183                                  MachineBasicBlock::iterator &MBBI,
184                                  DebugLoc dl,
185                                  unsigned DestReg, unsigned SubIdx,
186                                  int Val,
187                                  ARMCC::CondCodes Pred = ARMCC::AL,
188                                  unsigned PredReg = 0) const;
189
190   /// Code Generation virtual methods...
191   virtual bool isReservedReg(const MachineFunction &MF, unsigned Reg) const;
192
193   virtual bool requiresRegisterScavenging(const MachineFunction &MF) const;
194
195   virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const;
196
197   virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const;
198
199   virtual bool hasReservedCallFrame(const MachineFunction &MF) const;
200   virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const;
201
202   virtual void eliminateCallFramePseudoInstr(MachineFunction &MF,
203                                            MachineBasicBlock &MBB,
204                                            MachineBasicBlock::iterator I) const;
205
206   virtual void eliminateFrameIndex(MachineBasicBlock::iterator II,
207                                    int SPAdj, RegScavenger *RS = NULL) const;
208
209 private:
210   unsigned estimateRSStackSizeLimit(MachineFunction &MF) const;
211
212   unsigned getRegisterPairEven(unsigned Reg, const MachineFunction &MF) const;
213
214   unsigned getRegisterPairOdd(unsigned Reg, const MachineFunction &MF) const;
215 };
216
217 } // end namespace llvm
218
219 #endif