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/CodeGen/SelectionDAGNodes.h"
19#include "llvm/Support/CommandLine.h"
20
21namespace llvm {
22
23class MachineBasicBlock;
24class MachineInstr;
25class MachineOperand;
26class MCContext;
27class MCSymbolWasm;
28class MCRegisterClass;
29using TargetRegisterClass = MCRegisterClass;
30class WebAssemblyFunctionInfo;
31class WebAssemblySubtarget;
32class MachineSDNode;
33class SDLoc;
34class SelectionDAG;
35
36namespace WebAssembly {
37
38bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI);
39bool mayThrow(const MachineInstr &MI);
40
41// Exception-related function names
42extern const char *const ClangCallTerminateFn;
43extern const char *const CxaBeginCatchFn;
44extern const char *const CxaRethrowFn;
45extern const char *const StdTerminateFn;
46extern const char *const PersonalityWrapperFn;
47
48/// Returns the operand number of a callee, assuming the argument is a call
49/// instruction.
50const MachineOperand &getCalleeOp(const MachineInstr &MI);
51
52/// Returns the __indirect_function_table, for use in call_indirect and in
53/// function bitcasts.
54MCSymbolWasm *
55getOrCreateFunctionTableSymbol(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.
60MCSymbolWasm *
61getOrCreateFuncrefCallTableSymbol(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.
66MachineInstr *findCatch(MachineBasicBlock *EHPad);
67
68/// Returns the appropriate copy opcode for the given register class.
69unsigned getCopyOpcodeForRegClass(const TargetRegisterClass *RC);
70
71/// Returns true if multivalue returns of a function can be lowered directly,
72/// i.e., not indirectly via a pointer parameter that points to the value in
73/// memory.
74bool canLowerMultivalueReturn(const WebAssemblySubtarget *Subtarget);
75
76/// Returns true if the function's return value(s) can be lowered directly,
77/// i.e., not indirectly via a pointer parameter that points to the value in
78/// memory.
79bool canLowerReturn(size_t ResultSize, const WebAssemblySubtarget *Subtarget);
80
81// Get the TLS base value for the current target
82// If using libcall thread context, calls
83// __wasm_get_tls_base, otherwise, global.get __tls_base
84MachineSDNode *getTLSBase(SelectionDAG &DAG, const SDLoc &DL,
85 const WebAssemblySubtarget *Subtarget,
86 const SDValue Chain = SDValue());
87
88} // end namespace WebAssembly
89
90} // end namespace llvm
91
92#endif
93