diff options
author | Paulo Matos <pmatos@igalia.com> | 2021-06-10 10:02:10 +0200 |
---|---|---|
committer | Paulo Matos <pmatos@igalia.com> | 2021-07-02 09:46:28 +0200 |
commit | 4facbf213c51e4add2e8c19b08d5e58ad71c72de (patch) | |
tree | 3839ef3d80cdf776b0c168506aff893ed1a94aa4 /llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp | |
parent | 6944f7da25517cc554bf7fd11205082e2c976a97 (diff) | |
download | llvm-4facbf213c51e4add2e8c19b08d5e58ad71c72de.zip llvm-4facbf213c51e4add2e8c19b08d5e58ad71c72de.tar.gz llvm-4facbf213c51e4add2e8c19b08d5e58ad71c72de.tar.bz2 |
[WebAssembly] Implementation of global.get/set for reftypes in LLVM IR
Reland of 31859f896.
This change implements new DAG notes GLOBAL_GET/GLOBAL_SET, and
lowering methods for load and stores of reference types from IR
globals. Once the lowering creates the new nodes, tablegen pattern
matches those and converts them to Wasm global.get/set.
Differential Revision: https://reviews.llvm.org/D104797
Diffstat (limited to 'llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp index 824d336..3da80f4 100644 --- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp +++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp @@ -116,6 +116,31 @@ MCSymbolWasm *WebAssembly::getOrCreateFunctionTableSymbol( return Sym; } +MCSymbolWasm *WebAssembly::getOrCreateFuncrefCallTableSymbol( + MCContext &Ctx, const WebAssemblySubtarget *Subtarget) { + StringRef Name = "__funcref_call_table"; + MCSymbolWasm *Sym = cast_or_null<MCSymbolWasm>(Ctx.lookupSymbol(Name)); + if (Sym) { + if (!Sym->isFunctionTable()) + Ctx.reportError(SMLoc(), "symbol is not a wasm funcref table"); + } else { + Sym = cast<MCSymbolWasm>(Ctx.getOrCreateSymbol(Name)); + + // Setting Weak ensure only one table is left after linking when multiple + // modules define the table. + Sym->setWeak(true); + + wasm::WasmLimits Limits = {0, 1, 1}; + wasm::WasmTableType TableType = {wasm::WASM_TYPE_FUNCREF, Limits}; + Sym->setType(wasm::WASM_SYMBOL_TYPE_TABLE); + Sym->setTableType(TableType); + } + // MVP object files can't have symtab entries for tables. + if (!(Subtarget && Subtarget->hasReferenceTypes())) + Sym->setOmitFromLinkingSection(); + return Sym; +} + // Find a catch instruction from an EH pad. MachineInstr *WebAssembly::findCatch(MachineBasicBlock *EHPad) { assert(EHPad->isEHPad()); |