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 "llvm/BinaryFormat/Wasm.h"
20 #include "llvm/CodeGen/MachineValueType.h"
21 #include "llvm/CodeGen/WasmAddressSpaces.h"
22 #include "llvm/IR/DerivedTypes.h"
23 #include "llvm/MC/MCSymbolWasm.h"
24 
25 namespace llvm {
26 
27 class TargetRegisterClass;
28 
29 namespace WebAssembly {
30 
31 /// Return true if this is a WebAssembly Externref Type.
32 inline bool isWebAssemblyExternrefType(const Type *Ty) {
33   return Ty->getPointerAddressSpace() ==
34          WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
35 }
36 
37 /// Return true if this is a WebAssembly Funcref Type.
38 inline bool isWebAssemblyFuncrefType(const Type *Ty) {
39   return Ty->getPointerAddressSpace() ==
40          WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
41 }
42 
43 /// Return true if this is a WebAssembly Reference Type.
44 inline bool isWebAssemblyReferenceType(const Type *Ty) {
45   return isWebAssemblyExternrefType(Ty) || isWebAssemblyFuncrefType(Ty);
46 }
47 
48 // Convert StringRef to ValType / HealType / BlockType
49 
50 MVT parseMVT(StringRef Type);
51 
52 // Convert a MVT into its corresponding wasm ValType.
53 wasm::ValType toValType(MVT Type);
54 
55 // Convert a register class to a wasm ValType.
56 wasm::ValType regClassToValType(const TargetRegisterClass *RC);
57 
58 /// Sets a Wasm Symbol Type.
59 void wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
60                        const ArrayRef<MVT> &VTs);
61 
62 } // end namespace WebAssembly
63 } // end namespace llvm
64 
65 #endif
66