110e730a2SDan Gohman //===-- WebAssemblyFrameLowering.cpp - WebAssembly Frame Lowering ----------==//
210e730a2SDan Gohman //
310e730a2SDan Gohman //                     The LLVM Compiler Infrastructure
410e730a2SDan Gohman //
510e730a2SDan Gohman // This file is distributed under the University of Illinois Open Source
610e730a2SDan Gohman // License. See LICENSE.TXT for details.
710e730a2SDan Gohman //
810e730a2SDan Gohman //===----------------------------------------------------------------------===//
910e730a2SDan Gohman ///
1010e730a2SDan Gohman /// \file
1110e730a2SDan Gohman /// \brief This file contains the WebAssembly implementation of
1210e730a2SDan Gohman /// TargetFrameLowering class.
1310e730a2SDan Gohman ///
1410e730a2SDan Gohman /// On WebAssembly, there aren't a lot of things to do here. There are no
1510e730a2SDan Gohman /// callee-saved registers to save, and no spill slots.
1610e730a2SDan Gohman ///
1710e730a2SDan Gohman /// The stack grows downward.
1810e730a2SDan Gohman ///
1910e730a2SDan Gohman //===----------------------------------------------------------------------===//
2010e730a2SDan Gohman 
2110e730a2SDan Gohman #include "WebAssemblyFrameLowering.h"
2210e730a2SDan Gohman #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
2310e730a2SDan Gohman #include "WebAssemblyInstrInfo.h"
2410e730a2SDan Gohman #include "WebAssemblyMachineFunctionInfo.h"
2510e730a2SDan Gohman #include "WebAssemblySubtarget.h"
2610e730a2SDan Gohman #include "WebAssemblyTargetMachine.h"
2710e730a2SDan Gohman #include "llvm/CodeGen/MachineFrameInfo.h"
2810e730a2SDan Gohman #include "llvm/CodeGen/MachineFunction.h"
2910e730a2SDan Gohman #include "llvm/CodeGen/MachineInstrBuilder.h"
3010e730a2SDan Gohman #include "llvm/CodeGen/MachineModuleInfo.h"
3110e730a2SDan Gohman #include "llvm/CodeGen/MachineRegisterInfo.h"
3210e730a2SDan Gohman #include "llvm/Support/Debug.h"
3310e730a2SDan Gohman using namespace llvm;
3410e730a2SDan Gohman 
3503855df1SJF Bastien #define DEBUG_TYPE "wasm-frame-info"
3610e730a2SDan Gohman 
3710e730a2SDan Gohman // TODO: Implement a red zone?
3810e730a2SDan Gohman 
3910e730a2SDan Gohman /// Return true if the specified function should have a dedicated frame pointer
4010e730a2SDan Gohman /// register.
4110e730a2SDan Gohman bool WebAssemblyFrameLowering::hasFP(const MachineFunction &MF) const {
42b9073fb2SJF Bastien   const MachineFrameInfo *MFI = MF.getFrameInfo();
43*e419a7c3SDan Gohman   const auto *RegInfo =
44*e419a7c3SDan Gohman       MF.getSubtarget<WebAssemblySubtarget>().getRegisterInfo();
45b9073fb2SJF Bastien   return MFI->hasCalls() || MFI->hasVarSizedObjects() ||
46b9073fb2SJF Bastien          MFI->isFrameAddressTaken() || MFI->hasStackMap() ||
47b9073fb2SJF Bastien          MFI->hasPatchPoint() || RegInfo->needsStackRealignment(MF);
4810e730a2SDan Gohman }
4910e730a2SDan Gohman 
5010e730a2SDan Gohman /// Under normal circumstances, when a frame pointer is not required, we reserve
5110e730a2SDan Gohman /// argument space for call sites in the function immediately on entry to the
5210e730a2SDan Gohman /// current function. This eliminates the need for add/sub sp brackets around
5310e730a2SDan Gohman /// call sites. Returns true if the call frame is included as part of the stack
5410e730a2SDan Gohman /// frame.
5510e730a2SDan Gohman bool WebAssemblyFrameLowering::hasReservedCallFrame(
5610e730a2SDan Gohman     const MachineFunction &MF) const {
5710e730a2SDan Gohman   return !MF.getFrameInfo()->hasVarSizedObjects();
5810e730a2SDan Gohman }
5910e730a2SDan Gohman 
6010e730a2SDan Gohman void WebAssemblyFrameLowering::eliminateCallFramePseudoInstr(
6110e730a2SDan Gohman     MachineFunction &MF, MachineBasicBlock &MBB,
6210e730a2SDan Gohman     MachineBasicBlock::iterator I) const {
6310e730a2SDan Gohman   llvm_unreachable("TODO: implement eliminateCallFramePseudoInstr");
6410e730a2SDan Gohman }
6510e730a2SDan Gohman 
6610e730a2SDan Gohman void WebAssemblyFrameLowering::emitPrologue(MachineFunction &MF,
6710e730a2SDan Gohman                                             MachineBasicBlock &MBB) const {
68b9073fb2SJF Bastien   // FIXME: Implement WebAssemblyFrameLowering::emitPrologue.
6910e730a2SDan Gohman }
7010e730a2SDan Gohman 
7110e730a2SDan Gohman void WebAssemblyFrameLowering::emitEpilogue(MachineFunction &MF,
7210e730a2SDan Gohman                                             MachineBasicBlock &MBB) const {
7310e730a2SDan Gohman   llvm_unreachable("TODO: implement emitEpilogue");
7410e730a2SDan Gohman }
75