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 
36 public:
RISCVMachineFunctionInfo(const MachineFunction & MF)37   RISCVMachineFunctionInfo(const MachineFunction &MF) {}
38 
getVarArgsFrameIndex()39   int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
setVarArgsFrameIndex(int Index)40   void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
41 
getVarArgsSaveSize()42   unsigned getVarArgsSaveSize() const { return VarArgsSaveSize; }
setVarArgsSaveSize(int Size)43   void setVarArgsSaveSize(int Size) { VarArgsSaveSize = Size; }
44 
getMoveF64FrameIndex(MachineFunction & MF)45   int getMoveF64FrameIndex(MachineFunction &MF) {
46     if (MoveF64FrameIndex == -1)
47       MoveF64FrameIndex =
48           MF.getFrameInfo().CreateStackObject(8, Align(8), false);
49     return MoveF64FrameIndex;
50   }
51 
getLibCallStackSize()52   unsigned getLibCallStackSize() const { return LibCallStackSize; }
setLibCallStackSize(unsigned Size)53   void setLibCallStackSize(unsigned Size) { LibCallStackSize = Size; }
54 
useSaveRestoreLibCalls(const MachineFunction & MF)55   bool useSaveRestoreLibCalls(const MachineFunction &MF) const {
56     // We cannot use fixed locations for the callee saved spill slots if the
57     // function uses a varargs save area.
58     return MF.getSubtarget<RISCVSubtarget>().enableSaveRestore() &&
59            VarArgsSaveSize == 0 && !MF.getFrameInfo().hasTailCall();
60   }
61 };
62 
63 } // end namespace llvm
64 
65 #endif // LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H
66