Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 1 | //===-- WebAssemblyUtilities - WebAssembly Utility Functions ---*- 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 | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 10 | /// This file contains the declaration of the WebAssembly-specific |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 11 | /// utility functions. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYUTILITIES_H |
| 16 | #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYUTILITIES_H |
| 17 | |
Heejin Ahn | 817811ca | 2018-06-19 00:32:03 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 19 | |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 20 | namespace llvm { |
| 21 | |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 22 | class WebAssemblyFunctionInfo; |
| 23 | |
| 24 | namespace WebAssembly { |
| 25 | |
| 26 | bool isArgument(const MachineInstr &MI); |
| 27 | bool isCopy(const MachineInstr &MI); |
| 28 | bool isTee(const MachineInstr &MI); |
| 29 | bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI); |
Heejin Ahn | 817811ca | 2018-06-19 00:32:03 +0000 | [diff] [blame] | 30 | bool isCallDirect(const MachineInstr &MI); |
Dan Gohman | d934cb8 | 2017-02-24 23:18:00 +0000 | [diff] [blame] | 31 | bool isCallIndirect(const MachineInstr &MI); |
Heejin Ahn | 817811ca | 2018-06-19 00:32:03 +0000 | [diff] [blame] | 32 | bool isMarker(const MachineInstr &MI); |
| 33 | bool isThrow(const MachineInstr &MI); |
| 34 | bool isRethrow(const MachineInstr &MI); |
| 35 | bool isCatch(const MachineInstr &MI); |
| 36 | bool mayThrow(const MachineInstr &MI); |
| 37 | |
| 38 | /// Returns the operand number of a callee, assuming the argument is a call |
| 39 | /// instruction. |
| 40 | unsigned getCalleeOpNo(const MachineInstr &MI); |
| 41 | |
| 42 | /// Returns if the given BB is a single BB terminate pad which starts with a |
| 43 | /// 'catch' instruction. |
| 44 | bool isCatchTerminatePad(const MachineBasicBlock &MBB); |
| 45 | /// Returns if the given BB is a single BB terminate pad which starts with a |
| 46 | /// 'catch_all' insrtruction. |
| 47 | bool isCatchAllTerminatePad(const MachineBasicBlock &MBB); |
| 48 | |
| 49 | // Exception-related function names |
| 50 | extern const char *const ClangCallTerminateFn; |
| 51 | extern const char *const CxaBeginCatchFn; |
| 52 | extern const char *const CxaRethrowFn; |
| 53 | extern const char *const StdTerminateFn; |
| 54 | extern const char *const PersonalityWrapperFn; |
| 55 | |
| 56 | /// Return the "bottom" block of an entity, which can be either a MachineLoop or |
| 57 | /// WebAssemblyException. This differs from MachineLoop::getBottomBlock in that |
| 58 | /// it works even if the entity is discontiguous. |
| 59 | template <typename T> MachineBasicBlock *getBottom(const T *Unit) { |
| 60 | MachineBasicBlock *Bottom = Unit->getHeader(); |
| 61 | for (MachineBasicBlock *MBB : Unit->blocks()) |
| 62 | if (MBB->getNumber() > Bottom->getNumber()) |
| 63 | Bottom = MBB; |
| 64 | return Bottom; |
| 65 | } |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 66 | |
| 67 | } // end namespace WebAssembly |
Dan Gohman | f52ee17 | 2017-02-27 22:38:58 +0000 | [diff] [blame] | 68 | |
Dan Gohman | 4fc4e42 | 2016-10-24 19:49:43 +0000 | [diff] [blame] | 69 | } // end namespace llvm |
| 70 | |
| 71 | #endif |