ARMBaseRegisterInfo.h revision 98a0104014e9bb6ed89c2572f615351fd526674a
12cfd52c507bd5790457a171eb9bcb39019cc6860Chris Lattner//===- ARMBaseRegisterInfo.h - ARM Register Information Impl ----*- C++ -*-===//
2c140c4803dc3e10e08138670829bc0494986abe9David Goodwin//
3c140c4803dc3e10e08138670829bc0494986abe9David Goodwin//                     The LLVM Compiler Infrastructure
4c140c4803dc3e10e08138670829bc0494986abe9David Goodwin//
5c140c4803dc3e10e08138670829bc0494986abe9David Goodwin// This file is distributed under the University of Illinois Open Source
6c140c4803dc3e10e08138670829bc0494986abe9David Goodwin// License. See LICENSE.TXT for details.
7c140c4803dc3e10e08138670829bc0494986abe9David Goodwin//
8c140c4803dc3e10e08138670829bc0494986abe9David Goodwin//===----------------------------------------------------------------------===//
9c140c4803dc3e10e08138670829bc0494986abe9David Goodwin//
10c140c4803dc3e10e08138670829bc0494986abe9David Goodwin// This file contains the base ARM implementation of TargetRegisterInfo class.
11c140c4803dc3e10e08138670829bc0494986abe9David Goodwin//
12c140c4803dc3e10e08138670829bc0494986abe9David Goodwin//===----------------------------------------------------------------------===//
13c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
14c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#ifndef ARMBASEREGISTERINFO_H
15c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#define ARMBASEREGISTERINFO_H
16c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
17c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#include "ARM.h"
18c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#include "llvm/Target/TargetRegisterInfo.h"
19c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#include "ARMGenRegisterInfo.h.inc"
20c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
21c140c4803dc3e10e08138670829bc0494986abe9David Goodwinnamespace llvm {
22c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  class ARMSubtarget;
23db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin  class ARMBaseInstrInfo;
24c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  class Type;
25c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
26c140c4803dc3e10e08138670829bc0494986abe9David Goodwin/// Register allocation hints.
27c140c4803dc3e10e08138670829bc0494986abe9David Goodwinnamespace ARMRI {
28c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  enum {
29c140c4803dc3e10e08138670829bc0494986abe9David Goodwin    RegPairOdd  = 1,
30c140c4803dc3e10e08138670829bc0494986abe9David Goodwin    RegPairEven = 2
31c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  };
32c140c4803dc3e10e08138670829bc0494986abe9David Goodwin}
33c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
34c140c4803dc3e10e08138670829bc0494986abe9David Goodwin/// isARMLowRegister - Returns true if the register is low register r0-r7.
35c140c4803dc3e10e08138670829bc0494986abe9David Goodwin///
36c140c4803dc3e10e08138670829bc0494986abe9David Goodwinstatic inline bool isARMLowRegister(unsigned Reg) {
37c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  using namespace ARM;
38c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  switch (Reg) {
39c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  case R0:  case R1:  case R2:  case R3:
40c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  case R4:  case R5:  case R6:  case R7:
41c140c4803dc3e10e08138670829bc0494986abe9David Goodwin    return true;
42c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  default:
43c140c4803dc3e10e08138670829bc0494986abe9David Goodwin    return false;
44c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  }
45c140c4803dc3e10e08138670829bc0494986abe9David Goodwin}
46c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
47c140c4803dc3e10e08138670829bc0494986abe9David Goodwinstruct ARMBaseRegisterInfo : public ARMGenRegisterInfo {
48c140c4803dc3e10e08138670829bc0494986abe9David Goodwinprotected:
49db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin  const ARMBaseInstrInfo &TII;
50c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  const ARMSubtarget &STI;
51c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
52c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  /// FramePtr - ARM physical register used as frame ptr.
53c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  unsigned FramePtr;
54c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
55db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin  // Can be only subclassed.
56b5619f42f4fdf347380d28357549df09b9ca3946Evan Cheng  explicit ARMBaseRegisterInfo(const ARMBaseInstrInfo &tii,
57b5619f42f4fdf347380d28357549df09b9ca3946Evan Cheng                               const ARMSubtarget &STI);
58db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin
5977521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin  // Return the opcode that implements 'Op', or 0 if no opcode
6077521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin  unsigned getOpcode(int Op) const;
6177521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin
62db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwinpublic:
63c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  /// getRegisterNumbering - Given the enum value for some register, e.g.
648295d99bff6f8e3dfdfdaf1871cb72adab423f20Evan Cheng  /// ARM::LR, return the number that it corresponds to (e.g. 14). It
658295d99bff6f8e3dfdfdaf1871cb72adab423f20Evan Cheng  /// also returns true in isSPVFP if the register is a single precision
668295d99bff6f8e3dfdfdaf1871cb72adab423f20Evan Cheng  /// VFP register.
678295d99bff6f8e3dfdfdaf1871cb72adab423f20Evan Cheng  static unsigned getRegisterNumbering(unsigned RegEnum, bool *isSPVFP = 0);
68c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
69c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  /// Code Generation virtual methods...
70c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  const unsigned *getCalleeSavedRegs(const MachineFunction *MF = 0) const;
71c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
72c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  const TargetRegisterClass* const*
73c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  getCalleeSavedRegClasses(const MachineFunction *MF = 0) const;
74c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
75c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  BitVector getReservedRegs(const MachineFunction &MF) const;
76c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
772cfd52c507bd5790457a171eb9bcb39019cc6860Chris Lattner  const TargetRegisterClass *getPointerRegClass(unsigned Kind = 0) const;
78c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
79c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  std::pair<TargetRegisterClass::iterator,TargetRegisterClass::iterator>
80c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  getAllocationOrder(const TargetRegisterClass *RC,
81c140c4803dc3e10e08138670829bc0494986abe9David Goodwin                     unsigned HintType, unsigned HintReg,
82c140c4803dc3e10e08138670829bc0494986abe9David Goodwin                     const MachineFunction &MF) const;
83c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
84c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  unsigned ResolveRegAllocHint(unsigned Type, unsigned Reg,
85c140c4803dc3e10e08138670829bc0494986abe9David Goodwin                               const MachineFunction &MF) const;
86c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
87c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  void UpdateRegAllocHint(unsigned Reg, unsigned NewReg,
88c140c4803dc3e10e08138670829bc0494986abe9David Goodwin                          MachineFunction &MF) const;
89c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
90c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  bool hasFP(const MachineFunction &MF) const;
9198a0104014e9bb6ed89c2572f615351fd526674aEvan Cheng
9298a0104014e9bb6ed89c2572f615351fd526674aEvan Cheng  bool hasStackFrame(const MachineFunction &MF) const;
93c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
94c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
95c140c4803dc3e10e08138670829bc0494986abe9David Goodwin                                            RegScavenger *RS = NULL) const;
96c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
97c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  // Debug information queries.
98c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  unsigned getRARegister() const;
99c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  unsigned getFrameRegister(MachineFunction &MF) const;
100c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
101c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  // Exception handling queries.
102c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  unsigned getEHExceptionRegister() const;
103c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  unsigned getEHHandlerRegister() const;
104c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
105c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  int getDwarfRegNum(unsigned RegNum, bool isEH) const;
106c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
107c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  bool isLowRegister(unsigned Reg) const;
108c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
109db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin
110db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin  /// emitLoadConstPool - Emits a load from constpool to materialize the
111db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin  /// specified immediate.
112db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin  virtual void emitLoadConstPool(MachineBasicBlock &MBB,
113db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin                                 MachineBasicBlock::iterator &MBBI,
11477521f5232e679aa3de10aaaed2464aa91d7ff55David Goodwin                                 DebugLoc dl,
115378445303b10b092a898a75131141a8259cff50bEvan Cheng                                 unsigned DestReg, unsigned SubIdx,
116378445303b10b092a898a75131141a8259cff50bEvan Cheng                                 int Val,
117db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin                                 ARMCC::CondCodes Pred = ARMCC::AL,
118db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin                                 unsigned PredReg = 0) const;
119db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin
120db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin  /// Code Generation virtual methods...
121db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin  virtual bool isReservedReg(const MachineFunction &MF, unsigned Reg) const;
122db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin
123db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin  virtual bool requiresRegisterScavenging(const MachineFunction &MF) const;
124db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin
125db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin  virtual bool hasReservedCallFrame(MachineFunction &MF) const;
126db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin
127db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin  virtual void eliminateCallFramePseudoInstr(MachineFunction &MF,
128db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin                                             MachineBasicBlock &MBB,
129db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin                                             MachineBasicBlock::iterator I) const;
130db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin
1316495f63945e8dbde81f03a1dc2ab421993b9a495Evan Cheng  virtual void eliminateFrameIndex(MachineBasicBlock::iterator II,
1326495f63945e8dbde81f03a1dc2ab421993b9a495Evan Cheng                                   int SPAdj, RegScavenger *RS = NULL) const;
133db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin
134db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin  virtual void emitPrologue(MachineFunction &MF) const;
135db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin  virtual void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
136db5a71a8e01ed9a0d93a19176df6ea0aea510d7bDavid Goodwin
137c140c4803dc3e10e08138670829bc0494986abe9David Goodwinprivate:
138ee42fd309ee6a8febfafb97c2f3b6f2069758c5eEvan Cheng  unsigned estimateRSStackSizeLimit(MachineFunction &MF) const;
139ee42fd309ee6a8febfafb97c2f3b6f2069758c5eEvan Cheng
140c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  unsigned getRegisterPairEven(unsigned Reg, const MachineFunction &MF) const;
141c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
142c140c4803dc3e10e08138670829bc0494986abe9David Goodwin  unsigned getRegisterPairOdd(unsigned Reg, const MachineFunction &MF) const;
143c140c4803dc3e10e08138670829bc0494986abe9David Goodwin};
144c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
145c140c4803dc3e10e08138670829bc0494986abe9David Goodwin} // end namespace llvm
146c140c4803dc3e10e08138670829bc0494986abe9David Goodwin
147c140c4803dc3e10e08138670829bc0494986abe9David Goodwin#endif
148