1 //===- ARMTargetFrameLowering.h - Define frame lowering for ARM -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_TARGET_ARM_ARMFRAMELOWERING_H
10 #define LLVM_LIB_TARGET_ARM_ARMFRAMELOWERING_H
12 #include "llvm/CodeGen/TargetFrameLowering.h"
13 #include "llvm/Support/TypeSize.h"
18 class CalleeSavedInfo
;
19 class MachineFunction
;
21 class ARMFrameLowering
: public TargetFrameLowering
{
23 const ARMSubtarget
&STI
;
26 explicit ARMFrameLowering(const ARMSubtarget
&sti
);
28 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
30 void emitPrologue(MachineFunction
&MF
, MachineBasicBlock
&MBB
) const override
;
31 void emitEpilogue(MachineFunction
&MF
, MachineBasicBlock
&MBB
) const override
;
33 bool spillCalleeSavedRegisters(MachineBasicBlock
&MBB
,
34 MachineBasicBlock::iterator MI
,
35 ArrayRef
<CalleeSavedInfo
> CSI
,
36 const TargetRegisterInfo
*TRI
) const override
;
39 restoreCalleeSavedRegisters(MachineBasicBlock
&MBB
,
40 MachineBasicBlock::iterator MI
,
41 MutableArrayRef
<CalleeSavedInfo
> CSI
,
42 const TargetRegisterInfo
*TRI
) const override
;
44 bool keepFramePointer(const MachineFunction
&MF
) const;
46 bool enableCalleeSaveSkip(const MachineFunction
&MF
) const override
;
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 int ResolveFrameIndexReference(const MachineFunction
&MF
, int FI
,
55 Register
&FrameReg
, int SPAdj
) const;
57 void getCalleeSaves(const MachineFunction
&MF
,
58 BitVector
&SavedRegs
) const override
;
59 void determineCalleeSaves(MachineFunction
&MF
, BitVector
&SavedRegs
,
60 RegScavenger
*RS
) const override
;
62 /// Update the IsRestored flag on LR if it is spilled, based on the return
64 static void updateLRRestored(MachineFunction
&MF
);
66 void processFunctionBeforeFrameFinalized(
67 MachineFunction
&MF
, RegScavenger
*RS
= nullptr) const override
;
69 void adjustForSegmentedStacks(MachineFunction
&MF
,
70 MachineBasicBlock
&MBB
) const override
;
72 /// Returns true if the target will correctly handle shrink wrapping.
73 bool enableShrinkWrapping(const MachineFunction
&MF
) const override
;
75 bool isProfitableForNoCSROpt(const Function
&F
) const override
{
76 // The no-CSR optimisation is bad for code size on ARM, because we can save
77 // many registers with a single PUSH/POP pair.
82 assignCalleeSavedSpillSlots(MachineFunction
&MF
,
83 const TargetRegisterInfo
*TRI
,
84 std::vector
<CalleeSavedInfo
> &CSI
) const override
;
87 getCalleeSavedSpillSlots(unsigned &NumEntries
) const override
;
90 bool hasFPImpl(const MachineFunction
&MF
) const override
;
93 void emitPushInst(MachineBasicBlock
&MBB
, MachineBasicBlock::iterator MI
,
94 ArrayRef
<CalleeSavedInfo
> CSI
, unsigned StmOpc
,
95 unsigned StrOpc
, bool NoGap
,
96 function_ref
<bool(unsigned)> Func
) const;
97 void emitPopInst(MachineBasicBlock
&MBB
, MachineBasicBlock::iterator MI
,
98 MutableArrayRef
<CalleeSavedInfo
> CSI
, unsigned LdmOpc
,
99 unsigned LdrOpc
, bool isVarArg
, bool NoGap
,
100 function_ref
<bool(unsigned)> Func
) const;
102 MachineBasicBlock::iterator
103 eliminateCallFramePseudoInstr(MachineFunction
&MF
,
104 MachineBasicBlock
&MBB
,
105 MachineBasicBlock::iterator MI
) const override
;
108 } // end namespace llvm
110 #endif // LLVM_LIB_TARGET_ARM_ARMFRAMELOWERING_H