RISCVFrameLowering.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //===-- RISCVFrameLowering.h - Define frame lowering for RISCV -*- 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 class implements RISCV-specific bits of TargetFrameLowering class.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_RISCV_RISCVFRAMELOWERING_H
  13. #define LLVM_LIB_TARGET_RISCV_RISCVFRAMELOWERING_H
  14. #include "llvm/CodeGen/TargetFrameLowering.h"
  15. #include "llvm/Support/TypeSize.h"
  16. namespace llvm {
  17. class RISCVSubtarget;
  18. class RISCVFrameLowering : public TargetFrameLowering {
  19. public:
  20. explicit RISCVFrameLowering(const RISCVSubtarget &STI)
  21. : TargetFrameLowering(StackGrowsDown,
  22. /*StackAlignment=*/Align(16),
  23. /*LocalAreaOffset=*/0,
  24. /*TransientStackAlignment=*/Align(16)),
  25. STI(STI) {}
  26. void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
  27. void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
  28. uint64_t getStackSizeWithRVVPadding(const MachineFunction &MF) const;
  29. StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
  30. Register &FrameReg) const override;
  31. void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
  32. RegScavenger *RS) const override;
  33. void processFunctionBeforeFrameFinalized(MachineFunction &MF,
  34. RegScavenger *RS) const override;
  35. bool hasFP(const MachineFunction &MF) const override;
  36. bool hasBP(const MachineFunction &MF) const;
  37. bool hasReservedCallFrame(const MachineFunction &MF) const override;
  38. MachineBasicBlock::iterator
  39. eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
  40. MachineBasicBlock::iterator MI) const override;
  41. bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
  42. MachineBasicBlock::iterator MI,
  43. ArrayRef<CalleeSavedInfo> CSI,
  44. const TargetRegisterInfo *TRI) const override;
  45. bool
  46. restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
  47. MachineBasicBlock::iterator MI,
  48. MutableArrayRef<CalleeSavedInfo> CSI,
  49. const TargetRegisterInfo *TRI) const override;
  50. // Get the first stack adjustment amount for SplitSPAdjust.
  51. // Return 0 if we don't want to to split the SP adjustment in prologue and
  52. // epilogue.
  53. uint64_t getFirstSPAdjustAmount(const MachineFunction &MF) const;
  54. bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
  55. bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
  56. bool enableShrinkWrapping(const MachineFunction &MF) const override;
  57. bool isSupportedStackID(TargetStackID::Value ID) const override;
  58. TargetStackID::Value getStackIDForScalableVectors() const override;
  59. bool isStackIdSafeForLocalArea(unsigned StackId) const override {
  60. // We don't support putting RISCV Vector objects into the pre-allocated
  61. // local frame block at the moment.
  62. return StackId != TargetStackID::ScalableVector;
  63. }
  64. protected:
  65. const RISCVSubtarget &STI;
  66. private:
  67. void determineFrameLayout(MachineFunction &MF) const;
  68. void adjustStackForRVV(MachineFunction &MF, MachineBasicBlock &MBB,
  69. MachineBasicBlock::iterator MBBI, const DebugLoc &DL,
  70. int64_t Amount, MachineInstr::MIFlag Flag) const;
  71. std::pair<int64_t, Align>
  72. assignRVVStackObjectOffsets(MachineFunction &MF) const;
  73. };
  74. } // namespace llvm
  75. #endif