diff --git a/llvm/lib/Target/WebAssembly/AsmParser/CMakeLists.txt b/llvm/lib/Target/WebAssembly/AsmParser/CMakeLists.txt --- a/llvm/lib/Target/WebAssembly/AsmParser/CMakeLists.txt +++ b/llvm/lib/Target/WebAssembly/AsmParser/CMakeLists.txt @@ -5,8 +5,8 @@ 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 --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -15,10 +15,10 @@ #include "AsmParser/WebAssemblyAsmTypeCheck.h" #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" +#include "MCTargetDesc/WebAssemblyMCTypeUtilities.h" +#include "MCTargetDesc/WebAssemblyMCUtilities.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 --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp @@ -15,10 +15,10 @@ #include "AsmParser/WebAssemblyAsmTypeCheck.h" #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" +#include "MCTargetDesc/WebAssemblyMCTypeUtilities.h" +#include "MCTargetDesc/WebAssemblyMCUtilities.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 --- a/llvm/lib/Target/WebAssembly/Disassembler/CMakeLists.txt +++ b/llvm/lib/Target/WebAssembly/Disassembler/CMakeLists.txt @@ -5,7 +5,6 @@ WebAssemblyDesc MCDisassembler WebAssemblyInfo - WebAssemblyUtils Support MC diff --git a/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp b/llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp --- 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 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/CMakeLists.txt +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/CMakeLists.txt @@ -4,6 +4,8 @@ WebAssemblyMCAsmInfo.cpp WebAssemblyMCCodeEmitter.cpp WebAssemblyMCTargetDesc.cpp + WebAssemblyMCTypeUtilities.cpp + WebAssemblyMCUtilities.cpp WebAssemblyTargetStreamer.cpp WebAssemblyWasmObjectWriter.cpp @@ -12,7 +14,6 @@ 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 --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp @@ -13,8 +13,8 @@ #include "MCTargetDesc/WebAssemblyInstPrinter.h" #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" -#include "Utils/WebAssemblyTypeUtilities.h" -#include "Utils/WebAssemblyUtilities.h" +#include "MCTargetDesc/WebAssemblyMCTypeUtilities.h" +#include "MCTargetDesc/WebAssemblyMCUtilities.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 --- 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 "WebAssemblyMCUtilities.h" #include "llvm/TargetParser/Triple.h" using namespace llvm; diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h copy from llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h copy to llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h --- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.h @@ -1,4 +1,4 @@ -//===-- WebAssemblyTypeUtilities - WebAssembly Type Utilities---*- C++ -*-====// +//===-- 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. @@ -12,18 +12,13 @@ /// //===----------------------------------------------------------------------===// -#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYTYPEUTILITIES_H -#define LLVM_LIB_TARGET_WEBASSEMBLY_UTILS_WEBASSEMBLYTYPEUTILITIES_H +#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTYPEUTILITIES_H +#define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCTYPEUTILITIES_H #include "llvm/BinaryFormat/Wasm.h" -#include "llvm/IR/DerivedTypes.h" -#include "llvm/MC/MCSymbolWasm.h" -#include "llvm/Support/MachineValueType.h" namespace llvm { -class TargetRegisterClass; - namespace WebAssembly { /// Used as immediate MachineOperands for block signatures @@ -45,53 +40,10 @@ Multivalue = 0xffff, }; -enum WasmAddressSpace : unsigned { - // Default address space, for pointers to linear memory (stack, heap, data). - WASM_ADDRESS_SPACE_DEFAULT = 0, - // A non-integral address space for pointers to named objects outside of - // linear memory: WebAssembly globals or WebAssembly locals. Loads and stores - // to these pointers are lowered to global.get / global.set or local.get / - // local.set, as appropriate. - WASM_ADDRESS_SPACE_VAR = 1, - // A non-integral address space for externref values - WASM_ADDRESS_SPACE_EXTERNREF = 10, - // A non-integral address space for funcref values - WASM_ADDRESS_SPACE_FUNCREF = 20, -}; - -inline bool isDefaultAddressSpace(unsigned AS) { - return AS == WASM_ADDRESS_SPACE_DEFAULT; -} -inline bool isWasmVarAddressSpace(unsigned AS) { - return AS == WASM_ADDRESS_SPACE_VAR; -} -inline bool isValidAddressSpace(unsigned AS) { - return isDefaultAddressSpace(AS) || isWasmVarAddressSpace(AS); -} -inline bool isFuncrefType(const Type *Ty) { - return isa(Ty) && - Ty->getPointerAddressSpace() == - WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF; -} -inline bool isExternrefType(const Type *Ty) { - return isa(Ty) && - Ty->getPointerAddressSpace() == - WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF; -} -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 @@ -107,18 +59,13 @@ // 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); +// Convert StringRef to ValType / HealType / BlockType -/// Sets a Wasm Symbol Type. -void wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT, - const SmallVector &VTs); +std::optional parseType(StringRef Type); +BlockType parseBlockType(StringRef Type); } // end namespace WebAssembly } // end namespace llvm diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.cpp copy from llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp copy to llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.cpp --- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTypeUtilities.cpp @@ -1,4 +1,4 @@ -//===-- WebAssemblyTypeUtilities.cpp - WebAssembly Type Utility Functions -===// +//===- 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. @@ -11,13 +11,9 @@ /// //===----------------------------------------------------------------------===// -#include "WebAssemblyTypeUtilities.h" +#include "WebAssemblyMCTypeUtilities.h" +#include "WebAssemblyMCTargetDesc.h" #include "llvm/ADT/StringSwitch.h" -#include "llvm/CodeGen/TargetRegisterInfo.h" - -// Get register classes enum. -#define GET_REGINFO_ENUM -#include "WebAssemblyGenRegisterInfo.inc" using namespace llvm; @@ -56,22 +52,6 @@ .Default(WebAssembly::BlockType::Invalid); } -MVT WebAssembly::parseMVT(StringRef Type) { - return StringSwitch(Type) - .Case("i32", MVT::i32) - .Case("i64", MVT::i64) - .Case("f32", MVT::f32) - .Case("f64", MVT::f64) - .Case("i64", MVT::i64) - .Case("v16i8", MVT::v16i8) - .Case("v8i16", MVT::v8i16) - .Case("v4i32", MVT::v4i32) - .Case("v2i64", MVT::v2i64) - .Case("funcref", MVT::funcref) - .Case("externref", MVT::externref) - .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) { @@ -122,32 +102,6 @@ return S; } -wasm::ValType WebAssembly::toValType(MVT Type) { - switch (Type.SimpleTy) { - case MVT::i32: - return wasm::ValType::I32; - case MVT::i64: - return wasm::ValType::I64; - case MVT::f32: - return wasm::ValType::F32; - case MVT::f64: - return wasm::ValType::F64; - case MVT::v16i8: - case MVT::v8i16: - case MVT::v4i32: - case MVT::v2i64: - case MVT::v4f32: - case MVT::v2f64: - return wasm::ValType::V128; - case MVT::funcref: - return wasm::ValType::FUNCREF; - case MVT::externref: - return wasm::ValType::EXTERNREF; - default: - llvm_unreachable("unexpected type"); - } -} - wasm::ValType WebAssembly::regClassToValType(unsigned RC) { switch (RC) { case WebAssembly::I32RegClassID: @@ -168,41 +122,3 @@ llvm_unreachable("unexpected type"); } } - -wasm::ValType WebAssembly::regClassToValType(const TargetRegisterClass *RC) { - assert(RC != nullptr); - return regClassToValType(RC->getID()); -} - -void WebAssembly::wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT, - const SmallVector &VTs) { - assert(!Sym->getType()); - - // Tables are represented as Arrays in LLVM IR therefore - // they reach this point as aggregate Array types with an element type - // that is a reference type. - wasm::ValType ValTy; - bool IsTable = false; - if (GlobalVT->isArrayTy() && - WebAssembly::isRefType(GlobalVT->getArrayElementType())) { - IsTable = true; - const Type *ElTy = GlobalVT->getArrayElementType(); - if (WebAssembly::isExternrefType(ElTy)) - ValTy = wasm::ValType::EXTERNREF; - else if (WebAssembly::isFuncrefType(ElTy)) - ValTy = wasm::ValType::FUNCREF; - else - report_fatal_error("unhandled reference type"); - } else if (VTs.size() == 1) { - ValTy = WebAssembly::toValType(VTs[0]); - } else - report_fatal_error("Aggregate globals not yet implemented"); - - if (IsTable) { - Sym->setType(wasm::WASM_SYMBOL_TYPE_TABLE); - Sym->setTableType(ValTy); - } else { - Sym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL); - Sym->setGlobalType(wasm::WasmGlobalType{uint8_t(ValTy), /*Mutable=*/true}); - } -} diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCUtilities.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCUtilities.h new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCUtilities.h @@ -0,0 +1,28 @@ +//===-- WebAssemblyMCUtilities - WebAssembly Utility Functions -*- 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 +/// utility functions. +/// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCUTILITIES_H +#define LLVM_LIB_TARGET_WEBASSEMBLY_MCTARGETDESC_WEBASSEMBLYMCUTILITIES_H + +#include "llvm/Support/CommandLine.h" + +namespace llvm::WebAssembly { + +// Exception handling / setjmp-longjmp handling command-line options +extern cl::opt WasmEnableEH; // EH using Wasm EH instructions +extern cl::opt WasmEnableSjLj; // SjLj using Wasm EH instructions + +} // end namespace llvm::WebAssembly + +#endif diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCUtilities.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCUtilities.cpp new file mode 100644 --- /dev/null +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCUtilities.cpp @@ -0,0 +1,25 @@ +//===-- WebAssemblyMCUtilities.cpp - WebAssembly 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. +/// +//===----------------------------------------------------------------------===// + +#include "WebAssemblyMCUtilities.h" +using namespace llvm; + +// Exception handling & setjmp-longjmp handling related options. + +// 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")); diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp --- 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 --- a/llvm/lib/Target/WebAssembly/Utils/CMakeLists.txt +++ b/llvm/lib/Target/WebAssembly/Utils/CMakeLists.txt @@ -7,6 +7,7 @@ Core MC Support + WebAssemblyDesc ADD_TO_COMPONENT WebAssembly diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h --- 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 @@ 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 @@ 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/WebAssemblyTypeUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp --- 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 @@ .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::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/WebAssemblyUtilities.h b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h --- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h +++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h @@ -36,8 +36,6 @@ // 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; diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp --- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp +++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp @@ -18,8 +18,7 @@ #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. +// Exception handling & setjmp-longjmp handling related options. // Emscripten's asm.js-style exception handling cl::opt WebAssembly::WasmEnableEmEH( @@ -31,16 +30,6 @@ "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"; diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -15,6 +15,7 @@ #include "WebAssemblyAsmPrinter.h" #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" +#include "MCTargetDesc/WebAssemblyMCUtilities.h" #include "MCTargetDesc/WebAssemblyTargetStreamer.h" #include "TargetInfo/WebAssemblyTargetInfo.h" #include "Utils/WebAssemblyTypeUtilities.h" diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp @@ -267,6 +267,7 @@ /// ///===----------------------------------------------------------------------===// +#include "MCTargetDesc/WebAssemblyMCUtilities.h" #include "Utils/WebAssemblyUtilities.h" #include "WebAssembly.h" #include "WebAssemblyTargetMachine.h" diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include "WebAssemblyMCInstLower.h" +#include "MCTargetDesc/WebAssemblyMCUtilities.h" #include "TargetInfo/WebAssemblyTargetInfo.h" #include "Utils/WebAssemblyTypeUtilities.h" #include "Utils/WebAssemblyUtilities.h" diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -13,6 +13,7 @@ #include "WebAssemblyTargetMachine.h" #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" +#include "MCTargetDesc/WebAssemblyMCUtilities.h" #include "TargetInfo/WebAssemblyTargetInfo.h" #include "Utils/WebAssemblyUtilities.h" #include "WebAssembly.h"