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 13 #ifndef LLVM_LIB_TARGET_RISCV_RISCVFRAMELOWERING_H 14 #define LLVM_LIB_TARGET_RISCV_RISCVFRAMELOWERING_H 15 16 #include "llvm/CodeGen/TargetFrameLowering.h" 17 #include "llvm/Support/TypeSize.h" 18 19 namespace llvm { 20 class RISCVSubtarget; 21 22 class RISCVFrameLowering : public TargetFrameLowering { 23 public: 24 explicit RISCVFrameLowering(const RISCVSubtarget &STI) 25 : TargetFrameLowering(StackGrowsDown, 26 /*StackAlignment=*/Align(16), 27 /*LocalAreaOffset=*/0), 28 STI(STI) {} 29 30 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; 31 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; 32 33 StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, 34 Register &FrameReg) const override; 35 36 void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, 37 RegScavenger *RS) const override; 38 39 void processFunctionBeforeFrameFinalized(MachineFunction &MF, 40 RegScavenger *RS) const override; 41 42 bool hasFP(const MachineFunction &MF) const override; 43 44 bool hasBP(const MachineFunction &MF) const; 45 46 bool hasReservedCallFrame(const MachineFunction &MF) const override; 47 MachineBasicBlock::iterator 48 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, 49 MachineBasicBlock::iterator MI) const override; 50 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, 51 MachineBasicBlock::iterator MI, 52 ArrayRef<CalleeSavedInfo> CSI, 53 const TargetRegisterInfo *TRI) const override; 54 bool 55 restoreCalleeSavedRegisters(MachineBasicBlock &MBB, 56 MachineBasicBlock::iterator MI, 57 MutableArrayRef<CalleeSavedInfo> CSI, 58 const TargetRegisterInfo *TRI) const override; 59 60 // Get the first stack adjustment amount for SplitSPAdjust. 61 // Return 0 if we don't want to to split the SP adjustment in prologue and 62 // epilogue. 63 uint64_t getFirstSPAdjustAmount(const MachineFunction &MF) const; 64 65 bool canUseAsPrologue(const MachineBasicBlock &MBB) const override; 66 bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override; 67 68 bool enableShrinkWrapping(const MachineFunction &MF) const override; 69 70 bool isSupportedStackID(TargetStackID::Value ID) const override; 71 TargetStackID::Value getStackIDForScalableVectors() const override; 72 73 protected: 74 const RISCVSubtarget &STI; 75 76 private: 77 void determineFrameLayout(MachineFunction &MF) const; 78 void adjustReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, 79 const DebugLoc &DL, Register DestReg, Register SrcReg, 80 int64_t Val, MachineInstr::MIFlag Flag) const; 81 void adjustStackForRVV(MachineFunction &MF, MachineBasicBlock &MBB, 82 MachineBasicBlock::iterator MBBI, const DebugLoc &DL, 83 int64_t Amount, MachineInstr::MIFlag Flag) const; 84 int64_t assignRVVStackObjectOffsets(MachineFrameInfo &MFI) const; 85 }; 86 } 87 #endif 88