LLVM 22.0.0git
AArch64PrologueEpilogue.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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/// \file
10/// This file contains the declaration of the AArch64PrologueEmitter and
11/// AArch64EpilogueEmitter classes, which are is used to emit the prologue and
12/// epilogue on AArch64.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64PROLOGUEEPILOGUE_H
17#define LLVM_LIB_TARGET_AARCH64_AARCH64PROLOGUEEPILOGUE_H
18
19#include "AArch64RegisterInfo.h"
22
23namespace llvm {
24
29class TargetLowering;
30
36
41
43public:
46
52
53protected:
54 bool requiresGetVGCall() const;
55
57 const TargetLowering &TLI) const;
58
59 // Convert callee-save register save/restore instruction to do stack pointer
60 // decrement/increment to allocate/deallocate the callee-save stack area by
61 // converting store/load to use pre/post increment version.
63 MachineBasicBlock::iterator MBBI, const DebugLoc &DL, int CSStackSizeInc,
65 int CFAOffset = 0) const;
66
67 // Fixup callee-save register save/restore instructions to take into account
68 // combined SP bump by adding the local stack size to the stack offsets.
70 uint64_t LocalStackSize) const;
71
72 bool shouldCombineCSRLocalStackBump(uint64_t StackBumpBytes) const;
73
76
79
84
85 // Common flags. These generally should not change outside of the (possibly
86 // derived) constructor.
87 bool HasFP = false;
88 bool EmitCFI = false; // Note: Set in derived constructors.
89 bool IsFunclet = false; // Note: Set in derived constructors.
90 bool NeedsWinCFI = false; // Note: Can be changed in emitFramePointerSetup.
91 bool HomPrologEpilog = false; // Note: Set in derived constructors.
93
94 // Note: "HasWinCFI" is mutable as it can change in any "emit" function.
95 mutable bool HasWinCFI = false;
96
97 const AArch64InstrInfo *TII = nullptr;
99};
100
101/// A helper class for emitting the prologue. Substantial new functionality
102/// should be factored into a new method. Where possible "emit*" methods should
103/// be const, and any flags that change how the prologue is emitted should be
104/// set in the constructor.
106public:
109
110 /// Emit the prologue.
111 void emitPrologue();
112
114 MF.setHasWinCFI(HasWinCFI);
115#ifndef NDEBUG
116 verifyPrologueClobbers();
117#endif
118 }
119
120private:
121 void allocateStackSpace(MachineBasicBlock::iterator MBBI,
122 int64_t RealignmentPadding, StackOffset AllocSize,
123 bool EmitCFI, StackOffset InitialOffset,
124 bool FollowupAllocs);
125
126 void emitShadowCallStackPrologue(MachineBasicBlock::iterator MBBI,
127 const DebugLoc &DL) const;
128
129 void emitSwiftAsyncContextFramePointer(MachineBasicBlock::iterator MBBI,
130 const DebugLoc &DL) const;
131
132 void emitEmptyStackFramePrologue(int64_t NumBytes,
134 const DebugLoc &DL) const;
135
136 void emitFramePointerSetup(MachineBasicBlock::iterator MBBI,
137 const DebugLoc &DL, unsigned FixedObject);
138
139 void emitDefineCFAWithFP(MachineBasicBlock::iterator MBBI,
140 unsigned FixedObject) const;
141
142 void emitWindowsStackProbe(MachineBasicBlock::iterator MBBI,
143 const DebugLoc &DL, int64_t &NumBytes,
144 int64_t RealignmentPadding) const;
145
146 void emitCalleeSavedGPRLocations(MachineBasicBlock::iterator MBBI) const;
147 void emitCalleeSavedSVELocations(MachineBasicBlock::iterator MBBI) const;
148
149 void determineLocalsStackSize(uint64_t StackSize, uint64_t PrologueSaveSize);
150
151 const Function &F;
152
153#ifndef NDEBUG
155 MachineBasicBlock::iterator PrologueEndI;
156
157 void collectBlockLiveins();
158 void verifyPrologueClobbers() const;
159#endif
160
161 // Prologue flags. These generally should not change outside of the
162 // constructor.
163 bool EmitAsyncCFI = false;
164 bool CombineSPBump = false; // Note: This is set in determineLocalsStackSize.
165};
166
167/// A helper class for emitting the epilogue. Substantial new functionality
168/// should be factored into a new method. Where possible "emit*" methods should
169/// be const, and any flags that change how the epilogue is emitted should be
170/// set in the constructor.
172public:
175
176 /// Emit the epilogue.
177 void emitEpilogue();
178
179 ~AArch64EpilogueEmitter() { finalizeEpilogue(); }
180
181private:
182 bool shouldCombineCSRLocalStackBump(uint64_t StackBumpBytes) const;
183
184 /// A helper for moving the SP to a negative offset from the FP, without
185 /// deallocating any stack in the range FP to FP + Offset.
187
188 void emitSwiftAsyncContextFramePointer(MachineBasicBlock::iterator MBBI,
189 const DebugLoc &DL) const;
190
191 void emitShadowCallStackEpilogue(MachineBasicBlock::iterator MBBI,
192 const DebugLoc &DL) const;
193
194 void emitCalleeSavedRestores(MachineBasicBlock::iterator MBBI,
195 bool SVE) const;
196
197 void emitCalleeSavedGPRRestores(MachineBasicBlock::iterator MBBI) const {
198 emitCalleeSavedRestores(MBBI, /*SVE=*/false);
199 }
200
201 void emitCalleeSavedSVERestores(MachineBasicBlock::iterator MBBI) const {
202 emitCalleeSavedRestores(MBBI, /*SVE=*/true);
203 }
204
205 void finalizeEpilogue() const;
206
207 MachineBasicBlock::iterator SEHEpilogueStartI;
208 DebugLoc DL;
209};
210
211} // namespace llvm
212
213#endif
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
IRTranslator LLVM IR MI
This file implements the LivePhysRegs utility for tracking liveness of physical registers.
#define F(x, y, z)
Definition MD5.cpp:54
AArch64EpilogueEmitter(MachineFunction &MF, MachineBasicBlock &MBB, const AArch64FrameLowering &AFL)
AArch64FunctionInfo - This class is derived from MachineFunctionInfo and contains private AArch64-spe...
AArch64PrologueEmitter(MachineFunction &MF, MachineBasicBlock &MBB, const AArch64FrameLowering &AFL)
MachineBasicBlock::iterator convertCalleeSaveRestoreToSPPrePostIncDec(MachineBasicBlock::iterator MBBI, const DebugLoc &DL, int CSStackSizeInc, bool EmitCFI, MachineInstr::MIFlag FrameFlag=MachineInstr::FrameSetup, int CFAOffset=0) const
bool isVGInstruction(MachineBasicBlock::iterator MBBI, const TargetLowering &TLI) const
AArch64PrologueEpilogueCommon(MachineFunction &MF, MachineBasicBlock &MBB, const AArch64FrameLowering &AFL)
void fixupCalleeSaveRestoreStackOffset(MachineInstr &MI, uint64_t LocalStackSize) const
bool shouldCombineCSRLocalStackBump(uint64_t StackBumpBytes) const
SVEStackAllocations getSVEStackAllocations(SVEFrameSizes const &)
A debug info location.
Definition DebugLoc.h:123
A set of physical registers with utility functions to track liveness when walking backward/forward th...
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Representation of each machine instruction.
StackOffset holds a fixed and a scalable offset in bytes.
Definition TypeSize.h:30
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:532
struct llvm::SVEFrameSizes::@005032024062370221152241042070022264014337265150 PPR
struct llvm::SVEFrameSizes::@005032024062370221152241042070022264014337265150 ZPR