2019-03-18 14:30:34 +00:00
|
|
|
// Copyright 2019 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: --experimental-wasm-compilation-hints
|
|
|
|
|
|
|
|
load('test/mjsunit/wasm/wasm-module-builder.js');
|
|
|
|
|
|
|
|
(function testDecodeCompilationHintsSectionNoDowngrade() {
|
2019-04-25 08:24:11 +00:00
|
|
|
print(arguments.callee.name);
|
2019-03-18 14:30:34 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addImport('mod', 'pow', kSig_i_ii);
|
|
|
|
builder.addFunction('upow', kSig_i_i)
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, 0,
|
|
|
|
kExprLocalGet, 0,
|
2019-03-18 14:30:34 +00:00
|
|
|
kExprCallFunction, 0])
|
2019-04-17 17:55:36 +00:00
|
|
|
.setCompilationHint(kCompilationHintStrategyLazy,
|
|
|
|
kCompilationHintTierOptimized,
|
|
|
|
kCompilationHintTierBaseline)
|
2019-03-18 14:30:34 +00:00
|
|
|
.exportFunc();
|
|
|
|
assertThrows(() => builder.instantiate({mod: {pow: Math.pow}}),
|
|
|
|
WebAssembly.CompileError,
|
2020-04-29 15:04:46 +00:00
|
|
|
"WebAssembly.Module(): Invalid compilation hint 0x19 " +
|
2019-03-18 14:30:34 +00:00
|
|
|
"(forbidden downgrade) @+70");
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function testDecodeCompilationHintsSectionNoTiering() {
|
2019-04-25 08:24:11 +00:00
|
|
|
print(arguments.callee.name);
|
2019-03-18 14:30:34 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addImport('mod', 'pow', kSig_i_ii);
|
|
|
|
builder.addFunction('upow', kSig_i_i)
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, 0,
|
|
|
|
kExprLocalGet, 0,
|
2019-03-18 14:30:34 +00:00
|
|
|
kExprCallFunction, 0])
|
2019-04-17 17:55:36 +00:00
|
|
|
.setCompilationHint(kCompilationHintStrategyDefault,
|
2020-04-29 15:04:46 +00:00
|
|
|
kCompilationHintTierBaseline,
|
|
|
|
kCompilationHintTierBaseline)
|
2019-03-18 14:30:34 +00:00
|
|
|
.exportFunc();
|
|
|
|
builder.addFunction('upow2', kSig_i_i)
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, 0,
|
|
|
|
kExprLocalGet, 0,
|
2019-03-18 14:30:34 +00:00
|
|
|
kExprCallFunction, 0])
|
|
|
|
builder.addFunction('upow3', kSig_i_i)
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, 0,
|
|
|
|
kExprLocalGet, 0,
|
2019-03-18 14:30:34 +00:00
|
|
|
kExprCallFunction, 0])
|
|
|
|
let instance = builder.instantiate({mod: {pow: Math.pow}});
|
|
|
|
assertEquals(27, instance.exports.upow(3))
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function testDecodeCompilationHintsSectionUpgrade() {
|
2019-04-25 08:24:11 +00:00
|
|
|
print(arguments.callee.name);
|
2019-03-18 14:30:34 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addImport('mod', 'pow', kSig_i_ii);
|
|
|
|
builder.addFunction('upow2', kSig_i_i)
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, 0,
|
|
|
|
kExprLocalGet, 0,
|
2019-03-18 14:30:34 +00:00
|
|
|
kExprCallFunction, 0])
|
|
|
|
builder.addFunction('upow3', kSig_i_i)
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, 0,
|
|
|
|
kExprLocalGet, 0,
|
2019-03-18 14:30:34 +00:00
|
|
|
kExprCallFunction, 0])
|
|
|
|
builder.addFunction('upow', kSig_i_i)
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, 0,
|
|
|
|
kExprLocalGet, 0,
|
2019-03-18 14:30:34 +00:00
|
|
|
kExprCallFunction, 0])
|
2019-04-17 17:55:36 +00:00
|
|
|
.setCompilationHint(kCompilationHintStrategyEager,
|
|
|
|
kCompilationHintTierBaseline,
|
|
|
|
kCompilationHintTierOptimized)
|
2019-03-18 14:30:34 +00:00
|
|
|
.exportFunc();
|
|
|
|
let instance = builder.instantiate({mod: {pow: Math.pow}});
|
|
|
|
assertEquals(27, instance.exports.upow(3))
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function testDecodeCompilationHintsSectionNoImport() {
|
2019-04-25 08:24:11 +00:00
|
|
|
print(arguments.callee.name);
|
2019-03-18 14:30:34 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addFunction('sq', kSig_i_i)
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, 0,
|
|
|
|
kExprLocalGet, 0,
|
2019-03-18 14:30:34 +00:00
|
|
|
kExprI32Mul])
|
2019-04-17 17:55:36 +00:00
|
|
|
.setCompilationHint(kCompilationHintStrategyEager,
|
|
|
|
kCompilationHintTierDefault,
|
|
|
|
kCompilationHintTierOptimized)
|
2019-03-18 14:30:34 +00:00
|
|
|
.exportFunc();
|
|
|
|
let instance = builder.instantiate();
|
|
|
|
assertEquals(9, instance.exports.sq(3))
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function testDecodeCompilationHintsSectionNoExport() {
|
2019-04-25 08:24:11 +00:00
|
|
|
print(arguments.callee.name);
|
2019-03-18 14:30:34 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addFunction('sq', kSig_i_i)
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, 0,
|
|
|
|
kExprLocalGet, 0,
|
2019-03-18 14:30:34 +00:00
|
|
|
kExprI32Mul])
|
2019-04-17 17:55:36 +00:00
|
|
|
.setCompilationHint(kCompilationHintStrategyEager,
|
|
|
|
kCompilationHintTierDefault,
|
|
|
|
kCompilationHintTierOptimized)
|
2019-04-16 14:37:38 +00:00
|
|
|
builder.instantiate();
|
2019-03-18 14:30:34 +00:00
|
|
|
})();
|
|
|
|
|
2019-04-03 10:15:58 +00:00
|
|
|
(function testDecodeCompilationHintsSectionTopTierDefault() {
|
2019-04-25 08:24:11 +00:00
|
|
|
print(arguments.callee.name);
|
2019-03-18 14:30:34 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addFunction('sq', kSig_i_i)
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, 0,
|
|
|
|
kExprLocalGet, 0,
|
2019-03-18 14:30:34 +00:00
|
|
|
kExprI32Mul])
|
2019-04-17 17:55:36 +00:00
|
|
|
.setCompilationHint(kCompilationHintStrategyEager,
|
|
|
|
kCompilationHintTierOptimized,
|
|
|
|
kCompilationHintTierDefault)
|
2019-03-18 14:30:34 +00:00
|
|
|
.exportFunc();
|
|
|
|
let instance = builder.instantiate();
|
|
|
|
assertEquals(9, instance.exports.sq(3))
|
|
|
|
})();
|
|
|
|
|
2019-04-25 15:54:16 +00:00
|
|
|
(function testDecodeCompilationHintsLazyBaselineEagerTopTier() {
|
2019-04-25 08:24:11 +00:00
|
|
|
print(arguments.callee.name);
|
2019-03-18 14:30:34 +00:00
|
|
|
let builder = new WasmModuleBuilder();
|
|
|
|
builder.addFunction('sq', kSig_i_i)
|
2019-10-08 12:38:48 +00:00
|
|
|
.addBody([kExprLocalGet, 0,
|
|
|
|
kExprLocalGet, 0,
|
2019-03-18 14:30:34 +00:00
|
|
|
kExprI32Mul])
|
2019-04-25 15:54:16 +00:00
|
|
|
.setCompilationHint(kCompilationHintStrategyLazyBaselineEagerTopTier,
|
2019-04-17 17:55:36 +00:00
|
|
|
kCompilationHintTierOptimized,
|
|
|
|
kCompilationHintTierDefault)
|
2019-03-18 14:30:34 +00:00
|
|
|
.exportFunc();
|
2019-04-25 15:54:16 +00:00
|
|
|
builder.instantiate();
|
2019-03-18 14:30:34 +00:00
|
|
|
})();
|