xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AArch64/AArch64FrameLowering.h (revision 8bcb0991864975618c09697b1aca10683346d9f0)
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                              unsigned &FrameReg) const override;
43   StackOffset resolveFrameIndexReference(const MachineFunction &MF, int FI,
44                                          unsigned &FrameReg, bool PreferFP,
45                                          bool ForSimm) const;
46   StackOffset resolveFrameOffsetReference(const MachineFunction &MF,
47                                           int ObjectOffset, bool isFixed,
48                                           bool isSVE, unsigned &FrameReg,
49                                           bool PreferFP, bool ForSimm) const;
50   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
51                                  MachineBasicBlock::iterator MI,
52                                  const std::vector<CalleeSavedInfo> &CSI,
53                                  const TargetRegisterInfo *TRI) const override;
54 
55   bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
56                                   MachineBasicBlock::iterator MI,
57                                   std::vector<CalleeSavedInfo> &CSI,
58                                   const TargetRegisterInfo *TRI) const override;
59 
60   /// Can this function use the red zone for local allocations.
61   bool canUseRedZone(const MachineFunction &MF) const;
62 
63   bool hasFP(const MachineFunction &MF) const override;
64   bool hasReservedCallFrame(const MachineFunction &MF) const override;
65 
66   void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
67                             RegScavenger *RS) const override;
68 
69   /// Returns true if the target will correctly handle shrink wrapping.
70   bool enableShrinkWrapping(const MachineFunction &MF) const override {
71     return true;
72   }
73 
74   bool enableStackSlotScavenging(const MachineFunction &MF) const override;
75 
76   void processFunctionBeforeFrameFinalized(MachineFunction &MF,
77                                              RegScavenger *RS) const override;
78 
79   unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override;
80 
81   unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const;
82 
83   int getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI,
84                                      unsigned &FrameReg,
85                                      bool IgnoreSPUpdates) const override;
86   int getNonLocalFrameIndexReference(const MachineFunction &MF,
87                                int FI) const override;
88   int getSEHFrameIndexOffset(const MachineFunction &MF, int FI) const;
89 
90   bool isSupportedStackID(TargetStackID::Value ID) const override {
91     switch (ID) {
92     default:
93       return false;
94     case TargetStackID::Default:
95     case TargetStackID::SVEVector:
96     case TargetStackID::NoAlloc:
97       return true;
98     }
99   }
100 
101 private:
102   bool shouldCombineCSRLocalStackBump(MachineFunction &MF,
103                                       unsigned StackBumpBytes) const;
104   int64_t determineSVEStackSize(MachineFrameInfo &MF, unsigned &MaxAlign) const;
105 };
106 
107 } // End llvm namespace
108 
109 #endif
110