aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Matos <pmatos@igalia.com>2021-12-13 17:45:51 +0100
committerPaulo Matos <pmatos@igalia.com>2021-12-13 18:17:03 +0100
commitb5b5f0ac77ab9f7aab8b503a8b20cab9f67e15d1 (patch)
tree09e25d7086f5653d519c1c6fa3239b9a052275c4
parentb18b2a01ef040698e8e6a2400d55a5c290f097b9 (diff)
downloadllvm-b5b5f0ac77ab9f7aab8b503a8b20cab9f67e15d1.zip
llvm-b5b5f0ac77ab9f7aab8b503a8b20cab9f67e15d1.tar.gz
llvm-b5b5f0ac77ab9f7aab8b503a8b20cab9f67e15d1.tar.bz2
[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
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp7
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp13
-rw-r--r--llvm/test/CodeGen/WebAssembly/externref-tableget.ll2
-rw-r--r--llvm/test/CodeGen/WebAssembly/externref-tableset.ll2
-rw-r--r--llvm/test/CodeGen/WebAssembly/funcref-table_call.ll5
-rw-r--r--llvm/test/CodeGen/WebAssembly/funcref-tableget.ll2
-rw-r--r--llvm/test/CodeGen/WebAssembly/funcref-tableset.ll2
7 files changed, 23 insertions, 10 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
index 0d3f516..69911cb 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 f315b63..d3490e9 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 e54e9e8..1161b6e 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 20661237..025fb03 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 a9a3171..4b5a9b4 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 c374da7..63cd69a 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 1bb50d1..ddc6c3e 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