summaryrefslogtreecommitdiff
path: root/test/lit/wasm-split
Commit message (Collapse)AuthorAgeFilesLines
* Use empty blocks instead of nops for empty scopes in IRBuilder (#7080)Thomas Lively2024-11-142-4/+0
| | | | | | | | | | When IRBuilder builds an empty non-block scope such as a function body, an if arm, a try block, etc, it needs to produce some expression to represent the empty contents. Previously it produced a nop, but change it to produce an empty block instead. The binary writer and printer have special logic to elide empty blocks, so this produces smaller output. Update J2CLOpts to recognize functions containing empty blocks as trivial to avoid regressing one of its tests.
* [wasm-split] Minimize non-function export names (#6951)Thomas Lively2024-09-172-13/+13
| | | | | | | | The module splitting utility has a configuration option for minimizing new export names, but it was previously applied only to newly exported functions. Using the new multi-split mode can produce lots of exported tables and splitting WasmGC programs can produce lots of exported globals, so minimizing these export names can have a big impact on code size.
* [wasm-split] Configure split functions rather than kept functions (#6949)Thomas Lively2024-09-171-53/+49
| | | | | | | | The configuration for the module splitting utility previous took a set of functions to keep in the primary module. Change it to take a list of functions to split into the secondary module instead. This improves the code quality in multi-split mode because it keeps stub functions generated by previous splits from being moved into secondary modules during later splits.
* [wasm-split] Simplify handling of --keep-funcs and --split-funcs (#6948)Thomas Lively2024-09-173-8/+7
| | | | | | | | | | | | Maintain the invariant that every defined functions belongs to either the set of kept functions or the set of split functions. Functions are kept by default except when --keep-funcs is specified without --split-funcs on the command line. This is mostly NFC except that it changes the default behavior when no arguments are specified on the command line to keep all functions. This will simplify a follow-on PR that switches from passing the kept functions to the module splitting utility to passing the split functions.
* [wasm-split] Run RemoveUnusedElements on secondary modules (#6945)Thomas Lively2024-09-1711-23/+81
| | | | | | | | | Rather than analyze what module elements from the primary module a secondary module will need, the splitting logic conservatively imports all module elements from the primary module into the secondary module. Run RemoveUnusedElements on the secondary module to remove any of these imports that happen to be unnecessary. Leave a TODO mentioning the possibility of being more selective about which module elements get exported to reduce code size in the primary module, too.
* [wasm-split] Add a multi-split mode (#6943)Thomas Lively2024-09-162-0/+228
| | | | | | | Add a mode that splits a module into arbitrarily many parts based on a simple manifest file. This is currently implemented by splitting out one module at a time in a loop, but this could change in the future if splitting out all the modules at once would improve the quality of the output.
* [wasm-split] Add an option to skip importing placeholders (#6942)Thomas Lively2024-09-161-0/+54
| | | | | | | | | | | | | | Wasm-split generally assumes that calls to secondary functions made before the secondary module has been loaded and instantiated should go to imported placeholder functions that can be responsible for loading the secondary module and forwarding the call to the loaded function. That scheme makes the loading entirely transparent from the application's point of view, which is not always a good thing. Other schemes would make it impossible for a secondary function to be called before the secondary module has been explicitly loaded, in which case the placeholder functions would never be called. To improve code size and simplify instantiation under these schemes, add a new `--no-placeholders` option that skips adding imported placeholder functions.
* [wasm-split] Use a fresh table when reference types are enabled (#6726)Thomas Lively2024-07-112-33/+53
| | | | | | | Rather than trying to trampoline primary-to-secondary calls through an existing table, just create a fresh table for this purpose. This ensures that modifications to the existing tables cannot interfere with primary-to-secondary calls and conversely that loading the secondary module cannot overwrite modifications to the tables.
* Allow --keepfuncs and --splitfuncs to be use alongside a profile data (#6322)Benjamin Ling2024-07-103-18/+29
| | | | | | | | | There are times after collecting a profile, we wish to manually include specific functions into the primary module. It could be due to non-deterministic profiling or functions for error scenarios (e.g. _trap). This PR helps to unlock this workflow by honoring both the `--keep-funcs` flag as well as the `--profile` flag
* [tests] Remove use of CHECK-SAME (#6717)Anton Lydike2024-07-091-3/+1
| | | | The `filecheck` command used for tests does not support `CHECK-SAME`, so use should be avoided.
* Fix wasm-split bug in absence of active element segments (#6651)Thomas Lively2024-06-111-0/+41
| | | | | | | | The module splitting code incorrectly assumed that there would be at least one active element segment and failed to initialize the table slot manager with a function table if that was not the case. Fix the bug by setting the table even when there are no active segments and add a test. Fixes #6572 and #6637.
* wasm-split: Handle RefFuncs (#6513)Alon Zakai2024-05-082-0/+160
| | | | | When we have a ref.func that refers to the secondary module then make a trampoline that calls it directly. The trampoline's call is then fixed up like all direct calls to the secondary module.
* [jspi] Fix invalid wat in test case. (#6559)Brendan Dahl2024-04-291-1/+1
|
* [jspi] - Support new version of JSPI for module splitting. (#6546)Brendan Dahl2024-04-292-111/+52
| | | | | | With the old version of JSPI, the JSPI pass was required to be run before splitting and would automatically add an export to be able to find the load_secondary_module function. Now that the pass is no longer needed, just add an import manually for the load_secondary_module function.
* [Parser] Enable the new text parser by default (#6371)Thomas Lively2024-04-251-8/+0
| | | | | | | | | | | | | | The new text parser is faster and more standards compliant than the old text parser. Enable it by default in wasm-opt and update the tests to reflect the slightly different results it produces. Besides following the spec, the new parser differs from the old parser in that it: - Does not synthesize `loop` and `try` labels unnecessarily - Synthesizes different block names in some cases - Parses exports in a different order - Parses `nop`s instead of empty blocks for empty control flow arms - Does not support parsing Poppy IR - Produces different error messages - Cannot parse `pop` except as the first instruction inside a `catch`
* [wasm-split] Do not split out functions referring to segments (#6517)Thomas Lively2024-04-231-0/+94
| | | | | | | Since data and elem segments cannot be imported or exported, there is no way to access them from the secondary module, so functions that need to refer to them cannot be split out. Fixes #6512.
* Get more tests working with the new text parser (#6284)Thomas Lively2024-02-074-8/+8
| | | | | | | | The new parser enforces the rule that imports must come before declarations (except for type declarations). The old parser does not enforce this rule, so many of our tests did not follow it. Fix them to follow that rule and fix other invalid syntax. Also add missing finalization of Load expressions in wasm-builder.h that was causing a test to fail under the new parser and guard against an error case in wasm-ir-builder.cpp that used to cause a segfault.
* Require `then` and `else` with `if` (#6201)Thomas Lively2024-01-048-15/+27
| | | | | | | | | | | | We previously supported (and primarily used) a non-standard text format for conditionals in which the condition, if-true expression, and if-false expression were all simply s-expression children of the `if` expression. The standard text format, however, requires the use of `then` and `else` forms to introduce the if-true and if-false arms of the conditional. Update the legacy text parser to require the standard format and update all tests to match. Update the printer to print the standard format as well. The .wast and .wat test inputs were mechanically updated with this script: https://gist.github.com/tlively/85ae7f01f92f772241ec994c840ccbb1
* Use the standard shared memory text format (#6200)Thomas Lively2024-01-033-3/+3
| | | | | Update the legacy text parser and all tests to use the standard text format for shared memories, e.g. `(memory $m 1 1 shared)` rather than `(memory $m (shared 1 1))`. Also remove support for non-standard in-line "data" or "segment" declarations. This change makes the tests more compatible with the new text parser, which only supports the standard format.
* Match names more precisely in update_lit_checks.py (#6190)Thomas Lively2024-01-024-35/+38
| | | | | | | | | | Previously the lit test update script interpreted module names as the names of import items and export names as the names of export items, but it is more precise to use the actual identifiers of the imported or exported items as the names instead. Update update_lit_checks.py to use a more correct regex to match names and to correctly use the identifiers of import and export items as their names. In some cases this can improve the readability of test output.
* Fix Alpine CI by removing old node flag (#6054)Thomas Lively2023-10-261-8/+8
| | | | | Apparently the version of node on the Alpine runner was updated and no longer recognizes the --experimental-wasm-threads option. Delete this option out of the test that was using it.
* Remove autogeneration of instrument-memory64.wast (#6021)Thomas Lively2023-10-171-2/+2
| | | | | This test file cannot be auto-generated because its output contains a hash of its input, but the comment enabling that auto updater was accidentally left in during development. Remove the comment.
* [wasm-split] Fix instrumentation to work with memory 64 (#6013)Thomas Lively2023-10-161-0/+49
| | | | Correctly use the output memory's index type when generating the __write_profile function. Requires moving some code around, but is a very small fix.
* Simplify and consolidate type printing (#5816)Thomas Lively2023-08-246-35/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When printing Binaryen IR, we previously generated names for unnamed heap types based on their structure. This was useful for seeing the structure of simple types at a glance without having to separately go look up their definitions, but it also had two problems: 1. The same name could be generated for multiple types. The generated names did not take into account rec group structure or finality, so types that differed only in these properties would have the same name. Also, generated type names were limited in length, so very large types that shared only some structure could also end up with the same names. Using the same name for multiple types produces incorrect and unparsable output. 2. The generated names were not useful beyond the most trivial examples. Even with length limits, names for nontrivial types were extremely long and visually noisy, which made reading disassembled real-world code more challenging. Fix these problems by emitting simple indexed names for unnamed heap types instead. This regresses readability for very simple examples, but the trade off is worth it. This change also reduces the number of type printing systems we have by one. Previously we had the system in Print.cpp, but we had another, more general and extensible system in wasm-type-printing.h and wasm-type.cpp as well. Remove the old type printing system from Print.cpp and replace it with a much smaller use of the new system. This requires significant refactoring of Print.cpp so that PrintExpressionContents object now holds a reference to a parent PrintSExpression object that holds the type name state. This diff is very large because almost every test output changed slightly. To minimize the diff and ease review, change the type printer in wasm-type.cpp to behave the same as the old type printer in Print.cpp except for the differences in name generation. These changes will be reverted in much smaller PRs in the future to generally improve how types are printed.
* Rename multimemory flag (#5890)Ashley Nelson2023-08-211-3/+3
| | | Renaming the multimemory flag in Binaryen to match its naming in LLVM.
* Use Names instead of indices to identify segments (#5618)Thomas Lively2023-04-043-11/+11
| | | | | | | | | | All top-level Module elements are identified and referred to by Name, but for historical reasons element and data segments were referred to by index instead. Fix this inconsistency by using Names to refer to segments from expressions that use them. Also parse and print segment names like we do for other elements. The C API is partially converted to use names instead of indices, but there are still many functions that refer to data segments by index. Finishing the conversion can be done in the future once it becomes necessary.
* Support using JSPI to load the secondary wasm split module. (#5431)Brendan Dahl2023-01-203-174/+181
| | | | | | | | | | When using JSPI with wasm-split, any calls to secondary module functions will now first check a global to see if the module is loaded. If not loaded it will call a JSPI'ed function that will handle loading module. The setup is split into the JSPI pass and wasm-split tool since the JSPI pass is first run by emscripten and we need to JSPI'ify the load secondary module function. wasm-split then injects all the checks and calls to the load function.
* Maintain first memory import/export in Multi-Memory Lowering Pass (#5363)Ashley Nelson2023-01-034-0/+228
| | | This PR maintains the first memory's import/export in the single combined memory after multi-memories are lowered.
* Change the default type system to isorecursive (#5239)Thomas Lively2022-11-232-6/+6
| | | | | | | | | | This makes Binaryen's default type system match the WasmGC spec. Update the way type definitions without supertypes are printed to reduce the output diff for MVP tests that do not involve WasmGC. Also port some type-builder.cpp tests from test/example to test/gtest since they needed to be rewritten to work with isorecursive type anyway. A follow-on PR will remove equirecursive types completely.
* Multi-Memories wasm-split (#4977)Ashley Nelson2022-09-153-7/+129
| | | Adds an --in-secondary-memory switch to the wasm-split tool that allows profile data to be stored in a separate memory from module main memory. With this option, users do not need to reserve the initial memory region for profile data and the data can be shared between multiple threads.
* CI fix after #4837 (#4939)Ashley Nelson2022-08-191-0/+1
| | | | | A memory must be explicitly defined before being exported. Fix CI for 6b3f3af.
* [wasm-split] Test print-profile and unescape flags (#4837)sps-gold2022-08-181-0/+27
| | | Follow up to #4771 to test new --print-profile options for wasm-split.
* Mutli-Memories Support in IR (#4811)Ashley Nelson2022-08-174-0/+4
| | | | | | | This PR removes the single memory restriction in IR, adding support for a single module to reference multiple memories. To support this change, a new memory name field was added to 13 memory instructions in order to identify the memory for the instruction. It is a goal of this PR to maintain backwards compatibility with existing text and binary wasm modules, so memory indexes remain optional for memory instructions. Similarly, the JS API makes assumptions about which memory is intended when only one memory is present in the module. Another goal of this PR is that existing tests behavior be unaffected. That said, tests must now explicitly define a memory before invoking memory instructions or exporting a memory, and memory names are now printed for each memory instruction in the text format. There remain quite a few places where a hardcoded reference to the first memory persist (memory flattening, for example, will return early if more than one memory is present in the module). Many of these call-sites, particularly within passes, will require us to rethink how the optimization works in a multi-memories world. Other call-sites may necessitate more invasive code restructuring to fully convert away from relying on a globally available, single memory pointer.
* Update filecheck to 0.0.22 (#4537)Thomas Lively2022-03-211-1/+1
| | | | | | | | | | | | This update includes a [fix](https://github.com/mull-project/FileCheck.py/pull/188) to how the filecheck Python package matches whitespace to more closely match the behavior of upstream filecheck in LLVM. We have one test affected by this change, so all users who run the test suite will have to update their installed filecheck. This can be done via ``` pip3 install -r requirements-dev.txt ```
* [wasm-split] Add an --asyncify option (#4513)Thomas Lively2022-02-091-0/+174
| | | | | | | Add an option for running the asyncify transformation on the primary module emitted by wasm-split. The idea is that the placeholder functions should be able to unwind the stack while the secondary module is asynchronously loaded, then once the placeholder functions have been patched out by the secondary module the stack should be rewound and end up in the correct secondary function.
* [wasm-split] Disallow mixing --profile, --keep-funcs, and --split-funcs (#4187)Thomas Lively2021-09-243-1/+25
| | | | | | | | | | | | | Previously the set of functions to keep was initially empty, then the profile added new functions to keep, then the --keep-funcs functions were added, then the --split-funcs functions were removed. This method of composing these different options was arbitrary and not necessarily intuitive, and it prevented reasonable workflows from working. For example, providing only a --split-funcs list would result in all functions being split out not matter which functions were listed. To make the behavior of these options, and --split-funcs in particular, more intuitive, disallow mixing them and when --split-funcs is used, split out only the listed functions.
* [wasm-split] Do not add exports of imported memories (#4133)Thomas Lively2021-09-081-0/+12
| | | | | | We can assume that imported memories (and the profiling data they contain) are already accessible from the module's environment, so there's no need to export them. This also avoids needing to add knowledge of "profile-memory" to Emscripten's library_dylink.js.
* wasm-split: Export the memory if it is not already (#4121)Alon Zakai2021-09-071-1/+4
|
* [wasm-split] Add an option for recording profile data in memory (#4120)Thomas Lively2021-09-033-19/+139
| | | | | | | | | | | | | | | | To avoid requiring a static memory allocation, wasm-split's instrumentation defaults to recording profile data in Wasm globals. This causes problems for multithreaded applications because the globals are thread-local, but it is not always feasible to arrange for a separate profile to be dumped on each thread. To simplify the profiling of such multithreaded applications, add a new instrumentation mode that stores the profiling data in shared memory instead of in globals. This allows a single profile to be written that correctly reflects the called functions on all threads. This new mode is not on by default because it requires users to ensure that the program will not trample the in-memory profiling data. The data is stored beginning at address zero and occupies one byte per declared function in the instrumented module. Emscripten can be told to leave this memory free using the GLOBAL_BASE option.
* wasm-split: accept file in keep-funcs/split-funcs (#4053)Aleksander Guryanov2021-08-235-0/+30
|
* Lit tests for tool help messages (#3965)Thomas Lively2021-07-071-92/+0
| | | | | | Add list tests for the help messages of all tools, factoring out common options into shared tests. This is slightly brittle because the text wrapping depends on the length of the longest option, but that brittleness should be worth the benefit of being able to see the actual help text in the tests.
* Add space between options in --help text (#3940)Thomas Lively2021-06-171-0/+20
| | | | | Improve the legibility of the option documentation by adding vertical space between options. This is particularly helpful to delimit the text of options with longer explanations.
* [wasm-split] Add an option to emit a placeholder map (#3931)Thomas Lively2021-06-122-0/+26
| | | | | | The new instruction emits a file containing a map between placeholder index and the name of the split out function that placeholder is replacing in the table. This map is intended to be useful for debugging, as discussed in https://github.com/emscripten-core/emscripten/issues/14330.
* [wasm-split] Add a merge-profiles mode (#3917)Thomas Lively2021-06-023-6/+62
| | | | | | | Given a list of profiles for the same module, --merge-profiles produces a single combined profile the contains the minimum timestamp among the original profiles for each function. When verbose output is enabled, also emit a message for each profile that could individually be removed without affecting the set of functions in the combined profile, as suggested in #3912.
* [wasm-split] Make option validation declarative (#3916)Thomas Lively2021-06-012-13/+81
| | | | | | In anticipation of adding a third wasm-split mode, merge-profiles, in addition to the existing split and instrument modes, refactor wasm-split's option validation to let the valid modes be declared for each option. This approach is more scalable and robust than the ad-hoc validation we had previously.
* [wasm-split] Minimize names of newly created exports (#3905)Thomas Lively2021-06-012-44/+82
| | | | | | | | | wasm-split would previously use internal function names to create the external names of the functions that are newly exported from the primary module to be imported into the secondary module. When the input module contains full function names (as is commonly the case when emitting symbol maps), this caused the function names to be preserved as the export names, even when names are otherwise being stripped. To save on code size and properly anonymize functions, generate minimal export names when debuginfo is disabled instead.
* [wasm-split] Add an option to emit only the module names (#3901)Thomas Lively2021-05-251-0/+24
| | | | | | Even when other names are stripped, it can be useful for wasm-split to preserve the module name so that the split modules can be differentiated in stack traces. Adding this option to wasm-split requires adding similar options to ModuleWriter and WasmBinaryWriter.
* Emit imported functions first in symbol maps (#3900)Thomas Lively2021-05-201-1/+5
| | | | | | | | Imported functions come first when modules are emitted, so to ensure the function indices are correct, they need to come first in the symbol maps. We never noticed this bug before because imported functions are always the first functions when a module is parsed, so the bug never mattered in practice. However, wasm-split adds new imported functions after parsing and these were causing the symbol map indices to be incorrect.
* [wasm-split] Add a --symbolmap option (#3894)Thomas Lively2021-05-192-0/+30
| | | | | The new option emits a symbol map file for each of the split modules. The file names are created by appending ".symbols" to each of the Wasm output file names.
* Fix element segment ordering in Print (#3818)Abbas Mashayekh2021-04-201-2/+2
| | | | | | | | | | | We used to print active element segments right after corresponding tables, and passive segments came after those. We didn't print internal segment names, and empty segments weren't being printed at all. This meant that there was no way for instructions to refer to those table segments after round tripping. This will fix those issues by printing segments in the order they were defined, including segment names when necessary and not omitting empty segments anymore.