blob: 72dc945d53fa2d6dfba9a4fdb79692bafcc16e26 [file] [log] [blame]
Dan Gohman4fc4e422016-10-24 19:49:43 +00001//===-- WebAssemblyUtilities - WebAssembly Utility Functions ---*- C++ -*-====//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Gohman4fc4e422016-10-24 19:49:43 +00006//
7//===----------------------------------------------------------------------===//
8///
9/// \file
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000010/// This file contains the declaration of the WebAssembly-specific
Dan Gohman4fc4e422016-10-24 19:49:43 +000011/// utility functions.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYUTILITIES_H
16#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYUTILITIES_H
17
Heejin Ahn817811ca2018-06-19 00:32:03 +000018#include "llvm/CodeGen/MachineBasicBlock.h"
19
Dan Gohman4fc4e422016-10-24 19:49:43 +000020namespace llvm {
21
Dan Gohman4fc4e422016-10-24 19:49:43 +000022class WebAssemblyFunctionInfo;
23
24namespace WebAssembly {
25
26bool isArgument(const MachineInstr &MI);
27bool isCopy(const MachineInstr &MI);
28bool isTee(const MachineInstr &MI);
29bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI);
Heejin Ahn817811ca2018-06-19 00:32:03 +000030bool isCallDirect(const MachineInstr &MI);
Dan Gohmand934cb82017-02-24 23:18:00 +000031bool isCallIndirect(const MachineInstr &MI);
Heejin Ahn817811ca2018-06-19 00:32:03 +000032bool isMarker(const MachineInstr &MI);
33bool isThrow(const MachineInstr &MI);
34bool isRethrow(const MachineInstr &MI);
35bool isCatch(const MachineInstr &MI);
36bool mayThrow(const MachineInstr &MI);
37
38/// Returns the operand number of a callee, assuming the argument is a call
39/// instruction.
40unsigned getCalleeOpNo(const MachineInstr &MI);
41
42/// Returns if the given BB is a single BB terminate pad which starts with a
43/// 'catch' instruction.
44bool isCatchTerminatePad(const MachineBasicBlock &MBB);
45/// Returns if the given BB is a single BB terminate pad which starts with a
46/// 'catch_all' insrtruction.
47bool isCatchAllTerminatePad(const MachineBasicBlock &MBB);
48
49// Exception-related function names
50extern const char *const ClangCallTerminateFn;
51extern const char *const CxaBeginCatchFn;
52extern const char *const CxaRethrowFn;
53extern const char *const StdTerminateFn;
54extern 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.
59template <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 Gohman4fc4e422016-10-24 19:49:43 +000066
67} // end namespace WebAssembly
Dan Gohmanf52ee172017-02-27 22:38:58 +000068
Dan Gohman4fc4e422016-10-24 19:49:43 +000069} // end namespace llvm
70
71#endif