diff --git a/llvm/lib/Target/WebAssembly/AsmParser/CMakeLists.txt b/llvm/lib/Target/WebAssembly/AsmParser/CMakeLists.txt index 4376ce47c8f53..81cb693064bb4 100644 --- a/llvm/lib/Target/WebAssembly/AsmParser/CMakeLists.txt +++ b/llvm/lib/Target/WebAssembly/AsmParser/CMakeLists.txt @@ -5,8 +5,8 @@ add_llvm_component_library(LLVMWebAssemblyAsmParser LINK_COMPONENTS MC MCParser + WebAssemblyDesc WebAssemblyInfo - WebAssemblyUtils Support TargetParser diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp index 1cba0843f8910..ded5abd3fe3c1 100644 --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -15,10 +15,9 @@ #include "AsmParser/WebAssemblyAsmTypeCheck.h" #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" +#include "MCTargetDesc/WebAssemblyMCTypeUtilities.h" #include "MCTargetDesc/WebAssemblyTargetStreamer.h" #include "TargetInfo/WebAssemblyTargetInfo.h" -#include "Utils/WebAssemblyTypeUtilities.h" -#include "Utils/WebAssemblyUtilities.h" #include "WebAssembly.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp index b323b265b562b..997065037dda3 100644 --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp @@ -15,10 +15,9 @@ #include "AsmParser/WebAssemblyAsmTypeCheck.h" #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" +#include "MCTargetDesc/WebAssemblyMCTypeUtilities.h" #include "MCTargetDesc/WebAssemblyTargetStreamer.h" #include "TargetInfo/WebAssemblyTargetInfo.h" -#include "Utils/WebAssemblyTypeUtilities.h" -#include "Utils/WebAssemblyUtilities.h" #include "WebAssembly.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" diff --git a/llvm/lib/Target/WebAssembly/Disassembler/CMakeLists.txt b/llvm/lib/Target/WebAssembly/Disassembler/CMakeLists.txt index bb18b4dbabbb6..1782f576f3a65 100644 --- a/llvm/lib/Target/WebAssembly/Disassembler/CMakeLists.txt +++ b/llvm/lib/Target/WebAssembly/Disassembler/CMakeLists.txt @@ -5,7 +5,6 @@ add_llvm_component_library(LLVMWebAssemblyDisassembler WebAssemblyDesc MCDisassembler WebAssemblyInfo - WebAssemblyUtils Support MC diff --git a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp index 1f07b1619b493..2c3604cc72d28 100644 --- a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp +++ b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp @@ -14,8 +14,8 @@ /// //===----------------------------------------------------------------------===// +#include "MCTargetDesc/WebAssemblyMCTypeUtilities.h" #include "TargetInfo/WebAssemblyTargetInfo.h" -#include "Utils/WebAssemblyTypeUtilities.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCDecoderOps.h" #include "llvm/MC/MCDisassembler/MCDisassembler.h" diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/CMakeLists.txt b/llvm/lib/Target/WebAssembly/MCTargetDesc/CMakeLists.txt index 64201b0257e67..a6076c4245c74 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/CMakeLists.txt +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/CMakeLists.txt @@ -4,6 +4,7 @@ add_llvm_component_library(LLVMWebAssemblyDesc WebAssemblyMCAsmInfo.cpp WebAssemblyMCCodeEmitter.cpp WebAssemblyMCTargetDesc.cpp + WebAssemblyMCTypeUtilities.cpp WebAssemblyTargetStreamer.cpp WebAssemblyWasmObjectWriter.cpp @@ -12,7 +13,6 @@ add_llvm_component_library(LLVMWebAssemblyDesc Support TargetParser WebAssemblyInfo - WebAssemblyUtils ADD_TO_COMPONENT WebAssembly diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp index b925519e61627..a9673ab344d39 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp @@ -13,8 +13,7 @@ #include "MCTargetDesc/WebAssemblyInstPrinter.h" #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" -#include "Utils/WebAssemblyTypeUtilities.h" -#include "Utils/WebAssemblyUtilities.h" +#include "MCTargetDesc/WebAssemblyMCTypeUtilities.h" #include "WebAssembly.h" #include "WebAssemblyMachineFunctionInfo.h" #include "llvm/ADT/SmallSet.h" diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp index a56c4e7c7138f..9d43c0052d52e 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp @@ -13,7 +13,7 @@ //===----------------------------------------------------------------------===// #include "WebAssemblyMCAsmInfo.h" -#include "Utils/WebAssemblyUtilities.h" +#include "WebAssemblyMCTargetDesc.h" #include "llvm/TargetParser/Triple.h" using namespace llvm; diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp index 97dbc35c991bd..e49ada4b2119e 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp @@ -35,6 +35,26 @@ using namespace llvm; #define GET_REGINFO_MC_DESC #include "WebAssemblyGenRegisterInfo.inc" +// Exception handling & setjmp-longjmp handling related options. + +// Emscripten's asm.js-style exception handling +cl::opt WebAssembly::WasmEnableEmEH( + "enable-emscripten-cxx-exceptions", + cl::desc("WebAssembly Emscripten-style exception handling"), + cl::init(false)); +// Emscripten's asm.js-style setjmp/longjmp handling +cl::opt WebAssembly::WasmEnableEmSjLj( + "enable-emscripten-sjlj", + cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"), + cl::init(false)); +// Exception handling using wasm EH instructions +cl::opt + WebAssembly::WasmEnableEH("wasm-enable-eh", + cl::desc("WebAssembly exception handling")); +// setjmp/longjmp handling using wasm EH instrutions +cl::opt WebAssembly::WasmEnableSjLj( + "wasm-enable-sjlj", cl::desc("WebAssembly setjmp/longjmp handling")); + static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/, const Triple &TT, const MCTargetOptions &Options) { diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h index 476955e434f28..e46fb3d311ad6 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h @@ -36,6 +36,13 @@ std::unique_ptr createWebAssemblyWasmObjectWriter(bool Is64Bit, bool IsEmscripten); namespace WebAssembly { + +// Exception handling / setjmp-longjmp handling command-line options +extern cl::opt WasmEnableEmEH; // asm.js-style EH +extern cl::opt WasmEnableEmSjLj; // asm.js-style SjLJ +extern cl::opt WasmEnableEH; // EH using Wasm EH instructions +extern cl::opt WasmEnableSjLj; // SjLj using Wasm EH instructions + enum OperandType { /// Basic block label in a branch construct. OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET, diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.cpp new file mode 100644 index 0000000000000..b7b5b2a97c59e --- /dev/null +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.cpp @@ -0,0 +1,124 @@ +//===- WebAssemblyMCTypeUtilities.cpp - WebAssembly Type Utility Functions-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file implements several utility functions for WebAssembly type parsing. +/// +//===----------------------------------------------------------------------===// + +#include "WebAssemblyMCTypeUtilities.h" +#include "WebAssemblyMCTargetDesc.h" +#include "llvm/ADT/StringSwitch.h" + +using namespace llvm; + +std::optional WebAssembly::parseType(StringRef Type) { + // FIXME: can't use StringSwitch because wasm::ValType doesn't have a + // "invalid" value. + if (Type == "i32") + return wasm::ValType::I32; + if (Type == "i64") + return wasm::ValType::I64; + if (Type == "f32") + return wasm::ValType::F32; + if (Type == "f64") + return wasm::ValType::F64; + if (Type == "v128" || Type == "i8x16" || Type == "i16x8" || Type == "i32x4" || + Type == "i64x2" || Type == "f32x4" || Type == "f64x2") + return wasm::ValType::V128; + if (Type == "funcref") + return wasm::ValType::FUNCREF; + if (Type == "externref") + return wasm::ValType::EXTERNREF; + return std::nullopt; +} + +WebAssembly::BlockType WebAssembly::parseBlockType(StringRef Type) { + // Multivalue block types are handled separately in parseSignature + return StringSwitch(Type) + .Case("i32", WebAssembly::BlockType::I32) + .Case("i64", WebAssembly::BlockType::I64) + .Case("f32", WebAssembly::BlockType::F32) + .Case("f64", WebAssembly::BlockType::F64) + .Case("v128", WebAssembly::BlockType::V128) + .Case("funcref", WebAssembly::BlockType::Funcref) + .Case("externref", WebAssembly::BlockType::Externref) + .Case("void", WebAssembly::BlockType::Void) + .Default(WebAssembly::BlockType::Invalid); +} + +// We have various enums representing a subset of these types, use this +// function to convert any of them to text. +const char *WebAssembly::anyTypeToString(unsigned Type) { + switch (Type) { + case wasm::WASM_TYPE_I32: + return "i32"; + case wasm::WASM_TYPE_I64: + return "i64"; + case wasm::WASM_TYPE_F32: + return "f32"; + case wasm::WASM_TYPE_F64: + return "f64"; + case wasm::WASM_TYPE_V128: + return "v128"; + case wasm::WASM_TYPE_FUNCREF: + return "funcref"; + case wasm::WASM_TYPE_EXTERNREF: + return "externref"; + case wasm::WASM_TYPE_FUNC: + return "func"; + case wasm::WASM_TYPE_NORESULT: + return "void"; + default: + return "invalid_type"; + } +} + +const char *WebAssembly::typeToString(wasm::ValType Type) { + return anyTypeToString(static_cast(Type)); +} + +std::string WebAssembly::typeListToString(ArrayRef List) { + std::string S; + for (const auto &Type : List) { + if (&Type != &List[0]) + S += ", "; + S += WebAssembly::typeToString(Type); + } + return S; +} + +std::string WebAssembly::signatureToString(const wasm::WasmSignature *Sig) { + std::string S("("); + S += typeListToString(Sig->Params); + S += ") -> ("; + S += typeListToString(Sig->Returns); + S += ")"; + return S; +} + +wasm::ValType WebAssembly::regClassToValType(unsigned RC) { + switch (RC) { + case WebAssembly::I32RegClassID: + return wasm::ValType::I32; + case WebAssembly::I64RegClassID: + return wasm::ValType::I64; + case WebAssembly::F32RegClassID: + return wasm::ValType::F32; + case WebAssembly::F64RegClassID: + return wasm::ValType::F64; + case WebAssembly::V128RegClassID: + return wasm::ValType::V128; + case WebAssembly::FUNCREFRegClassID: + return wasm::ValType::FUNCREF; + case WebAssembly::EXTERNREFRegClassID: + return wasm::ValType::EXTERNREF; + default: + llvm_unreachable("unexpected type"); + } +} diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h new file mode 100644 index 0000000000000..18018dfc6d6fb --- /dev/null +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h @@ -0,0 +1,73 @@ +//===-- WebAssemblyMCTypeUtilities - WebAssembly Type Utilities-*- C++ -*-====// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +/// +/// \file +/// This file contains the declaration of the WebAssembly-specific type parsing +/// utility functions. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTYPEUTILITIES_H +#define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTYPEUTILITIES_H + +#include "llvm/BinaryFormat/Wasm.h" + +namespace llvm { + +namespace WebAssembly { + +/// Used as immediate MachineOperands for block signatures +enum class BlockType : unsigned { + Invalid = 0x00, + Void = 0x40, + I32 = unsigned(wasm::ValType::I32), + I64 = unsigned(wasm::ValType::I64), + F32 = unsigned(wasm::ValType::F32), + F64 = unsigned(wasm::ValType::F64), + V128 = unsigned(wasm::ValType::V128), + Externref = unsigned(wasm::ValType::EXTERNREF), + Funcref = unsigned(wasm::ValType::FUNCREF), + // Multivalue blocks (and other non-void blocks) are only emitted when the + // blocks will never be exited and are at the ends of functions (see + // WebAssemblyCFGStackify::fixEndsAtEndOfFunction). They also are never made + // to pop values off the stack, so the exact multivalue signature can always + // be inferred from the return type of the parent function in MCInstLower. + Multivalue = 0xffff, +}; + +inline bool isRefType(wasm::ValType Type) { + return Type == wasm::ValType::EXTERNREF || Type == wasm::ValType::FUNCREF; +} + +// Convert ValType or a list/signature of ValTypes to a string. + +// Convert an unsinged integer, which can be among wasm::ValType enum, to its +// type name string. If the input is not within wasm::ValType, returns +// "invalid_type". +const char *anyTypeToString(unsigned Type); +const char *typeToString(wasm::ValType Type); +// Convert a list of ValTypes into a string in the format of +// "type0, type1, ... typeN" +std::string typeListToString(ArrayRef List); +// Convert a wasm signature into a string in the format of +// "(params) -> (results)", where params and results are a string of ValType +// lists. +std::string signatureToString(const wasm::WasmSignature *Sig); + +// Convert a register class ID to a wasm ValType. +wasm::ValType regClassToValType(unsigned RC); + +// Convert StringRef to ValType / HealType / BlockType + +std::optional parseType(StringRef Type); +BlockType parseBlockType(StringRef Type); + +} // end namespace WebAssembly +} // end namespace llvm + +#endif diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp index 2da219d54c73d..f389ee2f50d8a 100644 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp @@ -14,7 +14,7 @@ #include "MCTargetDesc/WebAssemblyTargetStreamer.h" #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" -#include "Utils/WebAssemblyTypeUtilities.h" +#include "MCTargetDesc/WebAssemblyMCTypeUtilities.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCSectionWasm.h" #include "llvm/MC/MCSubtargetInfo.h" diff --git a/llvm/lib/Target/WebAssembly/Utils/CMakeLists.txt b/llvm/lib/Target/WebAssembly/Utils/CMakeLists.txt index 3fc1732cd409d..95c4d8fc40e26 100644 --- a/llvm/lib/Target/WebAssembly/Utils/CMakeLists.txt +++ b/llvm/lib/Target/WebAssembly/Utils/CMakeLists.txt @@ -7,6 +7,7 @@ add_llvm_component_library(LLVMWebAssemblyUtils Core MC Support + WebAssemblyDesc ADD_TO_COMPONENT WebAssembly diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp index 998905402b39d..ed1fde9a1cd59 100644 --- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp +++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp @@ -21,41 +21,6 @@ using namespace llvm; -std::optional WebAssembly::parseType(StringRef Type) { - // FIXME: can't use StringSwitch because wasm::ValType doesn't have a - // "invalid" value. - if (Type == "i32") - return wasm::ValType::I32; - if (Type == "i64") - return wasm::ValType::I64; - if (Type == "f32") - return wasm::ValType::F32; - if (Type == "f64") - return wasm::ValType::F64; - if (Type == "v128" || Type == "i8x16" || Type == "i16x8" || Type == "i32x4" || - Type == "i64x2" || Type == "f32x4" || Type == "f64x2") - return wasm::ValType::V128; - if (Type == "funcref") - return wasm::ValType::FUNCREF; - if (Type == "externref") - return wasm::ValType::EXTERNREF; - return std::nullopt; -} - -WebAssembly::BlockType WebAssembly::parseBlockType(StringRef Type) { - // Multivalue block types are handled separately in parseSignature - return StringSwitch(Type) - .Case("i32", WebAssembly::BlockType::I32) - .Case("i64", WebAssembly::BlockType::I64) - .Case("f32", WebAssembly::BlockType::F32) - .Case("f64", WebAssembly::BlockType::F64) - .Case("v128", WebAssembly::BlockType::V128) - .Case("funcref", WebAssembly::BlockType::Funcref) - .Case("externref", WebAssembly::BlockType::Externref) - .Case("void", WebAssembly::BlockType::Void) - .Default(WebAssembly::BlockType::Invalid); -} - MVT WebAssembly::parseMVT(StringRef Type) { return StringSwitch(Type) .Case("i32", MVT::i32) @@ -72,56 +37,6 @@ MVT WebAssembly::parseMVT(StringRef Type) { .Default(MVT::INVALID_SIMPLE_VALUE_TYPE); } -// We have various enums representing a subset of these types, use this -// function to convert any of them to text. -const char *WebAssembly::anyTypeToString(unsigned Type) { - switch (Type) { - case wasm::WASM_TYPE_I32: - return "i32"; - case wasm::WASM_TYPE_I64: - return "i64"; - case wasm::WASM_TYPE_F32: - return "f32"; - case wasm::WASM_TYPE_F64: - return "f64"; - case wasm::WASM_TYPE_V128: - return "v128"; - case wasm::WASM_TYPE_FUNCREF: - return "funcref"; - case wasm::WASM_TYPE_EXTERNREF: - return "externref"; - case wasm::WASM_TYPE_FUNC: - return "func"; - case wasm::WASM_TYPE_NORESULT: - return "void"; - default: - return "invalid_type"; - } -} - -const char *WebAssembly::typeToString(wasm::ValType Type) { - return anyTypeToString(static_cast(Type)); -} - -std::string WebAssembly::typeListToString(ArrayRef List) { - std::string S; - for (const auto &Type : List) { - if (&Type != &List[0]) - S += ", "; - S += WebAssembly::typeToString(Type); - } - return S; -} - -std::string WebAssembly::signatureToString(const wasm::WasmSignature *Sig) { - std::string S("("); - S += typeListToString(Sig->Params); - S += ") -> ("; - S += typeListToString(Sig->Returns); - S += ")"; - return S; -} - wasm::ValType WebAssembly::toValType(MVT Type) { switch (Type.SimpleTy) { case MVT::i32: @@ -148,27 +63,6 @@ wasm::ValType WebAssembly::toValType(MVT Type) { } } -wasm::ValType WebAssembly::regClassToValType(unsigned RC) { - switch (RC) { - case WebAssembly::I32RegClassID: - return wasm::ValType::I32; - case WebAssembly::I64RegClassID: - return wasm::ValType::I64; - case WebAssembly::F32RegClassID: - return wasm::ValType::F32; - case WebAssembly::F64RegClassID: - return wasm::ValType::F64; - case WebAssembly::V128RegClassID: - return wasm::ValType::V128; - case WebAssembly::FUNCREFRegClassID: - return wasm::ValType::FUNCREF; - case WebAssembly::EXTERNREFRegClassID: - return wasm::ValType::EXTERNREF; - default: - llvm_unreachable("unexpected type"); - } -} - wasm::ValType WebAssembly::regClassToValType(const TargetRegisterClass *RC) { assert(RC != nullptr); return regClassToValType(RC->getID()); diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h index 33f3bf31595d7..65107df7dfd15 100644 --- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h +++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h @@ -15,6 +15,7 @@ #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYTYPEUTILITIES_H #define LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYTYPEUTILITIES_H +#include "MCTargetDesc/WebAssemblyMCTypeUtilities.h" #include "llvm/BinaryFormat/Wasm.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/MC/MCSymbolWasm.h" @@ -26,25 +27,6 @@ class TargetRegisterClass; namespace WebAssembly { -/// Used as immediate MachineOperands for block signatures -enum class BlockType : unsigned { - Invalid = 0x00, - Void = 0x40, - I32 = unsigned(wasm::ValType::I32), - I64 = unsigned(wasm::ValType::I64), - F32 = unsigned(wasm::ValType::F32), - F64 = unsigned(wasm::ValType::F64), - V128 = unsigned(wasm::ValType::V128), - Externref = unsigned(wasm::ValType::EXTERNREF), - Funcref = unsigned(wasm::ValType::FUNCREF), - // Multivalue blocks (and other non-void blocks) are only emitted when the - // blocks will never be exited and are at the ends of functions (see - // WebAssemblyCFGStackify::fixEndsAtEndOfFunction). They also are never made - // to pop values off the stack, so the exact multivalue signature can always - // be inferred from the return type of the parent function in MCInstLower. - Multivalue = 0xffff, -}; - enum WasmAddressSpace : unsigned { // Default address space, for pointers to linear memory (stack, heap, data). WASM_ADDRESS_SPACE_DEFAULT = 0, @@ -82,37 +64,13 @@ inline bool isRefType(const Type *Ty) { return isFuncrefType(Ty) || isExternrefType(Ty); } -inline bool isRefType(wasm::ValType Type) { - return Type == wasm::ValType::EXTERNREF || Type == wasm::ValType::FUNCREF; -} - // Convert StringRef to ValType / HealType / BlockType -std::optional parseType(StringRef Type); -BlockType parseBlockType(StringRef Type); MVT parseMVT(StringRef Type); -// Convert ValType or a list/signature of ValTypes to a string. - -// Convert an unsinged integer, which can be among wasm::ValType enum, to its -// type name string. If the input is not within wasm::ValType, returns -// "invalid_type". -const char *anyTypeToString(unsigned Type); -const char *typeToString(wasm::ValType Type); -// Convert a list of ValTypes into a string in the format of -// "type0, type1, ... typeN" -std::string typeListToString(ArrayRef List); -// Convert a wasm signature into a string in the format of -// "(params) -> (results)", where params and results are a string of ValType -// lists. -std::string signatureToString(const wasm::WasmSignature *Sig); - // Convert a MVT into its corresponding wasm ValType. wasm::ValType toValType(MVT Type); -// Convert a register class ID to a wasm ValType. -wasm::ValType regClassToValType(unsigned RC); - // Convert a register class to a wasm ValType. wasm::ValType regClassToValType(const TargetRegisterClass *RC); diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp index a1e0db692390c..8d7fa4dc3dee1 100644 --- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp +++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp @@ -18,30 +18,6 @@ #include "llvm/MC/MCContext.h" using namespace llvm; -// Exception handling & setjmp-longjmp handling related options. These are -// defined here to be shared between WebAssembly and its subdirectories. - -// Emscripten's asm.js-style exception handling -cl::opt WebAssembly::WasmEnableEmEH( - "enable-emscripten-cxx-exceptions", - cl::desc("WebAssembly Emscripten-style exception handling"), - cl::init(false)); -// Emscripten's asm.js-style setjmp/longjmp handling -cl::opt WebAssembly::WasmEnableEmSjLj( - "enable-emscripten-sjlj", - cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"), - cl::init(false)); -// Exception handling using wasm EH instructions -cl::opt - WebAssembly::WasmEnableEH("wasm-enable-eh", - cl::desc("WebAssembly exception handling"), - cl::init(false)); -// setjmp/longjmp handling using wasm EH instrutions -cl::opt - WebAssembly::WasmEnableSjLj("wasm-enable-sjlj", - cl::desc("WebAssembly setjmp/longjmp handling"), - cl::init(false)); - // Function names in libc++abi and libunwind const char *const WebAssembly::CxaBeginCatchFn = "__cxa_begin_catch"; const char *const WebAssembly::CxaRethrowFn = "__cxa_rethrow"; diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h index d0639208fda98..7f28fb1858a69 100644 --- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h +++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h @@ -33,12 +33,6 @@ namespace WebAssembly { bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI); bool mayThrow(const MachineInstr &MI); -// Exception handling / setjmp-longjmp handling command-line options -extern cl::opt WasmEnableEmEH; // asm.js-style EH -extern cl::opt WasmEnableEmSjLj; // asm.js-style SjLJ -extern cl::opt WasmEnableEH; // EH using Wasm EH instructions -extern cl::opt WasmEnableSjLj; // SjLj using Wasm EH instructions - // Exception-related function names extern const char *const ClangCallTerminateFn; extern const char *const CxaBeginCatchFn; diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp index 5faa098b94ad8..71b930022214e 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp @@ -267,7 +267,7 @@ /// ///===----------------------------------------------------------------------===// -#include "Utils/WebAssemblyUtilities.h" +#include "MCTargetDesc/WebAssemblyMCTargetDesc.h" #include "WebAssembly.h" #include "WebAssemblyTargetMachine.h" #include "llvm/ADT/StringExtras.h"