LLVM 24.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"
17#include "llvm/ADT/DenseMap.h"
21
22namespace llvm {
23
25
26namespace yaml {
37
39 static void mapping(IO &YamlIO, RISCVMachineFunctionInfo &MFI) {
40 YamlIO.mapOptional("varArgsFrameIndex", MFI.VarArgsFrameIndex);
41 YamlIO.mapOptional("varArgsSaveSize", MFI.VarArgsSaveSize);
42 }
43};
44} // end namespace yaml
45
46/// RISCVMachineFunctionInfo - This class is derived from MachineFunctionInfo
47/// and contains private RISCV-specific information for each MachineFunction.
49private:
50 /// FrameIndex for start of varargs area
51 int VarArgsFrameIndex = 0;
52 /// Size of the save area used for varargs
53 int VarArgsSaveSize = 0;
54 /// FrameIndex used for transferring values between 64-bit FPRs and a pair
55 /// of 32-bit GPRs via the stack.
56 int MoveF64FrameIndex = -1;
57 /// FrameIndex of the spill slot for the scratch register in BranchRelaxation.
58 int BranchRelaxationScratchFrameIndex = -1;
59 /// Size of any opaque stack adjustment due to save/restore libcalls.
60 unsigned LibCallStackSize = 0;
61 /// Size of RVV stack.
62 uint64_t RVVStackSize = 0;
63 /// Alignment of RVV stack.
64 Align RVVStackAlign;
65 /// Padding required to keep RVV stack aligned within the main stack.
66 uint64_t RVVPadding = 0;
67 /// Size of stack frame to save callee saved registers
68 unsigned CalleeSavedStackSize = 0;
69
70 /// Incoming indirect argument pointers saved as virtual registers, keyed by
71 /// formal parameter index. Used for musttail forwarding of indirect args.
72 /// Virtual registers (not SDValues) are used because the SelectionDAG is
73 /// cleared between basic blocks, and musttail calls may be in non-entry
74 /// blocks.
75 DenseMap<unsigned, Register> IncomingIndirectArgs;
76
77 /// Is there any vector argument or return?
78 bool IsVectorCall = false;
79
80 /// Registers that have been sign extended from i32.
81 SmallVector<Register, 8> SExt32Registers;
82
83 /// Size of stack frame for Zcmp PUSH/POP
84 unsigned RVPushStackSize = 0;
85 unsigned RVPushRegs = 0;
86
87 /// Size of any opaque stack adjustment due to QCI Interrupt instructions.
88 unsigned QCIInterruptStackSize = 0;
89
90 /// Size of the frame pushed by ACLIC Smip/Ssip interrupt entry.
91 unsigned ACLICInterruptStackSize = 0;
92
93 /// Store Frame Indexes for Interrupt-Related CSR Spills.
94 SmallVector<int, 2> InterruptCSRFrameIndexes;
95
96 int64_t StackProbeSize = 0;
97
98 /// Does it probe the stack for a dynamic allocation?
99 bool HasDynamicAllocation = false;
100
101 /// Whether the function has cf-protection-branch module flag set.
102 bool CFProtectionBranch = false;
103
104public:
106
110 const override;
111
112 int getVarArgsFrameIndex() const { return VarArgsFrameIndex; }
113 void setVarArgsFrameIndex(int Index) { VarArgsFrameIndex = Index; }
114
115 unsigned getVarArgsSaveSize() const { return VarArgsSaveSize; }
116 void setVarArgsSaveSize(int Size) { VarArgsSaveSize = Size; }
117
119 if (MoveF64FrameIndex == -1)
120 MoveF64FrameIndex =
121 MF.getFrameInfo().CreateStackObject(8, Align(8), false);
122 return MoveF64FrameIndex;
123 }
124
126 return BranchRelaxationScratchFrameIndex;
127 }
129 BranchRelaxationScratchFrameIndex = Index;
130 }
131
132 unsigned getReservedSpillsSize() const {
133 return LibCallStackSize + RVPushStackSize + QCIInterruptStackSize +
134 ACLICInterruptStackSize;
135 }
136
137 unsigned getLibCallStackSize() const { return LibCallStackSize; }
138 void setLibCallStackSize(unsigned Size) { LibCallStackSize = Size; }
139
141 // We cannot use fixed locations for the callee saved spill slots if the
142 // function uses a varargs save area, or is an interrupt handler.
143 return !isPushable(MF) &&
144 MF.getSubtarget<RISCVSubtarget>().enableSaveRestore() &&
145 VarArgsSaveSize == 0 && !MF.getFrameInfo().hasTailCall() &&
146 !MF.getFunction().hasFnAttribute("interrupt");
147 }
148
149 uint64_t getRVVStackSize() const { return RVVStackSize; }
150 void setRVVStackSize(uint64_t Size) { RVVStackSize = Size; }
151
152 Align getRVVStackAlign() const { return RVVStackAlign; }
153 void setRVVStackAlign(Align StackAlign) { RVVStackAlign = StackAlign; }
154
155 uint64_t getRVVPadding() const { return RVVPadding; }
156 void setRVVPadding(uint64_t Padding) { RVVPadding = Padding; }
157
158 unsigned getCalleeSavedStackSize() const { return CalleeSavedStackSize; }
159 void setCalleeSavedStackSize(unsigned Size) { CalleeSavedStackSize = Size; }
160
161 void setIncomingIndirectArg(unsigned ArgIndex, Register Reg) {
162 IncomingIndirectArgs[ArgIndex] = Reg;
163 }
164 Register getIncomingIndirectArg(unsigned ArgIndex) const {
165 auto It = IncomingIndirectArgs.find(ArgIndex);
166 assert(It != IncomingIndirectArgs.end() && "No incoming indirect arg");
167 return It->second;
168 }
169
170 enum class ShadowStackKind { None = 0, Hardware, Software };
171
173 bool hasShadowStack(const MachineFunction &MF) const {
175 }
176
178
180
181 bool isPushable(const MachineFunction &MF) const {
182 return getPushPopKind(MF) != PushPopKind::None;
183 }
184
185 unsigned getRVPushRegs() const { return RVPushRegs; }
186 void setRVPushRegs(unsigned Regs) { RVPushRegs = Regs; }
187
188 unsigned getRVPushStackSize() const { return RVPushStackSize; }
189 void setRVPushStackSize(unsigned Size) { RVPushStackSize = Size; }
190
205
207
208 bool useQCIInterrupt(const MachineFunction &MF) const {
210 return Kind == InterruptStackKind::QCINest ||
212 }
213
214 unsigned getQCIInterruptStackSize() const { return QCIInterruptStackSize; }
215 void setQCIInterruptStackSize(unsigned Size) { QCIInterruptStackSize = Size; }
216
217 unsigned getACLICInterruptStackSize() const {
218 return ACLICInterruptStackSize;
219 }
220
222 ACLICInterruptStackSize = Size;
223 }
224
231
237
243
251
259
266
268 InterruptCSRFrameIndexes.push_back(FI);
269 }
270 int getInterruptCSRFrameIndex(size_t Idx) const {
271 return InterruptCSRFrameIndexes[Idx];
272 }
273 bool isInterruptCSRFrameIndex(int FI) const {
274 return llvm::is_contained(InterruptCSRFrameIndexes, FI);
275 }
276
277 // Some Stack Management Variants automatically update FP in a frame-pointer
278 // convention compatible way - which means we don't need to manually update
279 // the FP, but we still need to emit the correct CFI information for
280 // calculating the CFA based on FP.
281 bool hasImplicitFPUpdates(const MachineFunction &MF) const;
282
284
286 bool isSExt32Register(Register Reg) const;
287
288 bool isVectorCall() const { return IsVectorCall; }
289 void setIsVectorCall() { IsVectorCall = true; }
290
291 bool hasDynamicAllocation() const { return HasDynamicAllocation; }
292 void setDynamicAllocation() { HasDynamicAllocation = true; }
293
294 bool hasCFProtectionBranch() const { return CFProtectionBranch; }
295};
296
297} // end namespace llvm
298
299#endif // LLVM_LIB_TARGET_RISCV_RISCVMACHINEFUNCTIONINFO_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t uint64_t
This file defines the DenseMap class.
#define F(x, y, z)
Definition MD5.cpp:54
Register Reg
Basic Register Allocator
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Definition Function.cpp:731
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)
void setIncomingIndirectArg(unsigned ArgIndex, Register Reg)
bool isACLICPushPopInterrupt(const MachineFunction &MF) const
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 hasShadowStack(const MachineFunction &MF) const
RISCVMachineFunctionInfo(const Function &F, const RISCVSubtarget *STI)
bool isACLICPreemptibleInterrupt(const MachineFunction &MF) const
bool useSaveRestoreLibCalls(const MachineFunction &MF) const
bool isACLICSupervisorInterrupt(const MachineFunction &MF) const
Register getIncomingIndirectArg(unsigned ArgIndex) const
int getMoveF64FrameIndex(MachineFunction &MF)
ShadowStackKind getShadowStackKind(const MachineFunction &MF) const
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:20
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
void mapOptional(StringRef Key, T &Val)
Definition YAMLTraits.h:800
This is an optimization pass for GlobalISel generic memory operations.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:391
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)
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:63
void mappingImpl(yaml::IO &YamlIO) override
~RISCVMachineFunctionInfo() override=default