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