LLVM  17.0.0git
WebAssemblyUtilities.h
Go to the documentation of this file.
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 
19 
20 namespace llvm {
21 
22 class MachineBasicBlock;
23 class MachineInstr;
24 class MachineOperand;
25 class MCContext;
26 class MCSymbolWasm;
27 class TargetRegisterClass;
28 class WebAssemblyFunctionInfo;
29 class WebAssemblySubtarget;
30 
31 namespace WebAssembly {
32 
33 bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI);
34 bool mayThrow(const MachineInstr &MI);
35 
36 // Exception handling / setjmp-longjmp handling command-line options
37 extern cl::opt<bool> WasmEnableEmEH; // asm.js-style EH
38 extern cl::opt<bool> WasmEnableEmSjLj; // asm.js-style SjLJ
39 extern cl::opt<bool> WasmEnableEH; // EH using Wasm EH instructions
40 extern cl::opt<bool> WasmEnableSjLj; // SjLj using Wasm EH instructions
41 
42 // Exception-related function names
43 extern const char *const ClangCallTerminateFn;
44 extern const char *const CxaBeginCatchFn;
45 extern const char *const CxaRethrowFn;
46 extern const char *const StdTerminateFn;
47 extern const char *const PersonalityWrapperFn;
48 
49 /// Returns the operand number of a callee, assuming the argument is a call
50 /// instruction.
51 const MachineOperand &getCalleeOp(const MachineInstr &MI);
52 
53 /// Returns the __indirect_function_table, for use in call_indirect and in
54 /// function bitcasts.
55 MCSymbolWasm *
56 getOrCreateFunctionTableSymbol(MCContext &Ctx,
57  const WebAssemblySubtarget *Subtarget);
58 
59 /// Returns the __funcref_call_table, for use in funcref calls when lowered to
60 /// table.set + call_indirect.
61 MCSymbolWasm *
63  const WebAssemblySubtarget *Subtarget);
64 
65 /// Find a catch instruction from an EH pad. Returns null if no catch
66 /// instruction found or the catch is in an invalid location.
67 MachineInstr *findCatch(MachineBasicBlock *EHPad);
68 
69 /// Returns the appropriate copy opcode for the given register class.
70 unsigned getCopyOpcodeForRegClass(const TargetRegisterClass *RC);
71 
72 } // end namespace WebAssembly
73 
74 } // end namespace llvm
75 
76 #endif
llvm::WebAssembly::isChild
bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI)
Test whether MI is a child of some other node in an expression tree.
Definition: WebAssemblyUtilities.cpp:53
llvm::WebAssembly::getCalleeOp
const MachineOperand & getCalleeOp(const MachineInstr &MI)
Returns the operand number of a callee, assuming the argument is a call instruction.
Definition: WebAssemblyUtilities.cpp:108
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:109
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::WebAssembly::findCatch
MachineInstr * findCatch(MachineBasicBlock *EHPad)
Find a catch instruction from an EH pad.
Definition: WebAssemblyUtilities.cpp:170
llvm::WebAssembly::getOrCreateFunctionTableSymbol
MCSymbolWasm * getOrCreateFunctionTableSymbol(MCContext &Ctx, const WebAssemblySubtarget *Subtarget)
Returns the __indirect_function_table, for use in call_indirect and in function bitcasts.
Definition: WebAssemblyUtilities.cpp:125
llvm::WebAssembly::mayThrow
bool mayThrow(const MachineInstr &MI)
Definition: WebAssemblyUtilities.cpp:64
CommandLine.h
llvm::WebAssembly::WasmEnableEmSjLj
cl::opt< bool > WasmEnableEmSjLj
llvm::WebAssembly::getCopyOpcodeForRegClass
unsigned getCopyOpcodeForRegClass(const TargetRegisterClass *RC)
Returns the appropriate copy opcode for the given register class.
Definition: WebAssemblyUtilities.cpp:183
llvm::WebAssembly::StdTerminateFn
const char *const StdTerminateFn
Definition: WebAssemblyUtilities.cpp:48
llvm::WebAssembly::CxaBeginCatchFn
const char *const CxaBeginCatchFn
Definition: WebAssemblyUtilities.cpp:46
llvm::WebAssembly::CxaRethrowFn
const char *const CxaRethrowFn
Definition: WebAssemblyUtilities.cpp:47
llvm::WebAssembly::WasmEnableSjLj
cl::opt< bool > WasmEnableSjLj
llvm::WebAssembly::ClangCallTerminateFn
const char *const ClangCallTerminateFn
llvm::WebAssembly::PersonalityWrapperFn
const char *const PersonalityWrapperFn
Definition: WebAssemblyUtilities.cpp:49
llvm::WebAssembly::WasmEnableEH
cl::opt< bool > WasmEnableEH
llvm::WebAssembly::getOrCreateFuncrefCallTableSymbol
MCSymbolWasm * getOrCreateFuncrefCallTableSymbol(MCContext &Ctx, const WebAssemblySubtarget *Subtarget)
Returns the __funcref_call_table, for use in funcref calls when lowered to table.set + call_indirect.
Definition: WebAssemblyUtilities.cpp:144
llvm::WebAssembly::WasmEnableEmEH
cl::opt< bool > WasmEnableEmEH