1 //===-- WebAssemblyUtilities - WebAssembly Utility Functions ---*- C++ -*-====//
2 //
3 // 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
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file contains the declaration of the WebAssembly-specific
11 /// utility functions.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYUTILITIES_H
16 #define LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYUTILITIES_H
17 
18 #include "llvm/Support/CommandLine.h"
19 
20 namespace llvm {
21 
22 class MachineBasicBlock;
23 class MachineInstr;
24 class MachineOperand;
25 class MCContext;
26 class MCSymbolWasm;
27 class WebAssemblyFunctionInfo;
28 class WebAssemblySubtarget;
29 
30 namespace WebAssembly {
31 
32 bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI);
33 bool mayThrow(const MachineInstr &MI);
34 
35 // Exception handling / setjmp-longjmp handling command-line options
36 extern cl::opt<bool> WasmEnableEmEH;   // asm.js-style EH
37 extern cl::opt<bool> WasmEnableEmSjLj; // asm.js-style SjLJ
38 extern cl::opt<bool> WasmEnableEH;     // EH using Wasm EH instructions
39 extern cl::opt<bool> WasmEnableSjLj;   // SjLj using Wasm EH instructions
40 
41 // Exception-related function names
42 extern const char *const ClangCallTerminateFn;
43 extern const char *const CxaBeginCatchFn;
44 extern const char *const CxaRethrowFn;
45 extern const char *const StdTerminateFn;
46 extern const char *const PersonalityWrapperFn;
47 
48 /// Returns the operand number of a callee, assuming the argument is a call
49 /// instruction.
50 const MachineOperand &getCalleeOp(const MachineInstr &MI);
51 
52 /// Returns the __indirect_function_table, for use in call_indirect and in
53 /// function bitcasts.
54 MCSymbolWasm *
55 getOrCreateFunctionTableSymbol(MCContext &Ctx,
56                                const WebAssemblySubtarget *Subtarget);
57 
58 /// Returns the __funcref_call_table, for use in funcref calls when lowered to
59 /// table.set + call_indirect.
60 MCSymbolWasm *
61 getOrCreateFuncrefCallTableSymbol(MCContext &Ctx,
62                                   const WebAssemblySubtarget *Subtarget);
63 
64 /// Find a catch instruction from an EH pad. Returns null if no catch
65 /// instruction found or the catch is in an invalid location.
66 MachineInstr *findCatch(MachineBasicBlock *EHPad);
67 
68 } // end namespace WebAssembly
69 
70 } // end namespace llvm
71 
72 #endif
73