| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 1 | // WebAssemblyFrameLowering.h - TargetFrameLowering for WebAssembly -*- C++ -*-/ | 
|  | 2 | // | 
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 6 | // | 
|  | 7 | //===----------------------------------------------------------------------===// | 
|  | 8 | /// | 
|  | 9 | /// \file | 
| Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 10 | /// This class implements WebAssembly-specific bits of | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 11 | /// TargetFrameLowering class. | 
|  | 12 | /// | 
|  | 13 | //===----------------------------------------------------------------------===// | 
|  | 14 |  | 
|  | 15 | #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H | 
|  | 16 | #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYFRAMELOWERING_H | 
|  | 17 |  | 
| David Blaikie | 1be62f0 | 2017-11-03 22:32:11 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/TargetFrameLowering.h" | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 19 |  | 
|  | 20 | namespace llvm { | 
| Derek Schuff | 4b3bb21 | 2016-02-23 18:13:07 +0000 | [diff] [blame] | 21 | class MachineFrameInfo; | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 22 |  | 
|  | 23 | class WebAssemblyFrameLowering final : public TargetFrameLowering { | 
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 24 | public: | 
| Derek Schuff | 770bdfe | 2016-02-23 18:17:46 +0000 | [diff] [blame] | 25 | /// Size of the red zone for the user stack (leaf functions can use this much | 
| Heejin Ahn | c4df1d1 | 2018-08-22 00:20:02 +0000 | [diff] [blame] | 26 | /// space below the stack pointer without writing it back to __stack_pointer | 
|  | 27 | /// global). | 
| Derek Schuff | 770bdfe | 2016-02-23 18:17:46 +0000 | [diff] [blame] | 28 | // TODO: (ABI) Revisit and decide how large it should be. | 
| Derek Schuff | 4b3bb21 | 2016-02-23 18:13:07 +0000 | [diff] [blame] | 29 | static const size_t RedZoneSize = 128; | 
|  | 30 |  | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 31 | WebAssemblyFrameLowering() | 
|  | 32 | : TargetFrameLowering(StackGrowsDown, /*StackAlignment=*/16, | 
|  | 33 | /*LocalAreaOffset=*/0, | 
|  | 34 | /*TransientStackAlignment=*/16, | 
|  | 35 | /*StackRealignable=*/true) {} | 
|  | 36 |  | 
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 37 | MachineBasicBlock::iterator | 
|  | 38 | eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, | 
|  | 39 | MachineBasicBlock::iterator I) const override; | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 40 |  | 
|  | 41 | /// These methods insert prolog and epilog code into the function. | 
|  | 42 | void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; | 
|  | 43 | void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; | 
|  | 44 |  | 
|  | 45 | bool hasFP(const MachineFunction &MF) const override; | 
|  | 46 | bool hasReservedCallFrame(const MachineFunction &MF) const override; | 
| Derek Schuff | 4b3bb21 | 2016-02-23 18:13:07 +0000 | [diff] [blame] | 47 |  | 
| Heejin Ahn | 78d1910 | 2018-08-21 21:23:07 +0000 | [diff] [blame] | 48 | bool needsPrologForEH(const MachineFunction &MF) const; | 
|  | 49 |  | 
|  | 50 | /// Write SP back to __stack_pointer global. | 
|  | 51 | void writeSPToGlobal(unsigned SrcReg, MachineFunction &MF, | 
|  | 52 | MachineBasicBlock &MBB, | 
|  | 53 | MachineBasicBlock::iterator &InsertStore, | 
|  | 54 | const DebugLoc &DL) const; | 
|  | 55 |  | 
|  | 56 | private: | 
| Derek Schuff | 0d41b7b | 2016-11-07 22:00:48 +0000 | [diff] [blame] | 57 | bool hasBP(const MachineFunction &MF) const; | 
| Heejin Ahn | 972fc35 | 2018-08-22 21:13:49 +0000 | [diff] [blame] | 58 | bool needsSPForLocalFrame(const MachineFunction &MF) const; | 
| Heejin Ahn | bc6d897 | 2018-08-22 18:53:48 +0000 | [diff] [blame] | 59 | bool needsSP(const MachineFunction &MF) const; | 
|  | 60 | bool needsSPWriteback(const MachineFunction &MF) const; | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 61 | }; | 
|  | 62 |  | 
| Heejin Ahn | f208f63 | 2018-09-05 01:27:38 +0000 | [diff] [blame] | 63 | } // end namespace llvm | 
| Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 64 |  | 
|  | 65 | #endif |