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   MachineFunction &MF;
27   /// FrameIndex for start of varargs area
28   int VarArgsFrameIndex = 0;
29   /// Size of the save area used for varargs
30   int VarArgsSaveSize = 0;
31   /// FrameIndex used for transferring values between 64-bit FPRs and a pair
32   /// of 32-bit GPRs via the stack.
33   int MoveF64FrameIndex = -1;
34   /// Size of any opaque stack adjustment due to save/restore libcalls.
35   unsigned LibCallStackSize = 0;
36 
37 public:
38   RISCVMachineFunctionInfo(MachineFunction &MF) : MF(MF) {}
39 
40   int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
41   void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
42 
43   unsigned getVarArgsSaveSize() const { return VarArgsSaveSize; }
44   void setVarArgsSaveSize(int Size) { VarArgsSaveSize = Size; }
45 
46   int getMoveF64FrameIndex() {
47     if (MoveF64FrameIndex == -1)
48       MoveF64FrameIndex = MF.getFrameInfo().CreateStackObject(8, 8, false);
49     return MoveF64FrameIndex;
50   }
51 
52   unsigned getLibCallStackSize() const { return LibCallStackSize; }
53   void setLibCallStackSize(unsigned Size) { LibCallStackSize = Size; }
54 
55   bool useSaveRestoreLibCalls() 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