ARMBaseRegisterInfo.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //===-- ARMBaseRegisterInfo.h - ARM Register Information Impl ---*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file contains the base ARM implementation of TargetRegisterInfo class.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_ARM_ARMBASEREGISTERINFO_H
  13. #define LLVM_LIB_TARGET_ARM_ARMBASEREGISTERINFO_H
  14. #include "MCTargetDesc/ARMBaseInfo.h"
  15. #include "llvm/CodeGen/MachineBasicBlock.h"
  16. #include "llvm/CodeGen/MachineInstr.h"
  17. #include "llvm/CodeGen/TargetRegisterInfo.h"
  18. #include "llvm/IR/CallingConv.h"
  19. #include "llvm/MC/MCRegisterInfo.h"
  20. #include <cstdint>
  21. #define GET_REGINFO_HEADER
  22. #include "ARMGenRegisterInfo.inc"
  23. namespace llvm {
  24. class LiveIntervals;
  25. /// Register allocation hints.
  26. namespace ARMRI {
  27. enum {
  28. // Used for LDRD register pairs
  29. RegPairOdd = 1,
  30. RegPairEven = 2,
  31. // Used to hint for lr in t2DoLoopStart
  32. RegLR = 3
  33. };
  34. } // end namespace ARMRI
  35. /// isARMArea1Register - Returns true if the register is a low register (r0-r7)
  36. /// or a stack/pc register that we should push/pop.
  37. static inline bool isARMArea1Register(unsigned Reg, bool isIOS) {
  38. using namespace ARM;
  39. switch (Reg) {
  40. case R0: case R1: case R2: case R3:
  41. case R4: case R5: case R6: case R7:
  42. case LR: case SP: case PC:
  43. return true;
  44. case R8: case R9: case R10: case R11: case R12:
  45. // For iOS we want r7 and lr to be next to each other.
  46. return !isIOS;
  47. default:
  48. return false;
  49. }
  50. }
  51. static inline bool isARMArea2Register(unsigned Reg, bool isIOS) {
  52. using namespace ARM;
  53. switch (Reg) {
  54. case R8: case R9: case R10: case R11: case R12:
  55. // iOS has this second area.
  56. return isIOS;
  57. default:
  58. return false;
  59. }
  60. }
  61. static inline bool isARMArea3Register(unsigned Reg, bool isIOS) {
  62. using namespace ARM;
  63. switch (Reg) {
  64. case D15: case D14: case D13: case D12:
  65. case D11: case D10: case D9: case D8:
  66. case D7: case D6: case D5: case D4:
  67. case D3: case D2: case D1: case D0:
  68. case D31: case D30: case D29: case D28:
  69. case D27: case D26: case D25: case D24:
  70. case D23: case D22: case D21: case D20:
  71. case D19: case D18: case D17: case D16:
  72. return true;
  73. default:
  74. return false;
  75. }
  76. }
  77. static inline bool isCalleeSavedRegister(unsigned Reg,
  78. const MCPhysReg *CSRegs) {
  79. for (unsigned i = 0; CSRegs[i]; ++i)
  80. if (Reg == CSRegs[i])
  81. return true;
  82. return false;
  83. }
  84. class ARMBaseRegisterInfo : public ARMGenRegisterInfo {
  85. protected:
  86. /// BasePtr - ARM physical register used as a base ptr in complex stack
  87. /// frames. I.e., when we need a 3rd base, not just SP and FP, due to
  88. /// variable size stack objects.
  89. unsigned BasePtr = ARM::R6;
  90. // Can be only subclassed.
  91. explicit ARMBaseRegisterInfo();
  92. // Return the opcode that implements 'Op', or 0 if no opcode
  93. unsigned getOpcode(int Op) const;
  94. public:
  95. /// Code Generation virtual methods...
  96. const MCPhysReg *getCalleeSavedRegs(const MachineFunction *MF) const override;
  97. const MCPhysReg *
  98. getCalleeSavedRegsViaCopy(const MachineFunction *MF) const;
  99. const uint32_t *getCallPreservedMask(const MachineFunction &MF,
  100. CallingConv::ID) const override;
  101. const uint32_t *getNoPreservedMask() const override;
  102. const uint32_t *getTLSCallPreservedMask(const MachineFunction &MF) const;
  103. const uint32_t *getSjLjDispatchPreservedMask(const MachineFunction &MF) const;
  104. /// getThisReturnPreservedMask - Returns a call preserved mask specific to the
  105. /// case that 'returned' is on an i32 first argument if the calling convention
  106. /// is one that can (partially) model this attribute with a preserved mask
  107. /// (i.e. it is a calling convention that uses the same register for the first
  108. /// i32 argument and an i32 return value)
  109. ///
  110. /// Should return NULL in the case that the calling convention does not have
  111. /// this property
  112. const uint32_t *getThisReturnPreservedMask(const MachineFunction &MF,
  113. CallingConv::ID) const;
  114. ArrayRef<MCPhysReg>
  115. getIntraCallClobberedRegs(const MachineFunction *MF) const override;
  116. BitVector getReservedRegs(const MachineFunction &MF) const override;
  117. bool isAsmClobberable(const MachineFunction &MF,
  118. MCRegister PhysReg) const override;
  119. bool isInlineAsmReadOnlyReg(const MachineFunction &MF,
  120. unsigned PhysReg) const override;
  121. const TargetRegisterClass *
  122. getPointerRegClass(const MachineFunction &MF,
  123. unsigned Kind = 0) const override;
  124. const TargetRegisterClass *
  125. getCrossCopyRegClass(const TargetRegisterClass *RC) const override;
  126. const TargetRegisterClass *
  127. getLargestLegalSuperClass(const TargetRegisterClass *RC,
  128. const MachineFunction &MF) const override;
  129. unsigned getRegPressureLimit(const TargetRegisterClass *RC,
  130. MachineFunction &MF) const override;
  131. bool getRegAllocationHints(Register VirtReg, ArrayRef<MCPhysReg> Order,
  132. SmallVectorImpl<MCPhysReg> &Hints,
  133. const MachineFunction &MF, const VirtRegMap *VRM,
  134. const LiveRegMatrix *Matrix) const override;
  135. void updateRegAllocHint(Register Reg, Register NewReg,
  136. MachineFunction &MF) const override;
  137. bool hasBasePointer(const MachineFunction &MF) const;
  138. bool canRealignStack(const MachineFunction &MF) const override;
  139. int64_t getFrameIndexInstrOffset(const MachineInstr *MI,
  140. int Idx) const override;
  141. bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override;
  142. Register materializeFrameBaseRegister(MachineBasicBlock *MBB, int FrameIdx,
  143. int64_t Offset) const override;
  144. void resolveFrameIndex(MachineInstr &MI, Register BaseReg,
  145. int64_t Offset) const override;
  146. bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg,
  147. int64_t Offset) const override;
  148. bool cannotEliminateFrame(const MachineFunction &MF) const;
  149. // Debug information queries.
  150. Register getFrameRegister(const MachineFunction &MF) const override;
  151. Register getBaseRegister() const { return BasePtr; }
  152. /// emitLoadConstPool - Emits a load from constpool to materialize the
  153. /// specified immediate.
  154. virtual void
  155. emitLoadConstPool(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,
  156. const DebugLoc &dl, Register DestReg, unsigned SubIdx,
  157. int Val, ARMCC::CondCodes Pred = ARMCC::AL,
  158. Register PredReg = Register(),
  159. unsigned MIFlags = MachineInstr::NoFlags) const;
  160. /// Code Generation virtual methods...
  161. bool requiresRegisterScavenging(const MachineFunction &MF) const override;
  162. bool requiresFrameIndexScavenging(const MachineFunction &MF) const override;
  163. bool requiresVirtualBaseRegisters(const MachineFunction &MF) const override;
  164. void eliminateFrameIndex(MachineBasicBlock::iterator II,
  165. int SPAdj, unsigned FIOperandNum,
  166. RegScavenger *RS = nullptr) const override;
  167. /// SrcRC and DstRC will be morphed into NewRC if this returns true
  168. bool shouldCoalesce(MachineInstr *MI,
  169. const TargetRegisterClass *SrcRC,
  170. unsigned SubReg,
  171. const TargetRegisterClass *DstRC,
  172. unsigned DstSubReg,
  173. const TargetRegisterClass *NewRC,
  174. LiveIntervals &LIS) const override;
  175. bool shouldRewriteCopySrc(const TargetRegisterClass *DefRC,
  176. unsigned DefSubReg,
  177. const TargetRegisterClass *SrcRC,
  178. unsigned SrcSubReg) const override;
  179. };
  180. } // end namespace llvm
  181. #endif // LLVM_LIB_TARGET_ARM_ARMBASEREGISTERINFO_H