2024-08-14 20:41:00 +02:00
|
|
|
// Copyright 2024 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: --wasm-deopt --allow-natives-syntax --no-jit-fuzzing --liftoff
|
2025-04-29 08:03:15 +02:00
|
|
|
// Flags: --wasm-inlining-call-indirect
|
2024-08-14 20:41:00 +02:00
|
|
|
|
|
|
|
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
|
|
|
|
|
|
|
|
(function TestCallRef() {
|
|
|
|
const builder = new WasmModuleBuilder();
|
|
|
|
let calleeSig = builder.addType(makeSig([], [kWasmI32]));
|
|
|
|
let mainSig = builder.addType(makeSig([wasmRefType(calleeSig)], [kWasmI32]));
|
|
|
|
builder.addFunction("callee_0", calleeSig)
|
|
|
|
.exportFunc()
|
|
|
|
.addBody([kExprI32Const, 42]);
|
|
|
|
|
|
|
|
builder.addFunction("main", mainSig).exportFunc()
|
|
|
|
.addBody([
|
|
|
|
kExprLocalGet, 0,
|
|
|
|
kExprCallRef, calleeSig,
|
|
|
|
]);
|
|
|
|
|
|
|
|
const instance = builder.instantiate({});
|
|
|
|
|
|
|
|
instance.exports.main(instance.exports.callee_0);
|
|
|
|
%WasmTierUpFunction(instance.exports.main);
|
|
|
|
instance.exports.main(instance.exports.callee_0);
|
2024-09-17 12:09:47 +02:00
|
|
|
if (%IsWasmTieringPredictable()) {
|
2024-08-14 20:41:00 +02:00
|
|
|
assertTrue(%IsTurboFanFunction(instance.exports.main));
|
|
|
|
}
|
|
|
|
|
|
|
|
const instance2 = builder.instantiate({});
|
2024-09-17 12:09:47 +02:00
|
|
|
if (%IsWasmTieringPredictable()) {
|
2024-08-14 20:41:00 +02:00
|
|
|
assertTrue(%IsTurboFanFunction(instance2.exports.main));
|
|
|
|
}
|
|
|
|
instance2.exports.main(instance.exports.callee_0);
|
2024-09-17 12:09:47 +02:00
|
|
|
if (%IsWasmTieringPredictable()) {
|
2024-08-14 20:41:00 +02:00
|
|
|
assertFalse(%IsTurboFanFunction(instance2.exports.main));
|
|
|
|
}
|
|
|
|
%WasmTierUpFunction(instance2.exports.main);
|
|
|
|
instance2.exports.main(instance.exports.callee_0);
|
2024-09-17 12:09:47 +02:00
|
|
|
if (%IsWasmTieringPredictable()) {
|
2024-08-14 20:41:00 +02:00
|
|
|
assertTrue(%IsTurboFanFunction(instance2.exports.main));
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function TestCallIndirect() {
|
|
|
|
const builder = new WasmModuleBuilder();
|
|
|
|
let calleeSig = builder.addType(makeSig([], [kWasmI32]));
|
|
|
|
let mainSig = builder.addType(makeSig([kWasmI32], [kWasmI32]));
|
|
|
|
let callee1 = builder.addFunction("callee1", calleeSig)
|
|
|
|
.exportFunc()
|
|
|
|
.addBody([kExprI32Const, 42]);
|
|
|
|
let callee2 = builder.addFunction("callee2", calleeSig)
|
|
|
|
.exportFunc()
|
|
|
|
.addBody([kExprI32Const, 10]);
|
|
|
|
|
|
|
|
let table = builder.addTable(kWasmFuncRef, 2);
|
|
|
|
builder.addActiveElementSegment(table.index, wasmI32Const(0), [
|
|
|
|
[kExprRefFunc, callee1.index],
|
|
|
|
[kExprRefFunc, callee2.index],
|
|
|
|
], kWasmFuncRef);
|
|
|
|
|
|
|
|
|
|
|
|
builder.addFunction("main", mainSig).exportFunc()
|
|
|
|
.addBody([
|
|
|
|
kExprLocalGet, 0,
|
|
|
|
kExprCallIndirect, calleeSig, table.index,
|
|
|
|
]);
|
|
|
|
|
|
|
|
const instance = builder.instantiate({});
|
|
|
|
|
|
|
|
instance.exports.main(0);
|
|
|
|
%WasmTierUpFunction(instance.exports.main);
|
|
|
|
instance.exports.main(0);
|
2024-09-17 12:09:47 +02:00
|
|
|
if (%IsWasmTieringPredictable()) {
|
2024-08-14 20:41:00 +02:00
|
|
|
assertTrue(%IsTurboFanFunction(instance.exports.main));
|
|
|
|
}
|
|
|
|
|
|
|
|
const instance2 = builder.instantiate({});
|
2024-09-17 12:09:47 +02:00
|
|
|
if (%IsWasmTieringPredictable()) {
|
2024-08-14 20:41:00 +02:00
|
|
|
assertTrue(%IsTurboFanFunction(instance2.exports.main));
|
|
|
|
}
|
|
|
|
instance2.exports.main(1);
|
2024-09-17 12:09:47 +02:00
|
|
|
if (%IsWasmTieringPredictable()) {
|
2024-08-14 20:41:00 +02:00
|
|
|
assertFalse(%IsTurboFanFunction(instance2.exports.main));
|
|
|
|
}
|
|
|
|
%WasmTierUpFunction(instance2.exports.main);
|
|
|
|
instance2.exports.main(1);
|
2024-09-17 12:09:47 +02:00
|
|
|
if (%IsWasmTieringPredictable()) {
|
2024-08-14 20:41:00 +02:00
|
|
|
assertTrue(%IsTurboFanFunction(instance2.exports.main));
|
|
|
|
}
|
|
|
|
})();
|