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
25class TargetLowering;
29
35
40
42public:
45
51
52protected:
53 bool requiresGetVGCall() const;
54
56 const TargetLowering &TLI) const;
57
58 // Convert callee-save register save/restore instruction to do stack pointer
59 // decrement/increment to allocate/deallocate the callee-save stack area by
60 // converting store/load to use pre/post increment version.
62 MachineBasicBlock::iterator MBBI, const DebugLoc &DL, int CSStackSizeInc,
64 int CFAOffset = 0) const;
65
66 // Fixup callee-save register save/restore instructions to take into account
67 // combined SP bump by adding the local stack size to the stack offsets.
69 uint64_t LocalStackSize) const;
70
71 bool shouldCombineCSRLocalStackBump(uint64_t StackBumpBytes) const;
72
75
78
83
84 // Common flags. These generally should not change outside of the (possibly
85 // derived) constructor.
86 bool HasFP = false;
87 bool EmitCFI = false; // Note: Set in derived constructors.
88 bool IsFunclet = false; // Note: Set in derived constructors.
89 bool NeedsWinCFI = false; // Note: Can be changed in emitFramePointerSetup.
90 bool HomPrologEpilog = false; // Note: Set in derived constructors.
92
93 // Note: "HasWinCFI" is mutable as it can change in any "emit" function.
94 mutable bool HasWinCFI = false;
95
96 const TargetInstrInfo *TII = nullptr;
98};
99
100/// A helper class for emitting the prologue. Substantial new functionality
101/// should be factored into a new method. Where possible "emit*" methods should
102/// be const, and any flags that change how the prologue is emitted should be
103/// set in the constructor.
105public:
108
109 /// Emit the prologue.
110 void emitPrologue();
111
113 MF.setHasWinCFI(HasWinCFI);
114#ifndef NDEBUG
115 verifyPrologueClobbers();
116#endif
117 }
118
119private:
120 void allocateStackSpace(MachineBasicBlock::iterator MBBI,
121 int64_t RealignmentPadding, StackOffset AllocSize,
122 bool EmitCFI, StackOffset InitialOffset,
123 bool FollowupAllocs);
124
125 void emitShadowCallStackPrologue(MachineBasicBlock::iterator MBBI,
126 const DebugLoc &DL) const;
127
128 void emitSwiftAsyncContextFramePointer(MachineBasicBlock::iterator MBBI,
129 const DebugLoc &DL) const;
130
131 void emitEmptyStackFramePrologue(int64_t NumBytes,
133 const DebugLoc &DL) const;
134
135 void emitFramePointerSetup(MachineBasicBlock::iterator MBBI,
136 const DebugLoc &DL, unsigned FixedObject);
137
138 void emitDefineCFAWithFP(MachineBasicBlock::iterator MBBI,
139 unsigned FixedObject) const;
140
141 void emitWindowsStackProbe(MachineBasicBlock::iterator MBBI,
142 const DebugLoc &DL, int64_t &NumBytes,
143 int64_t RealignmentPadding) const;
144
145 void emitCalleeSavedGPRLocations(MachineBasicBlock::iterator MBBI) const;
146 void emitCalleeSavedSVELocations(MachineBasicBlock::iterator MBBI) const;
147
148 void determineLocalsStackSize(uint64_t StackSize, uint64_t PrologueSaveSize);
149
150 const Function &F;
151
152#ifndef NDEBUG
154 MachineBasicBlock::iterator PrologueEndI;
155
156 void collectBlockLiveins();
157 void verifyPrologueClobbers() const;
158#endif
159
160 // Prologue flags. These generally should not change outside of the
161 // constructor.
162 bool EmitAsyncCFI = false;
163 bool CombineSPBump = false; // Note: This is set in determineLocalsStackSize.
164};
165
166/// A helper class for emitting the epilogue. Substantial new functionality
167/// should be factored into a new method. Where possible "emit*" methods should
168/// be const, and any flags that change how the epilogue is emitted should be
169/// set in the constructor.
171public:
174
175 /// Emit the epilogue.
176 void emitEpilogue();
177
178 ~AArch64EpilogueEmitter() { finalizeEpilogue(); }
179
180private:
181 bool shouldCombineCSRLocalStackBump(uint64_t StackBumpBytes) const;
182
183 void emitSwiftAsyncContextFramePointer(MachineBasicBlock::iterator MBBI,
184 const DebugLoc &DL) const;
185
186 void emitShadowCallStackEpilogue(MachineBasicBlock::iterator MBBI,
187 const DebugLoc &DL) const;
188
189 void emitCalleeSavedRestores(MachineBasicBlock::iterator MBBI,
190 bool SVE) const;
191
192 void emitCalleeSavedGPRRestores(MachineBasicBlock::iterator MBBI) const {
193 emitCalleeSavedRestores(MBBI, /*SVE=*/false);
194 }
195
196 void emitCalleeSavedSVERestores(MachineBasicBlock::iterator MBBI) const {
197 emitCalleeSavedRestores(MBBI, /*SVE=*/true);
198 }
199
200 void finalizeEpilogue() const;
201
202 MachineBasicBlock::iterator SEHEpilogueStartI;
203 DebugLoc DL;
204};
205
206} // namespace llvm
207
208#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:55
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:124
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:31
TargetInstrInfo - Interface to description of machine instruction set.
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.
struct llvm::SVEFrameSizes::@005032024062370221152241042070022264014337265150 PPR
struct llvm::SVEFrameSizes::@005032024062370221152241042070022264014337265150 ZPR