LLVM  14.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 
20 namespace llvm {
21 
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;
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 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;
48 
49  bool needsPrologForEH(const MachineFunction &MF) const;
50 
51  /// Write SP back to __stack_pointer global.
52  void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF,
54  MachineBasicBlock::iterator &InsertStore,
55  const DebugLoc &DL) const;
56 
57  // Returns the index of the WebAssembly local to which the stack object
58  // FrameIndex in MF should be allocated, or None.
60  int FrameIndex);
61 
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);
70 
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;
76 };
77 
78 } // end namespace llvm
79 
80 #endif
llvm::WebAssemblyFrameLowering::getOpcAdd
static unsigned getOpcAdd(const MachineFunction &MF)
Definition: WebAssemblyFrameLowering.cpp:193
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::WebAssemblyFrameLowering::getSPReg
static unsigned getSPReg(const MachineFunction &MF)
Definition: WebAssemblyFrameLowering.cpp:174
TargetFrameLowering.h
llvm::TargetFrameLowering
Information about stack frame layout on the target.
Definition: TargetFrameLowering.h:43
llvm::WebAssemblyFrameLowering::isSupportedStackID
bool isSupportedStackID(TargetStackID::Value ID) const override
Definition: WebAssemblyFrameLowering.cpp:365
llvm::WebAssemblyFrameLowering::getOpcSub
static unsigned getOpcSub(const MachineFunction &MF)
Definition: WebAssemblyFrameLowering.cpp:199
llvm::WebAssemblyFrameLowering
Definition: WebAssemblyFrameLowering.h:22
llvm::Optional< unsigned >
llvm::WebAssemblyFrameLowering::writeSPToGlobal
void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator &InsertStore, const DebugLoc &DL) const
Write SP back to __stack_pointer global.
Definition: WebAssemblyFrameLowering.cpp:225
llvm::WebAssemblyFrameLowering::eliminateCallFramePseudoInstr
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...
Definition: WebAssemblyFrameLowering.cpp:239
llvm::WebAssemblyFrameLowering::emitPrologue
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
These methods insert prolog and epilog code into the function.
Definition: WebAssemblyFrameLowering.cpp:254
llvm::WebAssemblyFrameLowering::getOpcConst
static unsigned getOpcConst(const MachineFunction &MF)
Definition: WebAssemblyFrameLowering.cpp:187
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::WebAssemblyFrameLowering::getOpcGlobSet
static unsigned getOpcGlobSet(const MachineFunction &MF)
Definition: WebAssemblyFrameLowering.cpp:219
llvm::WebAssemblyFrameLowering::getDwarfFrameBase
DwarfFrameBase getDwarfFrameBase(const MachineFunction &MF) const override
Return the frame base information to be encoded in the DWARF subprogram debug info.
Definition: WebAssemblyFrameLowering.cpp:376
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::WebAssemblyFrameLowering::WebAssemblyFrameLowering
WebAssemblyFrameLowering()
Definition: WebAssemblyFrameLowering.h:30
DL
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Definition: AArch64SLSHardening.cpp:76
llvm::WebAssemblyFrameLowering::emitEpilogue
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Definition: WebAssemblyFrameLowering.cpp:324
llvm::WebAssemblyFrameLowering::getOpcAnd
static unsigned getOpcAnd(const MachineFunction &MF)
Definition: WebAssemblyFrameLowering.cpp:205
llvm::WebAssemblyFrameLowering::hasReservedCallFrame
bool hasReservedCallFrame(const MachineFunction &MF) const override
Under normal circumstances, when a frame pointer is not required, we reserve argument space for call ...
Definition: WebAssemblyFrameLowering.cpp:124
llvm::ISD::FrameIndex
@ FrameIndex
Definition: ISDOpcodes.h:80
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::WebAssemblyFrameLowering::getFPReg
static unsigned getFPReg(const MachineFunction &MF)
Definition: WebAssemblyFrameLowering.cpp:180
llvm::WebAssemblyFrameLowering::RedZoneSize
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...
Definition: WebAssemblyFrameLowering.h:28
llvm::WebAssemblyFrameLowering::hasFP
bool hasFP(const MachineFunction &MF) const override
Return true if the specified function should have a dedicated frame pointer register.
Definition: WebAssemblyFrameLowering.cpp:102
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::WebAssemblyFrameLowering::needsPrologForEH
bool needsPrologForEH(const MachineFunction &MF) const
Definition: WebAssemblyFrameLowering.cpp:140
llvm::TargetFrameLowering::StackGrowsDown
@ StackGrowsDown
Definition: TargetFrameLowering.h:47
llvm::WebAssemblyFrameLowering::getOpcGlobGet
static unsigned getOpcGlobGet(const MachineFunction &MF)
Definition: WebAssemblyFrameLowering.cpp:212
llvm::DebugLoc
A debug info location.
Definition: DebugLoc.h:33
llvm::WebAssemblyFrameLowering::getLocalForStackObject
static Optional< unsigned > getLocalForStackObject(MachineFunction &MF, int FrameIndex)
Definition: WebAssemblyFrameLowering.cpp:54
llvm::MachineInstrBundleIterator< MachineInstr >
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37