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 
16 #include "AArch64StackOffset.h"
17 #include "llvm/CodeGen/TargetFrameLowering.h"
18 
19 namespace llvm {
20 
21 class AArch64FrameLowering : public TargetFrameLowering {
22 public:
23   explicit AArch64FrameLowering()
24       : TargetFrameLowering(StackGrowsDown, Align(16), 0, Align(16),
25                             true /*StackRealignable*/) {}
26 
27   void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB,
28                                  MachineBasicBlock::iterator MBBI) const;
29 
30   MachineBasicBlock::iterator
31   eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
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   bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
40 
41   int getFrameIndexReference(const MachineFunction &MF, int FI,
42                              Register &FrameReg) const override;
43   StackOffset resolveFrameIndexReference(const MachineFunction &MF, int FI,
44                                          Register &FrameReg, bool PreferFP,
45                                          bool ForSimm) const;
46   StackOffset resolveFrameOffsetReference(const MachineFunction &MF,
47                                           int64_t ObjectOffset, bool isFixed,
48                                           bool isSVE, Register &FrameReg,
49                                           bool PreferFP, bool ForSimm) const;
50   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
51                                  MachineBasicBlock::iterator MI,
52                                  ArrayRef<CalleeSavedInfo> CSI,
53                                  const TargetRegisterInfo *TRI) const override;
54 
55   bool
56   restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
57                               MachineBasicBlock::iterator MI,
58                               MutableArrayRef<CalleeSavedInfo> CSI,
59                               const TargetRegisterInfo *TRI) const override;
60 
61   /// Can this function use the red zone for local allocations.
62   bool canUseRedZone(const MachineFunction &MF) const;
63 
64   bool hasFP(const MachineFunction &MF) const override;
65   bool hasReservedCallFrame(const MachineFunction &MF) const override;
66 
67   void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
68                             RegScavenger *RS) const override;
69 
70   /// Returns true if the target will correctly handle shrink wrapping.
71   bool enableShrinkWrapping(const MachineFunction &MF) const override {
72     return true;
73   }
74 
75   bool enableStackSlotScavenging(const MachineFunction &MF) const override;
76   TargetStackID::Value getStackIDForScalableVectors() const override;
77 
78   void processFunctionBeforeFrameFinalized(MachineFunction &MF,
79                                              RegScavenger *RS) const override;
80 
81   void
82   processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF,
83                                             RegScavenger *RS) const override;
84 
85   unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override;
86 
87   unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const;
88 
89   int getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI,
90                                      Register &FrameReg,
91                                      bool IgnoreSPUpdates) const override;
92   int getNonLocalFrameIndexReference(const MachineFunction &MF,
93                                int FI) const override;
94   int getSEHFrameIndexOffset(const MachineFunction &MF, int FI) const;
95 
96   bool isSupportedStackID(TargetStackID::Value ID) const override {
97     switch (ID) {
98     default:
99       return false;
100     case TargetStackID::Default:
101     case TargetStackID::SVEVector:
102     case TargetStackID::NoAlloc:
103       return true;
104     }
105   }
106 
107 private:
108   bool shouldCombineCSRLocalStackBump(MachineFunction &MF,
109                                       uint64_t StackBumpBytes) const;
110 
111   int64_t estimateSVEStackObjectOffsets(MachineFrameInfo &MF) const;
112   int64_t assignSVEStackObjectOffsets(MachineFrameInfo &MF,
113                                       int &MinCSFrameIndex,
114                                       int &MaxCSFrameIndex) const;
115   bool shouldCombineCSRLocalStackBumpInEpilogue(MachineBasicBlock &MBB,
116                                                 unsigned StackBumpBytes) const;
117 };
118 
119 } // End llvm namespace
120 
121 #endif
122