Generalize opcode selection in ARMBaseRegisterInfo.
[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, const ARMSubtarget &STI);
57
58   // Return the opcode that implements 'Op', or 0 if no opcode
59   unsigned getOpcode(int Op) const;
60
61 public:
62   /// getRegisterNumbering - Given the enum value for some register, e.g.
63   /// ARM::LR, return the number that it corresponds to (e.g. 14).
64   static unsigned getRegisterNumbering(unsigned RegEnum);
65
66   /// Same as previous getRegisterNumbering except it returns true in isSPVFP
67   /// if the register is a single precision VFP register.
68   static unsigned getRegisterNumbering(unsigned RegEnum, bool &isSPVFP);
69
70   /// Code Generation virtual methods...
71   const unsigned *getCalleeSavedRegs(const MachineFunction *MF = 0) const;
72
73   const TargetRegisterClass* const*
74   getCalleeSavedRegClasses(const MachineFunction *MF = 0) const;
75
76   BitVector getReservedRegs(const MachineFunction &MF) const;
77
78   const TargetRegisterClass *getPointerRegClass() const;
79
80   std::pair<TargetRegisterClass::iterator,TargetRegisterClass::iterator>
81   getAllocationOrder(const TargetRegisterClass *RC,
82                      unsigned HintType, unsigned HintReg,
83                      const MachineFunction &MF) const;
84
85   unsigned ResolveRegAllocHint(unsigned Type, unsigned Reg,
86                                const MachineFunction &MF) const;
87
88   void UpdateRegAllocHint(unsigned Reg, unsigned NewReg,
89                           MachineFunction &MF) const;
90
91   bool hasFP(const MachineFunction &MF) const;
92
93   void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
94                                             RegScavenger *RS = NULL) const;
95
96   // Debug information queries.
97   unsigned getRARegister() const;
98   unsigned getFrameRegister(MachineFunction &MF) const;
99
100   // Exception handling queries.
101   unsigned getEHExceptionRegister() const;
102   unsigned getEHHandlerRegister() const;
103
104   int getDwarfRegNum(unsigned RegNum, bool isEH) const;
105
106   bool isLowRegister(unsigned Reg) const;
107
108
109   /// emitLoadConstPool - Emits a load from constpool to materialize the
110   /// specified immediate.
111   virtual void emitLoadConstPool(MachineBasicBlock &MBB,
112                                  MachineBasicBlock::iterator &MBBI,
113                                  DebugLoc dl,
114                                  unsigned DestReg, int Val,
115                                  ARMCC::CondCodes Pred = ARMCC::AL,
116                                  unsigned PredReg = 0) const;
117
118   /// Code Generation virtual methods...
119   virtual bool isReservedReg(const MachineFunction &MF, unsigned Reg) const;
120
121   virtual bool requiresRegisterScavenging(const MachineFunction &MF) const;
122
123   virtual bool hasReservedCallFrame(MachineFunction &MF) const;
124
125   virtual void eliminateCallFramePseudoInstr(MachineFunction &MF,
126                                              MachineBasicBlock &MBB,
127                                              MachineBasicBlock::iterator I) const;
128
129   virtual void eliminateFrameIndex(MachineBasicBlock::iterator II,
130                                    int SPAdj, RegScavenger *RS = NULL) const;
131
132   virtual void emitPrologue(MachineFunction &MF) const;
133   virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
134
135 private:
136   unsigned getRegisterPairEven(unsigned Reg, const MachineFunction &MF) const;
137
138   unsigned getRegisterPairOdd(unsigned Reg, const MachineFunction &MF) const;
139 };
140
141 } // end namespace llvm
142
143 #endif