1 //==-- AArch64FrameLowering.h - TargetFrameLowering for AArch64 --*- C++ -*-==//
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
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_AARCH64_AARCH64FRAMELOWERING_H
14 #define LLVM_LIB_TARGET_AARCH64_AARCH64FRAMELOWERING_H
16 #include "AArch64StackOffset.h"
17 #include "llvm/CodeGen/TargetFrameLowering.h"
21 class MCCFIInstruction;
23 class AArch64FrameLowering : public TargetFrameLowering {
25 explicit AArch64FrameLowering()
26 : TargetFrameLowering(StackGrowsDown, Align(16), 0, Align(16),
27 true /*StackRealignable*/) {}
30 emitCalleeSavedFrameMoves(MachineBasicBlock &MBB,
31 MachineBasicBlock::iterator MBBI) const override;
33 MachineBasicBlock::iterator
34 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
35 MachineBasicBlock::iterator I) const override;
37 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
39 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
40 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
42 bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
44 int getFrameIndexReference(const MachineFunction &MF, int FI,
45 Register &FrameReg) const override;
46 StackOffset resolveFrameIndexReference(const MachineFunction &MF, int FI,
47 Register &FrameReg, bool PreferFP,
49 StackOffset resolveFrameOffsetReference(const MachineFunction &MF,
50 int64_t ObjectOffset, bool isFixed,
51 bool isSVE, Register &FrameReg,
52 bool PreferFP, bool ForSimm) const;
53 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
54 MachineBasicBlock::iterator MI,
55 ArrayRef<CalleeSavedInfo> CSI,
56 const TargetRegisterInfo *TRI) const override;
59 restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
60 MachineBasicBlock::iterator MI,
61 MutableArrayRef<CalleeSavedInfo> CSI,
62 const TargetRegisterInfo *TRI) const override;
64 /// Can this function use the red zone for local allocations.
65 bool canUseRedZone(const MachineFunction &MF) const;
67 bool hasFP(const MachineFunction &MF) const override;
68 bool hasReservedCallFrame(const MachineFunction &MF) const override;
70 void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
71 RegScavenger *RS) const override;
73 /// Returns true if the target will correctly handle shrink wrapping.
74 bool enableShrinkWrapping(const MachineFunction &MF) const override {
78 bool enableStackSlotScavenging(const MachineFunction &MF) const override;
79 TargetStackID::Value getStackIDForScalableVectors() const override;
81 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
82 RegScavenger *RS) const override;
85 processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF,
86 RegScavenger *RS) const override;
88 unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override;
90 unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const;
92 int getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI,
94 bool IgnoreSPUpdates) const override;
95 int getNonLocalFrameIndexReference(const MachineFunction &MF,
96 int FI) const override;
97 int getSEHFrameIndexOffset(const MachineFunction &MF, int FI) const;
99 bool isSupportedStackID(TargetStackID::Value ID) const override {
103 case TargetStackID::Default:
104 case TargetStackID::SVEVector:
105 case TargetStackID::NoAlloc:
110 bool isStackIdSafeForLocalArea(unsigned StackId) const override {
111 // We don't support putting SVE objects into the pre-allocated local
112 // frame block at the moment.
113 return StackId != TargetStackID::SVEVector;
117 bool shouldCombineCSRLocalStackBump(MachineFunction &MF,
118 uint64_t StackBumpBytes) const;
120 int64_t estimateSVEStackObjectOffsets(MachineFrameInfo &MF) const;
121 int64_t assignSVEStackObjectOffsets(MachineFrameInfo &MF,
122 int &MinCSFrameIndex,
123 int &MaxCSFrameIndex) const;
125 createDefCFAExpressionFromSP(const TargetRegisterInfo &TRI,
126 const StackOffset &OffsetFromSP) const;
127 MCCFIInstruction createCfaOffset(const TargetRegisterInfo &MRI, unsigned DwarfReg,
128 const StackOffset &OffsetFromDefCFA) const;
129 bool shouldCombineCSRLocalStackBumpInEpilogue(MachineBasicBlock &MBB,
130 unsigned StackBumpBytes) const;
133 } // End llvm namespace