LLVM 22.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
23public:
26 true /*StackRealignable*/) {}
27
28 void resetCFIToInitialState(MachineBasicBlock &MBB) const override;
29
32 MachineBasicBlock::iterator I) const override;
33
34 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
35 /// the function.
36 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
37 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
38
39 /// Harden the entire function with pac-ret.
40 ///
41 /// If pac-ret+leaf is requested, we want to harden as much code as possible.
42 /// This function inserts pac-ret hardening at the points where prologue and
43 /// epilogue are traditionally inserted, ignoring possible shrink-wrapping
44 /// optimization.
46
47 bool enableCFIFixup(const MachineFunction &MF) const override;
48
49 bool enableFullCFIFixup(const MachineFunction &MF) const override;
50
51 bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
52
54 Register &FrameReg) const override;
56 int FI) const override;
58 Register &FrameReg, bool PreferFP,
59 bool ForSimm) const;
61 int64_t ObjectOffset, bool isFixed,
62 bool isSVE, Register &FrameReg,
63 bool PreferFP, bool ForSimm) const;
67 const TargetRegisterInfo *TRI) const override;
68
69 bool
73 const TargetRegisterInfo *TRI) const override;
74
75 /// Can this function use the red zone for local allocations.
76 bool canUseRedZone(const MachineFunction &MF) const;
77
78 bool hasReservedCallFrame(const MachineFunction &MF) const override;
79
82 std::vector<CalleeSavedInfo> &CSI,
83 unsigned &MinCSFrameIndex,
84 unsigned &MaxCSFrameIndex) const override;
85
87 RegScavenger *RS) const override;
88
89 /// Returns true if the target will correctly handle shrink wrapping.
90 bool enableShrinkWrapping(const MachineFunction &MF) const override {
91 return true;
92 }
93
94 bool enableStackSlotScavenging(const MachineFunction &MF) const override;
96
98 RegScavenger *RS) const override;
99
100 void
102 RegScavenger *RS) const override;
103
104 unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override;
105
106 unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const;
107
110 Register &FrameReg,
111 bool IgnoreSPUpdates) const override;
113 int FI) const override;
114 int getSEHFrameIndexOffset(const MachineFunction &MF, int FI) const;
115
117 switch (ID) {
118 default:
119 return false;
123 return true;
124 }
125 }
126
127 bool isStackIdSafeForLocalArea(unsigned StackId) const override {
128 // We don't support putting SVE objects into the pre-allocated local
129 // frame block at the moment.
130 return StackId != TargetStackID::ScalableVector;
131 }
132
133 void
135 SmallVectorImpl<int> &ObjectsToAllocate) const override;
136
137 bool isFPReserved(const MachineFunction &MF) const;
138
139protected:
140 bool hasFPImpl(const MachineFunction &MF) const override;
141
142private:
143 /// Returns true if a homogeneous prolog or epilog code can be emitted
144 /// for the size optimization. If so, HOM_Prolog/HOM_Epilog pseudo
145 /// instructions are emitted in place. When Exit block is given, this check is
146 /// for epilog.
147 bool homogeneousPrologEpilog(MachineFunction &MF,
148 MachineBasicBlock *Exit = nullptr) const;
149
150 /// Returns true if CSRs should be paired.
151 bool producePairRegisters(MachineFunction &MF) const;
152
153 bool shouldCombineCSRLocalStackBump(MachineFunction &MF,
154 uint64_t StackBumpBytes) const;
155
156 int64_t estimateSVEStackObjectOffsets(MachineFrameInfo &MF) const;
157 int64_t assignSVEStackObjectOffsets(MachineFrameInfo &MF,
158 int &MinCSFrameIndex,
159 int &MaxCSFrameIndex) const;
160 bool shouldCombineCSRLocalStackBumpInEpilogue(MachineBasicBlock &MBB,
161 uint64_t StackBumpBytes) const;
162 void emitCalleeSavedGPRLocations(MachineBasicBlock &MBB,
164 void emitCalleeSavedSVELocations(MachineBasicBlock &MBB,
166 void emitCalleeSavedGPRRestores(MachineBasicBlock &MBB,
168 void emitCalleeSavedSVERestores(MachineBasicBlock &MBB,
170 void allocateStackSpace(MachineBasicBlock &MBB,
172 int64_t RealignmentPadding, StackOffset AllocSize,
173 bool NeedsWinCFI, bool *HasWinCFI, bool EmitCFI,
174 StackOffset InitialOffset, bool FollowupAllocs) const;
175 /// Make a determination whether a Hazard slot is used and create it if
176 /// needed.
177 void determineStackHazardSlot(MachineFunction &MF,
178 BitVector &SavedRegs) const;
179
180 /// Emit target zero call-used regs.
181 void emitZeroCallUsedRegs(BitVector RegsToZero,
182 MachineBasicBlock &MBB) const override;
183
184 /// Replace a StackProbe stub (if any) with the actual probe code inline
185 void inlineStackProbe(MachineFunction &MF,
186 MachineBasicBlock &PrologueMBB) const override;
187
188 void inlineStackProbeFixed(MachineBasicBlock::iterator MBBI,
189 Register ScratchReg, int64_t FrameSize,
190 StackOffset CFAOffset) const;
191
193 inlineStackProbeLoopExactMultiple(MachineBasicBlock::iterator MBBI,
194 int64_t NegProbeSize,
195 Register TargetReg) const;
196
197 void emitRemarks(const MachineFunction &MF,
198 MachineOptimizationRemarkEmitter *ORE) const override;
199};
200
201} // End llvm namespace
202
203#endif
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator MBBI
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition: MD5.cpp:58
===- MachineOptimizationRemarkEmitter.h - Opt Diagnostics -*- C++ -*-—===//
Register const TargetRegisterInfo * TRI
void processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameIndicesReplaced - This method is called immediately before MO_FrameIndex op...
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 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 enableShrinkWrapping(const MachineFunction &MF) const override
Returns true if the target will correctly handle shrink wrapping.
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
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.
StackOffset resolveFrameOffsetReference(const MachineFunction &MF, int64_t ObjectOffset, bool isFixed, bool isSVE, Register &FrameReg, bool PreferFP, bool ForSimm) const
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI, unsigned &MinCSFrameIndex, unsigned &MaxCSFrameIndex) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
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...
void emitPacRetPlusLeafHardening(MachineFunction &MF) const
Harden the entire function with pac-ret.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:303
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
StackOffset holds a fixed and a scalable offset in bytes.
Definition: TypeSize.h:34
Information about stack frame layout on the target.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39