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"
19 
20 namespace llvm {
21 
22 class MachineBasicBlock;
23 class MachineInstr;
24 class MachineOperand;
25 class MCContext;
26 class MCSymbolWasm;
27 class StringRef;
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-related function names
74 extern const char *const ClangCallTerminateFn;
75 extern const char *const CxaBeginCatchFn;
76 extern const char *const CxaRethrowFn;
77 extern const char *const StdTerminateFn;
78 extern const char *const PersonalityWrapperFn;
79 
80 /// Returns the operand number of a callee, assuming the argument is a call
81 /// instruction.
83 
84 /// Returns the __indirect_function_table, for use in call_indirect and in
85 /// function bitcasts.
88  const WebAssemblySubtarget *Subtarget);
89 
90 /// Returns the __funcref_call_table, for use in funcref calls when lowered to
91 /// table.set + call_indirect.
94  const WebAssemblySubtarget *Subtarget);
95 
96 /// Find a catch instruction from an EH pad. Returns null if no catch
97 /// instruction found or the catch is in an invalid location.
99 
100 } // end namespace WebAssembly
101 
102 } // end namespace llvm
103 
104 #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:105
llvm
This file implements support for optimizing divisions by a constant.
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::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:100
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:39
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
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::MCSymbolWasm
Definition: MCSymbolWasm.h:16
llvm::WebAssembly::CxaRethrowFn
const char *const CxaRethrowFn
Definition: WebAssemblyUtilities.cpp:22
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:24
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:119
llvm::WebAssembly::isWasmVarAddressSpace
bool isWasmVarAddressSpace(unsigned AS)
Definition: WebAssemblyUtilities.h:50
DerivedTypes.h
llvm::WebAssembly::isValidAddressSpace
bool isValidAddressSpace(unsigned AS)
Definition: WebAssemblyUtilities.h:53