summaryrefslogtreecommitdiff
path: root/test/wasm2js
Commit message (Collapse)AuthorAgeFilesLines
* Reflect instruction renaming in code (#2128)Heejin Ahn2019-05-2115-45/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - Reflected new renamed instruction names in code and tests: - `get_local` -> `local.get` - `set_local` -> `local.set` - `tee_local` -> `local.tee` - `get_global` -> `global.get` - `set_global` -> `global.set` - `current_memory` -> `memory.size` - `grow_memory` -> `memory.grow` - Removed APIs related to old instruction names in Binaryen.js and added APIs with new names if they are missing. - Renamed `typedef SortedVector LocalSet` to `SetsOfLocals` to prevent name clashes. - Resolved several TODO renaming items in wasm-binary.h: - `TableSwitch` -> `BrTable` - `I32ConvertI64` -> `I32WrapI64` - `I64STruncI32` -> `I64SExtendI32` - `I64UTruncI32` -> `I64UExtendI32` - `F32ConvertF64` -> `F32DemoteI64` - `F64ConvertF32` -> `F64PromoteF32` - Renamed `BinaryenGetFeatures` and `BinaryenSetFeatures` to `BinaryenModuleGetFeatures` and `BinaryenModuleSetFeatures` for consistency.
* Fix an infinite loop in avoid-reinterprets in unreachable code with loops of ↵Alon Zakai2019-05-173-0/+97
| | | | | gets (#2118) In unreachable code, a get may have a single set that assigns to it, and that set may be assigned to by that very get.
* wasm2js: more coercion optimization (#2109)Alon Zakai2019-05-154-1/+170
|
* wasm2js: remove unnecessary labels (#2108)Alon Zakai2019-05-154-5/+5
|
* wasm2js: optimize away unneeded load coercions (#2107)Alon Zakai2019-05-1591-1/+235
|
* wasm2js: Emit table in a way that is friendly to emscripten minification (#2102)Alon Zakai2019-05-132-2/+4
| | | Set it to a local in the asmFunc scope, so that minifiers can easily see it's a simple local value (instead of using it as an upvar from the parameters higher up, which was how the emscripten glue was emitting it).
* wasm2js: precompute bitwise operations (#2101)Alon Zakai2019-05-1315-183/+183
| | | This happens on e.g. an i32 load of a constant offset, then we have constant >> 2.
* Look through fallthrough values in precompute-propagate (#2093)Alon Zakai2019-05-1011-357/+75
| | | This helps quite a lot on wasm2js.
* wasm2js: avoid reinterprets (#2094)Alon Zakai2019-05-1011-324/+280
| | | | | In JS a reinterpret is especially expensive, as we implement it as a write to a temp buffer and a read using another view. This finds places where we load a value from memory, then reinterpret it later - in that case, we can load it using another view, at the cost of another load and another local. This is helpful on things like Box2D, where there are many reinterprets due to the main 2D vector class being an union over two floats/ints, and LLVM likes to do a single i64 load of them.
* wasm2js: optimize booleans (#2090)Alon Zakai2019-05-073-0/+26
|
* wasm2js: optimize loads (#2085)Alon Zakai2019-05-0391-121/+36
| | | | When loading a boolean, prefer the signed heap (which is more commonly used, and may be faster). We never use HEAPU32 (HEAP32 is always enough), just remove it.
* wasm2js: avoid some slow operations when not optimizing (#2082)Alon Zakai2019-05-0319-3747/+4081
| | | Without this PR, wasm2js0.test_printf in emscripten took an extremely long time to compile.
* wasm2js: don't emit obviously unnecessary parens (#2080)Alon Zakai2019-05-0249-8688/+5568
| | | A minifier would probably remove them later anyhow, but they make reading the code annoying and hard.
* wasm2js: ignore implicit traps (#2079)Alon Zakai2019-05-025-56/+29
| | | | | We don't actually try to emit traps for loads, stores, invalid float to ints, etc., so when optimizing we may as well do so under the assumption those traps do not exist. This lets us emit nice code for a select whose operands are loads, for example - otherwise, the values seem to have side effects.
* Add a pass to lower unaligned loads and stores (#2078)Alon Zakai2019-05-023-51/+104
| | | | | This replaces the wasm2js code that lowered them to pessimistic (1-byte aligned) loads and stores. The new pass will do the optimal thing, keeping 2-byte alignment where possible. This is also nicer as a standalone pass, which has the simple property that after it runs all loads and stores are aligned, instead of some code scattered inside wasm2js.
* wasm2js: don't run coalesce-locals if not optimizing (#2076)Alon Zakai2019-05-0149-16947/+22081
| | | That pass is very slow on unoptimized code (super-linear on the number of locals, which if unoptimized can be massive due to flatten).
* wasm2js: run more optimizations (#2073)Alon Zakai2019-05-0160-22417/+17230
| | | In particular, coalesce-locals is useful even if closure is run later (apparently it finds stuff closure can't).
* wasm2js: run full optimizations during the pipeline (#2071)Alon Zakai2019-04-3078-5965/+22887
| | | | | We flatten for the i64 lowering etc. passes, and it is worth optimizing afterwards, to clean up stuff they created. That is run if the user ran wasm2js with an optimization level (like wasm2js -O3). Split the test files to check both optimized and unoptimized code.
* wasm2js: optimize away casts going into a suitable store (#2069)Alon Zakai2019-04-303-6/+31
|
* I64ToI32Lowering: don't use alignment 1 everywhere (#2070)Alon Zakai2019-04-303-8/+8
| | | If an i64 load/store that is being broken up has higher alignment, use that.
* wasm2js: optimize switches (#2067)Alon Zakai2019-04-306-73950/+12
| | | | | | | | | | Don't emit unneeded breaks in switch cases, instead do case X: case Y: .. case W: break .. for each group. Also, the group with the default doesn't need any cases but the default itself.
* wasm2js: remove unneeded break/continue labels (#2058)Alon Zakai2019-04-2612-56/+56
|
* wasm2js2: optimize call_indirect and select operands (#2056)Alon Zakai2019-04-2513-95/+231
| | | Don't use temp vars to reorder them unless we need to.
* wasm2js: support non-constant indexes for memory and table segments (#2055)Alon Zakai2019-04-252-0/+87
| | | Mostly what we need for dynamic linking, at least on the binaryen side.
* wasm2js: optimize loops and eqz (#2051)Alon Zakai2019-04-2518-206/+178
|
* Remove f32 legalization from LegalizeJSInterface (#2052)Sam Clegg2019-04-2520-530/+126
| | | | | As well as i64 splitting this pass was also converting f32 to f64 at the wasm boundry. However it appears this is not actually useful and makes somethings (such as dynamic linking) harder.
* wasm2js: more js optimization (#2050)Alon Zakai2019-04-2447-2430/+1448
| | | | | | * Emit ints as signed, so -1 isn't a big unsigned number. * x - -c (where c is a constant) is larger than x + c in js (but not wasm) * +(+x) => +x * Avoid unnecessary coercions on calls, return, load, etc. - we just need coercions when entering or exiting "wasm" (not internally), and on actual operations that need them.
* wasm2js: start to optionally optimize the JS (#2046)Alon Zakai2019-04-2448-4989/+5011
| | | Removes redundant | 0s and similar things. (Apparently closure compiler doesn't do that, so makes sense to do here.)
* wasm2js: emit quoted properties for the exports, to support closure compiler ↵Alon Zakai2019-04-2355-992/+992
| | | | (#2043)
* wasm2js: emit calls for memory growth helper only if memory growth is used ↵Alon Zakai2019-04-231-1/+1
| | | | (#2042)
* wasm2js: avoid non-ES5 stuff like "let" (#2041)Alon Zakai2019-04-2361-1157/+1157
| | | Also fix the fuzzer's handling of feature flags so that wasm2js can work.
* wasm2js: remove more code we don't need since we have flat IR (#2039)Alon Zakai2019-04-2214-479/+255
| | | Also run remove-unused-names which became more noticeably necessary after this change.
* wasm2js: get rid of some non-flat code assumptions (#2036)Alon Zakai2019-04-2212-439/+161
| | | We run flatten there, which lets us simplify things a lot. Turns out that for assertions we didn't run it, which is why we still needed the old non-flat code paths. This adds flatten there and removes that old code and assumptions.
* wasm2js: unreachability fixes (#2037)Alon Zakai2019-04-2212-1856/+2382
| | | Also test in pass-debug mode, for better coverage.
* wasm2js: fix printing of negated negative constants (#2034)Alon Zakai2019-04-222-0/+58
| | | It is invalid to print --5, we need to add a space - -5 so that it is valid JS to parse.
* wasm2js: use scratch memory properly (#2033)Alon Zakai2019-04-2212-2104/+2388
| | | | | | | This replaces all uses of __tempMemory__, the old scratch space location, with calls to function imports for scratch memory access. This lets us then implement those in a way that does not use the same heap as main memory. This avoids possible bugs with scratch memory overwriting something, or just in general that it has observable side effects, which can confuse fuzzing etc. The intrinsics are currently implemented in the glue. We could perhaps emit them inline instead (but that might limit asm.js optimizations, so I wanted to keep our options open for now - easy to change later). Also fixes some places where we used 0 as the scratch space address.
* wasm2js2 import fixes (#2031)Alon Zakai2019-04-1958-1002/+11250
| | | | | | * Don't assume function types exist in legalize-js-interface. * Properly handle (ignore) imports in RemoveNonJSOps - do not try to recurse into them. * Run legalize-js-interface and remove-unused-module-elements in wasm2js, the first is necessary, the last is nice to have.
* wasm2js: handle unreachable select and global.set (#2029)Alon Zakai2019-04-186-8/+41
|
* wasm2js: do not try to be smart with not emitting if braces, the corner ↵Alon Zakai2019-04-1838-4002/+6288
| | | | | cases are tricky (#2026) leave them for later optimizers/minifiers
* wasm2js: remove "use asm", we are not asm.js anymore (#2020)Alon Zakai2019-04-1857-104/+278
| | | Also emit the memory growth code based on memory growth, and not whether we are "use asm" or not.
* Wasm2js: support i64 globals (#2021)Alon Zakai2019-04-182-0/+60
| | | Split them into two i32 globals.
* wasm2js: fix br_table to loop (#2018)Alon Zakai2019-04-172-0/+83
|
* Fix if else JS printing when if body is a labelled block (#2017)Alon Zakai2019-04-1723-571/+637
| | | | | | | | | | | | Before, we'd print if (..) label: { .. }; else .. But that is wrong, as it ends the if too early. After this, we print if (..) label: { .. } else .. The bug was we checked if the if body was a block, but not if it was a labelled block.
* wasm2js: support memory imports properly, updating their buffer too (#2013)Alon Zakai2019-04-162-2/+41
| | | | | * Emit an import statement for the memory. * Update the imported memory's buffer when we grow.
* Use a single table in wasm2js (#2005)Alon Zakai2019-04-1555-65/+118
| | | | | This replaces the multiple asm.js tables (of power-of-2 size) with a single simple table. Also supports importing the table.
* Wasm2js memory fixes (#2003)Alon Zakai2019-04-1216-402/+8860
| | | | | | | | * I64ToI32Lowering - don't assume address 0 is a hardcoded location for scratch memory. Import __tempMemory__ for that. * RemoveNonJSOps - also use __tempMemory__. Oddly here the address was a hardcoded 1024 (perhaps where the rust program put a static global?). * Support imported ints in wasm2js, coercing them as needed. * Add "env" import support in the tests, since now we emit imports from there. * Make wasm2js tests split out multi-module tests using split_wast which is more robust and avoids emitting multiple outputs in one file (which makes no sense for ES6 modules)
* wasm2js memory improvements (#2002)Alon Zakai2019-04-123-26/+44
| | | | | * Refactor memory code to share it between the two emitting modes. * Get memory emitting set up in the emscripten mode.
* wasm2js: emscripten glue option (#2000)Alon Zakai2019-04-112-0/+110
| | | | | | Add a wasm2js option for the glue to be in emscripten-compatible format (as opposed to ES6). This does a few things so far: * Emit START_FUNCTIONS, END_FUNCTIONS markers in the code, for future use in the optimizer. * Emit the glue as a function to be called from emscripten.
* Wasm2js refactoring (#1997)Alon Zakai2019-04-1154-0/+54
| | | | | | | | | | | | | Early work for #1929 * Leave core wasm module - the "asm.js function" - to Wasm2JSBuilder, and add Wasm2JSGlue which emits the code before and after that. Currently that's some ES6 code, but we may want to change that later. * Add add AssertionEmitter class for the sole purpose of emitting modules + assertions for testing. This avoids some hacks from before like starting from index 1 (assuming the module at first position was already parsed and printed) and printing of the f32Equal etc. functions not at the very top (which was due to technical limitations before). Logic-wise, there should be no visible change, except some whitespace and reodering, and that I made the exceptions print out the source of the assertion that failed from the wast: -if (!check2()) fail2(); +if (!check2()) throw 'assertion failed: ( assert_return ( call add ( i32.const 1 ) ( i32.const 1 ) ) ( i32.const 2 ) )'; (fail2 etc. did not exist, and seems to just have given a unique number for each assertion?)
* Minor wasm2js cleanups (#1995)Alon Zakai2019-04-105-10/+10
| | | | | * Only look at the sign of loads when they actually matter. * Prepare for imported globals (just refactoring/cleanup).