diff options
author | Alon Zakai <azakai@google.com> | 2019-05-28 10:58:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-28 10:58:14 -0700 |
commit | 4b223a33d9f44b99a783cb63329facea7edfb783 (patch) | |
tree | 05530ae1e9dc98acf18133c05ddfad1ba5826a1c /test/wasm2js/br_table_hoisting.2asm.js.opt | |
parent | 899263882c48dba8e34717af1e28005f8888dca7 (diff) | |
download | binaryen-4b223a33d9f44b99a783cb63329facea7edfb783.tar.gz binaryen-4b223a33d9f44b99a783cb63329facea7edfb783.tar.bz2 binaryen-4b223a33d9f44b99a783cb63329facea7edfb783.zip |
wasm2js: Switch optimizations (#2141)
This pattern-matches towers of blocks + a br_table into a JS switch. This is much smaller in code size and also avoids heavy nesting that can exceed the recursion limits of JS parsers.
This is not enough yet, because it pattern-matches very specifically. In reality, switches can look slightly different. Followup PRs will extend this. For now, this passes the test suite (what passed before - not including the massive-switch tests) + fuzzing so it's a good start.
Diffstat (limited to 'test/wasm2js/br_table_hoisting.2asm.js.opt')
-rw-r--r-- | test/wasm2js/br_table_hoisting.2asm.js.opt | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/test/wasm2js/br_table_hoisting.2asm.js.opt b/test/wasm2js/br_table_hoisting.2asm.js.opt new file mode 100644 index 000000000..df70cc86f --- /dev/null +++ b/test/wasm2js/br_table_hoisting.2asm.js.opt @@ -0,0 +1,182 @@ + +function asmFunc(global, env, buffer) { + "almost asm"; + var HEAP8 = new global.Int8Array(buffer); + var HEAP16 = new global.Int16Array(buffer); + var HEAP32 = new global.Int32Array(buffer); + var HEAPU8 = new global.Uint8Array(buffer); + var HEAPU16 = new global.Uint16Array(buffer); + var HEAPU32 = new global.Uint32Array(buffer); + var HEAPF32 = new global.Float32Array(buffer); + var HEAPF64 = new global.Float64Array(buffer); + var Math_imul = global.Math.imul; + var Math_fround = global.Math.fround; + var Math_abs = global.Math.abs; + var Math_clz32 = global.Math.clz32; + var Math_min = global.Math.min; + var Math_max = global.Math.max; + var Math_floor = global.Math.floor; + var Math_ceil = global.Math.ceil; + var Math_sqrt = global.Math.sqrt; + var abort = env.abort; + var nan = global.NaN; + var infinity = global.Infinity; + function zed($0) { + zed($0); + } + + function $1($0) { + $0 = $0 | 0; + a : { + b : { + switch ($0 | 0) { + default: + zed(-1); + zed(-2); + case 3: + zed(-3); + zed(-4); + case 2: + zed(-5); + zed(-6); + break a; + case 0: + break a; + case 1: + break b; + }; + } + zed(-7); + zed(-8); + } + zed(-9); + zed(-10); + } + + function $2($0) { + $0 = $0 | 0; + a : { + b : { + c : { + d : { + switch ($0 | 0) { + default: + zed(-1); + zed(-2); + break c; + case 0: + break a; + case 1: + break b; + case 2: + break c; + case 3: + break d; + }; + } + zed(-3); + zed(-4); + } + zed(-5); + zed(-6); + break a; + } + zed(-7); + zed(-8); + } + zed(-9); + zed(-10); + } + + function $3($0) { + $0 = $0 | 0; + a : { + b : { + c : { + d : { + switch ($0 | 0) { + default: + if ($0) { + break c + } + zed(-1); + zed(-2); + case 0: + break a; + case 1: + break b; + case 2: + break c; + case 3: + break d; + }; + } + zed(-3); + zed(-4); + } + zed(-5); + zed(-6); + break a; + } + zed(-7); + zed(-8); + } + zed(-9); + zed(-10); + } + + function $4($0) { + $0 = $0 | 0; + a : { + b : { + c : { + if ($0) { + break c + } + d : { + switch ($0 | 0) { + default: + if ($0) { + break c + } + zed(-1); + zed(-2); + case 0: + break a; + case 1: + break b; + case 2: + break c; + case 3: + break d; + }; + } + zed(-3); + zed(-4); + } + zed(-5); + zed(-6); + break a; + } + zed(-7); + zed(-8); + } + zed(-9); + zed(-10); + } + + var FUNCTION_TABLE = []; + return { + "foo1": $1, + "foo2": $2, + "foo3": $3, + "foo4": $4 + }; +} + +var memasmFunc = new ArrayBuffer(65536); +var retasmFunc = asmFunc({Math,Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,NaN,Infinity}, {abort:function() { throw new Error('abort'); }},memasmFunc); +export var foo1 = retasmFunc.foo1; +export var foo2 = retasmFunc.foo2; +export var foo3 = retasmFunc.foo3; +export var foo4 = retasmFunc.foo4; |