For ARM stack frames that utilize variable sized objects and have either
[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 class ARMBaseRegisterInfo : public ARMGenRegisterInfo {
48 protected:
49   const ARMBaseInstrInfo &TII;
50   const ARMSubtarget &STI;
51
52   /// FramePtr - ARM physical register used as frame ptr.
53   unsigned FramePtr;
54
55   /// BasePtr - ARM physical register used as a base ptr in complex stack
56   /// frames. I.e., when we need a 3rd base, not just SP and FP, due to
57   /// variable size stack objects.
58   unsigned BasePtr;
59
60   // Can be only subclassed.
61   explicit ARMBaseRegisterInfo(const ARMBaseInstrInfo &tii,
62                                const ARMSubtarget &STI);
63
64   // Return the opcode that implements 'Op', or 0 if no opcode
65   unsigned getOpcode(int Op) const;
66
67 public:
68   /// getRegisterNumbering - Given the enum value for some register, e.g.
69   /// ARM::LR, return the number that it corresponds to (e.g. 14). It
70   /// also returns true in isSPVFP if the register is a single precision
71   /// VFP register.
72   static unsigned getRegisterNumbering(unsigned RegEnum, bool *isSPVFP = 0);
73
74   /// Code Generation virtual methods...
75   const unsigned *getCalleeSavedRegs(const MachineFunction *MF = 0) const;
76
77   BitVector getReservedRegs(const MachineFunction &MF) const;
78
79   /// getMatchingSuperRegClass - Return a subclass of the specified register
80   /// class A so that each register in it has a sub-register of the
81   /// specified sub-register index which is in the specified register class B.
82   virtual const TargetRegisterClass *
83   getMatchingSuperRegClass(const TargetRegisterClass *A,
84                            const TargetRegisterClass *B, unsigned Idx) const;
85
86   /// canCombineSubRegIndices - Given a register class and a list of
87   /// subregister indices, return true if it's possible to combine the
88   /// subregister indices into one that corresponds to a larger
89   /// subregister. Return the new subregister index by reference. Note the
90   /// new index may be zero if the given subregisters can be combined to
91   /// form the whole register.
92   virtual bool canCombineSubRegIndices(const TargetRegisterClass *RC,
93                                        SmallVectorImpl<unsigned> &SubIndices,
94                                        unsigned &NewSubIdx) const;
95
96   const TargetRegisterClass *getPointerRegClass(unsigned Kind = 0) const;
97
98   std::pair<TargetRegisterClass::iterator,TargetRegisterClass::iterator>
99   getAllocationOrder(const TargetRegisterClass *RC,
100                      unsigned HintType, unsigned HintReg,
101                      const MachineFunction &MF) const;
102
103   unsigned ResolveRegAllocHint(unsigned Type, unsigned Reg,
104                                const MachineFunction &MF) const;
105
106   void UpdateRegAllocHint(unsigned Reg, unsigned NewReg,
107                           MachineFunction &MF) const;
108
109   bool hasFP(const MachineFunction &MF) const;
110   bool hasBasePointer(const MachineFunction &MF) const;
111
112   bool canRealignStack(const MachineFunction &MF) const;
113   bool needsStackRealignment(const MachineFunction &MF) const;
114   int64_t getFrameIndexInstrOffset(const MachineInstr *MI, int Idx) const;
115   bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const;
116   void materializeFrameBaseRegister(MachineBasicBlock::iterator I,
117                                     unsigned BaseReg, int FrameIdx,
118                                     int64_t Offset) const;
119   void resolveFrameIndex(MachineBasicBlock::iterator I,
120                          unsigned BaseReg, int64_t Offset) const;
121   bool isFrameOffsetLegal(const MachineInstr *MI, int64_t Offset) const;
122
123   bool cannotEliminateFrame(const MachineFunction &MF) const;
124
125   void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
126                                             RegScavenger *RS = NULL) const;
127
128   // Debug information queries.
129   unsigned getRARegister() const;
130   unsigned getFrameRegister(const MachineFunction &MF) const;
131   int getFrameIndexReference(const MachineFunction &MF, int FI,
132                              unsigned &FrameReg) const;
133   int ResolveFrameIndexReference(const MachineFunction &MF, int FI,
134                                  unsigned &FrameReg, int SPAdj) const;
135   int getFrameIndexOffset(const MachineFunction &MF, int FI) const;
136
137   // Exception handling queries.
138   unsigned getEHExceptionRegister() const;
139   unsigned getEHHandlerRegister() const;
140
141   int getDwarfRegNum(unsigned RegNum, bool isEH) const;
142
143   bool isLowRegister(unsigned Reg) const;
144
145
146   /// emitLoadConstPool - Emits a load from constpool to materialize the
147   /// specified immediate.
148   virtual void emitLoadConstPool(MachineBasicBlock &MBB,
149                                  MachineBasicBlock::iterator &MBBI,
150                                  DebugLoc dl,
151                                  unsigned DestReg, unsigned SubIdx,
152                                  int Val,
153                                  ARMCC::CondCodes Pred = ARMCC::AL,
154                                  unsigned PredReg = 0) const;
155
156   /// Code Generation virtual methods...
157   virtual bool isReservedReg(const MachineFunction &MF, unsigned Reg) const;
158
159   virtual bool requiresRegisterScavenging(const MachineFunction &MF) const;
160
161   virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const;
162
163   virtual bool requiresVirtualBaseRegisters(const MachineFunction &MF) const;
164
165   virtual bool hasReservedCallFrame(const MachineFunction &MF) const;
166   virtual bool canSimplifyCallFramePseudos(const MachineFunction &MF) const;
167
168   virtual void eliminateCallFramePseudoInstr(MachineFunction &MF,
169                                            MachineBasicBlock &MBB,
170                                            MachineBasicBlock::iterator I) const;
171
172   virtual void eliminateFrameIndex(MachineBasicBlock::iterator II,
173                                    int SPAdj, RegScavenger *RS = NULL) const;
174
175   virtual void emitPrologue(MachineFunction &MF) const;
176   virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
177
178 private:
179   unsigned estimateRSStackSizeLimit(MachineFunction &MF) const;
180
181   unsigned getRegisterPairEven(unsigned Reg, const MachineFunction &MF) const;
182
183   unsigned getRegisterPairOdd(unsigned Reg, const MachineFunction &MF) const;
184 };
185
186 } // end namespace llvm
187
188 #endif