1 // WebAssemblyFrameLowering.h - TargetFrameLowering for WebAssembly -*- C++ -*-/
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This class implements WebAssembly-specific bits of
12 /// TargetFrameLowering class.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
17 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
19 #include "llvm/CodeGen/TargetFrameLowering.h"
22 class MachineFrameInfo;
24 class WebAssemblyFrameLowering final : public TargetFrameLowering {
26 /// Size of the red zone for the user stack (leaf functions can use this much
27 /// space below the stack pointer without writing it back to __stack_pointer
29 // TODO: (ABI) Revisit and decide how large it should be.
30 static const size_t RedZoneSize = 128;
32 WebAssemblyFrameLowering()
33 : TargetFrameLowering(StackGrowsDown, /*StackAlignment=*/16,
34 /*LocalAreaOffset=*/0,
35 /*TransientStackAlignment=*/16,
36 /*StackRealignable=*/true) {}
38 MachineBasicBlock::iterator
39 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
40 MachineBasicBlock::iterator I) const override;
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;
46 bool hasFP(const MachineFunction &MF) const override;
47 bool hasReservedCallFrame(const MachineFunction &MF) const override;
49 bool needsPrologForEH(const MachineFunction &MF) const;
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;
58 bool hasBP(const MachineFunction &MF) const;
59 bool needsSPForLocalFrame(const MachineFunction &MF) const;
60 bool needsSP(const MachineFunction &MF) const;
61 bool needsSPWriteback(const MachineFunction &MF) const;
64 } // end namespace llvm