summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix comparison signedness errors in optimizeMemoryAccess() (#2211)Sean Stangl2019-07-101-3/+3
|
* wasm-emscripten-finalize: Internalize mutable __stack_pointer import (#2213)Sam Clegg2019-07-103-0/+31
| | | | | | | | | | | I'm working on a change to lld that will cause `-pie` binaries to import __stack_pointer, just like -shared do already. Because we don't yet support mutable globals everywhere this change will internalize the import and create a new immutable import that is used to initialize the internal one. This change is part of the fix for: https://github.com/emscripten-core/emscripten/issues/8915
* Ignore --initial-stack-pointer arg to wasm-emscripten-finalize (#2201)Sam Clegg2019-07-103-19/+4
| | | | | | | | | | | | | We were passing bad value in --initial-stack-pointer which did not include the STATIC_BUMP (since STATIC_BUMP is determinted by the output of finalize). If emscripten wants to set the stack pointer position it can do so by calling the stackRestore() function at startup. This argument will be removed completely once we stop passing it on the emscripten side. See https://github.com/emscripten-core/emscripten/issues/8905
* Allows multiple arguments to be passed to PassRunner::add<T>() (#2208)Ryoga2019-07-091-3/+3
| | | | | | | | | | | | | | | | | | | | | | struct FooPass : public wasm::Pass { FooPass(int a, int b); }; PassRunner runner {module}; runner.add<FooPass>(1, 2); // To allow this This change avoids unnecessary copying and allows us to pass the reference without reference_wrapper. struct BarPass : public wasm::Pass { BarPass(std::ostream& s); }; runner.add<BarPass>(std::cout); // Error (cout is uncopyable) runner.add<BarPass>(std::ref(std::cout)); // OK ↓ runner.add<BarPass>(std::cout); // OK (passed by reference) runner.add<BarPass>(std::ref(std::cout)); // OK
* fix wasm2js compilation after conflicting landings (#2209)Alon Zakai2019-07-081-0/+8
|
* wasm2js: use OverriddenVisitor, so we show a clear error on unsupported ↵Alon Zakai2019-07-081-2/+62
| | | | instructions (#2199)
* Initial tail call implementation (#2197)Thomas Lively2019-07-0313-27/+99
| | | | | | | | | | | Including parsing, printing, assembling, disassembling. TODO: - interpreting - effects - finalization and typing - fuzzing - JS/C API
* Loosen conditions on MemoryPacking (#2205)Thomas Lively2019-07-031-4/+12
| | | | Allow MemoryPacking to run when there are no passive segments, even if bulk memory is enabled.
* Clean up loose ends in feature handling (#2203)Thomas Lively2019-07-036-9/+20
| | | | | Fix and test mutable globals support, replace string literals with constants, and add a pass to emit the target features section.
* Minimal Push/Pop support (#2207)Alon Zakai2019-07-0316-14/+214
| | | | | | | This is the first stage of adding support for stacky/multivaluey things. It adds new push/pop instructions, and so far just shows that they can be read and written, and that the optimizer doesn't do anything immediately wrong on them. No fuzzer support, since there isn't a "correct" way to use these yet. The current test shows some "incorrect" usages of them, which is nice to see that we can parse/emit them, but we should replace them with proper usages of push/pop once we actually have those (see comments in the tests). This should be enough to unblock exceptions (which needs a pop in try-catches). It is also a step towards multivalue (I added some docs about that), but most of multivalue is left to be done.
* wasm2js: export memory growth function only if memory growth is enabled (#2194)Alon Zakai2019-07-031-2/+4
| | | Previously we tried to export it if the memory was exported, even if growth was not on, which caused an error.
* Fix event section order (#2202)Heejin Ahn2019-07-021-1/+1
| | | | | | The event section should be between the global section and the export section, if present. Here tests are missing, but we don't have a very good way of testing validity of binary anyway. We are planning to add d8 tests in a separate PR.
* Bysyncify: Assertion improvements (#2193)Alon Zakai2019-07-011-36/+37
| | | | | Add assertions on stack overflow in all 4 Bysyncify API calls (previously only 2 did it). Also add a check that those assertions are hit.
* Limit interpreter depth in precompute, but not when running whole modules ↵Alon Zakai2019-07-012-17/+33
| | | | | | | (#2191) Keep limiting in precompute as before: that is useful since that pass is run as part of normal compilation, and we want to avoid native stack limits on all platforms. Also that pass is not likely to find any pattern of size 50 of higher that it can't precompute as a sum of smaller pieces. Restore the 250 limit from before for interpreting entire modules, as without that the fuzzer will sometimes hit the limit and cause a false positive.
* Bysyncify: Fuzzing (#2192)Alon Zakai2019-07-012-1/+3
| | | | | | | | Gets fuzzing support for Bysyncify working. * Add the python to run the fuzzing on bysyncify. * Add a JS script to load and run a testcase with bysyncify support. The code has all the runtime support for sleep/resume etc., which it does on calls to imports at random in a deterministic manner. * Export memory from fuzzer so JS can access it. * Fix tiny builder bug with makeExport.
* Workaround for wasm2js output minification issue with emscripten (#2185)Brion Vibber2019-07-011-2/+3
| | | | | | | | | | | | | | * 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
* Relax bulk memory rules (#2186)Thomas Lively2019-06-301-17/+6
| | | As decided in the recent in-person CG meeting.
* Bysyncify: allow wildcard endings in import list (#2190)Alon Zakai2019-06-303-9/+82
| | | This allows us to do things in emscripten like note that all env.invoke_* functions are important.
* Bysyncify: fix skipping of flattened if condition (#2187)Alon Zakai2019-06-301-2/+5
| | | | | We assigned it to a local, but didn't run maybeSkip on it. As a result, it was executed during rewinding, which broke restoring the saved value. Found by the fuzzer.
* wip (#2189)Alon Zakai2019-06-301-1/+1
|
* Bysyncify: ensure memory exists (#2188)Alon Zakai2019-06-301-0/+5
| | | | | We need memory in order to read and write rewinding info, so add it if the module didn't have any memory at all. Found by the fuzzer.
* Bysyncify: optimize better by coalescing before instrumenting control flow ↵Alon Zakai2019-06-251-28/+138
| | | | | | | | | (#2183) This results in better code sizes on many testcases, sometimes much better. For example, on SQLite the 150K function has only 27 locals instead of 3,874 which it had before (!). This also reduces total code size on SQLite by 15%. The key issue is that after instrumenting control flow we have a lot bigger live ranges. This must be done rather carefully, as we need to introduce some temp locals early on (for breaking up ifs, for call return values, etc.).
* Skip imports in table during RemoveImports (#2181)Thomas Lively2019-06-241-1/+12
| | | | This prevents RemoveImports from producing an invalid module that references functions that no longer exist.
* Bysyncify: Don't instrument functions that call bysyncify_* directly (#2179)Alon Zakai2019-06-211-12/+52
| | | | | Those functions are assumed to be part of the runtime. Instrumenting them would mean nothing can work. With this fix, bysyncify is useful with pure wasm, and not just through imports.
* Bysyncify: add ignore-imports and ignore-indirect options (#2178)Alon Zakai2019-06-212-35/+65
| | | ignore-imports makes it not assume that any import may unwind/rewind the stack. ignore-indirect makes it not assume any indirect call can reach an unwind/rewind (which means, it assumes there is not an indirect call on the stack while unwinding).
* Make feature section errors into warnings (#2175)Alon Zakai2019-06-181-14/+18
| | | | Otherwise there is no way to view a wasm object file in binaryen.
* Bysyncify: bysyncify_stop_unwind (#2173)Alon Zakai2019-06-161-13/+30
| | | Add a method to note the stopping of an unwind. This is enough to implement coroutines. Includes an example of coroutine usage in the test suite.
* Bysyncify: async transform for wasm (#2172)Alon Zakai2019-06-159-5/+981
| | | | | | | | | This adds a new pass, Bysyncify, which transforms code to allow unwind and rewinding the call stack and local state. This allows things like coroutines, turning synchronous code asynchronous, etc. The new pass file itself has a large comment on top with docs. So far the tests here seem to show this works, but this hasn't been tested heavily yet. My next step is to hook this up to emscripten as a replacement for asyncify/emterpreter, see emscripten-core/emscripten#8561 Note that this is completely usable by itself, so it could be useful for any language that needs coroutines etc., and not just ones using LLVM and/or emscripten. See docs on the ABI in the pass source.
* Fix BinaryenRemoveEvent naming in binaryen-c.h (#2171)Daniel Wirtz2019-06-121-1/+1
| | | | | | * Fix BinaryenRemoveEvent naming in binaryen-c.h * Enable ERROR_ON_UNDEFINED_SYMBOLS=1 in build-js.sh
* Enable compiling on GCC < 5 (#2149)Matt Topol2019-06-121-1/+1
| | | _ISOC11_SOURCE is the preprocessor flag that specifies whether or not aligned_alloc is defined and exists. While GCC versions lower than 5 do include C++11 and C++14 constructs, they do not include std::aligned_alloc, so this check allows compiling on those versions of GCC by defaulting down to posix_memalign in those situations appropriately.
* Refactor -g param parsing (#2167)Alon Zakai2019-06-073-15/+9
| | | | | Use one shared location in optimization-options as much as possible. This also allows tools like wasm2js to receive that flag.
* Copy debug info when inlining (#2168)Alon Zakai2019-06-072-6/+70
|
* Fix bug and leak in relooper merge consecutive blocks (#2159)hobby82019-06-071-2/+9
| | | | | | | | | | | | | | | | | | Fixes in Relooper merge consecutive blocks: Entry block getting removed when it is part of a loop: bb1->AddBranchTo(bb2, nullptr); bb1->AddBranchTo(bb3, ...); bb2->AddBranchTo(bb1, nullptr); bb3->AddBranchTo(bb4, nullptr); relooper.AddBlock(bb1); relooper.AddBlock(bb2); relooper.AddBlock(bb3); relooper.AddBlock(bb4); relooper.Calculate(bb1); Branches memory leak
* Use splatted zero vector in makeZero (#2164)Thomas Lively2019-06-051-0/+8
| | | | | This prevents the optimizer from producing v128.const instructions, which are not supported by V8 at this time.
* Reduce interpreter recursion limit (#2162)Alon Zakai2019-06-041-1/+1
| | | | | | | This should be small enough to work in a 512K stack on Linux, which may then be small enough to work on all common OSes. I had to update some spec tests which actually did more recursive calls, but I don't think the change reduces any relevant amount of test coverage. This may fix the Mac bot finally, as with this it passes for me on the stack size I think Macs have by default.
* Use BinaryIndexes instead of copies in BinaryWriter (NFC) (#2161)Heejin Ahn2019-06-043-29/+13
|
* Add a recursion limit for the interpreter's expression runner (#2160)Alon Zakai2019-06-031-2/+11
| | | | | We previously had one for calls (the spec tests check for infinite recursion). This is an internal limit of the interpreter, until we un-recursify it, which may make sense at some point - but it's unlikely interpreting massively-recursive things will be beneficial in the optimizer anyhow, since if it could do something with them, it could also do so on the smaller pieces iteratively.
* Add event section (#2151)Heejin Ahn2019-05-3124-16/+810
| | | | | | | | | | | | | | | | | | This adds support for the event and the event section, as specified in https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md#changes-to-the-binary-model. Wasm events are features that suspend the current execution and transfer the control flow to a corresponding handler. Currently the only supported event kind is exceptions. For events, this includes support for - Binary file reading/writing - Wast file reading/writing - Binaryen.js API - Fuzzer - Validation - Metadce - Passes: metrics, minify-imports-and-exports, remove-unused-module-elements
* Add --print-function-map to print out a map of function index to name (#2155)Alon Zakai2019-05-314-0/+50
| | | | | | | | | | * work * fix * fix * format
* Un-recursify OptimizeInstructions::optimizeAddedConstants (#2157)Alon Zakai2019-05-311-16/+27
| | | | | This helps avoid issues with smaller stack sizes on some OSes. Should fix the last Mac test failure on emscripten-releases CI (other.test_js_function_names_are_minified, which happens to have massively-nested additions of constants).
* Refactor typeuse parsing more (NFC) (#2146)Heejin Ahn2019-05-291-10/+18
| | | | | Now `parseTypeUse` always returns `FunctionType*` and params/return pair and makes sure the two are consistent, so the caller does not have to populate params/results when only `(type)` is specified.
* Add Features.MVP and Features.All to binaryen.js (#2148)Heejin Ahn2019-05-293-0/+10
| | | | This adds `Features.MVP` and `Features.All` to binaryen.js and make test cases use it.
* Simplify function lists in RemoveUnusedModuleElements (NFC) (#2147)Heejin Ahn2019-05-281-9/+1
| | | | It looks there's no need to maintain `functions` and `functionImports` separately.
* wasm2js: Switch optimizations (#2141)Alon Zakai2019-05-281-8/+202
| | | | | 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.
* Refactor type and function parsing (#2143)Heejin Ahn2019-05-246-210/+242
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - Refactored & fixed typeuse parsing rules so now the rules more closely follow the spec. There have been multiple parsing rules that were different in subtle ways, which are supposed to be the same according to the spec. - Duplicate types, i.e., types with the same signature, in the type section are allowed as long as they don't have the same given name. If a name is given, we use it; if type name is not given, we generate one in the form of `$FUNCSIG$` + signature string. If the same generated name already exists in the type section, we append `_` at the end. This causes most of the changes in the autogenerated type names in test outputs. - A typeuse has to be in the order of (type) -> (param) -> (result), if more than one of them exist. In case of function definitions, (local) has to be after all of these. Fixed some test cases that violate this rule. - When only (param)/(result) are given, its type will be the type with the smallest existing type index whose parameter and result are the same. If there's no such type, a new type will be created and inserted. - Added a test case `duplicate_types.wast` to test type namings for duplicate types. - Refactored `parseFunction` function. - Add more overrides to helper functions: `getSig` and `ensureFunctionType`.
* Add `getGlobal` to binaryen.js (#2142)Heejin Ahn2019-05-243-2/+16
| | | | | We have `getFunction`, but not `getGlobal` because its name clashed with APIs for the deprecated instruction `get_global`. Now we have reflected instruction renaming in code, we can add it for consistency.
* Show line/col for parsing exceptions in gen-s-parser (#2138)Heejin Ahn2019-05-241-1/+1
|
* Inlining: exposed inlining thresholds as command-line parameters. (#2125)Wouter van Oortmerssen2019-05-233-23/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | * Inlining: exposed inlining thresholds as command-line parameters. This will allow easier experimentation with optimal settings. Also tweaked the default logic slightly to always inline single caller functions up to a certain size. The command-line arguments were tested to have the desired effect for example by the Makefile change in this commit: https://github.com/aardappel/lobster/commit/39ae393e27ff363ab095bbb26c90d6fe17570104 which in turn relies on: https://github.com/emscripten-core/emscripten/pull/8635 * Grouped inlining options & reverted defaults. Now uses same defaults for inlining as before for the sake of not having to redo a lot of tests. Added FIXME to indicate that the current inlining logic needs fixing. * Fixed default values now pulled from code. * clang-format
* Factor out elementStartsWith (NFC) (#2137)Heejin Ahn2019-05-233-32/+38
| | | | | Checking if a first string matches a certain string within a list element appears many times within the parser, so extracted it as a helper function.
* Add BinaryenModuleWriteSExpr to write a module to a string in s-expr format ↵Siddharth2019-05-212-0/+49
| | | | | (#2106) Fixes #2103.