mirror of
https://github.com/nodejs/node.git
synced 2025-05-15 16:01:52 +00:00

PR-URL: https://github.com/nodejs/node/pull/47251 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Richard Lau <rlau@redhat.com>
56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
// Copyright 2023 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// Flags: --allow-natives-syntax --turbofan --no-always-turbofan
|
|
|
|
d8.file.execute("test/mjsunit/wasm/wasm-module-builder.js");
|
|
|
|
function testOptimized(fct) {
|
|
%PrepareFunctionForOptimization(fct);
|
|
for (let i = 0; i < 10; ++i) {
|
|
fct();
|
|
}
|
|
%OptimizeFunctionOnNextCall(fct);
|
|
fct();
|
|
assertOptimized(fct);
|
|
}
|
|
|
|
(function TestWrapperInlining() {
|
|
print(arguments.callee.name);
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addFunction('i32Add', makeSig([kWasmI32, kWasmI32], [kWasmI32]))
|
|
.addBody([
|
|
kExprLocalGet, 0,
|
|
kExprLocalGet, 1,
|
|
kExprI32Add,
|
|
])
|
|
.exportFunc();
|
|
|
|
builder.addFunction('i32Mul', makeSig([kWasmI32, kWasmI32], [kWasmI32]))
|
|
.addBody([
|
|
kExprLocalGet, 0,
|
|
kExprLocalGet, 1,
|
|
kExprI32Mul,
|
|
])
|
|
.exportFunc();
|
|
|
|
let instance = builder.instantiate({});
|
|
let wasmFct = instance.exports.i32Add;
|
|
let fct = () => wasmFct(3, 5);
|
|
|
|
testOptimized(fct);
|
|
// Replacing the wasm function will cause a deopt.
|
|
wasmFct = instance.exports.i32Mul;
|
|
assertEquals(15, fct());
|
|
assertUnoptimized(fct);
|
|
|
|
// Running it again multiple times will optimize the function again.
|
|
testOptimized(fct);
|
|
// Switching back to the previous wasm function will not cause a deopt.
|
|
wasmFct = instance.exports.i32Add;
|
|
assertEquals(8, fct());
|
|
assertOptimized(fct);
|
|
})();
|