173471bf0Spatrick //===-- WebAssemblyUtilities - WebAssembly Utility Functions ---*- C++ -*-====//
273471bf0Spatrick //
373471bf0Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
473471bf0Spatrick // See https://llvm.org/LICENSE.txt for license information.
573471bf0Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
673471bf0Spatrick //
773471bf0Spatrick //===----------------------------------------------------------------------===//
873471bf0Spatrick ///
973471bf0Spatrick /// \file
1073471bf0Spatrick /// This file contains the declaration of the WebAssembly-specific
1173471bf0Spatrick /// utility functions.
1273471bf0Spatrick ///
1373471bf0Spatrick //===----------------------------------------------------------------------===//
1473471bf0Spatrick 
1573471bf0Spatrick #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYUTILITIES_H
1673471bf0Spatrick #define LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYUTILITIES_H
1773471bf0Spatrick 
18*d415bd75Srobert #include "llvm/Support/CommandLine.h"
19*d415bd75Srobert 
2073471bf0Spatrick namespace llvm {
2173471bf0Spatrick 
2273471bf0Spatrick class MachineBasicBlock;
2373471bf0Spatrick class MachineInstr;
2473471bf0Spatrick class MachineOperand;
2573471bf0Spatrick class MCContext;
2673471bf0Spatrick class MCSymbolWasm;
27*d415bd75Srobert class TargetRegisterClass;
2873471bf0Spatrick class WebAssemblyFunctionInfo;
2973471bf0Spatrick class WebAssemblySubtarget;
3073471bf0Spatrick 
3173471bf0Spatrick namespace WebAssembly {
3273471bf0Spatrick 
3373471bf0Spatrick bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI);
3473471bf0Spatrick bool mayThrow(const MachineInstr &MI);
3573471bf0Spatrick 
36*d415bd75Srobert // Exception handling / setjmp-longjmp handling command-line options
37*d415bd75Srobert extern cl::opt<bool> WasmEnableEmEH;   // asm.js-style EH
38*d415bd75Srobert extern cl::opt<bool> WasmEnableEmSjLj; // asm.js-style SjLJ
39*d415bd75Srobert extern cl::opt<bool> WasmEnableEH;     // EH using Wasm EH instructions
40*d415bd75Srobert extern cl::opt<bool> WasmEnableSjLj;   // SjLj using Wasm EH instructions
41*d415bd75Srobert 
4273471bf0Spatrick // Exception-related function names
4373471bf0Spatrick extern const char *const ClangCallTerminateFn;
4473471bf0Spatrick extern const char *const CxaBeginCatchFn;
4573471bf0Spatrick extern const char *const CxaRethrowFn;
4673471bf0Spatrick extern const char *const StdTerminateFn;
4773471bf0Spatrick extern const char *const PersonalityWrapperFn;
4873471bf0Spatrick 
4973471bf0Spatrick /// Returns the operand number of a callee, assuming the argument is a call
5073471bf0Spatrick /// instruction.
5173471bf0Spatrick const MachineOperand &getCalleeOp(const MachineInstr &MI);
5273471bf0Spatrick 
5373471bf0Spatrick /// Returns the __indirect_function_table, for use in call_indirect and in
5473471bf0Spatrick /// function bitcasts.
5573471bf0Spatrick MCSymbolWasm *
5673471bf0Spatrick getOrCreateFunctionTableSymbol(MCContext &Ctx,
5773471bf0Spatrick                                const WebAssemblySubtarget *Subtarget);
5873471bf0Spatrick 
5973471bf0Spatrick /// Returns the __funcref_call_table, for use in funcref calls when lowered to
6073471bf0Spatrick /// table.set + call_indirect.
6173471bf0Spatrick MCSymbolWasm *
6273471bf0Spatrick getOrCreateFuncrefCallTableSymbol(MCContext &Ctx,
6373471bf0Spatrick                                   const WebAssemblySubtarget *Subtarget);
6473471bf0Spatrick 
6573471bf0Spatrick /// Find a catch instruction from an EH pad. Returns null if no catch
6673471bf0Spatrick /// instruction found or the catch is in an invalid location.
6773471bf0Spatrick MachineInstr *findCatch(MachineBasicBlock *EHPad);
6873471bf0Spatrick 
69*d415bd75Srobert /// Returns the appropriate copy opcode for the given register class.
70*d415bd75Srobert unsigned getCopyOpcodeForRegClass(const TargetRegisterClass *RC);
71*d415bd75Srobert 
7273471bf0Spatrick } // end namespace WebAssembly
7373471bf0Spatrick 
7473471bf0Spatrick } // end namespace llvm
7573471bf0Spatrick 
7673471bf0Spatrick #endif
77