summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* Add string parameter to WASM_UNREACHABLE (#2499)Sam Clegg2019-12-0556-420/+450
| | | | | This works more like llvm's unreachable handler in that is preserves information even in release builds.
* Add BYN_ENABLE_ASSERTSION option to allow assertions to be disabled. (#2500)Sam Clegg2019-12-049-6/+29
| | | | | | | | We always enable assertions by default, but this options allows for a build without them. Fix all errors in the ASSERTIONS=OFF build, even though we don't normally build this its good to keep it building.
* Fix metadce debug info after #2497 (#2501)Sam Clegg2019-12-041-0/+1
| | | This like was mistakenly removed as part of the BYN_TRACE conversion.
* Remove 'none' type as a branch target in ReFinalize (#2492)Alon Zakai2019-12-0413-100/+21
| | | | | | | | | | | | | | | | | That was needed for super-old wasm type system, where we allowed (block $x (br_if $x (unreachable) (nop) ) ) That is, we differentiated "taken" branches from "named" ones (just referred to by name, but not actually taken as it's in unreachable code). We don't need to differentiate those any more. Remove the ReFinalize code that considered it, and also remove the named/taken distinction in other places.
* cmake: Convert to using lowercase for and functions/macros (#2495)Sam Clegg2019-12-047-14/+14
| | | This is line with modern cmake conventions is much less SHOUTY!
* Convert to using DEBUG macros (#2497)Sam Clegg2019-12-0420-647/+272
| | | | | | This means that debugging/tracing can now be enabled and controlled centrally without managing and passing state around the codebase.
* Add BYN_DEBUG/BYN_TRACE macros similar to LLVM's debug system (#2496)Sam Clegg2019-12-045-19/+127
| | | | | | | | | This allows for debug trace message to be split my channel. So you can pass `--debug` to simply debug everything, or `--debug=opt` to only debug wasm-opt. This change is the initial introduction but as a followup I hope to convert all tracing over to this new system so we can more easily control the debug output.
* Add Emscripten memory helpers for using the C-API (from Wasm) (#2476)Daniel Wirtz2019-12-031-1/+55
| | | | | | | | | | | | We already have exports for _malloc and _free in the Emscripten build, but there is no way yet to initialize the data without resorting to JS. Hence this PR adds a few additional memory helpers to the Emscripten build so it becomes possible to manipulate Binaryen memory without the need for extra glue code, for example when Binaryen is a WebAssembly import, and one is allocating strings to be used by / reading strings returned by Binaryen. I expect this to be a bit controversial because the use case is relatively specific, but it makes sense for us because we are consuming the C-API directly (from JS and eventually Wasm) and don't rely on binaryen.js-post.js.
* Refactor removing module elements (#2489)Heejin Ahn2019-12-025-102/+70
| | | | | | | | | | | This creates utility functions for removing module elements: removing one element by name, and removing multiple elements using a predicate function. And makes other parts of code use it. I think this is a light-handed approach than calling `Module::updateMaps` after removing only a part of module elements. This also fixes a bug in the inlining pass: it didn't call `Module::updateMaps` after removing functions. After this patch callers don't need to additionally call it anyway.
* Update spec test suite (#2484)Heejin Ahn2019-11-293-4/+7
| | | | | | | | | | | | | 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-267-8/+7
| | | | | | | | | 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)
* Refactor and optimize binary writing type collection (#2478)Alon Zakai2019-11-264-81/+105
| | | | | | | | | | Create a new ParallelFunctionAnalysis helper, which lets us run in parallel on all functions and collect info from them, without manually handling locks etc. Use that in the binary writing code's type collection logic, avoiding a lock for each type increment. Also add Signature printing which was useful to debug this.
* Update type information for em_asm functions (#2480)Thomas Lively2019-11-261-1/+3
| | | | | | | | | We were only updating the imported Function's type name field and failing to update its params and results. This caused the binary writer to start using the wrong types after #2466. This PR fixes the code to update both type representations on the imported function. This double bookkeeping will be removed entirely in an upcoming PR.
* Use opaque types for handle references in C API (#2473)Ingvar Stepanyan2019-11-262-15/+34
| | | | This improves typechecking by verifying that user passes pointers of correct types.
* Print only literal values when printing literals (#2469)Heejin Ahn2019-11-263-4/+6
| | | | | | | | | | | | | | | Current `<<` operator on `Literal` prints `[type].const` with it. But `[type].const` is rather an instruction than a literal itself, and printing it with the literals makes less sense when we later have literals whose type don't have `const` instructions (such as reference types). This patch - Makes `<<` operator on `Literal` print only its value - Makes wasm-shell's shell interface comply with the spec interpreter's printing format (`value : type`). - Prints wasm-shell's `[trap]` message to stderr These make all `fix_` routines for spec tests in check.py unnecessary.
* Revert "Build libbinaryen as a monolithic statically/shared library (#2463)" ↵Alon Zakai2019-11-257-7/+7
| | | | | (#2474) This reverts commit bf8f36c31c0b8e6213bce840be66937dd6d0f6af.
* Remove FunctionType from Event (#2466)Thomas Lively2019-11-2522-223/+252
| | | | | | | | | This is the start of a larger refactoring to remove FunctionType entirely and store types and signatures directly on the entities that use them. This PR updates BrOnExn and Events to remove their use of FunctionType and makes the BinaryWriter traverse the module and collect types rather than using the global FunctionType list. While we are collecting types, we also sort them by frequency as an optimization. Remaining uses of FunctionType in Function, CallIndirect, and parsing will be removed in a future PR.
* Build libbinaryen as a monolithic statically/shared library (#2463)Immanuel Haffner2019-11-227-7/+7
| | | | | | | | | | | | * 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.
* Multivalue type creation and inspection (#2459)Thomas Lively2019-11-2243-265/+451
| | | | | | | | | | | | | Adds the ability to create multivalue types from vectors of concrete value types. All types are transparently interned, so their representation is still a single uint32_t. Types can be extracted into vectors of their component parts, and all the single value types expand into vectors containing themselves. Multivalue types are not yet used in the IR, but their creation and inspection functionality is exposed and tested in the C and JS APIs. Also makes common type predicates methods of Type and improves the ergonomics of type printing.
* Add a pass to inline __original_main() into main() (#2461)Alon Zakai2019-11-214-3/+44
| | | | | | | | | | | | | | | | | | clang/llvm introduce __original_main as a workaround for the fact that main may have different signatures. A downside to that is that users get it in stack traces, which is confusing. In -O2 and above we normally inline __original_main anyhow, but as this is for debugging, non-optimized builds matter too, so add a pass for this. The implementation is trivial, just call doInling. However we must check some corner cases first. Bonus minor fixes to FindAllPointers, which unnecessarily created an object to get the class Id (which is not valid for all classes), and that it didn't take the input by reference properly, which meant we couldn't get the pointer to the function body's toplevel.
* Add a --strip-dwarf pass (#2454)Alon Zakai2019-11-194-6/+16
| | | | | | | | | | | | | This pass strips DWARF debug sections, but not other debug sections. This is useful when emitting source maps, as we do need the SourceMapURL section, but the DWARF sections are not longer necessary (and we've seen a testcase where they are massively large, so big the wasm can't even be loaded in a browser...). Also contains a trivial one-line fix in --extract-function which was necessary to create the testcase here: that pass extracts a function from a wasm file (like llvm-extract) but it didn't check if an export already existed for the function.
* Add PostAssemblyScript pass (#2407)Daniel Wirtz2019-11-195-0/+649
| | | | | Adds the AssemblyScript-specific passes post-assemblyscript and post-assemblyscript-finalize, eliminating redundant ARC-style retain/release patterns conservatively emitted by the compiler.
* Optimize away invoke_ calls where possible (#2442)Alon Zakai2019-11-191-0/+81
| | | | | | | | | | | | When we see invoke_ calls in emscripten-generated code, we know they call into JS just to do a try-catch for exceptions. If the target being called cannot throw, which we check in a whole-program manner, then we can simply skip the invoke. I confirmed that this fixes the regression in emscripten-core/emscripten#9817 (comment) (that is, with this optimization, upstream is around as fast as fastcomp). When we have native wasm exception handling, this can be extended to optimize that as well.
* Refactor a CallGraphPropertyAnalysis helper [NFC] (#2441)Alon Zakai2019-11-182-61/+103
| | | | | | | | | | | This moves code out of Asyncify into a general helper class. The class automates scanning the functions for a property, then propagating it to functions that call them. In Asyncify, the property is "may call something that leads to sleep", and we propagate backwards to callers, to find all those that may sleep. This will be useful in a future exceptions-optimizing pass I want to write, where the property will be "may throw". We will then be able to remove exceptions overhead in cases that definitely do not throw.
* Fix #2430 properly (#2449)Alon Zakai2019-11-181-10/+10
|
* Warning improvements (#2438)Alon Zakai2019-11-152-4/+17
| | | | | | | | If wasm-opt is run with no passes, warn, as we've gotten reports that people assume a tool called "wasm-opt" should optimize automatically (but we follow llvm's opt convention of not doing so). Add a --quiet (-q) flag that suppresses this minor warning, and the other minor warning where there is no output file.
* Reuse BINARYEN_API for Emscripten builds (#2435)Daniel Wirtz2019-11-131-1/+4
| | | | | | | | | | | | This is an alternative to #2361 in that it only implements reusing BINARYEN_API so we don't have to list all the functions in build-js.sh. Differs in that it keeps the sh file relatively straight forward without going overboard with bash functionality. Also adds various quotes in case of whitespace in paths and makes it so that *.sh files always use LF line endings to ease Windows support. For instance, I am pulling the repository in Windows but compile in WSL, which, if Git isn't properly configured to check out line endings as-is, would otherwise break the sh files. Fixes #2361.
* [NFC] Make Type a class instead of enum (#2433)Thomas Lively2019-11-132-14/+52
| | | | | | | | | The plan is to extend `Type` to represent arbitrary multivalue types, and as a prerequisite for that it is necessary to make it a class instead of an enum. This PR bends over backwards to add all the automatic conversions and constants necessary to allow the rest of the code to compile unmodified, but in the future it should be possible to standardize usage across the code base and remove some of these utilities.
* uint32_t instead of int64_t as return type for GetMemorySegmentByteOffset ↵COFFEETALES2019-11-122-3/+3
| | | | | (#2432) `uint32_t` instead of `int64_t` as return type for `GetMemorySegmentByteOffset` and minor fixes on tests.
* Cast to bool after bitwise operations, to avoid an MSVC warning (#2431)Alon Zakai2019-11-121-10/+12
| | | | Fixes #2430
* Support --pass-arg in ToolOptions. (#2429)Alon Zakai2019-11-114-17/+19
| | | | | | This will allow us to pass pass args to wasm-emscripten-finalize, which runs legalize-js-interface internally, which recently added an optional argument.
* When legalizing, optionally export the original function too with orig$X (#2427)Alon Zakai2019-11-111-1/+28
| | | | | The original is necessary if we want to pass it to wasm, where it will be called directly, without JS legalization. For example the JS dynamic loader in emscripten needs this, emscripten-core/emscripten#9562
* Fix catch parsing (#2428)Heejin Ahn2019-11-113-20/+15
| | | | | | | - When a catch body is a block, call its `finalize` function with the correct type - Don't create a block when there's one instruction in a catch body - Remove `makeCatch` from gen-s-parser.py; it's not necessary - Fix a test case that has a `catch` without `try`
* Add Stack IR optimization support for EH (#2425)Heejin Ahn2019-11-071-3/+7
|
* Improve type selection in fuzzer (#2424)Heejin Ahn2019-11-061-27/+27
| | | | | | | | | - Adds `items` function for `FeatureOptions` so we can get a vector of eligible types - Replaces hardcoded enumeration of MVP types with `getConcreteTypes`, which also adds v128 type to the list if SIMD is enabled - Removes `getType()` function; this does not seem to be used anywhere - Renames `vectorPick` with `pick` - Use the absolute path for d8 in the fuzzer
* Don't attempt to de-duplicate asm consts (#2422)Sam Clegg2019-11-041-13/+11
| | | | | | | | | | | | Since we switched the using memory addresses for asm const indexes and stopping trying to modify the code we can no loner de-duplicate the asm const strings here. If we want to de-duplicate in the strings in emscripten we could do that but it seems like a marginal benefit. This fixes the test_html5_gamepad failures which is currently showing up on the emscripten waterfall.
* Add i32x4.dot_i16x8_s (#2420)Thomas Lively2019-11-0415-0/+43
| | | | | This experimental instruction is specified in https://github.com/WebAssembly/simd/pull/127 and is being implemented to enable further investigation of its performance impact.
* OptimizeInstructions: Eq64 of 0 => Eqz64 (#2421)Alon Zakai2019-11-041-0/+2
| | | Fixes #2417
* Fix PostWalker traversal of push instruction (#2419)Heejin Ahn2019-11-041-0/+1
| | | PostWalker traversal should visit its value.
* Add SIMD integer min and max instructions (#2416)Thomas Lively2019-11-0115-9/+455
| | | As proposed in https://github.com/WebAssembly/simd/pull/27.
* Add EH support for DCE pass (#2415)Heejin Ahn2019-11-012-1/+45
| | | | Like an `If`, `Try` construct is reachable when either its try body or catch body is reachable. This adds support for that.
* Don't remove events used in instructions (#2412)Heejin Ahn2019-11-011-0/+12
| | | | | Previously RemoveUnusedModuleElements pass only preserved exported events and did not preserve events used in `throw` and `br_on_exn` instructions. This fixes it.
* Use absolute memory addresses for emasm string indexes. (#2408)Sam Clegg2019-10-311-25/+36
| | | | | | | | | | Before we used 0-based indexes which meant that we needed to modify the code calling the emasm function to replace the first argument. Now we use the string address itself as the index/code for the emasm constant. This allows use code to go unmodifed as the emscripten side will accept the memory address as the index/code. See: https://github.com/emscripten-core/emscripten/issues/9013
* Do not precompute SIMDLoad (#2409)Thomas Lively2019-10-301-0/+1
| | | This fixes a crash when programs containing load_splats are optimized.
* Fix BinaryenModuleAllocateAndWriteText parameter type (#2406)Irmen de Jong2019-10-282-3/+2
| | | This fixes a compiler error when trying to compile code calling this function with a C++ compiler.
* When renaming functions ensure the corresponding GOT.func entry is also ↵Sam Clegg2019-10-251-0/+7
| | | | | | renamed (#2382) Fixes https://github.com/WebAssembly/binaryen/issues/2180
* Add ModAsyncify* passes (#2404)Alon Zakai2019-10-233-1/+154
| | | | | | | | | | | | | | | | | | | | | | | | | | | | These passes are meant to be run after Asyncify has been run, they modify the output. We can assume that we will always unwind if we reach an import, or that we will never unwind, etc. This is meant to help with lazy code loading, that is, the ability for an initially-downloaded wasm to not contain all the code, and if code not present there is called, we download all the rest and continue with that. That could work something like this: * The wasm is created. It contains calls to a special import for lazy code loading. * Asyncify is run on it. * The initially downloaded wasm is created by running --mod-asyncify-always-and-only-unwind: if the special import for lazy code loading is called, we will definitely unwind, and we won't rewind in this binary. * The lazily downloaded wasm is created by running --mod-asyncify-never-unwind: we will rewind into this binary, but no longer need support for unwinding. (Optionally, there could also be a third wasm, which has not had Asyncify run on it, and which we'd swap to for max speed.) These --mod-asyncify passes allow the optimizer to do a lot of work, especially for the initially downloaded wasm if we have lots of calls to the lazy code loading import. In that case the optimizer will see that those calls unwind, which means the code after them is not reached, potentially making lots of code dead and removable.
* Convert usage of Pointer_stringify to UTF8ToString (#2403)Brad Morris2019-10-231-1/+1
| | | | This fixes #2396. This converts the use of the old Pointer_stringify to the new UTF8ToString. Added a js test in kitchen-sink.js to cover this.
* Fix incorrect assert in BinaryenHostGetOperand (#2393)Brad Morris2019-10-221-1/+1
|
* Ability to list each item on Exports/Data Segments/Functions (#2386)COFFEETALES2019-10-213-0/+168
| | | Adds functionality to the C API for getting the number of items in a module and fetching them out by index.