aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/WebAssembly/Utils
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/WebAssembly/Utils')
-rw-r--r--llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp116
-rw-r--r--llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h93
-rw-r--r--llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp24
-rw-r--r--llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.h6
4 files changed, 21 insertions, 218 deletions
diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
index 998905402b39..bf5db09e05de 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<wasm::ValType> 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<WebAssembly::BlockType>(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<MVT>(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<unsigned>(Type));
-}
-
-std::string WebAssembly::typeListToString(ArrayRef<wasm::ValType> 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,34 +63,13 @@ 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());
}
void WebAssembly::wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
- const SmallVector<MVT, 1> &VTs) {
+ const ArrayRef<MVT> &VTs) {
assert(!Sym->getType());
// Tables are represented as Arrays in LLVM IR therefore
@@ -183,13 +77,13 @@ void WebAssembly::wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
// that is a reference type.
wasm::ValType ValTy;
bool IsTable = false;
- if (GlobalVT->isArrayTy() &&
- WebAssembly::isRefType(GlobalVT->getArrayElementType())) {
+ if (GlobalVT->isArrayTy() && WebAssembly::isWebAssemblyReferenceType(
+ GlobalVT->getArrayElementType())) {
IsTable = true;
const Type *ElTy = GlobalVT->getArrayElementType();
- if (WebAssembly::isExternrefType(ElTy))
+ if (WebAssembly::isWebAssemblyExternrefType(ElTy))
ValTy = wasm::ValType::EXTERNREF;
- else if (WebAssembly::isFuncrefType(ElTy))
+ else if (WebAssembly::isWebAssemblyFuncrefType(ElTy))
ValTy = wasm::ValType::FUNCREF;
else
report_fatal_error("unhandled reference type");
diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
index 33f3bf31595d..9f58d7582fab 100644
--- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
+++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.h
@@ -15,10 +15,12 @@
#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/CodeGen/MachineValueType.h"
+#include "llvm/CodeGen/WasmAddressSpaces.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/MC/MCSymbolWasm.h"
-#include "llvm/Support/MachineValueType.h"
namespace llvm {
@@ -26,99 +28,36 @@ 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,
- // 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<PointerType>(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
+/// Return true if this is a WebAssembly Externref Type.
+inline bool isWebAssemblyExternrefType(const Type *Ty) {
+ return Ty->getPointerAddressSpace() ==
+ WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
}
-inline bool isExternrefType(const Type *Ty) {
- return isa<PointerType>(Ty) &&
- Ty->getPointerAddressSpace() ==
- WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF;
-}
-inline bool isRefType(const Type *Ty) {
- return isFuncrefType(Ty) || isExternrefType(Ty);
+
+/// Return true if this is a WebAssembly Funcref Type.
+inline bool isWebAssemblyFuncrefType(const Type *Ty) {
+ return Ty->getPointerAddressSpace() ==
+ WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF;
}
-inline bool isRefType(wasm::ValType Type) {
- return Type == wasm::ValType::EXTERNREF || Type == wasm::ValType::FUNCREF;
+/// Return true if this is a WebAssembly Reference Type.
+inline bool isWebAssemblyReferenceType(const Type *Ty) {
+ return isWebAssemblyExternrefType(Ty) || isWebAssemblyFuncrefType(Ty);
}
// Convert StringRef to ValType / HealType / BlockType
-std::optional<wasm::ValType> 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<wasm::ValType> 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);
/// Sets a Wasm Symbol Type.
void wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
- const SmallVector<MVT, 1> &VTs);
+ const ArrayRef<MVT> &VTs);
} // end namespace WebAssembly
} // end namespace llvm
diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp
index a1e0db692390..8d7fa4dc3dee 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<bool> 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<bool> WebAssembly::WasmEnableEmSjLj(
- "enable-emscripten-sjlj",
- cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
- cl::init(false));
-// Exception handling using wasm EH instructions
-cl::opt<bool>
- WebAssembly::WasmEnableEH("wasm-enable-eh",
- cl::desc("WebAssembly exception handling"),
- cl::init(false));
-// setjmp/longjmp handling using wasm EH instrutions
-cl::opt<bool>
- 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 d0639208fda9..7f28fb1858a6 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<bool> WasmEnableEmEH; // asm.js-style EH
-extern cl::opt<bool> WasmEnableEmSjLj; // asm.js-style SjLJ
-extern cl::opt<bool> WasmEnableEH; // EH using Wasm EH instructions
-extern cl::opt<bool> WasmEnableSjLj; // SjLj using Wasm EH instructions
-
// Exception-related function names
extern const char *const ClangCallTerminateFn;
extern const char *const CxaBeginCatchFn;