blob: f80b49662ea64215293ab472815d11f8e1ded71d [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);
Heejin Ahn817811ca2018-06-19 00:32:03 +000033bool mayThrow(const MachineInstr &MI);
34
35/// Returns the operand number of a callee, assuming the argument is a call
36/// instruction.
37unsigned getCalleeOpNo(const MachineInstr &MI);
38
Heejin Ahn817811ca2018-06-19 00:32:03 +000039// Exception-related function names
40extern const char *const ClangCallTerminateFn;
41extern const char *const CxaBeginCatchFn;
42extern const char *const CxaRethrowFn;
43extern const char *const StdTerminateFn;
44extern const char *const PersonalityWrapperFn;
45
46/// Return the "bottom" block of an entity, which can be either a MachineLoop or
47/// WebAssemblyException. This differs from MachineLoop::getBottomBlock in that
48/// it works even if the entity is discontiguous.
49template <typename T> MachineBasicBlock *getBottom(const T *Unit) {
50 MachineBasicBlock *Bottom = Unit->getHeader();
51 for (MachineBasicBlock *MBB : Unit->blocks())
52 if (MBB->getNumber() > Bottom->getNumber())
53 Bottom = MBB;
54 return Bottom;
55}
Dan Gohman4fc4e422016-10-24 19:49:43 +000056
57} // end namespace WebAssembly
Dan Gohmanf52ee172017-02-27 22:38:58 +000058
Dan Gohman4fc4e422016-10-24 19:49:43 +000059} // end namespace llvm
60
61#endif