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