xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AArch64/AArch64FrameLowering.h (revision 5c25fe9464cd01388704412b96df78a0e5fa8f74)
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
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.
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 
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   bool isStackIdSafeForLocalArea(unsigned StackId) const override {
109     // We don't support putting SVE objects into the pre-allocated local
110     // frame block at the moment.
111     return StackId != TargetStackID::SVEVector;
112   }
113 
114 private:
115   bool shouldCombineCSRLocalStackBump(MachineFunction &MF,
116                                       uint64_t StackBumpBytes) const;
117 
118   int64_t estimateSVEStackObjectOffsets(MachineFrameInfo &MF) const;
119   int64_t assignSVEStackObjectOffsets(MachineFrameInfo &MF,
120                                       int &MinCSFrameIndex,
121                                       int &MaxCSFrameIndex) const;
122   bool shouldCombineCSRLocalStackBumpInEpilogue(MachineBasicBlock &MBB,
123                                                 unsigned StackBumpBytes) const;
124 };
125 
126 } // End llvm namespace
127 
128 #endif
129