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
18#include "MCTargetDesc/WebAssemblyMCTypeUtilities.h"
19#include "WasmAddressSpaces.h"
20#include "llvm/BinaryFormat/Wasm.h"
21#include "llvm/CodeGenTypes/MachineValueType.h"
22#include "llvm/IR/DerivedTypes.h"
23#include "llvm/MC/MCSymbolWasm.h"
24
25namespace llvm {
26
27namespace WebAssembly {
28
29/// Return true if this is a WebAssembly Externref Type.
30inline bool isWebAssemblyExternrefType(const Type *Ty) {
31 const TargetExtType *TargetTy = dyn_cast<TargetExtType>(Val: Ty);
32 return TargetTy && TargetTy->getName() == "wasm.externref";
33}
34
35/// Return true if this is a WebAssembly Funcref Type.
36inline bool isWebAssemblyFuncrefType(const Type *Ty) {
37 const TargetExtType *TargetTy = dyn_cast<TargetExtType>(Val: Ty);
38 return TargetTy && TargetTy->getName() == "wasm.funcref";
39}
40
41/// Return true if this is a WebAssembly Reference Type.
42inline bool isWebAssemblyReferenceType(const Type *Ty) {
43 return isWebAssemblyExternrefType(Ty) || isWebAssemblyFuncrefType(Ty);
44}
45
46/// Return true if the table represents a WebAssembly table type.
47inline bool isWebAssemblyTableType(const Type *Ty) {
48 return Ty->isArrayTy() &&
49 isWebAssemblyReferenceType(Ty: Ty->getArrayElementType());
50}
51
52// Convert StringRef to ValType / HealType / BlockType
53
54MVT parseMVT(StringRef Type);
55
56// Convert a MVT into its corresponding wasm ValType.
57wasm::ValType toValType(MVT Type);
58
59/// Sets a Wasm Symbol Type.
60void wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
61 ArrayRef<MVT> VTs, bool Mutable);
62
63} // end namespace WebAssembly
64} // end namespace llvm
65
66#endif
67