1 //=- RISCVMachineFunctionInfo.h - RISCV machine function info -----*- 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 file declares RISCV-specific per-machine-function information.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H
14 #define LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H
15 
16 #include "RISCVSubtarget.h"
17 #include "llvm/CodeGen/MachineFrameInfo.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 
20 namespace llvm {
21 
22 /// RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo
23 /// and contains private RISCV-specific information for each MachineFunction.
24 class RISCVMachineFunctionInfo : public MachineFunctionInfo {
25 private:
26   /// FrameIndex for start of varargs area
27   int VarArgsFrameIndex = 0;
28   /// Size of the save area used for varargs
29   int VarArgsSaveSize = 0;
30   /// FrameIndex used for transferring values between 64-bit FPRs and a pair
31   /// of 32-bit GPRs via the stack.
32   int MoveF64FrameIndex = -1;
33   /// Size of any opaque stack adjustment due to save/restore libcalls.
34   unsigned LibCallStackSize = 0;
35   /// Size of RVV stack.
36   uint64_t RVVStackSize = 0;
37   /// Padding required to keep RVV stack aligned within the main stack.
38   uint64_t RVVPadding = 0;
39   /// Size of stack frame to save callee saved registers
40   unsigned CalleeSavedStackSize = 0;
41 
42 public:
RISCVMachineFunctionInfo(const MachineFunction & MF)43   RISCVMachineFunctionInfo(const MachineFunction &MF) {}
44 
getVarArgsFrameIndex()45   int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
setVarArgsFrameIndex(int Index)46   void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
47 
getVarArgsSaveSize()48   unsigned getVarArgsSaveSize() const { return VarArgsSaveSize; }
setVarArgsSaveSize(int Size)49   void setVarArgsSaveSize(int Size) { VarArgsSaveSize = Size; }
50 
getMoveF64FrameIndex(MachineFunction & MF)51   int getMoveF64FrameIndex(MachineFunction &MF) {
52     if (MoveF64FrameIndex == -1)
53       MoveF64FrameIndex =
54           MF.getFrameInfo().CreateStackObject(8, Align(8), false);
55     return MoveF64FrameIndex;
56   }
57 
getLibCallStackSize()58   unsigned getLibCallStackSize() const { return LibCallStackSize; }
setLibCallStackSize(unsigned Size)59   void setLibCallStackSize(unsigned Size) { LibCallStackSize = Size; }
60 
useSaveRestoreLibCalls(const MachineFunction & MF)61   bool useSaveRestoreLibCalls(const MachineFunction &MF) const {
62     // We cannot use fixed locations for the callee saved spill slots if the
63     // function uses a varargs save area, or is an interrupt handler.
64     return MF.getSubtarget<RISCVSubtarget>().enableSaveRestore() &&
65            VarArgsSaveSize == 0 && !MF.getFrameInfo().hasTailCall() &&
66            !MF.getFunction().hasFnAttribute("interrupt");
67   }
68 
getRVVStackSize()69   uint64_t getRVVStackSize() const { return RVVStackSize; }
setRVVStackSize(uint64_t Size)70   void setRVVStackSize(uint64_t Size) { RVVStackSize = Size; }
71 
getRVVPadding()72   uint64_t getRVVPadding() const { return RVVPadding; }
setRVVPadding(uint64_t Padding)73   void setRVVPadding(uint64_t Padding) { RVVPadding = Padding; }
74 
getCalleeSavedStackSize()75   unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
setCalleeSavedStackSize(unsigned Size)76   void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
77 };
78 
79 } // end namespace llvm
80 
81 #endif // LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H
82