blob: ac150e86c9eb5dcfee5d1e0e1629cc02fc2e7194 [file] [log] [blame]
Tim Northover3b0846e2014-05-24 12:50:23 +00001//==-- AArch64FrameLowering.h - TargetFrameLowering for AArch64 --*- C++ -*-==//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Tim Northover3b0846e2014-05-24 12:50:23 +00006//
7//===----------------------------------------------------------------------===//
8//
9//
10//
11//===----------------------------------------------------------------------===//
12
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000013#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64FRAMELOWERING_H
14#define LLVM_LIB_TARGET_AARCH64_AARCH64FRAMELOWERING_H
Tim Northover3b0846e2014-05-24 12:50:23 +000015
Sander de Smalen612b0382019-08-06 13:06:40 +000016#include "AArch64StackOffset.h"
David Blaikie1be62f02017-11-03 22:32:11 +000017#include "llvm/CodeGen/TargetFrameLowering.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000018
19namespace llvm {
20
Tim Northover3b0846e2014-05-24 12:50:23 +000021class AArch64FrameLowering : public TargetFrameLowering {
Tim Northover3b0846e2014-05-24 12:50:23 +000022public:
Eric Christopherbc76b972014-06-10 17:33:39 +000023 explicit AArch64FrameLowering()
Guillaume Chatelet3cc48352019-10-21 08:31:25 +000024 : TargetFrameLowering(StackGrowsDown, Align(16), 0, Align(16),
Kristof Beyls17cb8982015-04-09 08:49:47 +000025 true /*StackRealignable*/) {}
Tim Northover3b0846e2014-05-24 12:50:23 +000026
27 void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB,
Geoff Berry62d47252016-02-25 16:36:08 +000028 MachineBasicBlock::iterator MBBI) const;
Tim Northover3b0846e2014-05-24 12:50:23 +000029
Hans Wennborge1a2e902016-03-31 18:33:38 +000030 MachineBasicBlock::iterator
31 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
32 MachineBasicBlock::iterator I) const override;
Tim Northover3b0846e2014-05-24 12:50:23 +000033
34 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
35 /// the function.
Quentin Colombet61b305e2015-05-05 17:38:16 +000036 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
Tim Northover3b0846e2014-05-24 12:50:23 +000037 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
38
Geoff Berry7e4ba3d2016-02-19 18:27:32 +000039 bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
40
Tim Northover3b0846e2014-05-24 12:50:23 +000041 int getFrameIndexReference(const MachineFunction &MF, int FI,
42 unsigned &FrameReg) const override;
Sander de Smalen612b0382019-08-06 13:06:40 +000043 StackOffset resolveFrameIndexReference(const MachineFunction &MF, int FI,
44 unsigned &FrameReg, bool PreferFP,
45 bool ForSimm) const;
46 StackOffset resolveFrameOffsetReference(const MachineFunction &MF,
47 int ObjectOffset, bool isFixed,
Sander de Smalen77748122019-10-14 13:11:34 +000048 bool isSVE, unsigned &FrameReg,
49 bool PreferFP, bool ForSimm) const;
Tim Northover3b0846e2014-05-24 12:50:23 +000050 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
51 MachineBasicBlock::iterator MI,
52 const std::vector<CalleeSavedInfo> &CSI,
53 const TargetRegisterInfo *TRI) const override;
54
55 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
56 MachineBasicBlock::iterator MI,
Krzysztof Parzyszekbea30c62017-08-10 16:17:32 +000057 std::vector<CalleeSavedInfo> &CSI,
Tim Northover3b0846e2014-05-24 12:50:23 +000058 const TargetRegisterInfo *TRI) const override;
59
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000060 /// Can this function use the red zone for local allocations.
Tim Northover3b0846e2014-05-24 12:50:23 +000061 bool canUseRedZone(const MachineFunction &MF) const;
62
63 bool hasFP(const MachineFunction &MF) const override;
64 bool hasReservedCallFrame(const MachineFunction &MF) const override;
65
Matthias Braun02564862015-07-14 17:17:13 +000066 void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
67 RegScavenger *RS) const override;
Quentin Colombetf6645cc2015-11-18 23:12:20 +000068
69 /// Returns true if the target will correctly handle shrink wrapping.
70 bool enableShrinkWrapping(const MachineFunction &MF) const override {
71 return true;
72 }
Geoff Berrya5335642016-05-06 16:34:59 +000073
Geoff Berry66f6b652016-06-02 16:22:07 +000074 bool enableStackSlotScavenging(const MachineFunction &MF) const override;
75
Eli Friedmanad1151c2018-11-09 23:33:30 +000076 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
77 RegScavenger *RS) const override;
78
79 unsigned getWinEHParentFrameOffset(const MachineFunction &MF) const override;
80
81 unsigned getWinEHFuncletFrameSize(const MachineFunction &MF) const;
82
83 int getFrameIndexReferencePreferSP(const MachineFunction &MF, int FI,
84 unsigned &FrameReg,
85 bool IgnoreSPUpdates) const override;
Mandeep Singh Grang70d484d2019-02-01 21:41:33 +000086 int getNonLocalFrameIndexReference(const MachineFunction &MF,
87 int FI) const override;
88 int getSEHFrameIndexOffset(const MachineFunction &MF, int FI) const;
Eli Friedmanad1151c2018-11-09 23:33:30 +000089
Sander de Smalen4f99b6f2019-10-03 11:33:50 +000090 bool isSupportedStackID(TargetStackID::Value ID) const override {
91 switch (ID) {
92 default:
93 return false;
94 case TargetStackID::Default:
95 case TargetStackID::SVEVector:
96 case TargetStackID::NoAlloc:
97 return true;
98 }
99 }
100
Geoff Berrya5335642016-05-06 16:34:59 +0000101private:
102 bool shouldCombineCSRLocalStackBump(MachineFunction &MF,
103 unsigned StackBumpBytes) const;
Sander de Smalen77748122019-10-14 13:11:34 +0000104 int64_t determineSVEStackSize(MachineFrameInfo &MF, unsigned &MaxAlign) const;
Tim Northover3b0846e2014-05-24 12:50:23 +0000105};
106
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000107} // End llvm namespace
Tim Northover3b0846e2014-05-24 12:50:23 +0000108
109#endif