1 //===-- RISCVFrameLowering.h - Define frame lowering for RISCV -*- C++ -*--===//
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
7 //===----------------------------------------------------------------------===//
9 // This class implements RISCV-specific bits of TargetFrameLowering class.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_RISCV_RISCVFRAMELOWERING_H
14 #define LLVM_LIB_TARGET_RISCV_RISCVFRAMELOWERING_H
16 #include "llvm/CodeGen/TargetFrameLowering.h"
17 #include "llvm/Support/TypeSize.h"
22 class RISCVFrameLowering : public TargetFrameLowering {
24 explicit RISCVFrameLowering(const RISCVSubtarget &STI)
25 : TargetFrameLowering(StackGrowsDown,
26 /*StackAlignment=*/Align(16),
27 /*LocalAreaOffset=*/0),
30 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
31 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
33 StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
34 Register &FrameReg) const override;
36 void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
37 RegScavenger *RS) const override;
39 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
40 RegScavenger *RS) const override;
42 bool hasFP(const MachineFunction &MF) const override;
44 bool hasBP(const MachineFunction &MF) const;
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;
55 restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
56 MachineBasicBlock::iterator MI,
57 MutableArrayRef<CalleeSavedInfo> CSI,
58 const TargetRegisterInfo *TRI) const override;
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
63 uint64_t getFirstSPAdjustAmount(const MachineFunction &MF) const;
65 bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
66 bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
68 bool isSupportedStackID(TargetStackID::Value ID) const override;
69 TargetStackID::Value getStackIDForScalableVectors() const override;
72 const RISCVSubtarget &STI;
75 void determineFrameLayout(MachineFunction &MF) const;
76 void adjustReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
77 const DebugLoc &DL, Register DestReg, Register SrcReg,
78 int64_t Val, MachineInstr::MIFlag Flag) const;
79 void adjustStackForRVV(MachineFunction &MF, MachineBasicBlock &MBB,
80 MachineBasicBlock::iterator MBBI, const DebugLoc &DL,
81 int64_t Amount, MachineInstr::MIFlag Flag) const;
82 int64_t assignRVVStackObjectOffsets(MachineFrameInfo &MFI) const;