LLVM  16.0.0git
RISCVMachineFunctionInfo.h
Go to the documentation of this file.
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"
20 
21 namespace llvm {
22 
23 class RISCVMachineFunctionInfo;
24 
25 namespace yaml {
29 
30  RISCVMachineFunctionInfo() = default;
32 
33  void mappingImpl(yaml::IO &YamlIO) override;
34  ~RISCVMachineFunctionInfo() = default;
35 };
36 
38  static void mapping(IO &YamlIO, RISCVMachineFunctionInfo &MFI) {
39  YamlIO.mapOptional("varArgsFrameIndex", MFI.VarArgsFrameIndex);
40  YamlIO.mapOptional("varArgsSaveSize", MFI.VarArgsSaveSize);
41  }
42 };
43 } // end namespace yaml
44 
45 /// RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo
46 /// and contains private RISCV-specific information for each MachineFunction.
48 private:
49  /// FrameIndex for start of varargs area
50  int VarArgsFrameIndex = 0;
51  /// Size of the save area used for varargs
52  int VarArgsSaveSize = 0;
53  /// FrameIndex used for transferring values between 64-bit FPRs and a pair
54  /// of 32-bit GPRs via the stack.
55  int MoveF64FrameIndex = -1;
56  /// FrameIndex of the spill slot for the scratch register in BranchRelaxation.
57  int BranchRelaxationScratchFrameIndex = -1;
58  /// Size of any opaque stack adjustment due to save/restore libcalls.
59  unsigned LibCallStackSize = 0;
60  /// Size of RVV stack.
61  uint64_t RVVStackSize = 0;
62  /// Alignment of RVV stack.
63  Align RVVStackAlign;
64  /// Padding required to keep RVV stack aligned within the main stack.
65  uint64_t RVVPadding = 0;
66  /// Size of stack frame to save callee saved registers
67  unsigned CalleeSavedStackSize = 0;
68 
69 public:
71 
75  const override;
76 
77  int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
78  void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
79 
80  unsigned getVarArgsSaveSize() const { return VarArgsSaveSize; }
81  void setVarArgsSaveSize(int Size) { VarArgsSaveSize = Size; }
82 
84  if (MoveF64FrameIndex == -1)
85  MoveF64FrameIndex =
86  MF.getFrameInfo().CreateStackObject(8, Align(8), false);
87  return MoveF64FrameIndex;
88  }
89 
91  return BranchRelaxationScratchFrameIndex;
92  }
94  BranchRelaxationScratchFrameIndex = Index;
95  }
96 
97  unsigned getLibCallStackSize() const { return LibCallStackSize; }
98  void setLibCallStackSize(unsigned Size) { LibCallStackSize = Size; }
99 
100  bool useSaveRestoreLibCalls(const MachineFunction &MF) const {
101  // We cannot use fixed locations for the callee saved spill slots if the
102  // function uses a varargs save area, or is an interrupt handler.
103  return MF.getSubtarget<RISCVSubtarget>().enableSaveRestore() &&
104  VarArgsSaveSize == 0 && !MF.getFrameInfo().hasTailCall() &&
105  !MF.getFunction().hasFnAttribute("interrupt");
106  }
107 
108  uint64_t getRVVStackSize() const { return RVVStackSize; }
109  void setRVVStackSize(uint64_t Size) { RVVStackSize = Size; }
110 
111  Align getRVVStackAlign() const { return RVVStackAlign; }
112  void setRVVStackAlign(Align StackAlign) { RVVStackAlign = StackAlign; }
113 
114  uint64_t getRVVPadding() const { return RVVPadding; }
115  void setRVVPadding(uint64_t Padding) { RVVPadding = Padding; }
116 
117  unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
118  void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
119 
121 };
122 
123 } // end namespace llvm
124 
125 #endif // LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H
llvm::RISCVMachineFunctionInfo::clone
MachineFunctionInfo * clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, const DenseMap< MachineBasicBlock *, MachineBasicBlock * > &Src2DstMBB) const override
Make a functionally equivalent copy of this MachineFunctionInfo in MF.
Definition: RISCVMachineFunctionInfo.cpp:22
llvm::RISCVAttrs::StackAlign
StackAlign
Definition: RISCVAttributes.h:37
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::RISCVMachineFunctionInfo::setRVVStackSize
void setRVVStackSize(uint64_t Size)
Definition: RISCVMachineFunctionInfo.h:109
llvm::yaml::MachineFunctionInfo
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.
Definition: MIRYamlMapping.h:676
llvm::RISCVMachineFunctionInfo::setLibCallStackSize
void setLibCallStackSize(unsigned Size)
Definition: RISCVMachineFunctionInfo.h:98
llvm::RISCVMachineFunctionInfo::setRVVStackAlign
void setRVVStackAlign(Align StackAlign)
Definition: RISCVMachineFunctionInfo.h:112
llvm::RISCVMachineFunctionInfo::setBranchRelaxationScratchFrameIndex
void setBranchRelaxationScratchFrameIndex(int Index)
Definition: RISCVMachineFunctionInfo.h:93
YamlIO
IO & YamlIO
Definition: ELFYAML.cpp:1246
llvm::yaml::MappingTraits
Definition: ModuleSummaryIndex.h:51
llvm::RISCVMachineFunctionInfo::getLibCallStackSize
unsigned getLibCallStackSize() const
Definition: RISCVMachineFunctionInfo.h:97
llvm::RISCVMachineFunctionInfo::getCalleeSavedStackSize
unsigned getCalleeSavedStackSize() const
Definition: RISCVMachineFunctionInfo.h:117
MIRYamlMapping.h
llvm::RISCVMachineFunctionInfo::setRVVPadding
void setRVVPadding(uint64_t Padding)
Definition: RISCVMachineFunctionInfo.h:115
llvm::yaml::RISCVMachineFunctionInfo::VarArgsFrameIndex
int VarArgsFrameIndex
Definition: RISCVMachineFunctionInfo.h:27
llvm::RISCVMachineFunctionInfo::getMoveF64FrameIndex
int getMoveF64FrameIndex(MachineFunction &MF)
Definition: RISCVMachineFunctionInfo.h:83
llvm::RISCVMachineFunctionInfo::getRVVStackSize
uint64_t getRVVStackSize() const
Definition: RISCVMachineFunctionInfo.h:108
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
Align
uint64_t Align
Definition: ELFObjHandler.cpp:81
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::yaml::RISCVMachineFunctionInfo::RISCVMachineFunctionInfo
RISCVMachineFunctionInfo()=default
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:656
llvm::Function::hasFnAttribute
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.cpp:628
llvm::yaml::RISCVMachineFunctionInfo::VarArgsSaveSize
int VarArgsSaveSize
Definition: RISCVMachineFunctionInfo.h:28
llvm::RISCVMachineFunctionInfo::getVarArgsSaveSize
unsigned getVarArgsSaveSize() const
Definition: RISCVMachineFunctionInfo.h:80
Index
uint32_t Index
Definition: ELFObjHandler.cpp:82
uint64_t
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
llvm::DenseMap
Definition: DenseMap.h:714
llvm::RISCVMachineFunctionInfo
RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo and contains private RISCV-...
Definition: RISCVMachineFunctionInfo.h:47
llvm::RISCVMachineFunctionInfo::useSaveRestoreLibCalls
bool useSaveRestoreLibCalls(const MachineFunction &MF) const
Definition: RISCVMachineFunctionInfo.h:100
llvm::RISCVMachineFunctionInfo::getRVVStackAlign
Align getRVVStackAlign() const
Definition: RISCVMachineFunctionInfo.h:111
llvm::RISCVSubtarget
Definition: RISCVSubtarget.h:35
llvm::yaml::MappingTraits< RISCVMachineFunctionInfo >::mapping
static void mapping(IO &YamlIO, RISCVMachineFunctionInfo &MFI)
Definition: RISCVMachineFunctionInfo.h:38
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:672
llvm::yaml::RISCVMachineFunctionInfo::~RISCVMachineFunctionInfo
~RISCVMachineFunctionInfo()=default
llvm::RISCVMachineFunctionInfo::setCalleeSavedStackSize
void setCalleeSavedStackSize(unsigned Size)
Definition: RISCVMachineFunctionInfo.h:118
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::MachineFrameInfo::CreateStackObject
int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
Definition: MachineFrameInfo.cpp:51
llvm::RISCVMachineFunctionInfo::getBranchRelaxationScratchFrameIndex
int getBranchRelaxationScratchFrameIndex() const
Definition: RISCVMachineFunctionInfo.h:90
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:622
MachineFrameInfo.h
llvm::yaml::RISCVMachineFunctionInfo
Definition: RISCVMachineFunctionInfo.h:26
llvm::RISCVMachineFunctionInfo::getVarArgsFrameIndex
int getVarArgsFrameIndex() const
Definition: RISCVMachineFunctionInfo.h:77
llvm::RISCVMachineFunctionInfo::setVarArgsFrameIndex
void setVarArgsFrameIndex(int Index)
Definition: RISCVMachineFunctionInfo.h:78
RISCVSubtarget.h
llvm::yaml::RISCVMachineFunctionInfo::mappingImpl
void mappingImpl(yaml::IO &YamlIO) override
Definition: RISCVMachineFunctionInfo.cpp:29
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:143
llvm::RISCVMachineFunctionInfo::initializeBaseYamlFields
void initializeBaseYamlFields(const yaml::RISCVMachineFunctionInfo &YamlMFI)
Definition: RISCVMachineFunctionInfo.cpp:33
llvm::RISCVMachineFunctionInfo::RISCVMachineFunctionInfo
RISCVMachineFunctionInfo(const MachineFunction &MF)
Definition: RISCVMachineFunctionInfo.h:70
llvm::MachineFrameInfo::hasTailCall
bool hasTailCall() const
Returns true if the function contains a tail call.
Definition: MachineFrameInfo.h:630
MachineFunction.h
llvm::MachineFunctionInfo
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
Definition: MachineFunction.h:95
llvm::RISCVMachineFunctionInfo::getRVVPadding
uint64_t getRVVPadding() const
Definition: RISCVMachineFunctionInfo.h:114
llvm::RISCVMachineFunctionInfo::setVarArgsSaveSize
void setVarArgsSaveSize(int Size)
Definition: RISCVMachineFunctionInfo.h:81