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 #include "llvm/IR/DerivedTypes.h"
20 
21 namespace llvm {
22 
23 class MachineBasicBlock;
24 class MachineInstr;
25 class MachineOperand;
26 class MCContext;
27 class MCSymbolWasm;
28 class WebAssemblyFunctionInfo;
29 class WebAssemblySubtarget;
30 
31 namespace WebAssembly {
32 
33 enum WasmAddressSpace : unsigned {
34  // Default address space, for pointers to linear memory (stack, heap, data).
36  // A non-integral address space for pointers to named objects outside of
37  // linear memory: WebAssembly globals or WebAssembly locals. Loads and stores
38  // to these pointers are lowered to global.get / global.set or local.get /
39  // local.set, as appropriate.
41  // A non-integral address space for externref values
43  // A non-integral address space for funcref values
45 };
46 
47 inline bool isDefaultAddressSpace(unsigned AS) {
48  return AS == WASM_ADDRESS_SPACE_DEFAULT;
49 }
50 inline bool isWasmVarAddressSpace(unsigned AS) {
51  return AS == WASM_ADDRESS_SPACE_VAR;
52 }
53 inline bool isValidAddressSpace(unsigned AS) {
55 }
56 inline bool isFuncrefType(const Type *Ty) {
57  return isa<PointerType>(Ty) &&
58  Ty->getPointerAddressSpace() ==
60 }
61 inline bool isExternrefType(const Type *Ty) {
62  return isa<PointerType>(Ty) &&
63  Ty->getPointerAddressSpace() ==
65 }
66 inline bool isRefType(const Type *Ty) {
67  return isFuncrefType(Ty) || isExternrefType(Ty);
68 }
69 
70 bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI);
71 bool mayThrow(const MachineInstr &MI);
72 
73 // Exception handling / setjmp-longjmp handling command-line options
74 extern cl::opt<bool> WasmEnableEmEH; // asm.js-style EH
75 extern cl::opt<bool> WasmEnableEmSjLj; // asm.js-style SjLJ
76 extern cl::opt<bool> WasmEnableEH; // EH using Wasm EH instructions
77 extern cl::opt<bool> WasmEnableSjLj; // SjLj using Wasm EH instructions
78 
79 // Exception-related function names
80 extern const char *const ClangCallTerminateFn;
81 extern const char *const CxaBeginCatchFn;
82 extern const char *const CxaRethrowFn;
83 extern const char *const StdTerminateFn;
84 extern const char *const PersonalityWrapperFn;
85 
86 /// Returns the operand number of a callee, assuming the argument is a call
87 /// instruction.
89 
90 /// Returns the __indirect_function_table, for use in call_indirect and in
91 /// function bitcasts.
94  const WebAssemblySubtarget *Subtarget);
95 
96 /// Returns the __funcref_call_table, for use in funcref calls when lowered to
97 /// table.set + call_indirect.
100  const WebAssemblySubtarget *Subtarget);
101 
102 /// Find a catch instruction from an EH pad. Returns null if no catch
103 /// instruction found or the catch is in an invalid location.
105 
106 } // end namespace WebAssembly
107 
108 } // end namespace llvm
109 
110 #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:105
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::WebAssembly::findCatch
MachineInstr * findCatch(MachineBasicBlock *EHPad)
Find a catch instruction from an EH pad.
Definition: WebAssemblyUtilities.cpp:170
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
llvm::WebAssembly::isExternrefType
bool isExternrefType(const Type *Ty)
Definition: WebAssemblyUtilities.h:61
llvm::WebAssembly::WASM_ADDRESS_SPACE_FUNCREF
@ WASM_ADDRESS_SPACE_FUNCREF
Definition: WebAssemblyUtilities.h:44
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::isFuncrefType
bool isFuncrefType(const Type *Ty)
Definition: WebAssemblyUtilities.h:56
llvm::Type::getPointerAddressSpace
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:734
llvm::WebAssembly::mayThrow
bool mayThrow(const MachineInstr &MI)
Definition: WebAssemblyUtilities.cpp:64
llvm::WebAssembly::WasmAddressSpace
WasmAddressSpace
Definition: WebAssemblyUtilities.h:33
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::WebAssembly::WASM_ADDRESS_SPACE_EXTERNREF
@ WASM_ADDRESS_SPACE_EXTERNREF
Definition: WebAssemblyUtilities.h:42
llvm::WebAssembly::isDefaultAddressSpace
bool isDefaultAddressSpace(unsigned AS)
Definition: WebAssemblyUtilities.h:47
CommandLine.h
llvm::WebAssembly::WasmEnableEmSjLj
cl::opt< bool > WasmEnableEmSjLj
llvm::MachineOperand
MachineOperand class - Representation of each machine instruction operand.
Definition: MachineOperand.h:49
llvm::WebAssembly::StdTerminateFn
const char *const StdTerminateFn
Definition: WebAssemblyUtilities.cpp:48
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::WebAssembly::CxaBeginCatchFn
const char *const CxaBeginCatchFn
Definition: WebAssemblyUtilities.cpp:46
llvm::cl::opt< bool >
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::MCSymbolWasm
Definition: MCSymbolWasm.h:16
llvm::WebAssembly::CxaRethrowFn
const char *const CxaRethrowFn
Definition: WebAssemblyUtilities.cpp:47
llvm::WebAssembly::WasmEnableSjLj
cl::opt< bool > WasmEnableSjLj
llvm::WebAssembly::WASM_ADDRESS_SPACE_VAR
@ WASM_ADDRESS_SPACE_VAR
Definition: WebAssemblyUtilities.h:40
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::WebAssembly::isRefType
bool isRefType(const Type *Ty)
Definition: WebAssemblyUtilities.h:66
llvm::WebAssemblySubtarget
Definition: WebAssemblySubtarget.h:35
llvm::WebAssembly::PersonalityWrapperFn
const char *const PersonalityWrapperFn
Definition: WebAssemblyUtilities.cpp:49
llvm::WebAssembly::WasmEnableEH
cl::opt< bool > WasmEnableEH
llvm::WebAssembly::WASM_ADDRESS_SPACE_DEFAULT
@ WASM_ADDRESS_SPACE_DEFAULT
Definition: WebAssemblyUtilities.h:35
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::isWasmVarAddressSpace
bool isWasmVarAddressSpace(unsigned AS)
Definition: WebAssemblyUtilities.h:50
DerivedTypes.h
llvm::WebAssembly::isValidAddressSpace
bool isValidAddressSpace(unsigned AS)
Definition: WebAssemblyUtilities.h:53
llvm::WebAssembly::WasmEnableEmEH
cl::opt< bool > WasmEnableEmEH