Move some more hooks to TargetFrameInfo
[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 hasBasePointer(const MachineFunction &MF) const;
143
144   bool canRealignStack(const MachineFunction &MF) const;
145   bool needsStackRealignment(const MachineFunction &MF) const;
146   int64_t getFrameIndexInstrOffset(const MachineInstr *MI, int Idx) const;
147   bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const;
148   void materializeFrameBaseRegister(MachineBasicBlock::iterator I,
149                                     unsigned BaseReg, int FrameIdx,
150                                     int64_t Offset) const;
151   void resolveFrameIndex(MachineBasicBlock::iterator I,
152                          unsigned BaseReg, int64_t Offset) const;
153   bool isFrameOffsetLegal(const MachineInstr *MI, int64_t Offset) const;
154
155   bool cannotEliminateFrame(const MachineFunction &MF) const;
156
157   void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
158                                             RegScavenger *RS = NULL) const;
159
160   // Debug information queries.
161   unsigned getRARegister() const;
162   unsigned getFrameRegister(const MachineFunction &MF) const;
163   unsigned getBaseRegister() const { return BasePtr; }
164
165   // Exception handling queries.
166   unsigned getEHExceptionRegister() const;
167   unsigned getEHHandlerRegister() const;
168
169   int getDwarfRegNum(unsigned RegNum, bool isEH) const;
170
171   bool isLowRegister(unsigned Reg) const;
172
173
174   /// emitLoadConstPool - Emits a load from constpool to materialize the
175   /// specified immediate.
176   virtual void emitLoadConstPool(MachineBasicBlock &MBB,
177                                  MachineBasicBlock::iterator &MBBI,
178                                  DebugLoc dl,
179                                  unsigned DestReg, unsigned SubIdx,
180                                  int Val,
181                                  ARMCC::CondCodes Pred = ARMCC::AL,
182                                  unsigned PredReg = 0) const;
183
184   /// Code Generation virtual methods...
185   virtual bool isReservedReg(const MachineFunction &MF, unsigned Reg) const;
186
187   virtual bool requiresRegisterScavenging(const MachineFunction &MF) const;
188
189   virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const;
190
191   virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const;
192
193   virtual void eliminateCallFramePseudoInstr(MachineFunction &MF,
194                                            MachineBasicBlock &MBB,
195                                            MachineBasicBlock::iterator I) const;
196
197   virtual void eliminateFrameIndex(MachineBasicBlock::iterator II,
198                                    int SPAdj, RegScavenger *RS = NULL) const;
199
200 private:
201   unsigned estimateRSStackSizeLimit(MachineFunction &MF) const;
202
203   unsigned getRegisterPairEven(unsigned Reg, const MachineFunction &MF) const;
204
205   unsigned getRegisterPairOdd(unsigned Reg, const MachineFunction &MF) const;
206 };
207
208 } // end namespace llvm
209
210 #endif