LLVM 17.0.0git
WebAssemblyTypeUtilities.h
Go to the documentation of this file.
1//===-- WebAssemblyTypeUtilities - WebAssembly Type Utilities---*- 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 type parsing
11/// utility functions.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYTYPEUTILITIES_H
16#define LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYTYPEUTILITIES_H
17
22
23namespace llvm {
24
25class TargetRegisterClass;
26
27namespace WebAssembly {
28
29/// Used as immediate MachineOperands for block signatures
30enum class BlockType : unsigned {
31 Invalid = 0x00,
32 Void = 0x40,
40 // Multivalue blocks (and other non-void blocks) are only emitted when the
41 // blocks will never be exited and are at the ends of functions (see
42 // WebAssemblyCFGStackify::fixEndsAtEndOfFunction). They also are never made
43 // to pop values off the stack, so the exact multivalue signature can always
44 // be inferred from the return type of the parent function in MCInstLower.
45 Multivalue = 0xffff,
46};
47
48enum WasmAddressSpace : unsigned {
49 // Default address space, for pointers to linear memory (stack, heap, data).
51 // A non-integral address space for pointers to named objects outside of
52 // linear memory: WebAssembly globals or WebAssembly locals. Loads and stores
53 // to these pointers are lowered to global.get / global.set or local.get /
54 // local.set, as appropriate.
56 // A non-integral address space for externref values
58 // A non-integral address space for funcref values
60};
61
62inline bool isDefaultAddressSpace(unsigned AS) {
63 return AS == WASM_ADDRESS_SPACE_DEFAULT;
64}
65inline bool isWasmVarAddressSpace(unsigned AS) {
66 return AS == WASM_ADDRESS_SPACE_VAR;
67}
68inline bool isValidAddressSpace(unsigned AS) {
70}
71inline bool isFuncrefType(const Type *Ty) {
72 return isa<PointerType>(Ty) &&
75}
76inline bool isExternrefType(const Type *Ty) {
77 return isa<PointerType>(Ty) &&
80}
81inline bool isRefType(const Type *Ty) {
82 return isFuncrefType(Ty) || isExternrefType(Ty);
83}
84
87}
88
89// Convert StringRef to ValType / HealType / BlockType
90
91std::optional<wasm::ValType> parseType(StringRef Type);
94
95// Convert ValType or a list/signature of ValTypes to a string.
96
97// Convert an unsinged integer, which can be among wasm::ValType enum, to its
98// type name string. If the input is not within wasm::ValType, returns
99// "invalid_type".
100const char *anyTypeToString(unsigned Type);
101const char *typeToString(wasm::ValType Type);
102// Convert a list of ValTypes into a string in the format of
103// "type0, type1, ... typeN"
105// Convert a wasm signature into a string in the format of
106// "(params) -> (results)", where params and results are a string of ValType
107// lists.
108std::string signatureToString(const wasm::WasmSignature *Sig);
109
110// Convert a MVT into its corresponding wasm ValType.
112
113// Convert a register class ID to a wasm ValType.
115
116// Convert a register class to a wasm ValType.
118
119/// Sets a Wasm Symbol Type.
120void wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
121 const SmallVector<MVT, 1> &VTs);
122
123} // end namespace WebAssembly
124} // end namespace llvm
125
126#endif
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Machine Value Type.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1200
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool isDefaultAddressSpace(unsigned AS)
const char * typeToString(wasm::ValType Type)
BlockType parseBlockType(StringRef Type)
wasm::ValType regClassToValType(unsigned RC)
wasm::ValType toValType(MVT Type)
bool isExternrefType(const Type *Ty)
void wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT, const SmallVector< MVT, 1 > &VTs)
Sets a Wasm Symbol Type.
bool isFuncrefType(const Type *Ty)
bool isValidAddressSpace(unsigned AS)
BlockType
Used as immediate MachineOperands for block signatures.
std::string signatureToString(const wasm::WasmSignature *Sig)
const char * anyTypeToString(unsigned Type)
std::string typeListToString(ArrayRef< wasm::ValType > List)
MVT parseMVT(StringRef Type)
bool isRefType(const Type *Ty)
std::optional< wasm::ValType > parseType(StringRef Type)
bool isWasmVarAddressSpace(unsigned AS)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18