LLVM 20.0.0git
WebAssemblyFrameLowering.h
Go to the documentation of this file.
1// WebAssemblyFrameLowering.h - TargetFrameLowering for WebAssembly -*- C++ -*-/
2//
3// 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
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This class implements WebAssembly-specific bits of
11/// TargetFrameLowering class.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
16#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
17
19
20namespace llvm {
21
23public:
24 /// Size of the red zone for the user stack (leaf functions can use this much
25 /// space below the stack pointer without writing it back to __stack_pointer
26 /// global).
27 // TODO: (ABI) Revisit and decide how large it should be.
28 static const size_t RedZoneSize = 128;
29
31 : TargetFrameLowering(StackGrowsDown, /*StackAlignment=*/Align(16),
32 /*LocalAreaOffset=*/0,
33 /*TransientStackAlignment=*/Align(16),
34 /*StackRealignable=*/true) {}
35
38 MachineBasicBlock::iterator I) const override;
39
40 /// These methods insert prolog and epilog code into the function.
41 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
42 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
43
44 bool hasReservedCallFrame(const MachineFunction &MF) const override;
45 bool isSupportedStackID(TargetStackID::Value ID) const override;
46 DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const override;
47
48 bool needsPrologForEH(const MachineFunction &MF) const;
49
50 /// Write SP back to __stack_pointer global.
51 void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF,
53 MachineBasicBlock::iterator &InsertStore,
54 const DebugLoc &DL) const;
55
56 // Returns the index of the WebAssembly local to which the stack object
57 // FrameIndex in MF should be allocated, or std::nullopt.
58 static std::optional<unsigned> getLocalForStackObject(MachineFunction &MF,
59 int FrameIndex);
60
61 static unsigned getSPReg(const MachineFunction &MF);
62 static unsigned getFPReg(const MachineFunction &MF);
63 static unsigned getOpcConst(const MachineFunction &MF);
64 static unsigned getOpcAdd(const MachineFunction &MF);
65 static unsigned getOpcSub(const MachineFunction &MF);
66 static unsigned getOpcAnd(const MachineFunction &MF);
67 static unsigned getOpcGlobGet(const MachineFunction &MF);
68 static unsigned getOpcGlobSet(const MachineFunction &MF);
69
70protected:
71 bool hasFPImpl(const MachineFunction &MF) const override;
72
73private:
74 bool hasBP(const MachineFunction &MF) const;
75 bool needsSPForLocalFrame(const MachineFunction &MF) const;
76 bool needsSP(const MachineFunction &MF) const;
77 bool needsSPWriteback(const MachineFunction &MF) const;
78};
79
80} // end namespace llvm
81
82#endif
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
basic Basic Alias true
#define I(x, y, z)
Definition: MD5.cpp:58
A debug info location.
Definition: DebugLoc.h:33
Information about stack frame layout on the target.
static unsigned getOpcAdd(const MachineFunction &MF)
static unsigned getFPReg(const MachineFunction &MF)
bool needsPrologForEH(const MachineFunction &MF) const
static unsigned getOpcGlobSet(const MachineFunction &MF)
bool hasReservedCallFrame(const MachineFunction &MF) const override
Under normal circumstances, when a frame pointer is not required, we reserve argument space for call ...
static unsigned getOpcAnd(const MachineFunction &MF)
static unsigned getSPReg(const MachineFunction &MF)
static unsigned getOpcGlobGet(const MachineFunction &MF)
DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const override
Return the frame base information to be encoded in the DWARF subprogram debug info.
bool isSupportedStackID(TargetStackID::Value ID) const override
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
static unsigned getOpcConst(const MachineFunction &MF)
bool hasFPImpl(const MachineFunction &MF) const override
Return true if the specified function should have a dedicated frame pointer register.
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
These methods insert prolog and epilog code into the function.
void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator &InsertStore, const DebugLoc &DL) const
Write SP back to __stack_pointer global.
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
static const size_t RedZoneSize
Size of the red zone for the user stack (leaf functions can use this much space below the stack point...
static std::optional< unsigned > getLocalForStackObject(MachineFunction &MF, int FrameIndex)
static unsigned getOpcSub(const MachineFunction &MF)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39