blob: daddd4ca16ff89e8356ac3219653e89ff231f172 [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()
32 : TargetFrameLowering(StackGrowsDown, /*StackAlignment=*/16,
33 /*LocalAreaOffset=*/0,
34 /*TransientStackAlignment=*/16,
35 /*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 Schuff4b3bb212016-02-23 18:13:07 +000047
Heejin Ahn78d19102018-08-21 21:23:07 +000048 bool needsPrologForEH(const MachineFunction &MF) const;
49
50 /// Write SP back to __stack_pointer global.
51 void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF,
52 MachineBasicBlock &MBB,
53 MachineBasicBlock::iterator &InsertStore,
54 const DebugLoc &DL) const;
55
56private:
Derek Schuff0d41b7b2016-11-07 22:00:48 +000057 bool hasBP(const MachineFunction &MF) const;
Heejin Ahn972fc352018-08-22 21:13:49 +000058 bool needsSPForLocalFrame(const MachineFunction &MF) const;
Heejin Ahnbc6d8972018-08-22 18:53:48 +000059 bool needsSP(const MachineFunction &MF) const;
60 bool needsSPWriteback(const MachineFunction &MF) const;
Dan Gohman10e730a2015-06-29 23:51:55 +000061};
62
Heejin Ahnf208f632018-09-05 01:27:38 +000063} // end namespace llvm
Dan Gohman10e730a2015-06-29 23:51:55 +000064
65#endif