[llvm] 484b4f3 - [WebAssembly][NFC] Refactor table handling in WebAssembly::wasmSymbolSetType

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 5 21:18:10 PDT 2022


Author: Alex Bradbury
Date: 2022-07-06T05:16:25+01:00
New Revision: 484b4f3579808386b6b9314be1e841ffe3d769a6

URL: https://github.com/llvm/llvm-project/commit/484b4f3579808386b6b9314be1e841ffe3d769a6
DIFF: https://github.com/llvm/llvm-project/commit/484b4f3579808386b6b9314be1e841ffe3d769a6.diff

LOG: [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).

This relands 8ccc7e0aa461 (which had compilation errors).

Added: 
    

Modified: 
    llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
index 0f1655718481a..e0490c4b0b06c 100644
--- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
+++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyTypeUtilities.cpp
@@ -175,33 +175,28 @@ void WebAssembly::wasmSymbolSetType(MCSymbolWasm *Sym, const Type *GlobalVT,
   // 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 Type;
+  wasm::ValType ValTy;
   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))
+      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) {
-    Type = WebAssembly::toValType(VTs[0]);
+    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(Type);
+    Sym->setTableType(ValTy);
   } else {
     Sym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
-    Sym->setGlobalType(wasm::WasmGlobalType{uint8_t(Type), /*Mutable=*/true});
+    Sym->setGlobalType(wasm::WasmGlobalType{uint8_t(ValTy), /*Mutable=*/true});
   }
 }


        


More information about the llvm-commits mailing list