blob: cdb7873e9013bd900d70a26813d1865416311400 [file] [log] [blame]
Dan Gohman4fc4e422016-10-24 19:49:43 +00001//===-- 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 Prantl5f8f34e42018-05-01 15:54:18 +000011/// This file contains the declaration of the WebAssembly-specific
Dan Gohman4fc4e422016-10-24 19:49:43 +000012/// utility functions.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYUTILITIES_H
17#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYUTILITIES_H
18
Heejin Ahn817811ca2018-06-19 00:32:03 +000019#include "llvm/CodeGen/MachineBasicBlock.h"
20
Dan Gohman4fc4e422016-10-24 19:49:43 +000021namespace llvm {
22
Dan Gohman4fc4e422016-10-24 19:49:43 +000023class WebAssemblyFunctionInfo;
24
25namespace WebAssembly {
26
27bool isArgument(const MachineInstr &MI);
28bool isCopy(const MachineInstr &MI);
29bool isTee(const MachineInstr &MI);
30bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI);
Heejin Ahn817811ca2018-06-19 00:32:03 +000031bool isCallDirect(const MachineInstr &MI);
Dan Gohmand934cb82017-02-24 23:18:00 +000032bool isCallIndirect(const MachineInstr &MI);
Heejin Ahn817811ca2018-06-19 00:32:03 +000033bool isMarker(const MachineInstr &MI);
34bool isThrow(const MachineInstr &MI);
35bool isRethrow(const MachineInstr &MI);
36bool isCatch(const MachineInstr &MI);
37bool mayThrow(const MachineInstr &MI);
38
39/// Returns the operand number of a callee, assuming the argument is a call
40/// instruction.
41unsigned getCalleeOpNo(const MachineInstr &MI);
42
43/// Returns if the given BB is a single BB terminate pad which starts with a
44/// 'catch' instruction.
45bool isCatchTerminatePad(const MachineBasicBlock &MBB);
46/// Returns if the given BB is a single BB terminate pad which starts with a
47/// 'catch_all' insrtruction.
48bool isCatchAllTerminatePad(const MachineBasicBlock &MBB);
49
50// Exception-related function names
51extern const char *const ClangCallTerminateFn;
52extern const char *const CxaBeginCatchFn;
53extern const char *const CxaRethrowFn;
54extern const char *const StdTerminateFn;
55extern 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.
60template <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 Gohman4fc4e422016-10-24 19:49:43 +000067
68} // end namespace WebAssembly
Dan Gohmanf52ee172017-02-27 22:38:58 +000069
Dan Gohman4fc4e422016-10-24 19:49:43 +000070} // end namespace llvm
71
72#endif