From 8ccc7e0aa461350bce02d70669c11f4a5e300ee7 Mon Sep 17 00:00:00 2001 From: Alex Bradbury Date: Wed, 6 Jul 2022 04:54:13 +0100 Subject: [PATCH] [WebAssembly][NFC] Refactor table handling in WebAssembly::wasmSymbolSetType Use the isExternRefType and isFuncRefType helpers rather than reimplementing that logic in this function (which acts as a blocker to work to prototype alternative IR-level representations of reference types). --- .../Utils/WebAssemblyTypeUtilities.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp index 0f1655718481..e087c7bd52b3 100644 --- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp +++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp @@ -179,19 +179,14 @@ void WebAssembly::wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT, bool IsTable = false; if (GlobalVT->isArrayTy() && WebAssembly::isRefType(GlobalVT->getArrayElementType())) { - MVT VT; IsTable = true; - switch (GlobalVT->getArrayElementType()->getPointerAddressSpace()) { - case WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_FUNCREF: - VT = MVT::funcref; - break; - case WebAssembly::WasmAddressSpace::WASM_ADDRESS_SPACE_EXTERNREF: - VT = MVT::externref; - break; - default: - report_fatal_error("unhandled address space type"); - } - Type = WebAssembly::toValType(VT); + const Type *ElTy = GlobalVT->getArrayElementType(); + if (WebAssembly::isExternRefType(ElTy)) + Type = wasm::ValType::EXTERNREF; + else if (WebAssembly::isFuncRefType(ElTy)) + Type = wasm::ValType::FUNCREF; + else + report_fatal_error("unhandled reference type"); } else if (VTs.size() == 1) { Type = WebAssembly::toValType(VTs[0]); } else