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