xref: /freebsd/contrib/llvm-project/llvm/lib/Target/ARM/ARMFrameLowering.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 //===- ARMTargetFrameLowering.h - Define frame lowering for ARM -*- 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 #ifndef LLVM_LIB_TARGET_ARM_ARMFRAMELOWERING_H
10 #define LLVM_LIB_TARGET_ARM_ARMFRAMELOWERING_H
11 
12 #include "llvm/CodeGen/TargetFrameLowering.h"
13 #include "llvm/Support/TypeSize.h"
14 
15 namespace llvm {
16 
17 class ARMSubtarget;
18 class CalleeSavedInfo;
19 class MachineFunction;
20 
21 class ARMFrameLowering : public TargetFrameLowering {
22 protected:
23   const ARMSubtarget &STI;
24 
25 public:
26   explicit ARMFrameLowering(const ARMSubtarget &sti);
27 
28   /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
29   /// the function.
30   void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
31   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
32 
33   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
34                                  MachineBasicBlock::iterator MI,
35                                  ArrayRef<CalleeSavedInfo> CSI,
36                                  const TargetRegisterInfo *TRI) const override;
37 
38   bool
39   restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
40                               MachineBasicBlock::iterator MI,
41                               MutableArrayRef<CalleeSavedInfo> CSI,
42                               const TargetRegisterInfo *TRI) const override;
43 
44   bool keepFramePointer(const MachineFunction &MF) const override;
45 
46   bool enableCalleeSaveSkip(const MachineFunction &MF) const override;
47 
48   bool hasFP(const MachineFunction &MF) const override;
49   bool isFPReserved(const MachineFunction &MF) const;
50   bool requiresAAPCSFrameRecord(const MachineFunction &MF) const;
51   bool hasReservedCallFrame(const MachineFunction &MF) const override;
52   bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override;
53   StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
54                                      Register &FrameReg) const override;
55   int ResolveFrameIndexReference(const MachineFunction &MF, int FI,
56                                  Register &FrameReg, int SPAdj) const;
57 
58   void getCalleeSaves(const MachineFunction &MF,
59                       BitVector &SavedRegs) const override;
60   void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
61                             RegScavenger *RS) const override;
62 
63   /// Update the IsRestored flag on LR if it is spilled, based on the return
64   /// instructions.
65   static void updateLRRestored(MachineFunction &MF);
66 
67   void processFunctionBeforeFrameFinalized(
68       MachineFunction &MF, RegScavenger *RS = nullptr) const override;
69 
70   void adjustForSegmentedStacks(MachineFunction &MF,
71                                 MachineBasicBlock &MBB) const override;
72 
73   /// Returns true if the target will correctly handle shrink wrapping.
74   bool enableShrinkWrapping(const MachineFunction &MF) const override;
75 
isProfitableForNoCSROpt(const Function & F)76   bool isProfitableForNoCSROpt(const Function &F) const override {
77     // The no-CSR optimisation is bad for code size on ARM, because we can save
78     // many registers with a single PUSH/POP pair.
79     return false;
80   }
81 
82   bool
83   assignCalleeSavedSpillSlots(MachineFunction &MF,
84                               const TargetRegisterInfo *TRI,
85                               std::vector<CalleeSavedInfo> &CSI) const override;
86 
87   const SpillSlot *
88   getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
89 
90 private:
91   void emitPushInst(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
92                     ArrayRef<CalleeSavedInfo> CSI, unsigned StmOpc,
93                     unsigned StrOpc, bool NoGap, bool (*Func)(unsigned, bool),
94                     unsigned NumAlignedDPRCS2Regs, unsigned MIFlags = 0) const;
95   void emitPopInst(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
96                    MutableArrayRef<CalleeSavedInfo> CSI, unsigned LdmOpc,
97                    unsigned LdrOpc, bool isVarArg, bool NoGap,
98                    bool (*Func)(unsigned, bool),
99                    unsigned NumAlignedDPRCS2Regs) const;
100 
101   MachineBasicBlock::iterator
102   eliminateCallFramePseudoInstr(MachineFunction &MF,
103                                 MachineBasicBlock &MBB,
104                                 MachineBasicBlock::iterator MI) const override;
105 };
106 
107 } // end namespace llvm
108 
109 #endif // LLVM_LIB_TARGET_ARM_ARMFRAMELOWERING_H
110