PPCFrameLowering.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //===-- PPCFrameLowering.h - Define frame lowering for PowerPC --*- 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. //
  10. //===----------------------------------------------------------------------===//
  11. #ifndef LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
  12. #define LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
  13. #include "llvm/ADT/STLExtras.h"
  14. #include "llvm/CodeGen/TargetFrameLowering.h"
  15. #include "llvm/Target/TargetMachine.h"
  16. namespace llvm {
  17. class PPCSubtarget;
  18. class PPCFrameLowering: public TargetFrameLowering {
  19. const PPCSubtarget &Subtarget;
  20. const uint64_t ReturnSaveOffset;
  21. const uint64_t TOCSaveOffset;
  22. const uint64_t FramePointerSaveOffset;
  23. const unsigned LinkageSize;
  24. const uint64_t BasePointerSaveOffset;
  25. const uint64_t CRSaveOffset;
  26. // Map each group of one or two GPRs to corresponding VSR for spilling.
  27. // TODO: Use local table in methods to avoid this mutable member.
  28. mutable DenseMap<unsigned, std::pair<Register, Register>> VSRContainingGPRs;
  29. /**
  30. * Find register[s] that can be used in function prologue and epilogue
  31. *
  32. * Find register[s] that can be use as scratch register[s] in function
  33. * prologue and epilogue to save various registers (Link Register, Base
  34. * Pointer, etc.). Prefer R0/R12, if available. Otherwise choose whatever
  35. * register[s] are available.
  36. *
  37. * This method will return true if it is able to find enough unique scratch
  38. * registers (1 or 2 depending on the requirement). If it is unable to find
  39. * enough available registers in the block, it will return false and set
  40. * any passed output parameter that corresponds to a required unique register
  41. * to PPC::NoRegister.
  42. *
  43. * \param[in] MBB The machine basic block to find an available register for
  44. * \param[in] UseAtEnd Specify whether the scratch register will be used at
  45. * the end of the basic block (i.e., will the scratch
  46. * register kill a register defined in the basic block)
  47. * \param[in] TwoUniqueRegsRequired Specify whether this basic block will
  48. * require two unique scratch registers.
  49. * \param[out] SR1 The scratch register to use
  50. * \param[out] SR2 The second scratch register. If this pointer is not null
  51. * the function will attempt to set it to an available
  52. * register regardless of whether there is a hard requirement
  53. * for two unique scratch registers.
  54. * \return true if the required number of registers was found.
  55. * false if the required number of scratch register weren't available.
  56. * If either output parameter refers to a required scratch register
  57. * that isn't available, it will be set to an invalid value.
  58. */
  59. bool findScratchRegister(MachineBasicBlock *MBB,
  60. bool UseAtEnd,
  61. bool TwoUniqueRegsRequired = false,
  62. Register *SR1 = nullptr,
  63. Register *SR2 = nullptr) const;
  64. bool twoUniqueScratchRegsRequired(MachineBasicBlock *MBB) const;
  65. /**
  66. * Create branch instruction for PPC::TCRETURN* (tail call return)
  67. *
  68. * \param[in] MBB that is terminated by PPC::TCRETURN*
  69. */
  70. void createTailCallBranchInstr(MachineBasicBlock &MBB) const;
  71. /**
  72. * Check if the conditions are correct to allow for the stack update
  73. * to be moved past the CSR save/restore code.
  74. */
  75. bool stackUpdateCanBeMoved(MachineFunction &MF) const;
  76. public:
  77. PPCFrameLowering(const PPCSubtarget &STI);
  78. /**
  79. * Determine the frame layout and update the machine function.
  80. */
  81. uint64_t determineFrameLayoutAndUpdate(MachineFunction &MF,
  82. bool UseEstimate = false) const;
  83. /**
  84. * Determine the frame layout but do not update the machine function.
  85. * The MachineFunction object can be const in this case as it is not
  86. * modified.
  87. */
  88. uint64_t determineFrameLayout(const MachineFunction &MF,
  89. bool UseEstimate = false,
  90. unsigned *NewMaxCallFrameSize = nullptr) const;
  91. /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
  92. /// the function.
  93. void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
  94. void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
  95. void inlineStackProbe(MachineFunction &MF,
  96. MachineBasicBlock &PrologMBB) const override;
  97. bool hasFP(const MachineFunction &MF) const override;
  98. bool needsFP(const MachineFunction &MF) const;
  99. void replaceFPWithRealFP(MachineFunction &MF) const;
  100. void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
  101. RegScavenger *RS = nullptr) const override;
  102. void processFunctionBeforeFrameFinalized(MachineFunction &MF,
  103. RegScavenger *RS = nullptr) const override;
  104. void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;
  105. bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
  106. MachineBasicBlock::iterator MI,
  107. ArrayRef<CalleeSavedInfo> CSI,
  108. const TargetRegisterInfo *TRI) const override;
  109. /// This function will assign callee saved gprs to volatile vector registers
  110. /// for prologue spills when applicable. It returns false if there are any
  111. /// registers which were not spilled to volatile vector registers.
  112. bool
  113. assignCalleeSavedSpillSlots(MachineFunction &MF,
  114. const TargetRegisterInfo *TRI,
  115. std::vector<CalleeSavedInfo> &CSI) const override;
  116. MachineBasicBlock::iterator
  117. eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
  118. MachineBasicBlock::iterator I) const override;
  119. bool
  120. restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
  121. MachineBasicBlock::iterator MI,
  122. MutableArrayRef<CalleeSavedInfo> CSI,
  123. const TargetRegisterInfo *TRI) const override;
  124. /// targetHandlesStackFrameRounding - Returns true if the target is
  125. /// responsible for rounding up the stack frame (probably at emitPrologue
  126. /// time).
  127. bool targetHandlesStackFrameRounding() const override { return true; }
  128. /// getReturnSaveOffset - Return the previous frame offset to save the
  129. /// return address.
  130. uint64_t getReturnSaveOffset() const { return ReturnSaveOffset; }
  131. /// getTOCSaveOffset - Return the previous frame offset to save the
  132. /// TOC register -- 64-bit SVR4 ABI only.
  133. uint64_t getTOCSaveOffset() const;
  134. /// getFramePointerSaveOffset - Return the previous frame offset to save the
  135. /// frame pointer.
  136. uint64_t getFramePointerSaveOffset() const;
  137. /// getBasePointerSaveOffset - Return the previous frame offset to save the
  138. /// base pointer.
  139. uint64_t getBasePointerSaveOffset() const;
  140. /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
  141. ///
  142. unsigned getLinkageSize() const { return LinkageSize; }
  143. const SpillSlot *
  144. getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
  145. bool enableShrinkWrapping(const MachineFunction &MF) const override;
  146. /// Methods used by shrink wrapping to determine if MBB can be used for the
  147. /// function prologue/epilogue.
  148. bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
  149. bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
  150. };
  151. } // End llvm namespace
  152. #endif