10b57cec5SDimitry Andric //=- RISCVMachineFunctionInfo.h - RISCV machine function info -----*- C++ -*-=// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric // 90b57cec5SDimitry Andric // This file declares RISCV-specific per-machine-function information. 100b57cec5SDimitry Andric // 110b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 120b57cec5SDimitry Andric 130b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H 140b57cec5SDimitry Andric #define LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H 150b57cec5SDimitry Andric 165ffd83dbSDimitry Andric #include "RISCVSubtarget.h" 173a9a9c0cSDimitry Andric #include "llvm/CodeGen/MIRYamlMapping.h" 180b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFrameInfo.h" 190b57cec5SDimitry Andric #include "llvm/CodeGen/MachineFunction.h" 200b57cec5SDimitry Andric 210b57cec5SDimitry Andric namespace llvm { 220b57cec5SDimitry Andric 233a9a9c0cSDimitry Andric class RISCVMachineFunctionInfo; 243a9a9c0cSDimitry Andric 253a9a9c0cSDimitry Andric namespace yaml { 263a9a9c0cSDimitry Andric struct RISCVMachineFunctionInfo final : public yaml::MachineFunctionInfo { 273a9a9c0cSDimitry Andric int VarArgsFrameIndex; 283a9a9c0cSDimitry Andric int VarArgsSaveSize; 293a9a9c0cSDimitry Andric 303a9a9c0cSDimitry Andric RISCVMachineFunctionInfo() = default; 313a9a9c0cSDimitry Andric RISCVMachineFunctionInfo(const llvm::RISCVMachineFunctionInfo &MFI); 323a9a9c0cSDimitry Andric 333a9a9c0cSDimitry Andric void mappingImpl(yaml::IO &YamlIO) override; 343a9a9c0cSDimitry Andric ~RISCVMachineFunctionInfo() = default; 353a9a9c0cSDimitry Andric }; 363a9a9c0cSDimitry Andric 373a9a9c0cSDimitry Andric template <> struct MappingTraits<RISCVMachineFunctionInfo> { 383a9a9c0cSDimitry Andric static void mapping(IO &YamlIO, RISCVMachineFunctionInfo &MFI) { 393a9a9c0cSDimitry Andric YamlIO.mapOptional("varArgsFrameIndex", MFI.VarArgsFrameIndex); 403a9a9c0cSDimitry Andric YamlIO.mapOptional("varArgsSaveSize", MFI.VarArgsSaveSize); 413a9a9c0cSDimitry Andric } 423a9a9c0cSDimitry Andric }; 433a9a9c0cSDimitry Andric } // end namespace yaml 443a9a9c0cSDimitry Andric 450b57cec5SDimitry Andric /// RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo 460b57cec5SDimitry Andric /// and contains private RISCV-specific information for each MachineFunction. 470b57cec5SDimitry Andric class RISCVMachineFunctionInfo : public MachineFunctionInfo { 480b57cec5SDimitry Andric private: 490b57cec5SDimitry Andric /// FrameIndex for start of varargs area 500b57cec5SDimitry Andric int VarArgsFrameIndex = 0; 510b57cec5SDimitry Andric /// Size of the save area used for varargs 520b57cec5SDimitry Andric int VarArgsSaveSize = 0; 530b57cec5SDimitry Andric /// FrameIndex used for transferring values between 64-bit FPRs and a pair 540b57cec5SDimitry Andric /// of 32-bit GPRs via the stack. 550b57cec5SDimitry Andric int MoveF64FrameIndex = -1; 565ffd83dbSDimitry Andric /// Size of any opaque stack adjustment due to save/restore libcalls. 575ffd83dbSDimitry Andric unsigned LibCallStackSize = 0; 58fe6060f1SDimitry Andric /// Size of RVV stack. 59fe6060f1SDimitry Andric uint64_t RVVStackSize = 0; 60*81ad6265SDimitry Andric /// Alignment of RVV stack. 61*81ad6265SDimitry Andric Align RVVStackAlign; 62fe6060f1SDimitry Andric /// Padding required to keep RVV stack aligned within the main stack. 63fe6060f1SDimitry Andric uint64_t RVVPadding = 0; 64fe6060f1SDimitry Andric /// Size of stack frame to save callee saved registers 65fe6060f1SDimitry Andric unsigned CalleeSavedStackSize = 0; 660b57cec5SDimitry Andric 670b57cec5SDimitry Andric public: 685ffd83dbSDimitry Andric RISCVMachineFunctionInfo(const MachineFunction &MF) {} 690b57cec5SDimitry Andric 70*81ad6265SDimitry Andric MachineFunctionInfo * 71*81ad6265SDimitry Andric clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, 72*81ad6265SDimitry Andric const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB) 73*81ad6265SDimitry Andric const override; 74*81ad6265SDimitry Andric 750b57cec5SDimitry Andric int getVarArgsFrameIndex() const { return VarArgsFrameIndex; } 760b57cec5SDimitry Andric void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; } 770b57cec5SDimitry Andric 780b57cec5SDimitry Andric unsigned getVarArgsSaveSize() const { return VarArgsSaveSize; } 790b57cec5SDimitry Andric void setVarArgsSaveSize(int Size) { VarArgsSaveSize = Size; } 800b57cec5SDimitry Andric 815ffd83dbSDimitry Andric int getMoveF64FrameIndex(MachineFunction &MF) { 820b57cec5SDimitry Andric if (MoveF64FrameIndex == -1) 835ffd83dbSDimitry Andric MoveF64FrameIndex = 845ffd83dbSDimitry Andric MF.getFrameInfo().CreateStackObject(8, Align(8), false); 850b57cec5SDimitry Andric return MoveF64FrameIndex; 860b57cec5SDimitry Andric } 875ffd83dbSDimitry Andric 885ffd83dbSDimitry Andric unsigned getLibCallStackSize() const { return LibCallStackSize; } 895ffd83dbSDimitry Andric void setLibCallStackSize(unsigned Size) { LibCallStackSize = Size; } 905ffd83dbSDimitry Andric 915ffd83dbSDimitry Andric bool useSaveRestoreLibCalls(const MachineFunction &MF) const { 925ffd83dbSDimitry Andric // We cannot use fixed locations for the callee saved spill slots if the 93fe6060f1SDimitry Andric // function uses a varargs save area, or is an interrupt handler. 945ffd83dbSDimitry Andric return MF.getSubtarget<RISCVSubtarget>().enableSaveRestore() && 95fe6060f1SDimitry Andric VarArgsSaveSize == 0 && !MF.getFrameInfo().hasTailCall() && 96fe6060f1SDimitry Andric !MF.getFunction().hasFnAttribute("interrupt"); 975ffd83dbSDimitry Andric } 98fe6060f1SDimitry Andric 99fe6060f1SDimitry Andric uint64_t getRVVStackSize() const { return RVVStackSize; } 100fe6060f1SDimitry Andric void setRVVStackSize(uint64_t Size) { RVVStackSize = Size; } 101fe6060f1SDimitry Andric 102*81ad6265SDimitry Andric Align getRVVStackAlign() const { return RVVStackAlign; } 103*81ad6265SDimitry Andric void setRVVStackAlign(Align StackAlign) { RVVStackAlign = StackAlign; } 104*81ad6265SDimitry Andric 105fe6060f1SDimitry Andric uint64_t getRVVPadding() const { return RVVPadding; } 106fe6060f1SDimitry Andric void setRVVPadding(uint64_t Padding) { RVVPadding = Padding; } 107fe6060f1SDimitry Andric 108fe6060f1SDimitry Andric unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; } 109fe6060f1SDimitry Andric void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; } 1103a9a9c0cSDimitry Andric 1113a9a9c0cSDimitry Andric void initializeBaseYamlFields(const yaml::RISCVMachineFunctionInfo &YamlMFI); 1120b57cec5SDimitry Andric }; 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric } // end namespace llvm 1150b57cec5SDimitry Andric 1160b57cec5SDimitry Andric #endif // LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H 117