Revert " [LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)"
[llvm-project.git] / llvm / lib / Target / WebAssembly / WebAssemblyFrameLowering.h
blob528b33e34beeef5d3d87ddd5dec145751a6a9fd5
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 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
18 #include "llvm/CodeGen/TargetFrameLowering.h"
20 namespace llvm {
22 class WebAssemblyFrameLowering final : public TargetFrameLowering {
23 public:
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;
30 WebAssemblyFrameLowering()
31 : TargetFrameLowering(StackGrowsDown, /*StackAlignment=*/Align(16),
32 /*LocalAreaOffset=*/0,
33 /*TransientStackAlignment=*/Align(16),
34 /*StackRealignable=*/true) {}
36 MachineBasicBlock::iterator
37 eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
38 MachineBasicBlock::iterator I) const override;
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;
44 bool hasFP(const MachineFunction &MF) const override;
45 bool hasReservedCallFrame(const MachineFunction &MF) const override;
46 bool isSupportedStackID(TargetStackID::Value ID) const override;
47 DwarfFrameBase getDwarfFrameBase(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;
57 // Returns the index of the WebAssembly local to which the stack object
58 // FrameIndex in MF should be allocated, or std::nullopt.
59 static std::optional<unsigned> getLocalForStackObject(MachineFunction &MF,
60 int FrameIndex);
62 static unsigned getSPReg(const MachineFunction &MF);
63 static unsigned getFPReg(const MachineFunction &MF);
64 static unsigned getOpcConst(const MachineFunction &MF);
65 static unsigned getOpcAdd(const MachineFunction &MF);
66 static unsigned getOpcSub(const MachineFunction &MF);
67 static unsigned getOpcAnd(const MachineFunction &MF);
68 static unsigned getOpcGlobGet(const MachineFunction &MF);
69 static unsigned getOpcGlobSet(const MachineFunction &MF);
71 private:
72 bool hasBP(const MachineFunction &MF) const;
73 bool needsSPForLocalFrame(const MachineFunction &MF) const;
74 bool needsSP(const MachineFunction &MF) const;
75 bool needsSPWriteback(const MachineFunction &MF) const;
78 } // end namespace llvm
80 #endif