blob: 03a6b7c3ad1cba3781b9895fef587334a0749565 [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001// WebAssemblyFrameLowering.h - TargetFrameLowering for WebAssembly -*- C++ -*-/
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000011/// This class implements WebAssembly-specific bits of
Dan Gohman10e730a2015-06-29 23:51:55 +000012/// TargetFrameLowering class.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
17#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
18
David Blaikie1be62f02017-11-03 22:32:11 +000019#include "llvm/CodeGen/TargetFrameLowering.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000020
21namespace llvm {
Derek Schuff4b3bb212016-02-23 18:13:07 +000022class MachineFrameInfo;
Dan Gohman10e730a2015-06-29 23:51:55 +000023
24class WebAssemblyFrameLowering final : public TargetFrameLowering {
Derek Schuff3f063292016-02-11 20:57:09 +000025 public:
Derek Schuff770bdfe2016-02-23 18:17:46 +000026 /// Size of the red zone for the user stack (leaf functions can use this much
Heejin Ahnc4df1d12018-08-22 00:20:02 +000027 /// space below the stack pointer without writing it back to __stack_pointer
28 /// global).
Derek Schuff770bdfe2016-02-23 18:17:46 +000029 // TODO: (ABI) Revisit and decide how large it should be.
Derek Schuff4b3bb212016-02-23 18:13:07 +000030 static const size_t RedZoneSize = 128;
31
Dan Gohman10e730a2015-06-29 23:51:55 +000032 WebAssemblyFrameLowering()
33 : TargetFrameLowering(StackGrowsDown, /*StackAlignment=*/16,
34 /*LocalAreaOffset=*/0,
35 /*TransientStackAlignment=*/16,
36 /*StackRealignable=*/true) {}
37
Hans Wennborge1a2e902016-03-31 18:33:38 +000038 MachineBasicBlock::iterator eliminateCallFramePseudoInstr(
Derek Schuff3f063292016-02-11 20:57:09 +000039 MachineFunction &MF, MachineBasicBlock &MBB,
40 MachineBasicBlock::iterator I) const override;
Dan Gohman10e730a2015-06-29 23:51:55 +000041
42 /// These methods insert prolog and epilog code into the function.
43 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
44 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
45
46 bool hasFP(const MachineFunction &MF) const override;
47 bool hasReservedCallFrame(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
Derek Schuff3f063292016-02-11 20:57:09 +000064} // end namespace llvm
Dan Gohman10e730a2015-06-29 23:51:55 +000065
66#endif