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