LLVM  14.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 
18 namespace llvm {
19 
20 class MachineBasicBlock;
21 class MachineInstr;
22 class MachineOperand;
23 class MCContext;
24 class MCSymbolWasm;
25 class StringRef;
26 class WebAssemblyFunctionInfo;
27 class WebAssemblySubtarget;
28 
29 namespace WebAssembly {
30 
31 enum WasmAddressSpace : unsigned {
32  // Default address space, for pointers to linear memory (stack, heap, data).
34  // A non-integral address space for pointers to named objects outside of
35  // linear memory: WebAssembly globals or WebAssembly locals. Loads and stores
36  // to these pointers are lowered to global.get / global.set or local.get /
37  // local.set, as appropriate.
39 };
40 
41 inline bool isDefaultAddressSpace(unsigned AS) {
42  return AS == WASM_ADDRESS_SPACE_DEFAULT;
43 }
44 inline bool isWasmVarAddressSpace(unsigned AS) {
45  return AS == WASM_ADDRESS_SPACE_WASM_VAR;
46 }
47 inline bool isValidAddressSpace(unsigned AS) {
49 }
50 
51 bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI);
52 bool mayThrow(const MachineInstr &MI);
53 
54 // Exception-related function names
55 extern const char *const ClangCallTerminateFn;
56 extern const char *const CxaBeginCatchFn;
57 extern const char *const CxaRethrowFn;
58 extern const char *const StdTerminateFn;
59 extern const char *const PersonalityWrapperFn;
60 
61 /// Returns the operand number of a callee, assuming the argument is a call
62 /// instruction.
64 
65 /// Returns the __indirect_function_table, for use in call_indirect and in
66 /// function bitcasts.
69  const WebAssemblySubtarget *Subtarget);
70 
71 /// Returns the __funcref_call_table, for use in funcref calls when lowered to
72 /// table.set + call_indirect.
75  const WebAssemblySubtarget *Subtarget);
76 
77 /// Find a catch instruction from an EH pad. Returns null if no catch
78 /// instruction found or the catch is in an invalid location.
80 
81 } // end namespace WebAssembly
82 
83 } // end namespace llvm
84 
85 #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:28
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:83
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:102
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::WebAssembly::findCatch
MachineInstr * findCatch(MachineBasicBlock *EHPad)
Find a catch instruction from an EH pad.
Definition: WebAssemblyUtilities.cpp:145
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
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:100
llvm::WebAssembly::mayThrow
bool mayThrow(const MachineInstr &MI)
Definition: WebAssemblyUtilities.cpp:39
llvm::WebAssembly::WasmAddressSpace
WasmAddressSpace
Definition: WebAssemblyUtilities.h:31
llvm::WebAssembly::isDefaultAddressSpace
bool isDefaultAddressSpace(unsigned AS)
Definition: WebAssemblyUtilities.h:41
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::WebAssembly::StdTerminateFn
const char *const StdTerminateFn
Definition: WebAssemblyUtilities.cpp:23
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::WebAssembly::CxaBeginCatchFn
const char *const CxaBeginCatchFn
Definition: WebAssemblyUtilities.cpp:21
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::WebAssembly::WASM_ADDRESS_SPACE_WASM_VAR
@ WASM_ADDRESS_SPACE_WASM_VAR
Definition: WebAssemblyUtilities.h:38
llvm::MCSymbolWasm
Definition: MCSymbolWasm.h:16
llvm::WebAssembly::CxaRethrowFn
const char *const CxaRethrowFn
Definition: WebAssemblyUtilities.cpp:22
llvm::WebAssembly::ClangCallTerminateFn
const char *const ClangCallTerminateFn
llvm::WebAssemblyFunctionInfo
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
Definition: WebAssemblyMachineFunctionInfo.h:33
llvm::WebAssemblySubtarget
Definition: WebAssemblySubtarget.h:35
llvm::WebAssembly::PersonalityWrapperFn
const char *const PersonalityWrapperFn
Definition: WebAssemblyUtilities.cpp:24
llvm::WebAssembly::WASM_ADDRESS_SPACE_DEFAULT
@ WASM_ADDRESS_SPACE_DEFAULT
Definition: WebAssemblyUtilities.h:33
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:119
llvm::WebAssembly::isWasmVarAddressSpace
bool isWasmVarAddressSpace(unsigned AS)
Definition: WebAssemblyUtilities.h:44
llvm::WebAssembly::isValidAddressSpace
bool isValidAddressSpace(unsigned AS)
Definition: WebAssemblyUtilities.h:47