summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* Notice parse errors on number parsing in the text format (#1608)Loppin Vincent2018-07-241-0/+6
| | | | | | | * - Throw ParseException when istringstream failed to read a number. - Modify now invalid tests. * Add invalid_number.wast test
* Clarify what function-parallel passes can do, and fix an asm2wasm bug (#1627)Alon Zakai2018-07-233-13/+29
| | | | | The problem this fixes is that we made precompute look at globals in #1622, while asm2wasm was creating globals while adding functions and optimizing them - which could race. This was caught by threadSanitizer (with low frequency, so we missed it on the initial landing). The underlying issue is that function-parallel passes should be able to read global state, just not modify it, and not read other functions' contents (which is why the Call node has a name, not a pointer to a function). This PR clarifies that in the docs, and fixes asm2wasm by not handling function bodies in parallel to creating globals.
* Some minor LocalGraph improvements (#1625)Alon Zakai2018-07-211-80/+57
| | | | | * Remove the Action class - we just need a pointer to a get or set. This simplifies the code and saves a little memory, but doesn't seem to have any impact on speed. * Miscellaneous code style and comment changes.
* Mark arguments const in callExport (#1626)Alex Beregszaszi2018-07-211-6/+5
| | | The arguments is read only and therefore could be const. The immediate benefit is callers do not need to define it as a local variable (see Literal callExport(Name name)).
* Speedup localgraph (#1610)Loppin Vincent2018-07-201-18/+64
| | | | | | | | | | * LocalGraph : Replace seen unordered_set by boolean check. * LocalGraph : use unordered_map to store index -> last set_local instead of vector. * LocalGraph : - Use internal counter to avoid invalidation at each cycle. - Move all blocks structs into a contiguous vector of smaller ones.
* Support constant globals in precompute pass (#1622)Daniel Wirtz2018-07-182-24/+32
| | | | | | | | | This PR includes non-mutable globals in precompute, which will allow me to continue removing manual inlining of constants in AssemblyScript without breaking something. Related: #1621, i.e. enum Animal { CAT = 0, DOG = CAT + 1 // requires that `Animal.CAT` is evaluated to // precompute the constant value for `Animal.DOG` }
* Refactor stack writing code into a new StackWriter class (#1620)Alon Zakai2018-07-162-227/+247
| | | | | | | This separates out the WasmBinaryWriter parts that do stack writing into a separate class, StackWriter. Previously the WasmBinaryWriter did both the general writing and the stack stuff, and the stack stuff has global state, which it manually cleaned up etc. - seems nicer to have it as a separate class, a class focused on just that one thing. Should be no functional changes in this PR. Also add a timeout to the wasm-reduce test, which happened to fail on one of the commits here. It was running slower on that commit for some reason, could have been random - I verified that general wasm writing speed is unaffected by this PR. (But I added the timeout to prevent future random timeouts.)
* Minor code cleanups (#1617)Alon Zakai2018-07-104-125/+130
| | | | | | * code cleanups in wasm-binary: remove an & param, and standardize whitespace * add some docs for how the relooper handles blocks with no outgoing branches [ci skip]
* Proper error handling in add* and get* methods (#1570)Alon Zakai2018-07-103-32/+97
| | | | | | | See #1479 (comment) Also a one-line readme update, remove an obsolete compiler (mir2wasm) and add a new one (asterius). Also improve warning and error reporting in binaryen.js - show a stack trace when relevant (instead of node.js process.exit), and avoid atexit warning spam in debug builds.
* emscripten no longer allows modifying Module['print'] at runtime. Modify the ↵Alon Zakai2018-07-031-9/+9
| | | | internal out() method instead. see kripken/emscripten#6756 (#1614)
* Remove s2wasm (#1607)Sam Clegg2018-06-287-2535/+12
| | | | s2wasm is no longer used my emscripten and as far as I know now as no other users.
* Improve source map parsing to handle whitespace (#1598)Sam Clegg2018-06-131-14/+34
|
* Add source map handling to wasm-emscripten-finalize (#1595)Sam Clegg2018-06-102-5/+25
|
* -O4: When -O3 isn't enough (#1596)Alon Zakai2018-06-083-3/+17
| | | | | | | | | This defines a new -O4 optimization mode, as flatten + flat-only opts (currently local-cse) + -O3. In practice, flattening is not needed for LLVM output, which is pretty flat already (no block or if values, etc., even if it does use tees and does nest expressions; and LLVM has already done gvn etc. anyhow). In general, though, wasm generated by a non-LLVM compiler may naturally be nested because wasm allows that. See for example #1593 where an AssemblyScript testcase requires flattening to be fully optimized. So -O4 can help there. -O4 takes 3x longer to run than -O3 in my testing, basically because flat IR is much bigger. But when it's useful it may be worth it. It does handle that AssemblyScript testcase and others like it. There's not much big real-world code that isn't LLVM yet, but running the fuzzer - which happily creates nested stuff all the time - I see -O4 consistently shrink the size by around 20% over -O3.
* Improve local-cse (#1594)Alon Zakai2018-06-084-58/+96
| | | | | This makes it much more effective, by rewriting it to depend on flatten. In flattened IR, it is very simple to check if an expression is equivalent to one already available for use in a local, and use that one instead, basically we just track values in locals. Helps with #1521
* wasm-opt source map support (#1557)Alon Zakai2018-06-075-39/+51
| | | | | | | | | | * support source map input in wasm-opt, refactoring the loading code into wasm-io * use wasm-io in wasm-as * support output source maps in wasm-opt * add a test for wasm-opt and source maps
* duplicate-function-elimination improvements (#1590)Alon Zakai2018-06-076-59/+128
| | | | | | | On a codebase with 370K functions, 160K were in fact duplicate (!)... and it took many many passes to figure that out, over 2 minutes in fact (!), as A and B may be identical only after we see that the functions C1, C2 that they call are identical (so there can be long "chains" here). To avoid this, limit how many passes we do. In -O1, just do one pass - that gets most duplicates. In -O2, do 10 passes - that gets almost all of it on this codebase. And in -O3 (or -Os/-Oz) do as many passes as necessary (i.e., the old behavior). This at least lets iteration builds (-O1) be nice and fast. This PR also refactors the hashing code used in that pass, moving it to nicer header files for clearer readability. Also some other minor cleanups in hashing code that helped debug this.
* Handle parse errors in wasm-emscripten-finalize (#1589)Sam Clegg2018-06-061-1/+7
|
* Fix check in fixInvokeFunctionNames (#1588)Sam Clegg2018-06-061-1/+1
| | | | This check is supposed to check if rename is needed so it need to compare to the original.
* Ensure import and function names match during fixInvokeFunctionNames (#1587)Sam Clegg2018-06-051-1/+5
| | | | | | We ran into an issue recently where wasm-emscripten-finalize was being passed input without any debug names and this is not currently supported.
* run precompute-propagate early, when we would run it also late, as it is ↵Alon Zakai2018-06-041-2/+7
| | | | helpful in both positions on general code (#1581)
* Add -g/--debuginfo flag to wasm-emscripten-finalize (#1584)Sam Clegg2018-06-041-3/+9
| | | | | This brings this tool into parity with the existing s2wasm
* Always incorporate the table segment offset when calculating ↵Jacob Gravelle2018-06-011-4/+4
| | | | jsCallStartIndex (#1579)
* Optimize validation of many nested blocks (#1576)Alon Zakai2018-05-302-46/+50
| | | | | | | On the testcase from https://github.com/tweag/asterius/issues/19#issuecomment-393052653 this makes us almost 3x faster, and use 25% less memory. The main improvement here is to simplify and optimize the data structures the validator uses to validate br targets: use unordered maps, and use one less of them. Also some speedups from using that map more effectively (use of iterators to avoid multiple lookups). Also move the duplicate-node checks to the internal IR validation section, which makes more sense anyhow (it's not wasm validation, it's internal IR validation, which like the check for stale internal types, we do only if debugging).
* wasm2asm: Fix and enable a large number of spec tests (#1558)Alex Crichton2018-05-295-206/+439
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Import `abort` from the environment * Add passing spec tests * Bind the abort function * wasm2asm: Fix name collisions Currently function names and local names can collide in namespaces, causing buggy results when a function intends to call another function but ends up using a local value as the target! This fix was required to enable the `fac` spec test * wasm2asm: Get multiple modules in one file working The spec tests seem to have multiple modules defined in some tests and the invocations all use the most recently defined module. This commit updates the `--allow-asserts` mode of wasm2asm to work with this mode of tests, enabling us to enable more spec tests for wasm2asm. * wasm2asm: Enable the float_literals spec test This needed to be modified to account for how JS engines don't work with NaN bits the same way, but it's otherwise largely the same test. Additionally it turns out that asm.js doesn't accept either `Infinity` or `NaN` ambient globals so they needed to get imported through the `global` variable rather than defined as literals in code * wasm2asm: Fix function pointer invocations This commit fixes invocations of functions through function pointers as previously the table names on lookup and definition were mismatched. Both tables now go through signature-based namification rather than athe name of the type itself. Overall this enables a slew of spec tests * wasm2asm: Enable the left-to-right spec test There were two small bugs in the order of evaluation of operators with wasm2asm. The `select` instruction would sometimes evaluate the condition first when it was supposed to be last. Similarly a `call_indirect` instruction would evaluate the function pointer first when it was supposed to be evaluated last. The `select` instruction case was a relatively small fix but the one for `call_indirect` was a bit more pessimized to generate some temporaries. Hopefully if this becomes up a problem it can be tightened up. * wasm2asm: Fix signed load promotions of 64-bit ints This commit enables the `endianness` spec test which revealed a bug in 64-bit loads from smaller sizes which were signed. Previously the upper bits of the 64-bit number were all set to zero but the fix was for signed loads to have all the upper bits match the highest bit of the low 32 bits that we load. * wasm2asm: Enable the `stack` spec test Internally the spec test uses a mixture of the s-expression syntax and the wat syntax, so this is copied over into the `wasm2asm` folder after going through `wat2wasm` to ensure it's consistent for binaryen. * wasm2asm: Fix unaligned loads/stores of floats Replace these operations in `RemoveNonJSOps` by using reinterpretation to translate floats to integers and then use the existing code for unaligned loads/stores of integers. * wasm2asm: Fix a tricky grow_memory codegen bug This commit fixes a tricky codegen bug found in the `grow_memory` instruction. Specifically if you stored the result of `grow_memory` immediately into memory it would look like: HEAP32[..] = __wasm_grow_memory(..); Here though it looks like JS evaluates the destination *before* the grow function is called, but the grow function will invalidate the destination! Furthermore this is actually generalizable to all function calls: HEAP32[..] = foo(..); Because any function could transitively call `grow_memory`. This commit fixes the issue by ensuring that store instructions are always considered statements, unconditionally evaluating the value into a temporary and then storing that into the destination. While a bit of a pessmimization for now it should hopefully fix the bug here. * wasm2asm: Handle offsets in tables This commit fixes initializing tables whose elements have an initial offset. This should hopefully help fix some more Rust code which has all function pointers offset by default! * Update tests * Tweak * location on types * Rename entries of NameScope and document fromName * Comment on lowercase names * Update compiled JS * Update js test output expectation * Rename NameScope::Global to NameScope::Top * Switch to `enum class` * Switch to `Fatal()` * Add TODO for when asm.js is no longer generated
* allow --total-memory to be greater than a signed int32 (#1565)Alon Zakai2018-05-261-1/+1
|
* Fix embedwast.py for out-of-tree building (#1569)Sam Clegg2018-05-251-2/+2
|
* wasm2asm: Finish i64 lowering operations (#1563)Alex Crichton2018-05-259-685/+1307
| | | | | | | | | | | | | | | | | * wasm2asm: Finish i64 lowering operations This commit finishes out lowering i64 operations to JS with implementations of division and remainder for JS. The primary change here is to have these compiled from Rust to wasm and then have them "linked in" via intrinsics. The `RemoveNonJSOps` pass has been updated to include some of what `I64ToI32Lowering` was previously doing, basically replacing some instructions with calls to intrinsics. The intrinsics are now all tracked in one location. Hopefully the intrinsics don't need to be regenerated too much, but for posterity the source currently [lives in a gist][gist], although I suspect that gist won't continue to compile and work as-is for all of time. [gist]: https://gist.github.com/alexcrichton/e7ea67bcdd17ce4b6254e66f77165690
* wasm2asm: Finish f32/f64 operations (#1554)Alex Crichton2018-05-198-304/+521
|
* Fix optimizing equivalent locals bug introduced in #1540 (#1556)Alon Zakai2018-05-171-4/+2
| | | Don't skip through flowing tee values, just drop the current outermost which we find is redundant. the child tees may still be necessary.
* wasm2asm: Implement float<->int conversions (#1550)Alex Crichton2018-05-166-58/+472
| | | | | | | | | This commit lifts the same conversion strategy that `emcc` takes to convert between floats point numbers and integers, and it should implement all the various matrices of i32/u32/i64/u64 to f32/f64 Some refactoring was performed in the i64->i32 pass to allow for temporary variables to get allocated which have types other than i32, but otherwise this contains a pretty direct translation of `emcc`'s operations to `wasm2asm`.
* Clean up printing code (#1548)Alon Zakai2018-05-153-36/+34
| | | | | * make the iostream overrides receive a reference, not a pointer (i.e., like e.g. LLVM IR printing works, and avoiding overriding printing of pointer addresses which is sort of odd) * move more code out of headers, especially unrelated headers.
* wasm-emscripten: Don't use debug names in implementedFunctions (#1537)Sam Clegg2018-05-151-2/+4
| | | | | | | | | | | | | | implementFunctions should use the export names, not the internal/debug name for a function. This is especially imported with lld where the debug names are demanagled. implementFunctions should only contain functions that are accessible from outside the module. i.e. those that have been exported. There is no point in adding internal-only functions to this list as they won't be accessible from outside anyway. Tesed with emscripten using: ./tests/runner.py binaryen2.test_time
* wasm2asm: Implement f32/f64.copysign (#1551)Alex Crichton2018-05-155-0/+110
| | | | | | This commit implements the `copysign` instruction for the wasm2asm binary. The implementation here is a new pass which wholesale replaces `copysign` instructions with the equivalent bit ops and reinterpretation instructions. It's intended that this matches Emscripten's implementation of lowering here.
* In full-printing mode, print comments for control flow endings, to help ↵Alon Zakai2018-05-141-0/+22
| | | | | | | | | | | readability (#1552) Like this: (block $x .. ) ;; end block $x Also fix some current breakage on master.
* wasm2asm: Add math aliases for floor, ceil and sqrt (#1549)Daniel Wirtz2018-05-141-0/+3
|
* Implement 64-bit rotation lowering for wasm2asm (#1545)Alex Crichton2018-05-141-2/+193
| | | | Not much fancy here, but rather each operation is naively lowered inline to the if/else chain to execute it.
* wasm2asm: Implement reinterpretation instructions (#1547)Alex Crichton2018-05-132-3/+58
| | | | | | | | | | | | | As mentioned in #1458 a naive implementation of these instructions is to round trip the value through address 0 in linear memory. Also pointed out in #1458 this isn't necessarily valid for all languages. For now, though, languages like Rust, C, and C++ would likely be horribly broken if valid data could be stored at low addresses, so this commit goes ahead and adds an implementation of the reinterpretation instructions by traveling data through address 0. This will likely need an update if a language comes a long which can validly store data in the first 8 bytes of linear memory, but it seems like that won't happen in the near future. Closes #1458
* Implement signed 64-bit shift right for wasm2asm (#1544)Alex Crichton2018-05-121-6/+72
| | | | Mostly piggy-back pon the previous 64-bit shift lowering code, just filling in a few gaps.
* Merge loop tails up (#1543)Alon Zakai2018-05-101-29/+93
| | | | | | | | | | | | | | | E.g. ``` (block .. (loop $l .. (br_if $l (..)) .. code that does not branch to the loop top ) .. that code could be moved here .. ) ``` Moving the code out of the loop may help the loop body become a singleton expression, and is more readable anyhow.
* Move the renaming of llvm-generated __invoke_XX functions from s2wasm into ↵Sam Clegg2018-05-104-86/+144
| | | | | | | | | wasm-emscripten (#1539) This allows the same functionality to be used also in wasm-emscripten-finalize (i.e. the lld path).
* Optimize equivalent locals (#1540)Alon Zakai2018-05-107-80/+329
| | | | | | | | | If locals are known to contain the same value, we can * Pick which local to use for a get_local of any of them. Makes sense to prefer the most common, to increase the chance of one dropping to zero uses. * Remove copies between a local and one that we know contains the same value. This is a consistent win, small though, around 0.1-0.2%.
* Fix MSVC warnings when compiling the binaryen target (#1535)Daniel Wirtz2018-05-098-24/+18
|
* Add a way to remove function types to Binaryen-C/.js (#1536)Daniel Wirtz2018-05-083-0/+24
|
* More reducer improvements (#1533)Alon Zakai2018-05-084-136/+409
| | | | | | * Add a helper class to iterate over all a node's children, and use that when attempting to replace a node with its children. * If a child has a different type than the parent, try to replace the parent with a conversion + the child (for example, a call may receive two f32 inputs and return an i32; we can try to replace the call with one of those f32s and a conversion to an i32). * When possible, try to replace the function body with a child even if the child has a different type, by changing the function return value.
* Expose sign extension ops in Binaryen-C/.js (#1534)Daniel Wirtz2018-05-073-1/+31
|
* improve remove-unused-module-elements (#1532)Alon Zakai2018-05-044-13/+52
| | | | | Remove the entire memory/table when possible, in particular, when not imported, exported, or used. Previously we did not look at whether they were imported, so we assumed we could never remove them. Also add a variant that removes everything but functions, which can be useful when reducing a testcase that only cares about code in functions.
* reducer improvements: more if, block, loop and other node reduction attempts ↵Alon Zakai2018-05-041-0/+52
| | | | (#1530)
* misc minor cleanups in the codebase (#1531)Alon Zakai2018-05-042-1/+3
|
* add missing atomics to getExpressionName, which is used in --metrics (#1529)Alon Zakai2018-05-041-0/+4
|