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