blob: fec94554833b137dff53d0d37e74eb71de86112c [file] [log] [blame]
Dan Gohman10e730a2015-06-29 23:51:55 +00001//===-- WebAssemblyFrameLowering.cpp - WebAssembly Frame Lowering ----------==//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief This file contains the WebAssembly implementation of
12/// TargetFrameLowering class.
13///
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.
16///
17/// The stack grows downward.
18///
19//===----------------------------------------------------------------------===//
20
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"
33using namespace llvm;
34
JF Bastien03855df2015-07-01 23:41:25 +000035#define DEBUG_TYPE "wasm-frame-info"
Dan Gohman10e730a2015-06-29 23:51:55 +000036
37// TODO: Implement a red zone?
38
39/// Return true if the specified function should have a dedicated frame pointer
40/// register.
41bool WebAssemblyFrameLowering::hasFP(const MachineFunction &MF) const {
JF Bastienb9073fb2015-07-22 21:28:15 +000042 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);
Dan Gohman10e730a2015-06-29 23:51:55 +000048}
49
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
54/// frame.
55bool WebAssemblyFrameLowering::hasReservedCallFrame(
56 const MachineFunction &MF) const {
57 return !MF.getFrameInfo()->hasVarSizedObjects();
58}
59
60void WebAssemblyFrameLowering::eliminateCallFramePseudoInstr(
61 MachineFunction &MF, MachineBasicBlock &MBB,
62 MachineBasicBlock::iterator I) const {
63 llvm_unreachable("TODO: implement eliminateCallFramePseudoInstr");
64}
65
66void WebAssemblyFrameLowering::emitPrologue(MachineFunction &MF,
67 MachineBasicBlock &MBB) const {
JF Bastienb9073fb2015-07-22 21:28:15 +000068 // FIXME: Implement WebAssemblyFrameLowering::emitPrologue.
Dan Gohman10e730a2015-06-29 23:51:55 +000069}
70
71void WebAssemblyFrameLowering::emitEpilogue(MachineFunction &MF,
72 MachineBasicBlock &MBB) const {
73 llvm_unreachable("TODO: implement emitEpilogue");
74}