summaryrefslogtreecommitdiff
path: root/src/emscripten-optimizer
Commit message (Collapse)AuthorAgeFilesLines
* wasm2js: Fix null handling and RefAsNonNull (#6656)Alon Zakai2024-06-121-8/+4
|
* wasm2js: Add basic reference operations (#6648)Alon Zakai2024-06-102-2/+10
| | | This adds ref.eq, ref.null, ref.is_null, ref.func.
* Remove obsolete parser code (#6607)Thomas Lively2024-05-292-988/+0
| | | | | Remove `SExpressionParser`, `SExpressionWasmBuilder`, and `cashew::Parser`. Simplify gen-s-parser.py. Remove the --new-wat-parser and --deprecated-wat-parser flags.
* Use new wast parser in wasm2js (#6606)Thomas Lively2024-05-291-2/+1
| | | | When generating assertions, traverse the `WASTScript` data structure rather than interleaving assertion parsing with emitting.
* [NFC] Mark operator== as const (#5990)walkingeyerobot2023-10-031-1/+1
| | | | | C++20 will automatically generate an operator== with reversed operand order, which is ambiguous with the written operator== when one argument is marked const and the other isn't.
* wasm2js: Stop emitting nan and infinity (#5391)Will Cohen2023-01-041-14/+6
| | | | | | | As noted in #4739, legacy language emitting nan and infinity exists, with the observation that it can be removed once asm.js is no longer used and global NaN is available. This commit removes that asm.js-specific code accordingly.
* Fix warnings from -Wheader-hygiene and -Wimplicit-const-int-float-conversion ↵Martin Kustermann2022-11-172-4/+5
| | | | | | | | | (#5273) When `-Wheader-hygiene` is enabled, C compiler will warn when using namespace directive in global context in header file. When `-Wimplicit-const-int-float-conversion` is enabled C compiler will warn on implicit integer to double conversions that change values.
* Switch from `typedef` to `using` in C++ code. NFC (#5258)Sam Clegg2022-11-152-2/+2
| | | | This is more modern and (IMHO) easier to read than that old C typedef syntax.
* Make `Name` a pointer, length pair (#5122)Thomas Lively2022-10-117-244/+61
| | | | | | | | | | | | | | | | | | | | | | | With the goal of supporting null characters (i.e. zero bytes) in strings. Rewrite the underlying interned `IString` to store a `std::string_view` rather than a `const char*`, reduce the number of map lookups necessary to intern a string, and present a more immutable interface. Most importantly, replace the `c_str()` method that returned a `const char*` with a `toString()` method that returns a `std::string`. This new method can correctly handle strings containing null characters. A `const char*` can still be had by calling `data()` on the `std::string_view`, although this usage should be discouraged. This change is NFC in spirit, although not in practice. It does not intend to support any particular new functionality, but it is probably now possible to use strings containing null characters in at least some cases. At least one parser bug is also incidentally fixed. Follow-on PRs will explicitly support and test strings containing nulls for particular use cases. The C API still uses `const char*` to represent strings. As strings containing nulls become better supported by the rest of Binaryen, this will no longer be sufficient. Updating the C and JS APIs to use pointer, length pairs is left as future work.
* [wasm2js] Support exports of Globals (#4523)magic-akari2022-03-173-7/+55
| | | | | | Export an object with a `.value` property like the wasm JS API does in browsers, and implement them with a getter and setter. Fixes #4522
* Make static buffers in numToString thread local (#4134)Thomas Lively2021-09-091-4/+6
| | | | | | | Validation is performed on multiple threads at once and when there are multiple validation failures, those threads can all end up in `numToString` at the same time as they construct their respective error messages. Previously the threads would race on their access to the snprintf buffers, sometimes leading to segfaults. Fix the data races by making the buffers thread local.
* [Refactoring] Cleanup asm2wasm. Use JS instead ASM prefix where possible. ↵Max Graey2021-09-012-363/+54
| | | | NFC (#4090)
* cleanup to allow binaryen to be built in more strict environments (#3566)walkingeyerobot2021-02-162-3/+4
|
* Simplify some numeric code (#3186)Max Graey2020-10-012-3/+3
|
* Added headers to CMake files (#3037)Wouter van Oortmerssen2020-08-101-0/+2
| | | This is needed for headers to show up in IDE projects, and has no other effect on the build.
* wasm2js: Bulk memory support (#2923)Alon Zakai2020-06-222-0/+8
| | | | | | | | | | | | | | Adds a special helper functions for data.drop etc., as unlike most wasm instructions these are too big to emit inline. Track passive segments at runtime in var memorySegments whose indexes are the segment indexes. Emit var bufferView even if the memory exists even without memory segments, as we do still need the view in order to operate on it. Also adds a few constants for atomics that will be useful in future PRs (as this PR updates the constant lists anyhow).
* cmake: Convert to using lowercase for and functions/macros (#2495)Sam Clegg2019-12-041-2/+2
| | | This is line with modern cmake conventions is much less SHOUTY!
* Update spec test suite (#2484)Heejin Ahn2019-11-291-0/+3
| | | | | | | | | | | | | 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.
* Collect all object files from the object libraries in a CMake variable (#2477)Immanuel Haffner2019-11-261-1/+1
| | | | | | | | | using the `$<TARGET_OBJECTS:objlib>` syntax. Use this variable when adding `libbinaryen` as static or shared library. Additionally, use the variable with the object files to simplify the `TARGET_LINK_LIBRARIES` commands: add the object libraries to the sources of executables and drop the use of our libraries in `TARGET_LINK_LIBRARIES`. (Object libraries cannot be linked but must be used as sources. See https://cmake.org/pipermail/cmake/2018-June/067721.html)
* Revert "Build libbinaryen as a monolithic statically/shared library (#2463)" ↵Alon Zakai2019-11-251-1/+1
| | | | | (#2474) This reverts commit bf8f36c31c0b8e6213bce840be66937dd6d0f6af.
* Build libbinaryen as a monolithic statically/shared library (#2463)Immanuel Haffner2019-11-221-1/+1
| | | | | | | | | | | | * Transform libraries created in subdirectories from statically linked libraries to CMake object libraries. * Link object libraries as `PRIVATE` to `libbinaryen`. According to CMake documentation: "Libraries and targets following PRIVATE are linked to, but are not made part of the link interface." This is exactly what we want, as we only want the C API to be part of the interface.
* SIMD load and extend instructions (#2353)Thomas Lively2019-09-241-5/+2
| | | | | | Adds support for the new load and extend instructions. Also updates from C++11 to C++17 in order to use generic lambdas in the interpreter implementation.
* wasm2js: don't emit obviously unnecessary parens (#2080)Alon Zakai2019-05-021-12/+26
| | | A minifier would probably remove them later anyhow, but they make reading the code annoying and hard.
* clang-tidy braces changes (#2075)Alon Zakai2019-05-016-166/+285
| | | Applies the changes in #2065, and temprarily disables the hook since it's too slow to run on a change this large. We should re-enable it in a later commit.
* Apply format changes from #2048 (#2059)Alon Zakai2019-04-268-858/+1209
| | | Mass change to apply clang-format to everything. We are applying this in a PR by me so the (git) blame is all mine ;) but @aheejin did all the work to get clang-format set up and all the manual work to tidy up some things to make the output nicer in #2048
* wasm2js: remove unneeded break/continue labels (#2058)Alon Zakai2019-04-262-66/+4
|
* wasm2js: more js optimization (#2050)Alon Zakai2019-04-241-0/+3
| | | | | | * 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-243-190/+45
| | | 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-231-2/+17
| | | | (#2043)
* wasm2js: fix printing of negated negative constants (#2034)Alon Zakai2019-04-221-0/+3
| | | It is invalid to print --5, we need to add a space - -5 so that it is valid JS to parse.
* wasm2js: do not try to be smart with not emitting if braces, the corner ↵Alon Zakai2019-04-181-33/+17
| | | | | cases are tricky (#2026) leave them for later optimizers/minifiers
* Fix if else JS printing when if body is a labelled block (#2017)Alon Zakai2019-04-171-1/+4
| | | | | | | | | | | | 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.
* More misc ASAN fixes (#1882)Alon Zakai2019-01-222-0/+5
| | | | | | | | | | * fix buffer overflow in simple_ast.h printing. * check wasm binary format reading of function export indexes for errors. * check if s-expr format imports have a non-empty module and base. Fixes #1876 Fixes #1877 Fixes #1879
* Code style improvements (#1868)Alon Zakai2019-01-155-22/+24
| | | | * Use modern T p = v; notation to initialize class fields * Use modern X() = default; notation for empty class constructors
* Cleanup shared constants (#1784)Sam Clegg2018-11-293-7/+2
|
* standardize on 'template<' over 'template <' (i.e., remove a space) (#1782)Alon Zakai2018-11-292-3/+3
|
* Fix alignment in MixedAllocator (#1740)Alon Zakai2018-11-131-2/+2
| | | Necessary for simd, as we add a type with alignment >8. We were just broken on that before this PR.
* fix sign detection of a floating-point mod ; fixes kripken/emscripten#7123 ↵Alon Zakai2018-09-151-1/+1
| | | | (#1681)
* Optimize validation of many nested blocks (#1576)Alon Zakai2018-05-301-2/+1
| | | | | | | 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-291-6/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* wasm2asm: Implement float<->int conversions (#1550)Alex Crichton2018-05-161-0/+15
| | | | | | | | | 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`.
* EM_JS binaryen support (#1410)Jacob Gravelle2018-02-261-4/+8
| | | | | | | | | | | * Emit EM_JS metadata * Include s2wasm-style em_js support * Change em_js metadata to be keyed on name * Add testcase for em_js, don't always emit emJsFuncs metadata * Better error handling for unexpectedly-formatted __em_js__ functions
* Add startsWith function to IString (#1393)Heejin Ahn2018-01-291-0/+9
|
* i64 to i32 lowering for wasm2asm (#1134)Thomas Lively2017-09-011-3/+5
|
* wasm2asm test generation (#1124)Thomas Lively2017-08-163-61/+43
| | | | | | | | | | | | | | | | | * Translate assert_return invokes to asm * Translate assert_trap tests to JS * Enable wasm2asm tests * Fix wasm2asm translation of store * Update ubuntu nodejs in Travis * Free JSPrinter buffer * Use unique_ptr for Functions to prevent leaks * Add tests for assert translation
* wasm2asm i32 arithmetic support (#1120)Thomas Lively2017-08-072-0/+2
| | | * Rotations, popcnt, ctz, etc
* Get wasm2asm building again (#1107)Thomas Lively2017-08-021-0/+651
| | | | | | | | | | | | | | | | | | * Get wasm2asm building again Updates CMakeLists.txt to have wasm2asm built by default, updates wasm2asm.h to account for recent interface changes, and restores JSPrinter functionality. * Implement splice for array values * Clean up wasm2asm testing * Print semicolons after statements in blocks * Cleanups and semicolons for condition arms * Prettify semicolon emission
* Parallelize istring creation (#1008)Alon Zakai2017-05-161-14/+29
| | | | | | | | * parallelize istring creation, by having a thread-local set and a global set guarded by a mutex. each time a new string shows up in a thread, it will be added to that thread's set, after accessing the global set through the lock first, which means we lock at most once per new string per thread * don't leak strings in istring store * since we now create names in a parallel thread-safe manner, we don't need to pre-create names in RelooperJumpThreading
* Fix build with gcc 7 (#957)Morris Hafner2017-03-291-2/+1
| | | | 1. Add a missing <functional> include 2. Put the // fallthrough comment after the closing bracket so the compiler does not emit a implicit fallthrough warning.
* refactor asm.js ast to use an AssignName node, for the common case of ↵Alon Zakai (kripken)2017-01-312-9/+48
| | | | assigning to a name and not an arbitrary ast node