summaryrefslogtreecommitdiff
path: root/test/wasm2js
Commit message (Collapse)AuthorAgeFilesLines
* Update spec test suite (#2484)Heejin Ahn2019-11-2912-784/+4629
| | | | | | | | | | | | | This updates spec test suite to that of the current up-to-date version of https://github.com/WebAssembly/spec repo. - All failing tests are added in `BLACKLIST` in shared.py with reasons. - For tests that already existed and was passing and started failing after the update, we add the new test to the blacklist and preserve the old file by renaming it to 'old_[FILENAME].wast' not to lose test coverage. When the cause of the error is fixed or the unsupported construct gets support so the new test passes, we can delete the corresponding 'old_[FILENAME].wast' file. - Adds support for `spectest.print_[type] style imports.
* SimplifyGlobals: Apply known constant values in linear traces (#2340)Alon Zakai2019-09-131-1/+1
| | | | | | | | | | | | | This optimizes stuff like (global.set $x (i32.const 123)) (global.get $x) into (global.set $x (i32.const 123)) (i32.const 123) This doesn't help much with LLVM output as it's rare to use globals (except for the stack pointer, and that's already well optimized), but it may help on general wasm. It can also help with Asyncify that does use globals extensively.
* [wasm2js] Fix memory.size (#2330)Alon Zakai2019-09-0518-40/+72
| | | | | | | We emitted the __wasm_memory_size function only when memory growth was enabled, but it can be used without that too. In theory we could only emit it if either memory growth or memory.size is used, but I think we can expect JS minifiers to do that later. Also fix a test suite bug - the check/auto_update script didn't run all the wasm2js tests when you run it with argument wasm2js (it used that as the list of tests, instead of the list of files, which confused me here for a while...).
* Followup to workaround for minification of wasm2js mem init (#2318)Brion Vibber2019-08-309-27/+27
| | | | | | | | | | | | | Emscripten's minifier mis-minifies a couple bits in the memory init function that's used with wasm2js when not using an external memory init file: https://github.com/emscripten-core/emscripten/issues/8886 Previous fix worked around the bug in one place but failed to account for another. Have now confirmed that it works with this change in place. Updated test cases to match.
* Allow all features on wasm2js and add atomic tests (#2311)Heejin Ahn2019-08-283-0/+102
| | | | | | This adds `-all` argument to wasm2js testing and fixes wasm2js to actually take that argument (currently it doesn't, when it takes a wast file). This also adds a wasm2js test for `atomic.fence` instruction that was added in #2307.
* Do not hoist truncation of wasm2js divisions (#2305)Thomas Lively2019-08-263-0/+87
| | | | | | It is not valid to defer the truncation of divisions because accumulated non-integral results can produce different values when they are combined before truncation. This was causing a test failure in the Rust test suite.
* wasm2js: Fix switch lowering, don't fall through after the hoisted parts (#2301)Alon Zakai2019-08-167-0/+119
| | | | | The switch lowering will "hoist" blocks of code into the JS switch when it can. If it can hoist some but not others, it must not fall through into those others (while it can fall through the hoisted ones - they began as nested blocks with falling-through between them). To fix this, after the hoisted ones issue a break out of the switch (which now contains all the hoisted code, so breaking out of it gets to the code right after the hoisted ones). fixes #2300
* Support empty export names in wasm2js and JS mangling in general (#2290)Alon Zakai2019-08-093-0/+75
|
* Python3-ify check.py and auto_update_tests.py (#2270)Alon Zakai2019-07-311-30/+0
| | | | | I fixed flatten.bin.txt which seems to have just had some corrupted data, and I removed some fancy unicode from the spec comments tests, which I'm not sure it's important enough to figure out how to fix. Fixes #1691
* wasm2js: Mangle import names for JS (#2267)Alon Zakai2019-07-283-0/+80
| | | | | | | This fixes names that would be invalid in JS, like a.b. Turns out the Go compiler emits wasm with such imports. Also add some docs on how to use wasm2js. Fixes #2263
* Stop emitting "almost asm" in wasm2js output (#2221)Alon Zakai2019-07-1298-120/+0
| | | We don't ever emit "use asm" anymore, so this similar annotation is not really useful, it just increases size.
* wasm2js: export memory growth function only if memory growth is enabled (#2194)Alon Zakai2019-07-036-0/+384
| | | Previously we tried to export it if the memory was exported, even if growth was not on, which caused an error.
* Workaround for wasm2js output minification issue with emscripten (#2185)Brion Vibber2019-07-015-10/+15
| | | | | | | | | | | | | | * Workaround for wasm2js output minification issue with emscripten When using emscripten with -O2 and --memory-init-file 0, the JS minification breaks on this function for memory initialization setup, causing an exception to be thrown during module setup. Moving from two 'var' declarations for the same variable to one should avoid hitting this with no change in functionality (the var gets hoisted anyway). https://github.com/emscripten-core/emscripten/issues/8886
* wasm2js: Switch optimizations (#2141)Alon Zakai2019-05-2810-37278/+37616
| | | | | 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.
* 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.