[llvm] b5b5f0a - [WebAssembly] Lower global syms representing tables with .tabletype
Paulo Matos via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 13 09:18:13 PST 2021
Author: Paulo Matos
Date: 2021-12-13T18:17:03+01:00
New Revision: b5b5f0ac77ab9f7aab8b503a8b20cab9f67e15d1
URL: https://github.com/llvm/llvm-project/commit/b5b5f0ac77ab9f7aab8b503a8b20cab9f67e15d1
DIFF: https://github.com/llvm/llvm-project/commit/b5b5f0ac77ab9f7aab8b503a8b20cab9f67e15d1.diff
LOG: [WebAssembly] Lower global syms representing tables with .tabletype
This patch implements a fix to recognize global symbols that represent
WebAssembly appropriately and generate the necessary .tabletype
directives.
Reviewed By: sbc100
Differential Revision: https://reviews.llvm.org/D115511
Added:
Modified:
llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
llvm/test/CodeGen/WebAssembly/externref-tableget.ll
llvm/test/CodeGen/WebAssembly/externref-tableset.ll
llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index 0d3f516932618..69911cb297774 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
@@ -196,6 +196,13 @@ void WebAssemblyAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
Sym->setGlobalType(wasm::WasmGlobalType{uint8_t(Type), Mutable});
}
+ // If the GlobalVariable refers to a table, we handle it here instead of
+ // in emitExternalDecls
+ if (Sym->isTable()) {
+ getTargetStreamer()->emitTableType(Sym);
+ return;
+ }
+
emitVisibility(Sym, GV->getVisibility(), !GV->isDeclaration());
if (GV->hasInitializer()) {
assert(getSymbolPreferLocal(*GV) == Sym);
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
index f315b63d7f67c..d3490e9b40d7f 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp
@@ -66,9 +66,11 @@ WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {
// they reach this point as aggregate Array types with an element type
// that is a reference type.
wasm::ValType Type;
+ 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;
@@ -85,9 +87,14 @@ WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {
} else
report_fatal_error("Aggregate globals not yet implemented");
- WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
- WasmSym->setGlobalType(
- wasm::WasmGlobalType{uint8_t(Type), /*Mutable=*/true});
+ if (IsTable) {
+ WasmSym->setType(wasm::WASM_SYMBOL_TYPE_TABLE);
+ WasmSym->setTableType(Type);
+ } else {
+ WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
+ WasmSym->setGlobalType(
+ wasm::WasmGlobalType{uint8_t(Type), /*Mutable=*/true});
+ }
}
return WasmSym;
}
diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
index e54e9e8060941..1161b6e3659ac 100644
--- a/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
+++ b/llvm/test/CodeGen/WebAssembly/externref-tableget.ll
@@ -73,4 +73,4 @@ define %externref @get_externref_from_table_with_var_offset2(i32 %i) {
ret %externref %ref
}
-; CHECK: .globl externref_table
+; CHECK: .tabletype externref_table, externref
diff --git a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
index 206612372b75f..025fb037328e1 100644
--- a/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
+++ b/llvm/test/CodeGen/WebAssembly/externref-tableset.ll
@@ -79,4 +79,4 @@ define void @set_externref_table_with_var_offset2(%externref %g, i32 %i) {
ret void
}
-; CHECK: .globl externref_table
+; CHECK: .tabletype externref_table, externref
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
index a9a317175e260..4b5a9b42f68bc 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-table_call.ll
@@ -13,7 +13,7 @@ define void @call_funcref_from_table(i32 %i) {
ret void
}
-; CHECK: .tabletype __funcref_call_table, funcref, 1
+; CHECK: .tabletype __funcref_call_table, funcref, 1
; CHECK-LABEL: call_funcref_from_table:
; CHECK-NEXT: .functype call_funcref_from_table (i32) -> ()
@@ -28,6 +28,5 @@ define void @call_funcref_from_table(i32 %i) {
; CHECK-NEXT: table.set __funcref_call_table
; CHECK-NEXT: end_function
+; CHECK: .tabletype funcref_table, funcref
-; CHECK: .globl funcref_table
-; CHECK-NEXT .globaltype funcref_table, funcref
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
index c374da7d1eb39..63cd69a2e9ffa 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-tableget.ll
@@ -72,4 +72,4 @@ define %funcref @get_funcref_from_table_with_var_offset2(i32 %i) {
ret %funcref %ref
}
-; CHECK: .globl funcref_table
+; CHECK: .tabletype funcref_table, funcref
diff --git a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
index 1bb50d16e3fef..ddc6c3e26b67d 100644
--- a/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
+++ b/llvm/test/CodeGen/WebAssembly/funcref-tableset.ll
@@ -78,4 +78,4 @@ define void @set_funcref_table_with_var_offset2(%funcref %g, i32 %i) {
ret void
}
-; CHECK: .globl funcref_table
+; CHECK: .tabletype funcref_table, funcref
More information about the llvm-commits
mailing list