AArch64FrameLowering.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //==-- AArch64FrameLowering.h - TargetFrameLowering for AArch64 --*- 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. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64FRAMELOWERING_H
  13. #define LLVM_LIB_TARGET_AARCH64_AARCH64FRAMELOWERING_H
  14. #include "llvm/Support/TypeSize.h"
  15. #include "llvm/CodeGen/TargetFrameLowering.h"
  16. namespace llvm {
  17. class MCCFIInstruction;
  18. class AArch64FrameLowering : public TargetFrameLowering {
  19. public:
  20. explicit AArch64FrameLowering()
  21. : TargetFrameLowering(StackGrowsDown, Align(16), 0, Align(16),
  22. true /*StackRealignable*/) {}
  23. void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB,
  24. MachineBasicBlock::iterator MBBI) const;
  25. MachineBasicBlock::iterator
  26. eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
  27. MachineBasicBlock::iterator I) const override;
  28. /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
  29. /// the function.
  30. void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
  31. void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
  32. bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
  33. StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
  34. Register &FrameReg) const override;
  35. StackOffset resolveFrameIndexReference(const MachineFunction &MF, int FI,
  36. Register &FrameReg, bool PreferFP,
  37. bool ForSimm) const;
  38. StackOffset resolveFrameOffsetReference(const MachineFunction &MF,
  39. int64_t ObjectOffset, bool isFixed,
  40. bool isSVE, Register &FrameReg,
  41. bool PreferFP, bool ForSimm) const;
  42. bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
  43. MachineBasicBlock::iterator MI,
  44. ArrayRef<CalleeSavedInfo> CSI,
  45. const TargetRegisterInfo *TRI) const override;
  46. bool
  47. restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
  48. MachineBasicBlock::iterator MI,
  49. MutableArrayRef<CalleeSavedInfo> CSI,
  50. const TargetRegisterInfo *TRI) const override;
  51. /// Can this function use the red zone for local allocations.
  52. bool canUseRedZone(const MachineFunction &MF) const;
  53. bool hasFP(const MachineFunction &MF) const override;
  54. bool hasReservedCallFrame(const MachineFunction &MF) const override;
  55. bool assignCalleeSavedSpillSlots(MachineFunction &MF,
  56. const TargetRegisterInfo *TRI,
  57. std::vector<CalleeSavedInfo> &CSI,
  58. unsigned &MinCSFrameIndex,
  59. unsigned &MaxCSFrameIndex) const override;
  60. void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
  61. RegScavenger *RS) const override;
  62. /// Returns true if the target will correctly handle shrink wrapping.
  63. bool enableShrinkWrapping(const MachineFunction &MF) const override {
  64. return true;
  65. }
  66. bool enableStackSlotScavenging(const MachineFunction &MF) const override;
  67. TargetStackID::Value getStackIDForScalableVectors() const override;
  68. void processFunctionBeforeFrameFinalized(MachineFunction &MF,
  69. RegScavenger *RS) const override;
  70. void
  71. processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF,
  72. RegScavenger *RS) const override;
  73. unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override;
  74. unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const;
  75. StackOffset
  76. getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI,
  77. Register &FrameReg,
  78. bool IgnoreSPUpdates) const override;
  79. StackOffset getNonLocalFrameIndexReference(const MachineFunction &MF,
  80. int FI) const override;
  81. int getSEHFrameIndexOffset(const MachineFunction &MF, int FI) const;
  82. bool isSupportedStackID(TargetStackID::Value ID) const override {
  83. switch (ID) {
  84. default:
  85. return false;
  86. case TargetStackID::Default:
  87. case TargetStackID::ScalableVector:
  88. case TargetStackID::NoAlloc:
  89. return true;
  90. }
  91. }
  92. bool isStackIdSafeForLocalArea(unsigned StackId) const override {
  93. // We don't support putting SVE objects into the pre-allocated local
  94. // frame block at the moment.
  95. return StackId != TargetStackID::ScalableVector;
  96. }
  97. void
  98. orderFrameObjects(const MachineFunction &MF,
  99. SmallVectorImpl<int> &ObjectsToAllocate) const override;
  100. private:
  101. /// Returns true if a homogeneous prolog or epilog code can be emitted
  102. /// for the size optimization. If so, HOM_Prolog/HOM_Epilog pseudo
  103. /// instructions are emitted in place. When Exit block is given, this check is
  104. /// for epilog.
  105. bool homogeneousPrologEpilog(MachineFunction &MF,
  106. MachineBasicBlock *Exit = nullptr) const;
  107. /// Returns true if CSRs should be paired.
  108. bool producePairRegisters(MachineFunction &MF) const;
  109. bool shouldCombineCSRLocalStackBump(MachineFunction &MF,
  110. uint64_t StackBumpBytes) const;
  111. int64_t estimateSVEStackObjectOffsets(MachineFrameInfo &MF) const;
  112. int64_t assignSVEStackObjectOffsets(MachineFrameInfo &MF,
  113. int &MinCSFrameIndex,
  114. int &MaxCSFrameIndex) const;
  115. MCCFIInstruction
  116. createDefCFAExpressionFromSP(const TargetRegisterInfo &TRI,
  117. const StackOffset &OffsetFromSP) const;
  118. MCCFIInstruction createCfaOffset(const TargetRegisterInfo &MRI, unsigned DwarfReg,
  119. const StackOffset &OffsetFromDefCFA) const;
  120. bool shouldCombineCSRLocalStackBumpInEpilogue(MachineBasicBlock &MBB,
  121. unsigned StackBumpBytes) const;
  122. };
  123. } // End llvm namespace
  124. #endif