summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* | wasm-emscripten-finalize: Improve shared library support (#1961)Sam Clegg2019-04-025-34/+144
|/ | | | | | | | | | | | | | | | | Convert PIC code generated by llvm to work with the current emscripten ABI for dynamic linking: - Convert mutable global imports from GOT.mem and GOT.func into internal globals. - Initialize these globals on started up in g$foo and f$foo imported functions to calculate addresses at runtime. Also: - Add a test case for linking and finalizing a shared library - Allow __stack_pointer global to be non-existent as can be case for a shared library. - Allow __stack_pointer global to be an import, as can be the case for a shared library.
* Rename atomic wait/notify instructions (#1972)Heejin Ahn2019-03-3026-118/+113
| | | | | | | | This renames the following: - `i32.wait` -> `i32.atomic.wait` - `i64.wait` -> `i64.atomic.wait` - `wake` -> `atomic.notify` to match the spec.
* avoid risky iterator addition (#1970)Alon Zakai2019-03-291-1/+1
| | | Not an actual problem, but hits an assertion in D_GLIBCXX_DEBUG, and is likely UB.
* Delete wasm-merge (#1969)Thomas Lively2019-03-291-672/+0
| | | It is not very useful.
* Change ArenaVector<T>::Iterator to satisfy standard ↵Ryoga2019-03-261-5/+76
| | | | (Legacy)RandomAccessIterator concept (#1962)
* remove getString, which is not used, and was insecure to boot (#1966)Alon Zakai2019-03-262-10/+2
|
* More validation tests and fixes for SIMD (#1964)Thomas Lively2019-03-251-0/+8
| | | | | Moves the feature validation unit test file to a new directory, 'unit', and adds new tests for SIMD and sign-ext. Adds validation for v128 globals and v128.const.
* Semi-SSA improvements (#1965)Alon Zakai2019-03-253-6/+58
| | | | | | | This adds an ssa-nomerge pass, which like ssa creates new local indexes for each set, but it does not alter indexes that have merges (in practice adding indexes to merges can lead to more copies in the end.) This also stops adding a new local index for a set that is already in "ssa form", that is, has only one set (aside from the zero initialization which wasm mandates, but for an "ssa form" index, that must not be used). This then enables ssa-nomerge in -O3 and -Os. This doesn't help much on well-optimized code like from the wasm backend (but it does sometimes - 0.5% code size improvement on Box2D), but on AssemblyScript for example it can remove a copy in the n-body benchmark as can be seen in the test updates here.
* optimize-instructions after the last precompute-propagate (#1963)Alon Zakai2019-03-221-1/+1
| | | | | | | A propagated constant can be helpful in the various patterns in optimize instructions. Testcase shows an example of this in action - we can optimize out a load offset for a constant, but if we propagated it afterwards, we would miss that. In general these two passes can help each other, so maybe they should be combined and run multiple iterations, but that's what --converge is for. Meanwhile this change improves us on what seems to be the more common case - guessed at by it being what I noticed in practice, and when I run the fuzzer, I see only this type of case.
* Add export count to --metrics (#1954)Sam Clegg2019-03-191-1/+2
| | | | Also, always output high level metrics even when zero.
* Update v128.const text formats (#1934)Thomas Lively2019-03-194-29/+32
| | | | | Parse the formats allowed by the spec proposal and emit the i32x4 canonical format.
* Validate that types match features (#1949)Thomas Lively2019-03-185-43/+87
| | | | | | Refactors features into a new wasm-features.h file and updates the validator to check that all types are allowed. Currently this is only relevant for the v128 SIMD type, but new types will be added in the future. The test for this change is in #1948.
* Allow tools to read from stdin (#1950)Thomas Lively2019-03-184-9/+57
| | | | This is necessary to write tests that don't require temporary files, such as in #1948, and is generally useful.
* Add const specifiers (#1952)Ryoga2019-03-182-4/+15
| | | | | | With this we can write stuff like: const wasm::Expression* p; const wasm::Binary* q = p->cast<wasm::Binary>();
* Remove unnecessary semicolons (#1942)Ryoga2019-03-185-5/+5
| | | Removed semicolons that cause errors when compiling with -pedantic-errors.
* Add sign-ext feature (#1947)Thomas Lively2019-03-153-2/+22
|
* Add strip-target-features pass (#1946)Thomas Lively2019-03-146-0/+10
| | | And run it in wasm-emscripten-finalize. This will prevent the emscripten output from changing when the target features section lands in LLVM.
* Do not erase internal debug into in --strip-producers - the pass was ↵Alon Zakai2019-03-141-5/+9
| | | | unconditionally erasing it in all --strip passes (#1939)
* Add some checking in EmscriptenGlueGenerator::generateStackInitialization ↵Sam Clegg2019-03-131-4/+12
| | | | | | | | | (#1944) We expect the stack pointer to be of a certain type. This fixes a segfault we are seeing when passed a binary which doesn't quite meet our expectations.
* Add BinaryenConstGetValueV128 to C/JS-API (#1931)Daniel Wirtz2019-03-133-33/+80
| | | | | | | This PR adds void BinaryenConstGetValueV128(BinaryenExpressionRef expr, uint8_t* out); to the C-API and uses it in Binaryen.getExpressionInfo in the JS-API.
* wasm-emscripten-finalize: Remove JSCall thunk generation (#1938)Sam Clegg2019-03-123-137/+4
| | | | We now implement addFunction by creating a wasm module to wrap that JS function and simply adding it to the table.
* Optimize away sets of the same local (#1940)Alon Zakai2019-03-072-10/+39
|
* Fix getExitingBranches, which had |targets| instead of |curr->targets| (#1936)Alon Zakai2019-03-071-1/+1
| | | | | | | That caused it to miss switch targets, and a code-folding bug. Fixes #1838 Sadly the fuzzer didn't find this because code folding looks for very particular code patterns that are unlikely to be emitted randomly.
* Use stdout for --help message (#1937)Sam Clegg2019-03-061-9/+9
| | | | Noramlly --help is considered normal output not error output. For example its normally to pipe the output of --help to a pager.
* CoalesceLocals: run even if we have just 1 var, as we may be able to remove ↵Alon Zakai2019-03-061-5/+0
| | | | that one var by reusing a param
* Optimize added constants with propagation only if we see we will remove all ↵Alon Zakai2019-03-065-83/+201
| | | | uses of the original add, as otherwise we may just be adding work (both an offset, and an add). Refactor local-utils.h, and make UnneededSetRemover also check for side effects, so it cleanly removes all traces of unneeded sets.
* Run multiple iterations in OptimizeAddedConstantsAlon Zakai2019-03-061-13/+33
| | | | | Multiple propagations may be possible in some cases, like nested structs in C.
* Propagate a load/store offset even if locals are not in ssa formAlon Zakai2019-03-061-11/+89
| | | | | | | | | | | | | | | | | The initial OptimizeAddedConstants pass did not try to handle the case of non-ssa locals. However, that can happen, and optimizing those cases too improves us by almost 1% of code size on some large benchmarks like bullet. How this works is that if we see b = a + 10 a = c load(b) then we copy the base value at the add, a' = a b = a' + 10 a = c load(a', offset=10) This no longer has a guarantee of improving code size, since in theory both b and a may have other uses. However, in practice it's very common for b to be optimized out later.
* Don't create already-existing dynCalls (#1932)Alon Zakai2019-03-061-2/+8
| | | | | This can happen in emscripten if we run fpcast-emu after previous passes created dynCalls already. If so, it's fine to just do nothing. Fixes emscripten-core/emscripten#8229
* Align v128 text format with WABT (#1930)Daniel Wirtz2019-03-041-3/+8
| | | | | | | | This PR changes the formatting of v128.const literals in text format / stack ir like so - v128.const i32 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x80 + v128.const i32 0x04030201 0x08070605 0x0c0b0a09 0x800f0e0d Recently hit this when trying to load Binaryen generated text format with WABT, which errored with `error: unexpected token 0x5, expected ).
* Consistently optimize small added constants into load/store offsets (#1924)Alon Zakai2019-03-0116-101/+382
| | | | | | | | | | | | | | | | | | | | | | | | | | See #1919 - we did not do this consistently before. This adds a lowMemoryUnused option to PassOptions. It can be passed on the commandline with --low-memory-unused. If enabled, we run the new optimize-added-constants pass, which does the real work here, replacing older code in post-emscripten. Aside from running at the proper time (unlike the old pass, see #1919), this also has a -propagate mode, which can do stuff like this: y = x + 10 [..] load(y) [..] load(y) => y = x + 10 [..] load(x, offset=10) [..] load(x, offset=10) That is, it can propagate such offsets to the loads/stores. This pattern is common in big interpreter loops, where the pointers are offsets into a big struct of state. The pass does this propagation by using a new feature of LocalGraph, which can verify which locals are in SSA mode. Binaryen IR is not SSA (intentionally, since it's a later IR), but if a local only has a single set for all gets, that means that local is in such a state, and can be optimized. The tricky thing is that all locals are initialized to zero, so there are at minimum two sets. But if we verify that the real set dominates all the gets, then the zero initialization cannot reach them, and we are safe. This PR also makes safe-heap aware of lowMemoryUnused. If so, we check for not just an access of 0, but the range 0-1023. This makes zlib 5% faster, with either the wasm backend or asm2wasm. It also makes it 0.5% smaller. Also helps sqlite (1.5% faster) and lua (1% faster)
* Fix memory leaks (#1925)Bohdan2019-02-283-12/+26
| | | | | | Fixes #1921 Signed-off-by: Bogdan Vaneev <warchantua@gmail.com>
* Optimize normally with debug info (#1927)Alon Zakai2019-02-282-11/+20
| | | | | * optimize normally with debug info - some of it may be removed, but that's the price of higher optimization levels, and by optimizing normally in profiling and -g2 etc. builds they are more comparable to normal ones, yielding better data * copy debug locations automatically in replaceCurrent in wasm-traversal, so optimization passes at least by default will preserve debuggability
* Remove reference to old __wasm_nullptr function (#1928)Sam Clegg2019-02-281-5/+1
|
* Simplify ExpressionAnalyzer (#1920)Alon Zakai2019-02-274-497/+351
| | | | | This refactors the hashing and comparison code to use a single immediate-value iterator. This makes us have a single place that knows the list of immediate fields in every node type, instead of 2. This also fixes a few bugs found by doing that. In particular, this makes us slightly slower than before since we are hashing more fields.
* Dead return value elimination in DeadArgumentElimination (#1917)Alon Zakai2019-02-263-12/+111
| | | | | | | * Finds functions whose return value is always dropped, and removes the return. * Run multiple iterations of the pass, as one can enable others. * Do not run DeadArgumentElimination at all if debug info is present (with these improvements, it became much more likely to destroy debug info). Saves 2.5% on hello world, because of some simple libc calls.
* Vacuum unused values (#1918)Alon Zakai2019-02-251-9/+36
| | | | | | | | | | | | | | Checks if a value is being dropped higher up, like ``` (drop (block i32 (block i32 (i32.const 1) ) ) ) ``` Handling this forces us to be careful in that pass about whether a value is used, and whether the type matters (for example, we can't replace a unary with its child in all cases, if the return value matters).
* SmallVector (#1912)Alon Zakai2019-02-255-9/+187
| | | | | Trying to refactor the code to be simpler and less redundant, I ran into some perf issues that it seems like a small vector, with fixed-size storage and optional additional storage as needed, might help with. This implements that class and uses it in a few places. This seems to help, I see some 1-2% fewer instructions and cycles in `perf stat`, but it's hard to tell if it really makes a noticeable difference.
* add an option to not fuzz memory (#1915)Alon Zakai2019-02-252-1/+23
|
* NaN fuzzing improvements (#1913)Alon Zakai2019-02-196-10/+68
| | | | | | | | | * make DE_NAN avoid creating nan literals in the first place * add a reducer option `--denan` to not introduce nans in destructive reduction * add a `Literal::isNaN()` method * also remove the default exception logging from the fuzzer js glue, which is a source of non-useful VM differences (like nan nondeterminism) * added an option `--no-fuzz-nans` to make it easy to avoid nans when fuzzing (without hacking the source and recompiling). Background: trying to get fuzzing on jsc working despite this open issue: https://bugs.webkit.org/show_bug.cgi?id=175691
* if no output is specified to wasm-opt, warn that we are emitting nothing (#1908)Alon Zakai2019-02-151-1/+3
| | | | | | | | | | | | | | A user that just does ``` wasm-opt input.wasm -O ``` may assume that the input file should have been optimized. But without `-o` we don't emit any output. Often you may not want any output, like if you just want to run a pass like `--metrics`. But for most users wasm-opt is probably going to be used as an optimizer of files. So this PR suggests we emit a warning in that case. For comparison, `llvm-opt` would print to the console, but it avoids printing a binary there so it issues a warning. Instead of this warning, perhaps we should do the same? That would also not be confusing. Closes #1907
* respect --no-validation in pass-debug mode (#1904)Alon Zakai2019-02-121-15/+18
|
* Optimize stack writer on deeply nested blocks, fixes #1903 (#1905)Alon Zakai2019-02-121-43/+55
| | | | also remove some old debugging
* legalize invokes even when doing minimal legalization, as js needs them (#1883)Alon Zakai2019-02-081-40/+47
| | | See [emscripten-core/emscripten#7679
* avoid the deprecated and removed Pointer_stringify (#1906)Alon Zakai2019-02-071-21/+21
|
* Fix a fuzz bug with peeking forward in binary reading. (#1902)Alon Zakai2019-02-071-2/+1
| | | Fixes #1900
* wasm-emscripten-finalize: separateDataSegments() fix (#1897)Alon Zakai2019-02-063-3/+10
| | | | | We should emit a file with only the data segments, starting from the global base, and not starting from zero (the data before is unneeded, and the emscripten loading code assumes it isn't there). Also fix the auto updater to work properly on .mem test updating.
* fix breakage (#1901)Alon Zakai2019-02-061-10/+0
| | | We landed two PRs that had a logic conflict but not a source conflict (bulk memory added ops, comparison optimization removed the need for PUSH ops that bulk memory added).
* fix printing of unreachable atomics, and add print fuzzing (#1899)Alon Zakai2019-02-061-2/+2
|
* fix binaryen.js bindings handling of literals (#1896)Alon Zakai2019-02-063-14/+26
| | | The hardcoded 16 size was no longer valid. This was broken for a while, but happened to not overwrite important memory. Testing with the wasm backend did hit breakage.