Path: blob/main/contrib/llvm-project/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.h
35266 views
// WebAssemblyFrameLowering.h - TargetFrameLowering for WebAssembly -*- C++ -*-/1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file9/// This class implements WebAssembly-specific bits of10/// TargetFrameLowering class.11///12//===----------------------------------------------------------------------===//1314#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H15#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H1617#include "llvm/CodeGen/TargetFrameLowering.h"1819namespace llvm {2021class WebAssemblyFrameLowering final : public TargetFrameLowering {22public:23/// Size of the red zone for the user stack (leaf functions can use this much24/// space below the stack pointer without writing it back to __stack_pointer25/// global).26// TODO: (ABI) Revisit and decide how large it should be.27static const size_t RedZoneSize = 128;2829WebAssemblyFrameLowering()30: TargetFrameLowering(StackGrowsDown, /*StackAlignment=*/Align(16),31/*LocalAreaOffset=*/0,32/*TransientStackAlignment=*/Align(16),33/*StackRealignable=*/true) {}3435MachineBasicBlock::iterator36eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,37MachineBasicBlock::iterator I) const override;3839/// These methods insert prolog and epilog code into the function.40void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;41void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;4243bool hasFP(const MachineFunction &MF) const override;44bool hasReservedCallFrame(const MachineFunction &MF) const override;45bool isSupportedStackID(TargetStackID::Value ID) const override;46DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const override;4748bool needsPrologForEH(const MachineFunction &MF) const;4950/// Write SP back to __stack_pointer global.51void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF,52MachineBasicBlock &MBB,53MachineBasicBlock::iterator &InsertStore,54const DebugLoc &DL) const;5556// Returns the index of the WebAssembly local to which the stack object57// FrameIndex in MF should be allocated, or std::nullopt.58static std::optional<unsigned> getLocalForStackObject(MachineFunction &MF,59int FrameIndex);6061static unsigned getSPReg(const MachineFunction &MF);62static unsigned getFPReg(const MachineFunction &MF);63static unsigned getOpcConst(const MachineFunction &MF);64static unsigned getOpcAdd(const MachineFunction &MF);65static unsigned getOpcSub(const MachineFunction &MF);66static unsigned getOpcAnd(const MachineFunction &MF);67static unsigned getOpcGlobGet(const MachineFunction &MF);68static unsigned getOpcGlobSet(const MachineFunction &MF);6970private:71bool hasBP(const MachineFunction &MF) const;72bool needsSPForLocalFrame(const MachineFunction &MF) const;73bool needsSP(const MachineFunction &MF) const;74bool needsSPWriteback(const MachineFunction &MF) const;75};7677} // end namespace llvm7879#endif808182