Teach two-address pass to do some coalescing while eliminating REG_SEQUENCE
[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 struct 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   // Can be only subclassed.
56   explicit ARMBaseRegisterInfo(const ARMBaseInstrInfo &tii,
57                                const ARMSubtarget &STI);
58
59   // Return the opcode that implements 'Op', or 0 if no opcode
60   unsigned getOpcode(int Op) const;
61
62 public:
63   /// getRegisterNumbering - Given the enum value for some register, e.g.
64   /// ARM::LR, return the number that it corresponds to (e.g. 14). It
65   /// also returns true in isSPVFP if the register is a single precision
66   /// VFP register.
67   static unsigned getRegisterNumbering(unsigned RegEnum, bool *isSPVFP = 0);
68
69   /// Code Generation virtual methods...
70   const unsigned *getCalleeSavedRegs(const MachineFunction *MF = 0) const;
71
72   const TargetRegisterClass* const*
73   getCalleeSavedRegClasses(const MachineFunction *MF = 0) const;
74
75   BitVector getReservedRegs(const MachineFunction &MF) const;
76
77   /// getMatchingSuperRegClass - Return a subclass of the specified register
78   /// class A so that each register in it has a sub-register of the
79   /// specified sub-register index which is in the specified register class B.
80   virtual const TargetRegisterClass *
81   getMatchingSuperRegClass(const TargetRegisterClass *A,
82                            const TargetRegisterClass *B, unsigned Idx) const;
83
84   /// canCombinedSubRegIndex - Given a register class and a list of sub-register
85   /// indices, return true if it's possible to combine the sub-register indices
86   /// into one that corresponds to a larger sub-register. Return the new sub-
87   /// register index by reference. Note the new index by be zero if the given
88   /// sub-registers combined to form the whole register.
89   virtual bool canCombinedSubRegIndex(const TargetRegisterClass *RC,
90                                       SmallVectorImpl<unsigned> &SubIndices,
91                                       unsigned &NewSubIdx) const;
92
93   const TargetRegisterClass *getPointerRegClass(unsigned Kind = 0) const;
94
95   std::pair<TargetRegisterClass::iterator,TargetRegisterClass::iterator>
96   getAllocationOrder(const TargetRegisterClass *RC,
97                      unsigned HintType, unsigned HintReg,
98                      const MachineFunction &MF) const;
99
100   unsigned ResolveRegAllocHint(unsigned Type, unsigned Reg,
101                                const MachineFunction &MF) const;
102
103   void UpdateRegAllocHint(unsigned Reg, unsigned NewReg,
104                           MachineFunction &MF) const;
105
106   bool hasFP(const MachineFunction &MF) const;
107
108   bool canRealignStack(const MachineFunction &MF) const;
109   bool needsStackRealignment(const MachineFunction &MF) const;
110
111   bool cannotEliminateFrame(const MachineFunction &MF) const;
112
113   void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
114                                             RegScavenger *RS = NULL) const;
115
116   // Debug information queries.
117   unsigned getRARegister() const;
118   unsigned getFrameRegister(const MachineFunction &MF) const;
119   int getFrameIndexReference(const MachineFunction &MF, int FI,
120                              unsigned &FrameReg) const;
121   int getFrameIndexOffset(const MachineFunction &MF, int FI) const;
122
123   // Exception handling queries.
124   unsigned getEHExceptionRegister() const;
125   unsigned getEHHandlerRegister() const;
126
127   int getDwarfRegNum(unsigned RegNum, bool isEH) const;
128
129   bool isLowRegister(unsigned Reg) const;
130
131
132   /// emitLoadConstPool - Emits a load from constpool to materialize the
133   /// specified immediate.
134   virtual void emitLoadConstPool(MachineBasicBlock &MBB,
135                                  MachineBasicBlock::iterator &MBBI,
136                                  DebugLoc dl,
137                                  unsigned DestReg, unsigned SubIdx,
138                                  int Val,
139                                  ARMCC::CondCodes Pred = ARMCC::AL,
140                                  unsigned PredReg = 0) const;
141
142   /// Code Generation virtual methods...
143   virtual bool isReservedReg(const MachineFunction &MF, unsigned Reg) const;
144
145   virtual bool requiresRegisterScavenging(const MachineFunction &MF) const;
146
147   virtual bool requiresFrameIndexScavenging(const MachineFunction &MF) const;
148
149   virtual bool hasReservedCallFrame(MachineFunction &MF) const;
150   virtual bool canSimplifyCallFramePseudos(MachineFunction &MF) const;
151
152   virtual void eliminateCallFramePseudoInstr(MachineFunction &MF,
153                                              MachineBasicBlock &MBB,
154                                              MachineBasicBlock::iterator I) const;
155
156   virtual unsigned eliminateFrameIndex(MachineBasicBlock::iterator II,
157                                        int SPAdj, FrameIndexValue *Value = NULL,
158                                        RegScavenger *RS = NULL) const;
159
160   virtual void emitPrologue(MachineFunction &MF) const;
161   virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
162
163 private:
164   unsigned estimateRSStackSizeLimit(MachineFunction &MF) const;
165
166   unsigned getRegisterPairEven(unsigned Reg, const MachineFunction &MF) const;
167
168   unsigned getRegisterPairOdd(unsigned Reg, const MachineFunction &MF) const;
169 };
170
171 } // end namespace llvm
172
173 #endif