LLVM 24.0.0git
AArch64FrameLowering.h
Go to the documentation of this file.
1//==-- AArch64FrameLowering.h - TargetFrameLowering for AArch64 --*- 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//
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64FRAMELOWERING_H
14#define LLVM_LIB_TARGET_AARCH64_AARCH64FRAMELOWERING_H
15
19
20namespace llvm {
21
26
31
33public:
36 true /*StackRealignable*/) {}
37
38 void resetCFIToInitialState(MachineBasicBlock &MBB) const override;
39
42 MachineBasicBlock::iterator I) const override;
43
44 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
45 /// the function.
46 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
47 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
48
49 /// Harden the entire function with pac-ret.
50 ///
51 /// If pac-ret+leaf is requested, we want to harden as much code as possible.
52 /// This function inserts pac-ret hardening at the points where prologue and
53 /// epilogue are traditionally inserted, ignoring possible shrink-wrapping
54 /// optimization.
56
57 bool enableCFIFixup(const MachineFunction &MF) const override;
58
59 bool enableFullCFIFixup(const MachineFunction &MF) const override;
60
61 bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
62
64 Register &FrameReg) const override;
66 int FI) const override;
68 Register &FrameReg, bool PreferFP,
69 bool ForSimm) const;
71 int64_t ObjectOffset, bool isFixed,
73 Register &FrameReg, bool PreferFP,
74 bool ForSimm) const;
78 const TargetRegisterInfo *TRI) const override;
79
80 bool
84 const TargetRegisterInfo *TRI) const override;
85
86 /// Can this function use the red zone for local allocations.
87 bool canUseRedZone(const MachineFunction &MF) const;
88
89 /// Returns how much of the incoming argument stack area (in bytes) we should
90 /// clean up in an epilogue. For the C calling convention this will be 0, for
91 /// guaranteed tail call conventions it can be positive (a normal return or a
92 /// tail call to a function that uses less stack space for arguments) or
93 /// negative (for a tail call to a function that needs more stack space than
94 /// us for arguments).
96 MachineBasicBlock &MBB) const;
97
98 /// Whether the return address is authenticated before the epilogue starts,
99 /// in the return block MBB, with the authenticated value then kept in LR
100 /// instead of being restored from the stack by the epilogue.
101 ///
102 /// We need to do this on Windows when doing tail calls where the caller
103 /// and callee use different amounts of stack space for arguments.
105 MachineBasicBlock &MBB) const;
106
107 bool hasReservedCallFrame(const MachineFunction &MF) const override;
108
109 bool
111 const TargetRegisterInfo *TRI,
112 std::vector<CalleeSavedInfo> &CSI) const override;
113
115 RegScavenger *RS) const override;
116
117 /// Returns true if the target will correctly handle shrink wrapping.
118 bool enableShrinkWrapping(const MachineFunction &MF) const override;
119 bool enableWindowsCFIShrinkWrapping(const MachineFunction &MF) const override;
120
121 bool enableStackSlotScavenging(const MachineFunction &MF) const override;
123
125 RegScavenger *RS) const override;
126
127 void
129 RegScavenger *RS) const override;
130
131 unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override;
132
133 unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const;
134
137 Register &FrameReg,
138 bool IgnoreSPUpdates) const override;
140 int FI) const override;
141 int getSEHFrameIndexOffset(const MachineFunction &MF, int FI) const;
142
143 bool isSupportedStackID(TargetStackID::Value ID) const override {
144 switch (ID) {
145 default:
146 return false;
151 return true;
152 }
153 }
154
155 bool isStackIdSafeForLocalArea(unsigned StackId) const override {
156 // We don't support putting SVE objects into the pre-allocated local
157 // frame block at the moment.
158 return (StackId != TargetStackID::ScalableVector &&
160 }
161
162 void
164 SmallVectorImpl<int> &ObjectsToAllocate) const override;
165
166 bool isFPReserved(const MachineFunction &MF) const;
167
168 bool requiresSaveVG(const MachineFunction &MF) const;
169
170 /// Returns the size of the entire ZPR stackframe (calleesaves + spills).
172
173 /// Returns the size of the entire PPR stackframe (calleesaves + spills +
174 /// hazard padding).
176
177 /// Returns the size of the entire SVE stackframe (PPRs + ZPRs).
179 return getZPRStackSize(MF) + getPPRStackSize(MF);
180 }
181
185
186 // Windows unwind can't represent the required stack adjustments if we have
187 // both SVE callee-saves and dynamic stack allocations, and the frame
188 // pointer is before the SVE spills. The allocation of the frame pointer
189 // must be the last instruction in the prologue so the unwinder can restore
190 // the stack pointer correctly. (And there isn't any unwind opcode for
191 // `addvl sp, x29, -17`.)
192 //
193 // Because of this, we do spills in the opposite order on Windows: first SVE,
194 // then GPRs. The main side-effect of this is that it makes accessing
195 // parameters passed on the stack more expensive.
196 //
197 // We could consider rearranging the spills for simpler cases.
199
200protected:
201 bool hasFPImpl(const MachineFunction &MF) const override;
202
203private:
204 /// Returns true if a homogeneous prolog or epilog code can be emitted
205 /// for the size optimization. If so, HOM_Prolog/HOM_Epilog pseudo
206 /// instructions are emitted in place. When Exit block is given, this check is
207 /// for epilog.
208 bool homogeneousPrologEpilog(MachineFunction &MF,
209 MachineBasicBlock *Exit = nullptr) const;
210
211 /// Returns true if CSRs should be paired.
212 bool producePairRegisters(MachineFunction &MF) const;
213
214 /// Make a determination whether a Hazard slot is used and create it if
215 /// needed.
216 void determineStackHazardSlot(MachineFunction &MF,
217 BitVector &SavedRegs) const;
218
219 /// Emit target zero call-used regs.
220 void emitZeroCallUsedRegs(BitVector RegsToZero, MachineBasicBlock &MBB,
221 RegScavenger *RS) const override;
222
223 /// Replace a StackProbe stub (if any) with the actual probe code inline
224 void inlineStackProbe(MachineFunction &MF,
225 MachineBasicBlock &PrologueMBB) const override;
226
227 void inlineStackProbeFixed(MachineBasicBlock::iterator MBBI,
228 Register ScratchReg, int64_t FrameSize,
229 StackOffset CFAOffset) const;
230
232 inlineStackProbeLoopExactMultiple(MachineBasicBlock::iterator MBBI,
233 int64_t NegProbeSize,
234 Register TargetReg) const;
235
236 void emitRemarks(const MachineFunction &MF,
237 MachineOptimizationRemarkEmitter *ORE) const override;
238
239 bool windowsRequiresStackProbe(const MachineFunction &MF,
240 uint64_t StackSizeInBytes) const;
241
242 bool shouldSignReturnAddressEverywhere(const MachineFunction &MF) const;
243
244 StackOffset getFPOffset(const MachineFunction &MF,
245 int64_t ObjectOffset) const;
246
247 StackOffset getStackOffset(const MachineFunction &MF,
248 int64_t ObjectOffset) const;
249
250 // Given a load or a store instruction, generate an appropriate unwinding SEH
251 // code on Windows.
253 const AArch64InstrInfo &TII,
254 MachineInstr::MIFlag Flag) const;
255
256 // Find a scratch register that we can use at the start of the prologue to
257 // re-align the stack pointer. We avoid using callee-save registers since
258 // they may appear to be free when this is called from canUseAsPrologue
259 // (during shrink wrapping), but then no longer be free when this is called
260 // from emitPrologue.
261 //
262 // FIXME: This is a bit conservative, since in the above case we could use one
263 // of the callee-save registers as a scratch temp to re-align the stack
264 // pointer, but we would then have to make sure that we were in fact saving at
265 // least one callee-save register in the prologue, which is additional
266 // complexity that doesn't seem worth the benefit.
268 bool HasCall = false) const;
269
270 /// Returns the size of the fixed object area (allocated next to sp on entry)
271 /// On Win64 this may include a var args area and an UnwindHelp object for EH.
272 unsigned getFixedObjectSize(const MachineFunction &MF,
273 const AArch64FunctionInfo *AFI, bool IsWin64,
274 bool IsFunclet) const;
275};
276
277} // End llvm namespace
278
279#endif
const AArch64InstrInfo & TII
uint64_t uint64_t
static MachineBasicBlock::iterator insertSEH(MachineBasicBlock::iterator MBBI, const TargetInstrInfo &TII, unsigned Flags)
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
===- MachineOptimizationRemarkEmitter.h - Opt Diagnostics -*- C++ -*-—===//
Register const TargetRegisterInfo * TRI
static MCRegister findScratchNonCalleeSaveRegister(MachineRegisterInfo &MRI, LiveRegUnits &LiveUnits, const TargetRegisterClass &RC, bool Unused=false)
A helper class for emitting the epilogue.
StackOffset getSVEStackSize(const MachineFunction &MF) const
Returns the size of the entire SVE stackframe (PPRs + ZPRs).
StackOffset getZPRStackSize(const MachineFunction &MF) const
Returns the size of the entire ZPR stackframe (calleesaves + spills).
void processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameIndicesReplaced - This method is called immediately before MO_FrameIndex op...
bool enableShrinkWrapping(const MachineFunction &MF) const override
Returns true if the target will correctly handle shrink wrapping.
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a prologue for the target.
bool enableStackSlotScavenging(const MachineFunction &MF) const override
Returns true if the stack slot holes in the fixed and callee-save stack area should be used when allo...
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
bool enableFullCFIFixup(const MachineFunction &MF) const override
enableFullCFIFixup - Returns true if we may need to fix the unwind information such that it is accura...
StackOffset getFrameIndexReferenceFromSP(const MachineFunction &MF, int FI) const override
getFrameIndexReferenceFromSP - This method returns the offset from the stack pointer to the slot of t...
bool enableCFIFixup(const MachineFunction &MF) const override
Returns true if we may need to fix the unwind information for the function.
StackOffset getNonLocalFrameIndexReference(const MachineFunction &MF, int FI) const override
getNonLocalFrameIndexReference - This method returns the offset used to reference a frame index locat...
TargetStackID::Value getStackIDForScalableVectors() const override
Returns the StackID that scalable vectors should be associated with.
bool hasFPImpl(const MachineFunction &MF) const override
hasFPImpl - Return true if the specified function should have a dedicated frame pointer register.
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
void resetCFIToInitialState(MachineBasicBlock &MBB) const override
Emit CFI instructions that recreate the state of the unwind information upon function entry.
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
bool hasSVECalleeSavesAboveFrameRecord(const MachineFunction &MF) const
StackOffset resolveFrameOffsetReference(const MachineFunction &MF, int64_t ObjectOffset, bool isFixed, TargetStackID::Value StackID, Register &FrameReg, bool PreferFP, bool ForSimm) const
bool canUseRedZone(const MachineFunction &MF) const
Can this function use the red zone for local allocations.
bool isSupportedStackID(TargetStackID::Value ID) const override
bool isFPReserved(const MachineFunction &MF) const
Should the Frame Pointer be reserved for the current function?
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
int getSEHFrameIndexOffset(const MachineFunction &MF, int FI) const
unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const
Funclets only need to account for space for the callee saved registers, as the locals are accounted f...
void orderFrameObjects(const MachineFunction &MF, SmallVectorImpl< int > &ObjectsToAllocate) const override
Order the symbols in the local stack frame.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
StackOffset getPPRStackSize(const MachineFunction &MF) const
Returns the size of the entire PPR stackframe (calleesaves + spills + hazard padding).
int64_t getArgumentStackToRestore(MachineFunction &MF, MachineBasicBlock &MBB) const
Returns how much of the incoming argument stack area (in bytes) we should clean up in an epilogue.
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - Provide a base+offset reference to an FI slot for debug info.
bool authenticatesReturnAddressEarly(MachineFunction &MF, MachineBasicBlock &MBB) const
Whether the return address is authenticated before the epilogue starts, in the return block MBB,...
bool enableWindowsCFIShrinkWrapping(const MachineFunction &MF) const override
Returns true if Windows CFI shrink wrapping should be enabled by default.
StackOffset getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI, Register &FrameReg, bool IgnoreSPUpdates) const override
For Win64 AArch64 EH, the offset to the Unwind object is from the SP before the update.
bool isStackIdSafeForLocalArea(unsigned StackId) const override
This method returns whether or not it is safe for an object with the given stack id to be bundled int...
StackOffset resolveFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg, bool PreferFP, bool ForSimm) const
unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override
The parent frame offset (aka dispFrame) is only used on X86_64 to retrieve the parent's frame pointer...
bool requiresSaveVG(const MachineFunction &MF) const
void emitPacRetPlusLeafHardening(MachineFunction &MF) const
Harden the entire function with pac-ret.
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
A helper class for emitting the prologue.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
MachineInstrBundleIterator< MachineInstr > iterator
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:294
Wrapper class representing virtual and physical registers.
Definition Register.h:20
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:31
TargetFrameLowering(StackDirection D, Align StackAl, int LAO, Align TransAl=Align(1), bool StackReal=true)
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This is an optimization pass for GlobalISel generic memory operations.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39