[llvm] 219a2eb - [WebAssembly] Update WebAssemblyAsmTypeCheck for table.get
Paulo Matos via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 5 07:57:34 PST 2022
Author: kamenokonokotan
Date: 2022-03-05T16:57:29+01:00
New Revision: 219a2eb4d48fd5708452ed5cec14a9e1609c9ee5
URL: https://github.com/llvm/llvm-project/commit/219a2eb4d48fd5708452ed5cec14a9e1609c9ee5
DIFF: https://github.com/llvm/llvm-project/commit/219a2eb4d48fd5708452ed5cec14a9e1609c9ee5.diff
LOG: [WebAssembly] Update WebAssemblyAsmTypeCheck for table.get
This patch is aimed to resolve [[ https://github.com/llvm/llvm-project/issues/53789 | GitHub Issue #53789 ]].
Reviewed By: sbc100
Differential Revision: https://reviews.llvm.org/D120229
Added:
llvm/test/MC/WebAssembly/funcref-from-table.s
Modified:
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
index 128ce5c4fec0a..d9f96d9a64190 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.cpp
@@ -182,6 +182,20 @@ bool WebAssemblyAsmTypeCheck::getGlobal(SMLoc ErrorLoc, const MCInst &Inst,
return false;
}
+bool WebAssemblyAsmTypeCheck::getTable(SMLoc ErrorLoc, const MCInst &Inst,
+ wasm::ValType &Type) {
+ const MCSymbolRefExpr *SymRef;
+ if (getSymRef(ErrorLoc, Inst, SymRef))
+ return true;
+ auto WasmSym = cast<MCSymbolWasm>(&SymRef->getSymbol());
+ if (WasmSym->getType().getValueOr(wasm::WASM_SYMBOL_TYPE_DATA) !=
+ wasm::WASM_SYMBOL_TYPE_TABLE)
+ return typeError(ErrorLoc, StringRef("symbol ") + WasmSym->getName() +
+ " missing .tabletype");
+ Type = static_cast<wasm::ValType>(WasmSym->getTableType().ElemType);
+ return false;
+}
+
bool WebAssemblyAsmTypeCheck::endOfFunction(SMLoc ErrorLoc) {
// Check the return types.
for (auto RVT : llvm::reverse(ReturnTypes)) {
@@ -225,6 +239,28 @@ bool WebAssemblyAsmTypeCheck::typeCheck(SMLoc ErrorLoc, const MCInst &Inst) {
return true;
if (popType(ErrorLoc, Type))
return true;
+ } else if (Name == "table.get") {
+ if (getTable(ErrorLoc, Inst, Type))
+ return true;
+ if (popType(ErrorLoc, wasm::ValType::I32))
+ return true;
+ Stack.push_back(Type);
+ } else if (Name == "table.set") {
+ if (getTable(ErrorLoc, Inst, Type))
+ return true;
+ if (popType(ErrorLoc, Type))
+ return true;
+ if (popType(ErrorLoc, wasm::ValType::I32))
+ return true;
+ } else if (Name == "table.fill") {
+ if (getTable(ErrorLoc, Inst, Type))
+ return true;
+ if (popType(ErrorLoc, wasm::ValType::I32))
+ return true;
+ if (popType(ErrorLoc, Type))
+ return true;
+ if (popType(ErrorLoc, wasm::ValType::I32))
+ return true;
} else if (Name == "drop") {
if (popType(ErrorLoc, {}))
return true;
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.h b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.h
index 2b07faf67a182..a186762dc2de4 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.h
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmTypeCheck.h
@@ -44,6 +44,7 @@ class WebAssemblyAsmTypeCheck final {
bool getSymRef(SMLoc ErrorLoc, const MCInst &Inst,
const MCSymbolRefExpr *&SymRef);
bool getGlobal(SMLoc ErrorLoc, const MCInst &Inst, wasm::ValType &Type);
+ bool getTable(SMLoc ErrorLoc, const MCInst &Inst, wasm::ValType &Type);
public:
WebAssemblyAsmTypeCheck(MCAsmParser &Parser, const MCInstrInfo &MII, bool is64);
diff --git a/llvm/test/MC/WebAssembly/funcref-from-table.s b/llvm/test/MC/WebAssembly/funcref-from-table.s
new file mode 100644
index 0000000000000..62c817c8b76bc
--- /dev/null
+++ b/llvm/test/MC/WebAssembly/funcref-from-table.s
@@ -0,0 +1,21 @@
+# RUN: llvm-mc -mattr=+reference-types -triple=wasm32-unknown-unknown -filetype=obj -o - < %s | obj2yaml | FileCheck %s
+
+.globl __indirect_function_table
+.tabletype __indirect_function_table, funcref
+
+.globl obtain_funcref_from_table_index
+
+obtain_funcref_from_table_index:
+ .functype obtain_funcref_from_table_index(i32) -> (funcref)
+ local.get 0
+ table.get __indirect_function_table
+ end_function
+
+# CHECK: Sections:
+# CHECK-NEXT: - Type: TYPE
+# CHECK-NEXT: Signatures:
+# CHECK-NEXT: - Index: 0
+# CHECK-NEXT: ParamTypes:
+# CHECK-NEXT: - I32
+# CHECK-NEXT: ReturnTypes:
+# CHECK-NEXT: - FUNCREF
More information about the llvm-commits
mailing list