1 //===-- WebAssemblyUtilities - WebAssembly Utility Functions ---*- C++ -*-====//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// This file contains the declaration of the WebAssembly-specific
12 /// utility functions.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYUTILITIES_H
17 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYUTILITIES_H
19 #include "llvm/CodeGen/MachineBasicBlock.h"
23 class WebAssemblyFunctionInfo;
25 namespace WebAssembly {
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);
31 bool isCallDirect(const MachineInstr &MI);
32 bool isCallIndirect(const MachineInstr &MI);
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);
39 /// Returns the operand number of a callee, assuming the argument is a call
41 unsigned getCalleeOpNo(const MachineInstr &MI);
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);
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;
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())
68 } // end namespace WebAssembly
70 } // end namespace llvm