compilation-hints-decoder.js 5 KB
Newer Older
1 2 3 4 5 6 7 8 9
// 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() {
10
  print(arguments.callee.name);
11 12 13 14 15 16
  let builder = new WasmModuleBuilder();
  builder.addImport('mod', 'pow', kSig_i_ii);
  builder.addFunction('upow', kSig_i_i)
         .addBody([kExprGetLocal, 0,
                   kExprGetLocal, 0,
                   kExprCallFunction, 0])
17 18 19
         .setCompilationHint(kCompilationHintStrategyLazy,
                             kCompilationHintTierOptimized,
                             kCompilationHintTierBaseline)
20 21 22 23 24 25 26 27
         .exportFunc();
  assertThrows(() => builder.instantiate({mod: {pow: Math.pow}}),
               WebAssembly.CompileError,
               "WebAssembly.Module(): Invalid compilation hint 0x2d " +
               "(forbidden downgrade) @+70");
})();

(function testDecodeCompilationHintsSectionNoTiering() {
28
  print(arguments.callee.name);
29 30 31 32 33 34
  let builder = new WasmModuleBuilder();
  builder.addImport('mod', 'pow', kSig_i_ii);
  builder.addFunction('upow', kSig_i_i)
         .addBody([kExprGetLocal, 0,
                   kExprGetLocal, 0,
                   kExprCallFunction, 0])
35 36 37
         .setCompilationHint(kCompilationHintStrategyDefault,
                             kCompilationHintTierInterpreter,
                             kCompilationHintTierInterpreter)
38 39 40 41 42 43 44 45 46 47 48 49 50 51
         .exportFunc();
  builder.addFunction('upow2', kSig_i_i)
         .addBody([kExprGetLocal, 0,
                   kExprGetLocal, 0,
                   kExprCallFunction, 0])
  builder.addFunction('upow3', kSig_i_i)
         .addBody([kExprGetLocal, 0,
                   kExprGetLocal, 0,
                   kExprCallFunction, 0])
  let instance = builder.instantiate({mod: {pow: Math.pow}});
  assertEquals(27, instance.exports.upow(3))
})();

(function testDecodeCompilationHintsSectionUpgrade() {
52
  print(arguments.callee.name);
53 54 55 56 57 58 59 60 61 62 63 64 65 66
  let builder = new WasmModuleBuilder();
  builder.addImport('mod', 'pow', kSig_i_ii);
  builder.addFunction('upow2', kSig_i_i)
         .addBody([kExprGetLocal, 0,
                   kExprGetLocal, 0,
                   kExprCallFunction, 0])
  builder.addFunction('upow3', kSig_i_i)
         .addBody([kExprGetLocal, 0,
                   kExprGetLocal, 0,
                   kExprCallFunction, 0])
  builder.addFunction('upow', kSig_i_i)
         .addBody([kExprGetLocal, 0,
                   kExprGetLocal, 0,
                   kExprCallFunction, 0])
67 68 69
         .setCompilationHint(kCompilationHintStrategyEager,
                             kCompilationHintTierBaseline,
                             kCompilationHintTierOptimized)
70 71 72 73 74 75
         .exportFunc();
  let instance = builder.instantiate({mod: {pow: Math.pow}});
  assertEquals(27, instance.exports.upow(3))
})();

(function testDecodeCompilationHintsSectionNoImport() {
76
  print(arguments.callee.name);
77 78 79 80 81
  let builder = new WasmModuleBuilder();
  builder.addFunction('sq', kSig_i_i)
         .addBody([kExprGetLocal, 0,
                   kExprGetLocal, 0,
                   kExprI32Mul])
82 83 84
         .setCompilationHint(kCompilationHintStrategyEager,
                             kCompilationHintTierDefault,
                             kCompilationHintTierOptimized)
85 86 87 88 89 90
         .exportFunc();
  let instance = builder.instantiate();
  assertEquals(9, instance.exports.sq(3))
})();

(function testDecodeCompilationHintsSectionNoExport() {
91
  print(arguments.callee.name);
92 93 94 95 96
  let builder = new WasmModuleBuilder();
  builder.addFunction('sq', kSig_i_i)
         .addBody([kExprGetLocal, 0,
                   kExprGetLocal, 0,
                   kExprI32Mul])
97 98 99
         .setCompilationHint(kCompilationHintStrategyEager,
                             kCompilationHintTierDefault,
                             kCompilationHintTierOptimized)
100
  builder.instantiate();
101 102
})();

103
(function testDecodeCompilationHintsSectionTopTierDefault() {
104
  print(arguments.callee.name);
105 106 107 108 109
  let builder = new WasmModuleBuilder();
  builder.addFunction('sq', kSig_i_i)
         .addBody([kExprGetLocal, 0,
                   kExprGetLocal, 0,
                   kExprI32Mul])
110 111 112
         .setCompilationHint(kCompilationHintStrategyEager,
                             kCompilationHintTierOptimized,
                             kCompilationHintTierDefault)
113 114 115 116 117
         .exportFunc();
  let instance = builder.instantiate();
  assertEquals(9, instance.exports.sq(3))
})();

118
(function testDecodeCompilationHintsLazyBaselineEagerTopTier() {
119
  print(arguments.callee.name);
120 121 122 123 124
  let builder = new WasmModuleBuilder();
  builder.addFunction('sq', kSig_i_i)
         .addBody([kExprGetLocal, 0,
                   kExprGetLocal, 0,
                   kExprI32Mul])
125
         .setCompilationHint(kCompilationHintStrategyLazyBaselineEagerTopTier,
126 127
                             kCompilationHintTierOptimized,
                             kCompilationHintTierDefault)
128
         .exportFunc();
129
  builder.instantiate();
130
})();