xref: /netbsd-src/external/apache2/llvm/dist/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.h (revision 82d56013d7b633d116a93943de88e08335357a7c)
17330f729Sjoerg // WebAssemblyFrameLowering.h - TargetFrameLowering for WebAssembly -*- C++ -*-/
27330f729Sjoerg //
37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg //
77330f729Sjoerg //===----------------------------------------------------------------------===//
87330f729Sjoerg ///
97330f729Sjoerg /// \file
107330f729Sjoerg /// This class implements WebAssembly-specific bits of
117330f729Sjoerg /// TargetFrameLowering class.
127330f729Sjoerg ///
137330f729Sjoerg //===----------------------------------------------------------------------===//
147330f729Sjoerg 
157330f729Sjoerg #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
167330f729Sjoerg #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H
177330f729Sjoerg 
187330f729Sjoerg #include "llvm/CodeGen/TargetFrameLowering.h"
197330f729Sjoerg 
207330f729Sjoerg namespace llvm {
217330f729Sjoerg 
227330f729Sjoerg class WebAssemblyFrameLowering final : public TargetFrameLowering {
237330f729Sjoerg public:
247330f729Sjoerg   /// Size of the red zone for the user stack (leaf functions can use this much
257330f729Sjoerg   /// space below the stack pointer without writing it back to __stack_pointer
267330f729Sjoerg   /// global).
277330f729Sjoerg   // TODO: (ABI) Revisit and decide how large it should be.
287330f729Sjoerg   static const size_t RedZoneSize = 128;
297330f729Sjoerg 
WebAssemblyFrameLowering()307330f729Sjoerg   WebAssemblyFrameLowering()
317330f729Sjoerg       : TargetFrameLowering(StackGrowsDown, /*StackAlignment=*/Align(16),
327330f729Sjoerg                             /*LocalAreaOffset=*/0,
337330f729Sjoerg                             /*TransientStackAlignment=*/Align(16),
347330f729Sjoerg                             /*StackRealignable=*/true) {}
357330f729Sjoerg 
367330f729Sjoerg   MachineBasicBlock::iterator
377330f729Sjoerg   eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
387330f729Sjoerg                                 MachineBasicBlock::iterator I) const override;
397330f729Sjoerg 
407330f729Sjoerg   /// These methods insert prolog and epilog code into the function.
417330f729Sjoerg   void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
427330f729Sjoerg   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
437330f729Sjoerg 
447330f729Sjoerg   bool hasFP(const MachineFunction &MF) const override;
457330f729Sjoerg   bool hasReservedCallFrame(const MachineFunction &MF) const override;
46*82d56013Sjoerg   DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const override;
477330f729Sjoerg 
487330f729Sjoerg   bool needsPrologForEH(const MachineFunction &MF) const;
497330f729Sjoerg 
507330f729Sjoerg   /// Write SP back to __stack_pointer global.
517330f729Sjoerg   void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF,
527330f729Sjoerg                        MachineBasicBlock &MBB,
537330f729Sjoerg                        MachineBasicBlock::iterator &InsertStore,
547330f729Sjoerg                        const DebugLoc &DL) const;
557330f729Sjoerg 
56*82d56013Sjoerg   static unsigned getSPReg(const MachineFunction &MF);
57*82d56013Sjoerg   static unsigned getFPReg(const MachineFunction &MF);
58*82d56013Sjoerg   static unsigned getOpcConst(const MachineFunction &MF);
59*82d56013Sjoerg   static unsigned getOpcAdd(const MachineFunction &MF);
60*82d56013Sjoerg   static unsigned getOpcSub(const MachineFunction &MF);
61*82d56013Sjoerg   static unsigned getOpcAnd(const MachineFunction &MF);
62*82d56013Sjoerg   static unsigned getOpcGlobGet(const MachineFunction &MF);
63*82d56013Sjoerg   static unsigned getOpcGlobSet(const MachineFunction &MF);
64*82d56013Sjoerg 
657330f729Sjoerg private:
667330f729Sjoerg   bool hasBP(const MachineFunction &MF) const;
677330f729Sjoerg   bool needsSPForLocalFrame(const MachineFunction &MF) const;
687330f729Sjoerg   bool needsSP(const MachineFunction &MF) const;
697330f729Sjoerg   bool needsSPWriteback(const MachineFunction &MF) const;
707330f729Sjoerg };
717330f729Sjoerg 
727330f729Sjoerg } // end namespace llvm
737330f729Sjoerg 
747330f729Sjoerg #endif
75