Thanks to visit codestin.com
Credit goes to llvm.org

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