summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* wasm2js: emscripten glue option (#2000)Alon Zakai2019-04-112-4/+66
| | | | | | 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-114-536/+561
| | | | | | | | | | | | | 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?)
* Bulk memory side effects (#1998)Thomas Lively2019-04-111-12/+40
|
* don't precompute anything to a vector for now (#1999)Alon Zakai2019-04-101-1/+2
| | | We handled this for the normal case, but the optimizer can also precompute a return into a value, so check the output of the precomputation as well.
* Handle relocatable code in AsmConstWalker (#1992)Sam Clegg2019-04-101-4/+17
| | | | | | In relocatable code the constant offset might be relative to __memory_base.
* Minor wasm2js cleanups (#1995)Alon Zakai2019-04-101-21/+40
| | | | | * Only look at the sign of loads when they actually matter. * Prepare for imported globals (just refactoring/cleanup).
* Fuzz fixes (#1991)Alon Zakai2019-04-103-5/+15
| | | | | | | Get fuzzer to attempt to create almost all features. Pass v8 all the flags to allow that. Fix fuzz bugs where we read signed_ even when it was irrelevant for that type of load. Improve wasm-reduce on fuzz testcases, try to replace a node with drops of its children, not just the children themselves.
* avoid signed overflow undefined behavior in OptimizeInstructions constant ↵Alon Zakai2019-04-091-2/+2
| | | | computations (#1990)
* Directize: if we change a type to unreachable, we need to propagate that out ↵Alon Zakai2019-04-091-0/+10
| | | | (#1989)
* Better memory fuzzing (#1987)Alon Zakai2019-04-085-12/+77
| | | | | | | | Hash the contents of all of memory and log that out in random places in the fuzzer, so we are more sensitive there and can catch memory bugs. Fix UB that was uncovered by this in the binary writing code - if a segment is empty, we should not look at &vector[0], and instead use vector.data(). Add Builder::addExport convenience method.
* wasm-emscripten-finalize: rename function pointer getter functions (#1988)Sam Clegg2019-04-081-4/+25
| | | | | | | | Turns out there was already a precedent in emscripten for using `fp$` for these functions. Also, improve the heuristics for guessing the stack pointer global. There are cases where we don't use have an explicit stack pointer at all but *do* have both imported and exported globals.
* Move segment merging to fit web limits into its own pass (#1980)Thomas Lively2019-04-088-138/+228
| | | | | | It was previously part of writing a binary, but changing the number of segments at such a late stage would not work in the presence of bulk memory's datacount section. Also updates the memory packing pass to respect the web's limits on the number of data segments.
* Directize: arguments may have had side effects, don't just remove them when ↵Alon Zakai2019-04-081-5/+14
| | | | optimizing to an unreachable (#1985)
* Passive segments (#1976)Thomas Lively2019-04-0522-89/+196
| | | | | Adds support for the bulk memory proposal's passive segments. Uses a new (data passive ...) s-expression syntax to mark sections as passive.
* Add missing comma in metadata JSON (#1983)Thomas Lively2019-04-051-1/+1
|
* Add feature options to emscripten metadata (#1982)Thomas Lively2019-04-055-25/+62
| | | Emscripten runs wasm-emscripten-finalize before running wasm-opt, so the target features section is stripped out before optimizations are run. One option would have been to add another wasm-opt invocation at the very end to strip the target features section, but dumping the features as metadata avoids the extra tool invocation. In the long run, it would be nice to have only as single binaryen invocation to do all the work that needs doing.
* wasm-emscripten-finalize: add namedGlobals to output metadata (#1979)Sam Clegg2019-04-042-8/+21
| | | | | | This key is used by emscripten when building with MAIN_MODULE in order to export global variables from the main module to the side modules.
* Use target features section in wasm-opt (#1967)Thomas Lively2019-04-0311-91/+198
| | | | | | | If the user does not supply features explicitly on the command line, read and use the features in the target features section for validation and passes. If the user does supply features explicitly, error if they are not a superset of the features marked as used in the target features section and the user does not explicitly handle this.
* Update test/spec/memory.wast to latest upstream (#1801)Alon Zakai2019-04-035-3/+34
| | | | | | | Minus multi-memory which we don't support yet. Improve validator. Fix some minor validation issues in our tests.
* Add a mechanism to pass arguments to passes (#1941)Alon Zakai2019-04-033-13/+29
| | | | | | | | | This allows wasm-opt --pass-arg=KEY:VALUE where KEY and VALUE are strings. It is then added to passOptions.arguments, where passes can read it. This is used in ExtractFunction instead of an env var.
* Directize: turns indirect calls into direct ones (#1974)Alon Zakai2019-04-024-2/+136
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | * wip [ci skip] * works * test output * test update * js build * better location for running directize
| * better location for running directizeAlon Zakai2019-04-021-1/+1
| |
| * worksAlon Zakai (kripken)2019-03-312-16/+18
| |
| * wip [ci skip]Alon Zakai (kripken)2019-03-314-2/+134
| |
* | 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.