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
15namespace llvm {
16
17class ARMSubtarget;
18class CalleeSavedInfo;
19class MachineFunction;
20
21class ARMFrameLowering : public TargetFrameLowering {
22protected:
23 const ARMSubtarget &STI;
24
25public:
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;
45
46 bool enableCalleeSaveSkip(const MachineFunction &MF) const override;
47
48 bool isFPReserved(const MachineFunction &MF) const;
49 bool requiresAAPCSFrameRecord(const MachineFunction &MF) const;
50 bool hasReservedCallFrame(const MachineFunction &MF) const override;
51 bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override;
52 StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
53 Register &FrameReg) const override;
54 StackOffset getNonLocalFrameIndexReference(const MachineFunction &MF,
55 int FI) const override;
56 int ResolveFrameIndexReference(const MachineFunction &MF, int FI,
57 Register &FrameReg, int SPAdj) const;
58
59 void getCalleeSaves(const MachineFunction &MF,
60 BitVector &SavedRegs) const override;
61 void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
62 RegScavenger *RS) const override;
63
64 /// Update the IsRestored flag on LR if it is spilled, based on the return
65 /// instructions.
66 static void updateLRRestored(MachineFunction &MF);
67
68 void processFunctionBeforeFrameFinalized(
69 MachineFunction &MF, RegScavenger *RS = nullptr) const override;
70
71 void adjustForSegmentedStacks(MachineFunction &MF,
72 MachineBasicBlock &MBB) const override;
73
74 /// Returns true if the target will correctly handle shrink wrapping.
75 bool enableShrinkWrapping(const MachineFunction &MF) const override;
76
77 bool isProfitableForNoCSROpt(const Function &F) const override {
78 // The no-CSR optimisation is bad for code size on ARM, because we can save
79 // many registers with a single PUSH/POP pair.
80 return false;
81 }
82
83 bool
84 assignCalleeSavedSpillSlots(MachineFunction &MF,
85 const TargetRegisterInfo *TRI,
86 std::vector<CalleeSavedInfo> &CSI) const override;
87
88 const SpillSlot *
89 getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
90
91protected:
92 bool hasFPImpl(const MachineFunction &MF) const override;
93
94private:
95 void emitPushInst(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
96 ArrayRef<CalleeSavedInfo> CSI, unsigned StmOpc,
97 unsigned StrOpc, bool NoGap,
98 function_ref<bool(unsigned)> Func) const;
99 void emitPopInst(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
100 MutableArrayRef<CalleeSavedInfo> CSI, unsigned LdmOpc,
101 unsigned LdrOpc, bool isVarArg, bool NoGap,
102 function_ref<bool(unsigned)> Func) const;
103
104 void emitFPStatusSaves(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
105 ArrayRef<CalleeSavedInfo> CSI,
106 unsigned PushOneOpc) const;
107
108 void emitFPStatusRestores(MachineBasicBlock &MBB,
109 MachineBasicBlock::iterator MI,
110 MutableArrayRef<CalleeSavedInfo> CSI,
111 unsigned LdrOpc) const;
112
113 MachineBasicBlock::iterator
114 eliminateCallFramePseudoInstr(MachineFunction &MF,
115 MachineBasicBlock &MBB,
116 MachineBasicBlock::iterator MI) const override;
117};
118
119} // end namespace llvm
120
121#endif // LLVM_LIB_TARGET_ARM_ARMFRAMELOWERING_H
122