4c762dc1a23481102a225ace8c896a532d1959c3
[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 LLVM_LIB_TARGET_ARM_ARMBASEREGISTERINFO_H
15 #define LLVM_LIB_TARGET_ARM_ARMBASEREGISTERINFO_H
16
17 #include "MCTargetDesc/ARMBaseInfo.h"
18 #include "llvm/Target/TargetRegisterInfo.h"
19
20 #define GET_REGINFO_HEADER
21 #include "ARMGenRegisterInfo.inc"
22
23 namespace llvm {
24 /// Register allocation hints.
25 namespace ARMRI {
26   enum {
27     RegPairOdd  = 1,
28     RegPairEven = 2
29   };
30 }
31
32 /// isARMArea1Register - Returns true if the register is a low register (r0-r7)
33 /// or a stack/pc register that we should push/pop.
34 static inline bool isARMArea1Register(unsigned Reg, bool isIOS) {
35   using namespace ARM;
36   switch (Reg) {
37     case R0:  case R1:  case R2:  case R3:
38     case R4:  case R5:  case R6:  case R7:
39     case LR:  case SP:  case PC:
40       return true;
41     case R8:  case R9:  case R10: case R11: case R12:
42       // For iOS we want r7 and lr to be next to each other.
43       return !isIOS;
44     default:
45       return false;
46   }
47 }
48
49 static inline bool isARMArea2Register(unsigned Reg, bool isIOS) {
50   using namespace ARM;
51   switch (Reg) {
52     case R8: case R9: case R10: case R11: case R12:
53       // iOS has this second area.
54       return isIOS;
55     default:
56       return false;
57   }
58 }
59
60 static inline bool isARMArea3Register(unsigned Reg, bool isIOS) {
61   using namespace ARM;
62   switch (Reg) {
63     case D15: case D14: case D13: case D12:
64     case D11: case D10: case D9:  case D8:
65     case D7:  case D6:  case D5:  case D4:
66     case D3:  case D2:  case D1:  case D0:
67     case D31: case D30: case D29: case D28:
68     case D27: case D26: case D25: case D24:
69     case D23: case D22: case D21: case D20:
70     case D19: case D18: case D17: case D16:
71       return true;
72     default:
73       return false;
74   }
75 }
76
77 static inline bool isCalleeSavedRegister(unsigned Reg,
78                                          const MCPhysReg *CSRegs) {
79   for (unsigned i = 0; CSRegs[i]; ++i)
80     if (Reg == CSRegs[i])
81       return true;
82   return false;
83 }
84
85 class ARMBaseRegisterInfo : public ARMGenRegisterInfo {
86 protected:
87   /// BasePtr - ARM physical register used as a base ptr in complex stack
88   /// frames. I.e., when we need a 3rd base, not just SP and FP, due to
89   /// variable size stack objects.
90   unsigned BasePtr;
91
92   // Can be only subclassed.
93   explicit ARMBaseRegisterInfo();
94
95   // Return the opcode that implements 'Op', or 0 if no opcode
96   unsigned getOpcode(int Op) const;
97
98 public:
99   /// Code Generation virtual methods...
100   const MCPhysReg *getCalleeSavedRegs(const MachineFunction *MF) const override;
101   const uint32_t *getCallPreservedMask(const MachineFunction &MF,
102                                        CallingConv::ID) const override;
103   const uint32_t *getNoPreservedMask() const override;
104   const uint32_t *getTLSCallPreservedMask(const MachineFunction &MF) const;
105
106   /// getThisReturnPreservedMask - Returns a call preserved mask specific to the
107   /// case that 'returned' is on an i32 first argument if the calling convention
108   /// is one that can (partially) model this attribute with a preserved mask
109   /// (i.e. it is a calling convention that uses the same register for the first
110   /// i32 argument and an i32 return value)
111   ///
112   /// Should return NULL in the case that the calling convention does not have
113   /// this property
114   const uint32_t *getThisReturnPreservedMask(const MachineFunction &MF,
115                                              CallingConv::ID) const;
116
117   BitVector getReservedRegs(const MachineFunction &MF) const override;
118
119   const TargetRegisterClass *
120   getPointerRegClass(const MachineFunction &MF,
121                      unsigned Kind = 0) const override;
122   const TargetRegisterClass *
123   getCrossCopyRegClass(const TargetRegisterClass *RC) const override;
124
125   const TargetRegisterClass *
126   getLargestLegalSuperClass(const TargetRegisterClass *RC,
127                             const MachineFunction &MF) const override;
128
129   unsigned getRegPressureLimit(const TargetRegisterClass *RC,
130                                MachineFunction &MF) const override;
131
132   void getRegAllocationHints(unsigned VirtReg,
133                              ArrayRef<MCPhysReg> Order,
134                              SmallVectorImpl<MCPhysReg> &Hints,
135                              const MachineFunction &MF,
136                              const VirtRegMap *VRM,
137                              const LiveRegMatrix *Matrix) const override;
138
139   void updateRegAllocHint(unsigned Reg, unsigned NewReg,
140                           MachineFunction &MF) const override;
141
142   bool hasBasePointer(const MachineFunction &MF) const;
143
144   bool canRealignStack(const MachineFunction &MF) const override;
145   int64_t getFrameIndexInstrOffset(const MachineInstr *MI,
146                                    int Idx) const override;
147   bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override;
148   void materializeFrameBaseRegister(MachineBasicBlock *MBB,
149                                     unsigned BaseReg, int FrameIdx,
150                                     int64_t Offset) const override;
151   void resolveFrameIndex(MachineInstr &MI, unsigned BaseReg,
152                          int64_t Offset) const override;
153   bool isFrameOffsetLegal(const MachineInstr *MI, unsigned BaseReg,
154                           int64_t Offset) const override;
155
156   bool cannotEliminateFrame(const MachineFunction &MF) const;
157
158   // Debug information queries.
159   unsigned getFrameRegister(const MachineFunction &MF) const override;
160   unsigned getBaseRegister() const { return BasePtr; }
161
162   bool isLowRegister(unsigned Reg) const;
163
164
165   /// emitLoadConstPool - Emits a load from constpool to materialize the
166   /// specified immediate.
167   virtual void emitLoadConstPool(MachineBasicBlock &MBB,
168                                  MachineBasicBlock::iterator &MBBI,
169                                  DebugLoc dl, unsigned DestReg, unsigned SubIdx,
170                                  int Val, ARMCC::CondCodes Pred = ARMCC::AL,
171                                  unsigned PredReg = 0,
172                                  unsigned MIFlags = MachineInstr::NoFlags)const;
173
174   /// Code Generation virtual methods...
175   bool requiresRegisterScavenging(const MachineFunction &MF) const override;
176
177   bool trackLivenessAfterRegAlloc(const MachineFunction &MF) const override;
178
179   bool requiresFrameIndexScavenging(const MachineFunction &MF) const override;
180
181   bool requiresVirtualBaseRegisters(const MachineFunction &MF) const override;
182
183   void eliminateFrameIndex(MachineBasicBlock::iterator II,
184                            int SPAdj, unsigned FIOperandNum,
185                            RegScavenger *RS = nullptr) const override;
186
187   /// \brief SrcRC and DstRC will be morphed into NewRC if this returns true
188   bool shouldCoalesce(MachineInstr *MI,
189                       const TargetRegisterClass *SrcRC,
190                       unsigned SubReg,
191                       const TargetRegisterClass *DstRC,
192                       unsigned DstSubReg,
193                       const TargetRegisterClass *NewRC) const override;
194 };
195
196 } // end namespace llvm
197
198 #endif