WebAssembly: basic bitcode → assembly CodeGen test
[oota-llvm.git] / lib / Target / WebAssembly / WebAssemblyFrameLowering.cpp
1 //===-- 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"
33 using namespace llvm;
34
35 #define DEBUG_TYPE "wasm-frame-info"
36
37 // TODO: Implement a red zone?
38
39 /// Return true if the specified function should have a dedicated frame pointer
40 /// register.
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);
48 }
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.
55 bool WebAssemblyFrameLowering::hasReservedCallFrame(
56     const MachineFunction &MF) const {
57   return !MF.getFrameInfo()->hasVarSizedObjects();
58 }
59
60 void WebAssemblyFrameLowering::eliminateCallFramePseudoInstr(
61     MachineFunction &MF, MachineBasicBlock &MBB,
62     MachineBasicBlock::iterator I) const {
63   llvm_unreachable("TODO: implement eliminateCallFramePseudoInstr");
64 }
65
66 void WebAssemblyFrameLowering::emitPrologue(MachineFunction &MF,
67                                             MachineBasicBlock &MBB) const {
68   // FIXME: Implement WebAssemblyFrameLowering::emitPrologue.
69 }
70
71 void WebAssemblyFrameLowering::emitEpilogue(MachineFunction &MF,
72                                             MachineBasicBlock &MBB) const {
73   llvm_unreachable("TODO: implement emitEpilogue");
74 }