1285163Sdim// WebAssemblyFrameLowering.h - TargetFrameLowering for WebAssembly -*- C++ -*-/
2285163Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6285163Sdim//
7285163Sdim//===----------------------------------------------------------------------===//
8285163Sdim///
9285163Sdim/// \file
10341825Sdim/// This class implements WebAssembly-specific bits of
11285163Sdim/// TargetFrameLowering class.
12285163Sdim///
13285163Sdim//===----------------------------------------------------------------------===//
14285163Sdim
15285163Sdim#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
16285163Sdim#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
17285163Sdim
18327952Sdim#include "llvm/CodeGen/TargetFrameLowering.h"
19285163Sdim
20285163Sdimnamespace llvm {
21309124Sdimclass MachineFrameInfo;
22285163Sdim
23285163Sdimclass WebAssemblyFrameLowering final : public TargetFrameLowering {
24344779Sdimpublic:
25309124Sdim  /// Size of the red zone for the user stack (leaf functions can use this much
26344779Sdim  /// space below the stack pointer without writing it back to __stack_pointer
27344779Sdim  /// global).
28309124Sdim  // TODO: (ABI) Revisit and decide how large it should be.
29309124Sdim  static const size_t RedZoneSize = 128;
30309124Sdim
31285163Sdim  WebAssemblyFrameLowering()
32360784Sdim      : TargetFrameLowering(StackGrowsDown, /*StackAlignment=*/Align(16),
33285163Sdim                            /*LocalAreaOffset=*/0,
34360784Sdim                            /*TransientStackAlignment=*/Align(16),
35285163Sdim                            /*StackRealignable=*/true) {}
36285163Sdim
37344779Sdim  MachineBasicBlock::iterator
38344779Sdim  eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
39344779Sdim                                MachineBasicBlock::iterator I) const override;
40285163Sdim
41285163Sdim  /// These methods insert prolog and epilog code into the function.
42285163Sdim  void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
43285163Sdim  void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
44285163Sdim
45285163Sdim  bool hasFP(const MachineFunction &MF) const override;
46285163Sdim  bool hasReservedCallFrame(const MachineFunction &MF) const override;
47309124Sdim
48344779Sdim  bool needsPrologForEH(const MachineFunction &MF) const;
49344779Sdim
50344779Sdim  /// Write SP back to __stack_pointer global.
51344779Sdim  void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF,
52344779Sdim                       MachineBasicBlock &MBB,
53344779Sdim                       MachineBasicBlock::iterator &InsertStore,
54344779Sdim                       const DebugLoc &DL) const;
55344779Sdim
56344779Sdimprivate:
57314564Sdim  bool hasBP(const MachineFunction &MF) const;
58344779Sdim  bool needsSPForLocalFrame(const MachineFunction &MF) const;
59344779Sdim  bool needsSP(const MachineFunction &MF) const;
60344779Sdim  bool needsSPWriteback(const MachineFunction &MF) const;
61285163Sdim};
62285163Sdim
63344779Sdim} // end namespace llvm
64285163Sdim
65285163Sdim#endif
66