diff options
author | Ashley Nelson <nashley@google.com> | 2022-08-17 18:44:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-17 18:44:29 -0700 |
commit | 3aff4c6e85623c970280219c6699a66bc9de5f9b (patch) | |
tree | e5440bc966e523a7404ae2cec3458dacbe1281d1 /test/binaryen.js/expressions.js | |
parent | b70fe755aa4c90727edfd91dc0a9a51febf0239d (diff) | |
download | binaryen-3aff4c6e85623c970280219c6699a66bc9de5f9b.tar.gz binaryen-3aff4c6e85623c970280219c6699a66bc9de5f9b.tar.bz2 binaryen-3aff4c6e85623c970280219c6699a66bc9de5f9b.zip |
Mutli-Memories Support in IR (#4811)
This PR removes the single memory restriction in IR, adding support for a single module to reference multiple memories. To support this change, a new memory name field was added to 13 memory instructions in order to identify the memory for the instruction.
It is a goal of this PR to maintain backwards compatibility with existing text and binary wasm modules, so memory indexes remain optional for memory instructions. Similarly, the JS API makes assumptions about which memory is intended when only one memory is present in the module. Another goal of this PR is that existing tests behavior be unaffected. That said, tests must now explicitly define a memory before invoking memory instructions or exporting a memory, and memory names are now printed for each memory instruction in the text format.
There remain quite a few places where a hardcoded reference to the first memory persist (memory flattening, for example, will return early if more than one memory is present in the module). Many of these call-sites, particularly within passes, will require us to rethink how the optimization works in a multi-memories world. Other call-sites may necessitate more invasive code restructuring to fully convert away from relying on a globally available, single memory pointer.
Diffstat (limited to 'test/binaryen.js/expressions.js')
-rw-r--r-- | test/binaryen.js/expressions.js | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/test/binaryen.js/expressions.js b/test/binaryen.js/expressions.js index 40d4194fd..71846f3c6 100644 --- a/test/binaryen.js/expressions.js +++ b/test/binaryen.js/expressions.js @@ -476,7 +476,7 @@ console.log("# GlobalSet"); console.log("# MemorySize"); (function testMemorySize() { const module = new binaryen.Module(); - + module.setMemory(1, 1, null); var type = binaryen.i32; const theMemorySize = binaryen.MemorySize(module.memory.size()); assert(theMemorySize instanceof binaryen.MemorySize); @@ -492,7 +492,7 @@ console.log("# MemorySize"); assert( theMemorySize.toText() == - "(memory.size)\n" + "(memory.size $0)\n" ); module.dispose(); @@ -501,6 +501,7 @@ console.log("# MemorySize"); console.log("# MemoryGrow"); (function testMemoryGrow() { const module = new binaryen.Module(); + module.setMemory(1, 1, null); var type = binaryen.i32; var delta = module.i32.const(1); @@ -521,7 +522,7 @@ console.log("# MemoryGrow"); assert( theMemoryGrow.toText() == - "(memory.grow\n (i32.const 2)\n)\n" + "(memory.grow $0\n (i32.const 2)\n)\n" ); module.dispose(); @@ -530,6 +531,7 @@ console.log("# MemoryGrow"); console.log("# Load"); (function testLoad() { const module = new binaryen.Module(); + module.setMemory(1, 1, null); var offset = 16; var align = 2; @@ -566,7 +568,7 @@ console.log("# Load"); assert( theLoad.toText() == - "(i64.atomic.load offset=32 align=4\n (i32.const 128)\n)\n" + "(i64.atomic.load $0 offset=32 align=4\n (i32.const 128)\n)\n" ); module.dispose(); @@ -575,6 +577,7 @@ console.log("# Load"); console.log("# Store"); (function testStore() { const module = new binaryen.Module(); + module.setMemory(1, 1, null); var offset = 16; var align = 2; @@ -615,7 +618,7 @@ console.log("# Store"); assert( theStore.toText() == - "(i64.atomic.store offset=32 align=4\n (i32.const 128)\n (i32.const 2)\n)\n" + "(i64.atomic.store $0 offset=32 align=4\n (i32.const 128)\n (i32.const 2)\n)\n" ); module.dispose(); @@ -822,6 +825,7 @@ console.log("# Return"); console.log("# AtomicRMW"); (function testAtomicRMW() { const module = new binaryen.Module(); + module.setMemory(1, 1, null); var op = binaryen.Operations.AtomicRMWAdd; var offset = 8; @@ -855,7 +859,7 @@ console.log("# AtomicRMW"); assert( theAtomicRMW.toText() == - "(i64.atomic.rmw16.sub_u offset=16\n (i32.const 4)\n (i64.const 5)\n)\n" + "(i64.atomic.rmw16.sub_u $0 offset=16\n (i32.const 4)\n (i64.const 5)\n)\n" ); module.dispose(); @@ -864,6 +868,7 @@ console.log("# AtomicRMW"); console.log("# AtomicCmpxchg"); (function testAtomicCmpxchg() { const module = new binaryen.Module(); + module.setMemory(1, 1, null); var offset = 8; var ptr = module.i32.const(2); @@ -897,7 +902,7 @@ console.log("# AtomicCmpxchg"); assert( theAtomicCmpxchg.toText() == - "(i64.atomic.rmw16.cmpxchg_u offset=16\n (i32.const 5)\n (i64.const 6)\n (i64.const 7)\n)\n" + "(i64.atomic.rmw16.cmpxchg_u $0 offset=16\n (i32.const 5)\n (i64.const 6)\n (i64.const 7)\n)\n" ); module.dispose(); @@ -906,6 +911,7 @@ console.log("# AtomicCmpxchg"); console.log("# AtomicWait"); (function testAtomicWait() { const module = new binaryen.Module(); + module.setMemory(1, 1, null); var ptr = module.i32.const(2); var expected = module.i32.const(3); @@ -935,7 +941,7 @@ console.log("# AtomicWait"); assert( theAtomicWait.toText() == - "(memory.atomic.wait64\n (i32.const 5)\n (i32.const 6)\n (i64.const 7)\n)\n" + "(memory.atomic.wait64 $0\n (i32.const 5)\n (i32.const 6)\n (i64.const 7)\n)\n" ); module.dispose(); @@ -944,6 +950,7 @@ console.log("# AtomicWait"); console.log("# AtomicNotify"); (function testAtomicNotify() { const module = new binaryen.Module(); + module.setMemory(1, 1, null); var ptr = module.i32.const(1); var notifyCount = module.i32.const(2); @@ -966,7 +973,7 @@ console.log("# AtomicNotify"); assert( theAtomicNotify.toText() == - "(memory.atomic.notify\n (i32.const 3)\n (i32.const 4)\n)\n" + "(memory.atomic.notify $0\n (i32.const 3)\n (i32.const 4)\n)\n" ); module.dispose(); @@ -1172,6 +1179,7 @@ console.log("# SIMDShift"); console.log("# SIMDLoad"); (function testSIMDLoad() { const module = new binaryen.Module(); + module.setMemory(1, 1, null); var op = binaryen.Operations.Load8x8SVec128; var offset = 16; @@ -1201,7 +1209,7 @@ console.log("# SIMDLoad"); assert( theSIMDLoad.toText() == - "(v128.load8_splat offset=32 align=4\n (i32.const 2)\n)\n" + "(v128.load8_splat $0 offset=32 align=4\n (i32.const 2)\n)\n" ); module.dispose(); @@ -1210,6 +1218,7 @@ console.log("# SIMDLoad"); console.log("# SIMDLoadStoreLane"); (function testSIMDLoadStoreLane() { const module = new binaryen.Module(); + module.setMemory(1, 1, null); var op = binaryen.Operations.Load8LaneVec128; var offset = 16; @@ -1249,7 +1258,7 @@ console.log("# SIMDLoadStoreLane"); assert( theSIMDLoadStoreLane.toText() == - "(v128.load16_lane offset=32 2\n (i32.const 2)\n (v128.const i32x4 0x01010101 0x01010101 0x01010101 0x01010101)\n)\n" + "(v128.load16_lane $0 offset=32 2\n (i32.const 2)\n (v128.const i32x4 0x01010101 0x01010101 0x01010101 0x01010101)\n)\n" ); theSIMDLoadStoreLane.op = op = binaryen.Operations.Store16LaneVec128; @@ -1263,7 +1272,7 @@ console.log("# SIMDLoadStoreLane"); assert( theSIMDLoadStoreLane.toText() == - "(v128.store16_lane offset=32 2\n (i32.const 2)\n (v128.const i32x4 0x01010101 0x01010101 0x01010101 0x01010101)\n)\n" + "(v128.store16_lane $0 offset=32 2\n (i32.const 2)\n (v128.const i32x4 0x01010101 0x01010101 0x01010101 0x01010101)\n)\n" ); module.dispose(); @@ -1272,6 +1281,7 @@ console.log("# SIMDLoadStoreLane"); console.log("# MemoryInit"); (function testMemoryInit() { const module = new binaryen.Module(); + module.setMemory(1, 1, null); var segment = 1; var dest = module.i32.const(2); @@ -1302,7 +1312,7 @@ console.log("# MemoryInit"); assert( theMemoryInit.toText() == - "(memory.init 5\n (i32.const 6)\n (i32.const 7)\n (i32.const 8)\n)\n" + "(memory.init $0 5\n (i32.const 6)\n (i32.const 7)\n (i32.const 8)\n)\n" ); module.dispose(); @@ -1338,6 +1348,7 @@ console.log("# DataDrop"); console.log("# MemoryCopy"); (function testMemoryCopy() { const module = new binaryen.Module(); + module.setMemory(1, 1, null); var dest = module.i32.const(1); var source = module.i32.const(2); @@ -1364,7 +1375,7 @@ console.log("# MemoryCopy"); assert( theMemoryCopy.toText() == - "(memory.copy\n (i32.const 4)\n (i32.const 5)\n (i32.const 6)\n)\n" + "(memory.copy $0 $0\n (i32.const 4)\n (i32.const 5)\n (i32.const 6)\n)\n" ); module.dispose(); @@ -1373,6 +1384,7 @@ console.log("# MemoryCopy"); console.log("# MemoryFill"); (function testMemoryFill() { const module = new binaryen.Module(); + module.setMemory(1, 1, null); var dest = module.i32.const(1); var value = module.i32.const(2); @@ -1399,7 +1411,7 @@ console.log("# MemoryFill"); assert( theMemoryFill.toText() == - "(memory.fill\n (i32.const 4)\n (i32.const 5)\n (i32.const 6)\n)\n" + "(memory.fill $0\n (i32.const 4)\n (i32.const 5)\n (i32.const 6)\n)\n" ); module.dispose(); |