1 //===-- WebAssemblyFrameLowering.cpp - WebAssembly Frame Lowering ----------==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief This file contains the WebAssembly implementation of
12 /// TargetFrameLowering class.
14 /// On WebAssembly, there aren't a lot of things to do here. There are no
15 /// callee-saved registers to save, and no spill slots.
17 /// The stack grows downward.
19 //===----------------------------------------------------------------------===//
21 #include "WebAssemblyFrameLowering.h"
22 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
23 #include "WebAssemblyInstrInfo.h"
24 #include "WebAssemblyMachineFunctionInfo.h"
25 #include "WebAssemblySubtarget.h"
26 #include "WebAssemblyTargetMachine.h"
27 #include "llvm/CodeGen/MachineFrameInfo.h"
28 #include "llvm/CodeGen/MachineFunction.h"
29 #include "llvm/CodeGen/MachineInstrBuilder.h"
30 #include "llvm/CodeGen/MachineModuleInfo.h"
31 #include "llvm/CodeGen/MachineRegisterInfo.h"
32 #include "llvm/Support/Debug.h"
35 #define DEBUG_TYPE "wasm-frame-info"
37 // TODO: Implement a red zone?
39 /// Return true if the specified function should have a dedicated frame pointer
41 bool WebAssemblyFrameLowering::hasFP(const MachineFunction &MF) const {
42 const MachineFrameInfo *MFI = MF.getFrameInfo();
43 const auto *RegInfo = static_cast<const WebAssemblyRegisterInfo *>(
44 MF.getSubtarget().getRegisterInfo());
45 return MFI->hasCalls() || MFI->hasVarSizedObjects() ||
46 MFI->isFrameAddressTaken() || MFI->hasStackMap() ||
47 MFI->hasPatchPoint() || RegInfo->needsStackRealignment(MF);
50 /// Under normal circumstances, when a frame pointer is not required, we reserve
51 /// argument space for call sites in the function immediately on entry to the
52 /// current function. This eliminates the need for add/sub sp brackets around
53 /// call sites. Returns true if the call frame is included as part of the stack
55 bool WebAssemblyFrameLowering::hasReservedCallFrame(
56 const MachineFunction &MF) const {
57 return !MF.getFrameInfo()->hasVarSizedObjects();
60 void WebAssemblyFrameLowering::eliminateCallFramePseudoInstr(
61 MachineFunction &MF, MachineBasicBlock &MBB,
62 MachineBasicBlock::iterator I) const {
63 llvm_unreachable("TODO: implement eliminateCallFramePseudoInstr");
66 void WebAssemblyFrameLowering::emitPrologue(MachineFunction &MF,
67 MachineBasicBlock &MBB) const {
68 // FIXME: Implement WebAssemblyFrameLowering::emitPrologue.
71 void WebAssemblyFrameLowering::emitEpilogue(MachineFunction &MF,
72 MachineBasicBlock &MBB) const {
73 llvm_unreachable("TODO: implement emitEpilogue");