LLVM 22.0.0git
RISCVMachineFunctionInfo.h
Go to the documentation of this file.
1//=- RISCVMachineFunctionInfo.h - RISC-V 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
21namespace llvm {
22
23class RISCVMachineFunctionInfo;
24
25namespace yaml {
29
32
33 void mappingImpl(yaml::IO &YamlIO) override;
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.
48private:
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 /// Is there any vector argument or return?
69 bool IsVectorCall = false;
70
71 /// Registers that have been sign extended from i32.
72 SmallVector<Register, 8> SExt32Registers;
73
74 /// Size of stack frame for Zcmp PUSH/POP
75 unsigned RVPushStackSize = 0;
76 unsigned RVPushRegs = 0;
77
78 /// Size of any opaque stack adjustment due to QCI Interrupt instructions.
79 unsigned QCIInterruptStackSize = 0;
80
81 /// Store Frame Indexes for Interrupt-Related CSR Spills.
82 SmallVector<int, 2> InterruptCSRFrameIndexes;
83
84 int64_t StackProbeSize = 0;
85
86 /// Does it probe the stack for a dynamic allocation?
87 bool HasDynamicAllocation = false;
88
89public:
91
95 const override;
96
97 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
98 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
99
100 unsigned getVarArgsSaveSize() const { return VarArgsSaveSize; }
101 void setVarArgsSaveSize(int Size) { VarArgsSaveSize = Size; }
102
104 if (MoveF64FrameIndex == -1)
105 MoveF64FrameIndex =
106 MF.getFrameInfo().CreateStackObject(8, Align(8), false);
107 return MoveF64FrameIndex;
108 }
109
111 return BranchRelaxationScratchFrameIndex;
112 }
114 BranchRelaxationScratchFrameIndex = Index;
115 }
116
117 unsigned getReservedSpillsSize() const {
118 return LibCallStackSize + RVPushStackSize + QCIInterruptStackSize;
119 }
120
121 unsigned getLibCallStackSize() const { return LibCallStackSize; }
122 void setLibCallStackSize(unsigned Size) { LibCallStackSize = Size; }
123
125 // We cannot use fixed locations for the callee saved spill slots if the
126 // function uses a varargs save area, or is an interrupt handler.
127 return !isPushable(MF) &&
128 MF.getSubtarget<RISCVSubtarget>().enableSaveRestore() &&
129 VarArgsSaveSize == 0 && !MF.getFrameInfo().hasTailCall() &&
130 !MF.getFunction().hasFnAttribute("interrupt");
131 }
132
133 uint64_t getRVVStackSize() const { return RVVStackSize; }
134 void setRVVStackSize(uint64_t Size) { RVVStackSize = Size; }
135
136 Align getRVVStackAlign() const { return RVVStackAlign; }
137 void setRVVStackAlign(Align StackAlign) { RVVStackAlign = StackAlign; }
138
139 uint64_t getRVVPadding() const { return RVVPadding; }
140 void setRVVPadding(uint64_t Padding) { RVVPadding = Padding; }
141
142 unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
143 void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
144
146
148
149 bool isPushable(const MachineFunction &MF) const {
150 return getPushPopKind(MF) != PushPopKind::None;
151 }
152
153 unsigned getRVPushRegs() const { return RVPushRegs; }
154 void setRVPushRegs(unsigned Regs) { RVPushRegs = Regs; }
155
156 unsigned getRVPushStackSize() const { return RVPushStackSize; }
157 void setRVPushStackSize(unsigned Size) { RVPushStackSize = Size; }
158
160 None = 0,
161 QCINest,
162 QCINoNest,
166 };
167
169
170 bool useQCIInterrupt(const MachineFunction &MF) const {
172 return Kind == InterruptStackKind::QCINest ||
174 }
175
176 unsigned getQCIInterruptStackSize() const { return QCIInterruptStackSize; }
177 void setQCIInterruptStackSize(unsigned Size) { QCIInterruptStackSize = Size; }
178
179 bool useSiFiveInterrupt(const MachineFunction &MF) const {
184 }
185
190 }
191
196 }
197
199 InterruptCSRFrameIndexes.push_back(FI);
200 }
201 int getInterruptCSRFrameIndex(size_t Idx) const {
202 return InterruptCSRFrameIndexes[Idx];
203 }
204
205 // Some Stack Management Variants automatically update FP in a frame-pointer
206 // convention compatible way - which means we don't need to manually update
207 // the FP, but we still need to emit the correct CFI information for
208 // calculating the CFA based on FP.
209 bool hasImplicitFPUpdates(const MachineFunction &MF) const;
210
212
214 bool isSExt32Register(Register Reg) const;
215
216 bool isVectorCall() const { return IsVectorCall; }
217 void setIsVectorCall() { IsVectorCall = true; }
218
219 bool hasDynamicAllocation() const { return HasDynamicAllocation; }
220 void setDynamicAllocation() { HasDynamicAllocation = true; }
221};
222
223} // end namespace llvm
224
225#endif // LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
uint32_t Index
uint64_t Size
IO & YamlIO
Definition: ELFYAML.cpp:1327
#define F(x, y, z)
Definition: MD5.cpp:55
Register Reg
Basic Register Allocator
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition: Function.cpp:727
LLVM_ABI 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.
bool hasTailCall() const
Returns true if the function contains a tail call.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Function & getFunction()
Return the LLVM function that this machine code represents.
RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo and contains private RISCV-...
bool hasImplicitFPUpdates(const MachineFunction &MF) const
bool isPushable(const MachineFunction &MF) const
void initializeBaseYamlFields(const yaml::RISCVMachineFunctionInfo &YamlMFI)
InterruptStackKind getInterruptStackKind(const MachineFunction &MF) const
bool useSiFiveInterrupt(const MachineFunction &MF) const
bool isSiFivePreemptibleInterrupt(const MachineFunction &MF) const
MachineFunctionInfo * clone(BumpPtrAllocator &Allocator, MachineFunction &DestMF, const DenseMap< MachineBasicBlock *, MachineBasicBlock * > &Src2DstMBB) const override
Make a functionally equivalent copy of this MachineFunctionInfo in MF.
PushPopKind getPushPopKind(const MachineFunction &MF) const
bool useSaveRestoreLibCalls(const MachineFunction &MF) const
int getMoveF64FrameIndex(MachineFunction &MF)
bool useQCIInterrupt(const MachineFunction &MF) const
bool isSiFiveStackSwapInterrupt(const MachineFunction &MF) const
int getInterruptCSRFrameIndex(size_t Idx) const
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.
static void mapping(IO &YamlIO, RISCVMachineFunctionInfo &MFI)
void mappingImpl(yaml::IO &YamlIO) override