xref: /freebsd/contrib/llvm-project/llvm/lib/Target/AArch64/AArch64FrameLowering.h (revision d56accc7c3dcc897489b6a07834763a03b9f3d68)
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 "llvm/Support/TypeSize.h"
17 #include "llvm/CodeGen/TargetFrameLowering.h"
18 
19 namespace llvm {
20 
21 class MCCFIInstruction;
22 
23 class AArch64FrameLowering : public TargetFrameLowering {
24 public:
25   explicit AArch64FrameLowering()
26       : TargetFrameLowering(StackGrowsDown, Align(16), 0, Align(16),
27                             true /*StackRealignable*/) {}
28 
29   void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB,
30                                  MachineBasicBlock::iterator MBBI) const;
31 
32   MachineBasicBlock::iterator
33   eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
34                                 MachineBasicBlock::iterator I) const override;
35 
36   /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
37   /// the function.
38   void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
39   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
40 
41   bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
42 
43   StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
44                                      Register &FrameReg) const override;
45   StackOffset resolveFrameIndexReference(const MachineFunction &MF, int FI,
46                                          Register &FrameReg, bool PreferFP,
47                                          bool ForSimm) const;
48   StackOffset resolveFrameOffsetReference(const MachineFunction &MF,
49                                           int64_t ObjectOffset, bool isFixed,
50                                           bool isSVE, Register &FrameReg,
51                                           bool PreferFP, bool ForSimm) const;
52   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
53                                  MachineBasicBlock::iterator MI,
54                                  ArrayRef<CalleeSavedInfo> CSI,
55                                  const TargetRegisterInfo *TRI) const override;
56 
57   bool
58   restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
59                               MachineBasicBlock::iterator MI,
60                               MutableArrayRef<CalleeSavedInfo> CSI,
61                               const TargetRegisterInfo *TRI) const override;
62 
63   /// Can this function use the red zone for local allocations.
64   bool canUseRedZone(const MachineFunction &MF) const;
65 
66   bool hasFP(const MachineFunction &MF) const override;
67   bool hasReservedCallFrame(const MachineFunction &MF) const override;
68 
69   bool assignCalleeSavedSpillSlots(MachineFunction &MF,
70                                    const TargetRegisterInfo *TRI,
71                                    std::vector<CalleeSavedInfo> &CSI,
72                                    unsigned &MinCSFrameIndex,
73                                    unsigned &MaxCSFrameIndex) const override;
74 
75   void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
76                             RegScavenger *RS) const override;
77 
78   /// Returns true if the target will correctly handle shrink wrapping.
79   bool enableShrinkWrapping(const MachineFunction &MF) const override {
80     return true;
81   }
82 
83   bool enableStackSlotScavenging(const MachineFunction &MF) const override;
84   TargetStackID::Value getStackIDForScalableVectors() const override;
85 
86   void processFunctionBeforeFrameFinalized(MachineFunction &MF,
87                                            RegScavenger *RS) const override;
88 
89   void
90   processFunctionBeforeFrameIndicesReplaced(MachineFunction &MF,
91                                             RegScavenger *RS) const override;
92 
93   unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override;
94 
95   unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const;
96 
97   StackOffset
98   getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI,
99                                  Register &FrameReg,
100                                  bool IgnoreSPUpdates) const override;
101   StackOffset getNonLocalFrameIndexReference(const MachineFunction &MF,
102                                              int FI) const override;
103   int getSEHFrameIndexOffset(const MachineFunction &MF, int FI) const;
104 
105   bool isSupportedStackID(TargetStackID::Value ID) const override {
106     switch (ID) {
107     default:
108       return false;
109     case TargetStackID::Default:
110     case TargetStackID::ScalableVector:
111     case TargetStackID::NoAlloc:
112       return true;
113     }
114   }
115 
116   bool isStackIdSafeForLocalArea(unsigned StackId) const override {
117     // We don't support putting SVE objects into the pre-allocated local
118     // frame block at the moment.
119     return StackId != TargetStackID::ScalableVector;
120   }
121 
122   void
123   orderFrameObjects(const MachineFunction &MF,
124                     SmallVectorImpl<int> &ObjectsToAllocate) const override;
125 
126 private:
127   /// Returns true if a homogeneous prolog or epilog code can be emitted
128   /// for the size optimization. If so, HOM_Prolog/HOM_Epilog pseudo
129   /// instructions are emitted in place. When Exit block is given, this check is
130   /// for epilog.
131   bool homogeneousPrologEpilog(MachineFunction &MF,
132                                MachineBasicBlock *Exit = nullptr) const;
133 
134   /// Returns true if CSRs should be paired.
135   bool producePairRegisters(MachineFunction &MF) const;
136 
137   bool shouldCombineCSRLocalStackBump(MachineFunction &MF,
138                                       uint64_t StackBumpBytes) const;
139 
140   int64_t estimateSVEStackObjectOffsets(MachineFrameInfo &MF) const;
141   int64_t assignSVEStackObjectOffsets(MachineFrameInfo &MF,
142                                       int &MinCSFrameIndex,
143                                       int &MaxCSFrameIndex) const;
144   MCCFIInstruction
145   createDefCFAExpressionFromSP(const TargetRegisterInfo &TRI,
146                                const StackOffset &OffsetFromSP) const;
147   MCCFIInstruction createCfaOffset(const TargetRegisterInfo &MRI, unsigned DwarfReg,
148                                    const StackOffset &OffsetFromDefCFA) const;
149   bool shouldCombineCSRLocalStackBumpInEpilogue(MachineBasicBlock &MBB,
150                                                 unsigned StackBumpBytes) const;
151 };
152 
153 } // End llvm namespace
154 
155 #endif
156