RISCVMachineFunctionInfo.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #ifndef LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H
  13. #define LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H
  14. #include "RISCVSubtarget.h"
  15. #include "llvm/CodeGen/MIRYamlMapping.h"
  16. #include "llvm/CodeGen/MachineFrameInfo.h"
  17. #include "llvm/CodeGen/MachineFunction.h"
  18. namespace llvm {
  19. class RISCVMachineFunctionInfo;
  20. namespace yaml {
  21. struct RISCVMachineFunctionInfo final : public yaml::MachineFunctionInfo {
  22. int VarArgsFrameIndex;
  23. int VarArgsSaveSize;
  24. RISCVMachineFunctionInfo() = default;
  25. RISCVMachineFunctionInfo(const llvm::RISCVMachineFunctionInfo &MFI);
  26. void mappingImpl(yaml::IO &YamlIO) override;
  27. ~RISCVMachineFunctionInfo() = default;
  28. };
  29. template <> struct MappingTraits<RISCVMachineFunctionInfo> {
  30. static void mapping(IO &YamlIO, RISCVMachineFunctionInfo &MFI) {
  31. YamlIO.mapOptional("varArgsFrameIndex", MFI.VarArgsFrameIndex);
  32. YamlIO.mapOptional("varArgsSaveSize", MFI.VarArgsSaveSize);
  33. }
  34. };
  35. } // end namespace yaml
  36. /// RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo
  37. /// and contains private RISCV-specific information for each MachineFunction.
  38. class RISCVMachineFunctionInfo : public MachineFunctionInfo {
  39. private:
  40. /// FrameIndex for start of varargs area
  41. int VarArgsFrameIndex = 0;
  42. /// Size of the save area used for varargs
  43. int VarArgsSaveSize = 0;
  44. /// FrameIndex used for transferring values between 64-bit FPRs and a pair
  45. /// of 32-bit GPRs via the stack.
  46. int MoveF64FrameIndex = -1;
  47. /// FrameIndex of the spill slot for the scratch register in BranchRelaxation.
  48. int BranchRelaxationScratchFrameIndex = -1;
  49. /// Size of any opaque stack adjustment due to save/restore libcalls.
  50. unsigned LibCallStackSize = 0;
  51. /// Size of RVV stack.
  52. uint64_t RVVStackSize = 0;
  53. /// Alignment of RVV stack.
  54. Align RVVStackAlign;
  55. /// Padding required to keep RVV stack aligned within the main stack.
  56. uint64_t RVVPadding = 0;
  57. /// Size of stack frame to save callee saved registers
  58. unsigned CalleeSavedStackSize = 0;
  59. /// Is there any vector argument or return?
  60. bool IsVectorCall = false;
  61. /// Registers that have been sign extended from i32.
  62. SmallVector<Register, 8> SExt32Registers;
  63. public:
  64. RISCVMachineFunctionInfo(const Function &F, const TargetSubtargetInfo *STI) {}
  65. MachineFunctionInfo *
  66. clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF,
  67. const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
  68. const override;
  69. int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
  70. void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
  71. unsigned getVarArgsSaveSize() const { return VarArgsSaveSize; }
  72. void setVarArgsSaveSize(int Size) { VarArgsSaveSize = Size; }
  73. int getMoveF64FrameIndex(MachineFunction &MF) {
  74. if (MoveF64FrameIndex == -1)
  75. MoveF64FrameIndex =
  76. MF.getFrameInfo().CreateStackObject(8, Align(8), false);
  77. return MoveF64FrameIndex;
  78. }
  79. int getBranchRelaxationScratchFrameIndex() const {
  80. return BranchRelaxationScratchFrameIndex;
  81. }
  82. void setBranchRelaxationScratchFrameIndex(int Index) {
  83. BranchRelaxationScratchFrameIndex = Index;
  84. }
  85. unsigned getLibCallStackSize() const { return LibCallStackSize; }
  86. void setLibCallStackSize(unsigned Size) { LibCallStackSize = Size; }
  87. bool useSaveRestoreLibCalls(const MachineFunction &MF) const {
  88. // We cannot use fixed locations for the callee saved spill slots if the
  89. // function uses a varargs save area, or is an interrupt handler.
  90. return MF.getSubtarget<RISCVSubtarget>().enableSaveRestore() &&
  91. VarArgsSaveSize == 0 && !MF.getFrameInfo().hasTailCall() &&
  92. !MF.getFunction().hasFnAttribute("interrupt");
  93. }
  94. uint64_t getRVVStackSize() const { return RVVStackSize; }
  95. void setRVVStackSize(uint64_t Size) { RVVStackSize = Size; }
  96. Align getRVVStackAlign() const { return RVVStackAlign; }
  97. void setRVVStackAlign(Align StackAlign) { RVVStackAlign = StackAlign; }
  98. uint64_t getRVVPadding() const { return RVVPadding; }
  99. void setRVVPadding(uint64_t Padding) { RVVPadding = Padding; }
  100. unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
  101. void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
  102. void initializeBaseYamlFields(const yaml::RISCVMachineFunctionInfo &YamlMFI);
  103. void addSExt32Register(Register Reg);
  104. bool isSExt32Register(Register Reg) const;
  105. bool isVectorCall() const { return IsVectorCall; }
  106. void setIsVectorCall() { IsVectorCall = true; }
  107. };
  108. } // end namespace llvm
  109. #endif // LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H