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