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