LLVM  14.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 
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/BinaryFormat/Wasm.h"
21 
22 namespace llvm {
23 namespace WebAssembly {
24 
25 /// Used as immediate MachineOperands for block signatures
26 enum class BlockType : unsigned {
27  Invalid = 0x00,
28  Void = 0x40,
29  I32 = unsigned(wasm::ValType::I32),
30  I64 = unsigned(wasm::ValType::I64),
31  F32 = unsigned(wasm::ValType::F32),
32  F64 = unsigned(wasm::ValType::F64),
33  V128 = unsigned(wasm::ValType::V128),
35  Funcref = unsigned(wasm::ValType::FUNCREF),
36  // Multivalue blocks (and other non-void blocks) are only emitted when the
37  // blocks will never be exited and are at the ends of functions (see
38  // WebAssemblyCFGStackify::fixEndsAtEndOfFunction). They also are never made
39  // to pop values off the stack, so the exact multivalue signature can always
40  // be inferred from the return type of the parent function in MCInstLower.
41  Multivalue = 0xffff,
42 };
43 
44 /// Used as immediate MachineOperands for heap types, e.g. for ref.null.
45 enum class HeapType : unsigned {
46  Invalid = 0x00,
48  Funcref = unsigned(wasm::ValType::FUNCREF),
49 };
50 
51 // Convert StringRef to ValType / HealType / BlockType
52 
57 
58 // Convert ValType or a list/signature of ValTypes to a string.
59 
60 // Convert an unsinged integer, which can be among wasm::ValType enum, to its
61 // type name string. If the input is not within wasm::ValType, returns
62 // "invalid_type".
63 const char *anyTypeToString(unsigned Type);
64 const char *typeToString(wasm::ValType Type);
65 // Convert a list of ValTypes into a string in the format of
66 // "type0, type1, ... typeN"
68 // Convert a wasm signature into a string in the format of
69 // "(params) -> (results)", where params and results are a string of ValType
70 // lists.
71 std::string signatureToString(const wasm::WasmSignature *Sig);
72 
73 // Convert a MVT into its corresponding wasm ValType.
75 
76 // Convert a register class to a wasm ValType.
77 wasm::ValType regClassToValType(unsigned RC);
78 
79 } // end namespace WebAssembly
80 } // end namespace llvm
81 
82 #endif
llvm::WebAssembly::parseMVT
MVT parseMVT(StringRef Type)
Definition: WebAssemblyTypeUtilities.cpp:65
llvm::WebAssembly::BlockType::I64
@ I64
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::wasm::ValType::I32
@ I32
Optional.h
llvm::WebAssembly::HeapType
HeapType
Used as immediate MachineOperands for heap types, e.g. for ref.null.
Definition: WebAssemblyTypeUtilities.h:45
llvm::WebAssembly::HeapType::Funcref
@ Funcref
llvm::WebAssembly::signatureToString
std::string signatureToString(const wasm::WasmSignature *Sig)
Definition: WebAssemblyTypeUtilities.cpp:122
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::Optional
Definition: APInt.h:33
llvm::WebAssembly::BlockType::Invalid
@ Invalid
llvm::WebAssembly::BlockType::F64
@ F64
llvm::WebAssembly::regClassToValType
wasm::ValType regClassToValType(unsigned RC)
Definition: WebAssemblyTypeUtilities.cpp:157
llvm::WebAssembly::BlockType::Void
@ Void
MachineValueType.h
llvm::WebAssembly::parseType
Optional< wasm::ValType > parseType(StringRef Type)
Definition: WebAssemblyTypeUtilities.cpp:23
llvm::wasm::ValType::F64
@ F64
llvm::wasm::ValType::F32
@ F32
llvm::WebAssembly::toValType
wasm::ValType toValType(MVT Type)
Definition: WebAssemblyTypeUtilities.cpp:131
llvm::WebAssembly::BlockType::V128
@ V128
llvm::wasm::ValType
ValType
Definition: Wasm.h:410
llvm::WebAssembly::typeListToString
std::string typeListToString(ArrayRef< wasm::ValType > List)
Definition: WebAssemblyTypeUtilities.cpp:112
llvm::WebAssembly::BlockType::Funcref
@ Funcref
llvm::wasm::ValType::EXTERNREF
@ EXTERNREF
llvm::wasm::ValType::I64
@ I64
llvm::wasm::ValType::FUNCREF
@ FUNCREF
llvm::WebAssembly::BlockType::Multivalue
@ Multivalue
llvm::WebAssembly::BlockType::Externref
@ Externref
llvm::MVT
Machine Value Type.
Definition: MachineValueType.h:31
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::WebAssembly::BlockType::I32
@ I32
llvm::WebAssembly::HeapType::Externref
@ Externref
Wasm.h
llvm::WebAssembly::parseBlockType
BlockType parseBlockType(StringRef Type)
Definition: WebAssemblyTypeUtilities.cpp:51
llvm::WebAssembly::typeToString
const char * typeToString(wasm::ValType Type)
Definition: WebAssemblyTypeUtilities.cpp:108
llvm::wasm::ValType::V128
@ V128
llvm::WebAssembly::HeapType::Invalid
@ Invalid
llvm::WebAssembly::BlockType
BlockType
Used as immediate MachineOperands for block signatures.
Definition: WebAssemblyTypeUtilities.h:26
llvm::WebAssembly::anyTypeToString
const char * anyTypeToString(unsigned Type)
Definition: WebAssemblyTypeUtilities.cpp:83
llvm::wasm::WasmSignature
Definition: Wasm.h:420
llvm::WebAssembly::BlockType::F32
@ F32
llvm::WebAssembly::parseHeapType
HeapType parseHeapType(StringRef Type)
Definition: WebAssemblyTypeUtilities.cpp:44