(callType, whatToInline)
| 18 | d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js'); |
| 19 | |
| 20 | function Test(callType, whatToInline) { |
| 21 | console.log(`Test: ${callType}, ${whatToInline}`); |
| 22 | |
| 23 | const builder = new WasmModuleBuilder(); |
| 24 | |
| 25 | let sig_index = builder.addType(kSig_v_v); |
| 26 | let mem_index = builder.addMemory(0); |
| 27 | |
| 28 | let mutateInstanceField = builder.addFunction(undefined, kSig_v_v).addBody([ |
| 29 | ...wasmI32Const(1), |
| 30 | kExprMemoryGrow, mem_index, |
| 31 | kExprDrop, |
| 32 | ]); |
| 33 | let noMutateInstanceField = builder.addFunction(undefined, kSig_v_v).addBody([ |
| 34 | kExprNop, |
| 35 | ]); |
| 36 | |
| 37 | let table = builder.addTable(kWasmFuncRef, 2, 2); |
| 38 | builder.addActiveElementSegment(table.index, wasmI32Const(0), [ |
| 39 | [kExprRefFunc, mutateInstanceField.index], |
| 40 | [kExprRefFunc, noMutateInstanceField.index], |
| 41 | ], kWasmFuncRef); |
| 42 | const kMutateInstanceFieldTableIndex = 0; |
| 43 | const kNoMutateInstanceFieldTableIndex = 1; |
| 44 | |
| 45 | let inlinedInBetween = builder.addFunction(undefined, kSig_v_i); |
| 46 | if (callType === 'return_call_ref') { |
| 47 | inlinedInBetween.addBody([ |
| 48 | kExprLocalGet, /* parameter */ 0, |
| 49 | kExprTableGet, table.index, |
| 50 | kGCPrefix, kExprRefCast, sig_index, |
| 51 | kExprReturnCallRef, sig_index |
| 52 | ]); |
| 53 | } else if (callType === 'return_call_indirect') { |
| 54 | inlinedInBetween.addBody([ |
| 55 | kExprLocalGet, /* parameter */ 0, |
| 56 | kExprCallIndirect, sig_index, table.index |
| 57 | ]); |
| 58 | } |
| 59 | |
| 60 | builder.addFunction("main", kSig_i_i).addBody([ |
| 61 | kExprLocalGet, 0, |
| 62 | kExprCallFunction, inlinedInBetween.index, |
| 63 | // Uses the mutable `memory_size_` field from the `InstanceCache` due to |
| 64 | // --wasm-enforce-bounds-checks. |
| 65 | ...wasmI32Const(42), |
| 66 | kExprI32LoadMem, mem_index, /* no alignment hint */ 0, |
| 67 | ]).exportFunc(); |
| 68 | |
| 69 | let { main } = builder.instantiate({}).exports; |
| 70 | if (whatToInline === "inline_memory_grow") { |
| 71 | // 1. Collect feedback with the version we want to be inlined. |
| 72 | // 2. Compile optimized code, transitively inline (confirm with --trace-wasm-inlining). |
| 73 | // 3. Run Turboshaft compiled version, but now run the slowpath. |
| 74 | assertEquals(0, main(kMutateInstanceFieldTableIndex)); |
| 75 | %WasmTierUpFunction(main); |
| 76 | assertEquals(0, main(kNoMutateInstanceFieldTableIndex)); |
| 77 | } else if (whatToInline === "inline_nop") { |
no test coverage detected
searching dependent graphs…