blob: 42fe8e5755523cae5962574aff80788c39c330c5 [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001// WebAssemblyFrameLowering.h - TargetFrameLowering for WebAssembly -*- 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
Dan Gohman10e730a2015-06-29 23:51:55 +00006//
7//===----------------------------------------------------------------------===//
8///
9/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000010/// This class implements WebAssembly-specific bits of
Dan Gohman10e730a2015-06-29 23:51:55 +000011/// TargetFrameLowering class.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
16#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
17
David Blaikie1be62f02017-11-03 22:32:11 +000018#include "llvm/CodeGen/TargetFrameLowering.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000019
20namespace llvm {
Derek Schuff4b3bb212016-02-23 18:13:07 +000021class MachineFrameInfo;
Dan Gohman10e730a2015-06-29 23:51:55 +000022
23class WebAssemblyFrameLowering final : public TargetFrameLowering {
Heejin Ahnf208f632018-09-05 01:27:38 +000024public:
Derek Schuff770bdfe2016-02-23 18:17:46 +000025 /// Size of the red zone for the user stack (leaf functions can use this much
Heejin Ahnc4df1d12018-08-22 00:20:02 +000026 /// space below the stack pointer without writing it back to __stack_pointer
27 /// global).
Derek Schuff770bdfe2016-02-23 18:17:46 +000028 // TODO: (ABI) Revisit and decide how large it should be.
Derek Schuff4b3bb212016-02-23 18:13:07 +000029 static const size_t RedZoneSize = 128;
30
Dan Gohman10e730a2015-06-29 23:51:55 +000031 WebAssemblyFrameLowering()
Guillaume Chatelet882c43d2019-10-17 07:49:39 +000032 : TargetFrameLowering(StackGrowsDown, /*StackAlignment=*/Align(16),
Dan Gohman10e730a2015-06-29 23:51:55 +000033 /*LocalAreaOffset=*/0,
Guillaume Chatelet3cc48352019-10-21 08:31:25 +000034 /*TransientStackAlignment=*/Align(16),
Dan Gohman10e730a2015-06-29 23:51:55 +000035 /*StackRealignable=*/true) {}
36
Heejin Ahnf208f632018-09-05 01:27:38 +000037 MachineBasicBlock::iterator
38 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
39 MachineBasicBlock::iterator I) const override;
Dan Gohman10e730a2015-06-29 23:51:55 +000040
41 /// These methods insert prolog and epilog code into the function.
42 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
43 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
44
45 bool hasFP(const MachineFunction &MF) const override;
46 bool hasReservedCallFrame(const MachineFunction &MF) const override;
Derek Schuffff171ac2019-12-18 14:50:19 -080047 DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const override;
Derek Schuff4b3bb212016-02-23 18:13:07 +000048
Heejin Ahn78d19102018-08-21 21:23:07 +000049 bool needsPrologForEH(const MachineFunction &MF) const;
50
51 /// Write SP back to __stack_pointer global.
52 void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF,
53 MachineBasicBlock &MBB,
54 MachineBasicBlock::iterator &InsertStore,
55 const DebugLoc &DL) const;
56
57private:
Derek Schuff0d41b7b2016-11-07 22:00:48 +000058 bool hasBP(const MachineFunction &MF) const;
Heejin Ahn972fc352018-08-22 21:13:49 +000059 bool needsSPForLocalFrame(const MachineFunction &MF) const;
Heejin Ahnbc6d8972018-08-22 18:53:48 +000060 bool needsSP(const MachineFunction &MF) const;
61 bool needsSPWriteback(const MachineFunction &MF) const;
Dan Gohman10e730a2015-06-29 23:51:55 +000062};
63
Heejin Ahnf208f632018-09-05 01:27:38 +000064} // end namespace llvm
Dan Gohman10e730a2015-06-29 23:51:55 +000065
66#endif