xref: /freebsd/contrib/llvm-project/llvm/lib/Target/RISCV/RISCVFrameLowering.h (revision 9e5787d2284e187abb5b654d924394a65772e004)
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 
18 namespace llvm {
19 class RISCVSubtarget;
20 
21 class RISCVFrameLowering : public TargetFrameLowering {
22 public:
23   explicit RISCVFrameLowering(const RISCVSubtarget &STI)
24       : TargetFrameLowering(StackGrowsDown,
25                             /*StackAlignment=*/Align(16),
26                             /*LocalAreaOffset=*/0),
27         STI(STI) {}
28 
29   void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
30   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
31 
32   int getFrameIndexReference(const MachineFunction &MF, int FI,
33                              Register &FrameReg) const override;
34 
35   void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
36                             RegScavenger *RS) const override;
37 
38   void processFunctionBeforeFrameFinalized(MachineFunction &MF,
39                                            RegScavenger *RS) const override;
40 
41   bool hasFP(const MachineFunction &MF) const override;
42 
43   bool hasBP(const MachineFunction &MF) const;
44 
45   bool hasReservedCallFrame(const MachineFunction &MF) const override;
46   MachineBasicBlock::iterator
47   eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
48                                 MachineBasicBlock::iterator MI) const override;
49   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
50                                  MachineBasicBlock::iterator MI,
51                                  ArrayRef<CalleeSavedInfo> CSI,
52                                  const TargetRegisterInfo *TRI) const override;
53   bool
54   restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
55                               MachineBasicBlock::iterator MI,
56                               MutableArrayRef<CalleeSavedInfo> CSI,
57                               const TargetRegisterInfo *TRI) const override;
58 
59   // Get the first stack adjustment amount for SplitSPAdjust.
60   // Return 0 if we don't want to to split the SP adjustment in prologue and
61   // epilogue.
62   uint64_t getFirstSPAdjustAmount(const MachineFunction &MF) const;
63 
64   bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
65   bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
66 
67 protected:
68   const RISCVSubtarget &STI;
69 
70 private:
71   void determineFrameLayout(MachineFunction &MF) const;
72   void adjustReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
73                  const DebugLoc &DL, Register DestReg, Register SrcReg,
74                  int64_t Val, MachineInstr::MIFlag Flag) const;
75 };
76 }
77 #endif
78