1//===-- RISCVFrameLowering.h - Define frame lowering for RISC-V -*- 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 RISC-V 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
19namespace llvm {
20class RISCVSubtarget;
21
22class RISCVFrameLowering : public TargetFrameLowering {
23public:
24 explicit RISCVFrameLowering(const RISCVSubtarget &STI);
25
26 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
27 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
28
29 uint64_t getStackSizeWithRVVPadding(const MachineFunction &MF) const;
30
31 StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
32 Register &FrameReg) const override;
33
34 void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
35 RegScavenger *RS) const override;
36
37 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
38 RegScavenger *RS) const override;
39
40 bool hasFP(const MachineFunction &MF) const override;
41
42 bool hasBP(const MachineFunction &MF) const;
43
44 bool hasReservedCallFrame(const MachineFunction &MF) const override;
45 MachineBasicBlock::iterator
46 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
47 MachineBasicBlock::iterator MI) const override;
48
49 bool assignCalleeSavedSpillSlots(MachineFunction &MF,
50 const TargetRegisterInfo *TRI,
51 std::vector<CalleeSavedInfo> &CSI,
52 unsigned &MinCSFrameIndex,
53 unsigned &MaxCSFrameIndex) const override;
54 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
55 MachineBasicBlock::iterator MI,
56 ArrayRef<CalleeSavedInfo> CSI,
57 const TargetRegisterInfo *TRI) const override;
58 bool
59 restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
60 MachineBasicBlock::iterator MI,
61 MutableArrayRef<CalleeSavedInfo> CSI,
62 const TargetRegisterInfo *TRI) const override;
63
64 // Get the first stack adjustment amount for SplitSPAdjust.
65 // Return 0 if we don't want to split the SP adjustment in prologue and
66 // epilogue.
67 uint64_t getFirstSPAdjustAmount(const MachineFunction &MF) const;
68
69 bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
70 bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
71
72 bool enableShrinkWrapping(const MachineFunction &MF) const override;
73
74 bool isSupportedStackID(TargetStackID::Value ID) const override;
75 TargetStackID::Value getStackIDForScalableVectors() const override;
76
77 bool isStackIdSafeForLocalArea(unsigned StackId) const override {
78 // We don't support putting RISC-V Vector objects into the pre-allocated
79 // local frame block at the moment.
80 return StackId != TargetStackID::ScalableVector;
81 }
82
83protected:
84 const RISCVSubtarget &STI;
85
86private:
87 void determineFrameLayout(MachineFunction &MF) const;
88 void adjustStackForRVV(MachineFunction &MF, MachineBasicBlock &MBB,
89 MachineBasicBlock::iterator MBBI, const DebugLoc &DL,
90 int64_t Amount, MachineInstr::MIFlag Flag) const;
91 void emitCalleeSavedRVVPrologCFI(MachineBasicBlock &MBB,
92 MachineBasicBlock::iterator MI,
93 bool HasFP) const;
94 std::pair<int64_t, Align>
95 assignRVVStackObjectOffsets(MachineFunction &MF) const;
96};
97} // namespace llvm
98#endif
99

source code of llvm/lib/Target/RISCV/RISCVFrameLowering.h