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