xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVFrameLowering.h (revision 357378bbdedf24ce2b90e9bd831af4a9db3ec70a)
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 
19 namespace llvm {
20 class RISCVSubtarget;
21 
22 class RISCVFrameLowering : public TargetFrameLowering {
23 public:
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   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
49                                  MachineBasicBlock::iterator MI,
50                                  ArrayRef<CalleeSavedInfo> CSI,
51                                  const TargetRegisterInfo *TRI) const override;
52   bool
53   restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
54                               MachineBasicBlock::iterator MI,
55                               MutableArrayRef<CalleeSavedInfo> CSI,
56                               const TargetRegisterInfo *TRI) const override;
57 
58   // Get the first stack adjustment amount for SplitSPAdjust.
59   // Return 0 if we don't want to split the SP adjustment in prologue and
60   // epilogue.
61   uint64_t getFirstSPAdjustAmount(const MachineFunction &MF) const;
62 
63   bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
64   bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
65 
66   bool enableShrinkWrapping(const MachineFunction &MF) const override;
67 
68   bool isSupportedStackID(TargetStackID::Value ID) const override;
69   TargetStackID::Value getStackIDForScalableVectors() const override;
70 
71   bool isStackIdSafeForLocalArea(unsigned StackId) const override {
72     // We don't support putting RISC-V Vector objects into the pre-allocated
73     // local frame block at the moment.
74     return StackId != TargetStackID::ScalableVector;
75   }
76 
77 protected:
78   const RISCVSubtarget &STI;
79 
80 private:
81   void determineFrameLayout(MachineFunction &MF) const;
82   void adjustStackForRVV(MachineFunction &MF, MachineBasicBlock &MBB,
83                          MachineBasicBlock::iterator MBBI, const DebugLoc &DL,
84                          int64_t Amount, MachineInstr::MIFlag Flag) const;
85   std::pair<int64_t, Align>
86   assignRVVStackObjectOffsets(MachineFunction &MF) const;
87 };
88 } // namespace llvm
89 #endif
90