PPCRegisterInfo.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //===-- PPCRegisterInfo.h - PowerPC 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 PowerPC implementation of the TargetRegisterInfo
  10. // class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_LIB_TARGET_POWERPC_PPCREGISTERINFO_H
  14. #define LLVM_LIB_TARGET_POWERPC_PPCREGISTERINFO_H
  15. #include "MCTargetDesc/PPCMCTargetDesc.h"
  16. #include "llvm/ADT/DenseMap.h"
  17. #define GET_REGINFO_HEADER
  18. #include "PPCGenRegisterInfo.inc"
  19. namespace llvm {
  20. class PPCTargetMachine;
  21. inline static unsigned getCRFromCRBit(unsigned SrcReg) {
  22. unsigned Reg = 0;
  23. if (SrcReg == PPC::CR0LT || SrcReg == PPC::CR0GT ||
  24. SrcReg == PPC::CR0EQ || SrcReg == PPC::CR0UN)
  25. Reg = PPC::CR0;
  26. else if (SrcReg == PPC::CR1LT || SrcReg == PPC::CR1GT ||
  27. SrcReg == PPC::CR1EQ || SrcReg == PPC::CR1UN)
  28. Reg = PPC::CR1;
  29. else if (SrcReg == PPC::CR2LT || SrcReg == PPC::CR2GT ||
  30. SrcReg == PPC::CR2EQ || SrcReg == PPC::CR2UN)
  31. Reg = PPC::CR2;
  32. else if (SrcReg == PPC::CR3LT || SrcReg == PPC::CR3GT ||
  33. SrcReg == PPC::CR3EQ || SrcReg == PPC::CR3UN)
  34. Reg = PPC::CR3;
  35. else if (SrcReg == PPC::CR4LT || SrcReg == PPC::CR4GT ||
  36. SrcReg == PPC::CR4EQ || SrcReg == PPC::CR4UN)
  37. Reg = PPC::CR4;
  38. else if (SrcReg == PPC::CR5LT || SrcReg == PPC::CR5GT ||
  39. SrcReg == PPC::CR5EQ || SrcReg == PPC::CR5UN)
  40. Reg = PPC::CR5;
  41. else if (SrcReg == PPC::CR6LT || SrcReg == PPC::CR6GT ||
  42. SrcReg == PPC::CR6EQ || SrcReg == PPC::CR6UN)
  43. Reg = PPC::CR6;
  44. else if (SrcReg == PPC::CR7LT || SrcReg == PPC::CR7GT ||
  45. SrcReg == PPC::CR7EQ || SrcReg == PPC::CR7UN)
  46. Reg = PPC::CR7;
  47. assert(Reg != 0 && "Invalid CR bit register");
  48. return Reg;
  49. }
  50. class PPCRegisterInfo : public PPCGenRegisterInfo {
  51. DenseMap<unsigned, unsigned> ImmToIdxMap;
  52. const PPCTargetMachine &TM;
  53. public:
  54. PPCRegisterInfo(const PPCTargetMachine &TM);
  55. /// getMappedIdxOpcForImmOpc - Return the mapped index form load/store opcode
  56. /// for a given imm form load/store opcode \p ImmFormOpcode.
  57. /// FIXME: move this to PPCInstrInfo class.
  58. unsigned getMappedIdxOpcForImmOpc(unsigned ImmOpcode) const {
  59. if (!ImmToIdxMap.count(ImmOpcode))
  60. return PPC::INSTRUCTION_LIST_END;
  61. return ImmToIdxMap.find(ImmOpcode)->second;
  62. }
  63. /// getPointerRegClass - Return the register class to use to hold pointers.
  64. /// This is used for addressing modes.
  65. const TargetRegisterClass *
  66. getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const override;
  67. unsigned getRegPressureLimit(const TargetRegisterClass *RC,
  68. MachineFunction &MF) const override;
  69. const TargetRegisterClass *
  70. getLargestLegalSuperClass(const TargetRegisterClass *RC,
  71. const MachineFunction &MF) const override;
  72. /// Code Generation virtual methods...
  73. const MCPhysReg *getCalleeSavedRegs(const MachineFunction *MF) const override;
  74. const uint32_t *getCallPreservedMask(const MachineFunction &MF,
  75. CallingConv::ID CC) const override;
  76. const uint32_t *getNoPreservedMask() const override;
  77. void adjustStackMapLiveOutMask(uint32_t *Mask) const override;
  78. BitVector getReservedRegs(const MachineFunction &MF) const override;
  79. bool isAsmClobberable(const MachineFunction &MF,
  80. MCRegister PhysReg) const override;
  81. bool isCallerPreservedPhysReg(MCRegister PhysReg,
  82. const MachineFunction &MF) const override;
  83. // Provide hints to the register allocator for allocating subregisters
  84. // of primed and unprimed accumulators. For example, if accumulator
  85. // ACC5 is assigned, we also want to assign UACC5 to the input.
  86. // Similarly if UACC5 is assigned, we want to assign VSRp10, VSRp11
  87. // to its inputs.
  88. bool getRegAllocationHints(Register VirtReg, ArrayRef<MCPhysReg> Order,
  89. SmallVectorImpl<MCPhysReg> &Hints,
  90. const MachineFunction &MF, const VirtRegMap *VRM,
  91. const LiveRegMatrix *Matrix) const override;
  92. /// We require the register scavenger.
  93. bool requiresRegisterScavenging(const MachineFunction &MF) const override {
  94. return true;
  95. }
  96. bool requiresFrameIndexScavenging(const MachineFunction &MF) const override;
  97. bool requiresVirtualBaseRegisters(const MachineFunction &MF) const override;
  98. void lowerDynamicAlloc(MachineBasicBlock::iterator II) const;
  99. void lowerDynamicAreaOffset(MachineBasicBlock::iterator II) const;
  100. void prepareDynamicAlloca(MachineBasicBlock::iterator II,
  101. Register &NegSizeReg, bool &KillNegSizeReg,
  102. Register &FramePointer) const;
  103. void lowerPrepareProbedAlloca(MachineBasicBlock::iterator II) const;
  104. void lowerCRSpilling(MachineBasicBlock::iterator II,
  105. unsigned FrameIndex) const;
  106. void lowerCRRestore(MachineBasicBlock::iterator II,
  107. unsigned FrameIndex) const;
  108. void lowerCRBitSpilling(MachineBasicBlock::iterator II,
  109. unsigned FrameIndex) const;
  110. void lowerCRBitRestore(MachineBasicBlock::iterator II,
  111. unsigned FrameIndex) const;
  112. void lowerACCSpilling(MachineBasicBlock::iterator II,
  113. unsigned FrameIndex) const;
  114. void lowerACCRestore(MachineBasicBlock::iterator II,
  115. unsigned FrameIndex) const;
  116. void lowerQuadwordSpilling(MachineBasicBlock::iterator II,
  117. unsigned FrameIndex) const;
  118. void lowerQuadwordRestore(MachineBasicBlock::iterator II,
  119. unsigned FrameIndex) const;
  120. static void emitAccCopyInfo(MachineBasicBlock &MBB, MCRegister DestReg,
  121. MCRegister SrcReg);
  122. bool hasReservedSpillSlot(const MachineFunction &MF, Register Reg,
  123. int &FrameIdx) const override;
  124. void eliminateFrameIndex(MachineBasicBlock::iterator II, int SPAdj,
  125. unsigned FIOperandNum,
  126. RegScavenger *RS = nullptr) const override;
  127. // Support for virtual base registers.
  128. bool needsFrameBaseReg(MachineInstr *MI, int64_t Offset) const override;
  129. Register materializeFrameBaseRegister(MachineBasicBlock *MBB, int FrameIdx,
  130. int64_t Offset) const override;
  131. void resolveFrameIndex(MachineInstr &MI, Register BaseReg,
  132. int64_t Offset) const override;
  133. bool isFrameOffsetLegal(const MachineInstr *MI, Register BaseReg,
  134. int64_t Offset) const override;
  135. // Debug information queries.
  136. Register getFrameRegister(const MachineFunction &MF) const override;
  137. // Base pointer (stack realignment) support.
  138. Register getBaseRegister(const MachineFunction &MF) const;
  139. bool hasBasePointer(const MachineFunction &MF) const;
  140. /// stripRegisterPrefix - This method strips the character prefix from a
  141. /// register name so that only the number is left. Used by for linux asm.
  142. static const char *stripRegisterPrefix(const char *RegName) {
  143. switch (RegName[0]) {
  144. case 'a':
  145. if (RegName[1] == 'c' && RegName[2] == 'c')
  146. return RegName + 3;
  147. break;
  148. case 'r':
  149. case 'f':
  150. case 'v':
  151. if (RegName[1] == 's') {
  152. if (RegName[2] == 'p')
  153. return RegName + 3;
  154. return RegName + 2;
  155. }
  156. return RegName + 1;
  157. case 'c': if (RegName[1] == 'r') return RegName + 2;
  158. }
  159. return RegName;
  160. }
  161. bool isNonallocatableRegisterCalleeSave(MCRegister Reg) const override {
  162. return Reg == PPC::LR || Reg == PPC::LR8;
  163. }
  164. };
  165. } // end namespace llvm
  166. #endif