summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* Update lit tests to parse with the new parser (#6290)Thomas Lively2024-02-081-1/+1
| | | | | | | | | Get as many of the lit tests as possible to parse with the new parser, mostly by moving declared module items to be after imports. Also fix a bug in the new parser's pop validation to allow supertypes of the expected type. The two big issues that still prevent some lit tests from working correctly under the new parser are missing support for symbolic field names and missing support for source map annotations.
* Remove support for legacy stringref text syntax (#6289)Thomas Lively2024-02-081-85/+16
| | | | Removing support for the legacy syntax will allow us to avoid implementing support for it in the new text parser.
* [NFC] Add links to specs in StringLowering (#6292)Alon Zakai2024-02-081-0/+4
|
* Add a pass to propagate global constants to other globals (#6287)Alon Zakai2024-02-083-2/+21
| | | | | | | | | | | | | | | | | SimplifyGlobals already does this, so this is a subset of that pass, and does not add anything new. It is useful for testing, however. In particular it allows testing that we propagate subsequent globals in a single pass, that is if one global reads from another and becomes constant, then it can be propagated as well. SimplifyGlobals runs multiple passes so this always worked, but with this pass we can test that we do it efficiently in one pass. This will also be useful for comparing stringref to imported strings, as it allows gathered strings to be propagated to other globals (possible with stringref, but not imported strings) but not anywhere else (which might have downsides as it could lead to more allocations). Also add an additional test for simplify-globals that we do not get confused by an unoptimizable global.get in the middle (see last part).
* StringLowering: Lower all remaining important string operations (#6283)Alon Zakai2024-02-081-0/+84
| | | All those in the list from #6271 (comment)
* [Parser] Do not involve IRBuilder for imported functions (#6286)Thomas Lively2024-02-074-13/+14
| | | | | | | | | | We previously had a bug where we would begin and end an IRBuilder context for imported functions even though they don't have bodies. For functions that return results, ending this empty scope should have produced an error except that we had another bug where we only produced that error for multivalue functions. We did not previously have imported multivalue functions in wat-kitchen-sink.wast, so both of these bugs went undetected. Fix both bugs and update the test to include an imported multivalue function so that it would have failed without this fix.
* SimplifyGlobals: Propagate constant globals into nested gets in other ↵Alon Zakai2024-02-071-2/+4
| | | | | globals (#6285) Before we propagated to the top level, but not to anything interior.
* Get more tests working with the new text parser (#6284)Thomas Lively2024-02-072-0/+4
| | | | | | | | 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.
* [NFC] Move code to string.cpp (#6282)Thomas Lively2024-02-062-84/+92
| | | | Now that we have a .cpp file, none of the code that was in string.h needs to be in a header any more.
* StringLowering: Start to lower instructions (#6281)Alon Zakai2024-02-061-0/+82
|
* Properly stringify names in tests (#6279)Thomas Lively2024-02-067-130/+199
| | | | | | | | | | | | | Update identifiers used in tests to use a format supported by the new text parser, i.e. either the standard format with its limited set of allowed characters or the non-standard `$"..."` format. Notably, any name containing square or curly braces now uses the string format. Input automatically updated with this script: https://gist.github.com/tlively/4e22311736661849e641d02e521a0748 The printer is updated to properly escape names in more places as well. The logic for escaping names is moved to a common location so that the type printing logic in wasm-type.cpp can use it as well.
* [Parser] Support string-style identifiers (#6278)Thomas Lively2024-02-062-29/+68
| | | | | | | | | | In addition to normal identifiers, support parsing identifiers of the format `$"..."`. This format is not yet allowed by the standard, but it is a popular proposed extension (see https://github.com/WebAssembly/spec/issues/617 and https://github.com/WebAssembly/annotations/issues/21). Binaryen has historically allowed a similar format and has supported arbitrary non-standard identifier characters, so it's much easier to support this extended syntax than to fix everything to use the restricted standard syntax.
* Make `array.new_fixed` length annotations mandatory (#6277)Thomas Lively2024-02-061-11/+5
| | | | | They were previously optional to ease the transition to the standard text format, but now we can make them mandatory to match the spec. This will simplify the new text parser as well.
* [EH] Add --experimental-new-eh option to wasm-opt (#6270)Heejin Ahn2024-02-061-2/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds `--experimental-new-eh` option to `wasm-opt`. The difference between this and `--translate-to-new-eh` is, `--translate-to-new-eh` just runs `TranslateToNewEH` pass, while `--experimental-new-eh` attaches `TranslateToNewEH` pass at the end of the whole optimization pipeline. So if no other passes or optimization options (`-On`) are specified, it is equivalent to `--translate-to-new-eh`. If other optimization passes are specified, it runs them and at the end run the translator to ensure the new EH instructions are emitted. The reason we are doing this this way is that the optimization pipeline as a whole does not support the new EH instruction yet, but we would like to provide an option to emit a reasonably OK code with the new EH instructions. This also means when the optimization level > 3, it will also run the StackIR + local2stack optimization after the translation. Not sure how to test the output of this option, given that there is not much point in testing the default optimization passes, and it is also not clear how to print the stack IR if the stack ir generation and optimization runs as a part of the pipeline and not the explicit command line options. This is created in favor of #6267, which added the option to `optimization-options.h`. It had a problem of running the translator multiple times when `-On` was given multiple times in the command line, which I learned was rather a common usage. This adds the option directly to `wasm-opt.cpp`, which avoids the problem. With this, it is still possible to create and optimize Stack IR unnecessarily, but that feels a better alternative.
* StringLowering pass (#6271)Alon Zakai2024-02-053-4/+64
| | | | | | | | | | | | | | | | | | This extends StringGathering by replacing the gathered string globals to imported globals. It adds a custom section with the strings that the imports are expected to provide. It also replaces the string type with extern. This is a complete lowering of strings, except for string operations that are a TODO. After running this, no strings remain in the wasm, and the outside JS is expected to provide the proper imports, which it can do by processing the JSON of the strings in the custom section "string.consts", which looks like ["foo", "bar", ..] That is, an array of strings, which are imported as (import "string.const" "0" (global $string.const_foo (ref extern))) ;; foo (import "string.const" "1" (global $string.const_bar (ref extern))) ;; bar
* wasm-ctor-eval: Properly eval strings (#6276)Alon Zakai2024-02-051-8/+3
| | | | | | | #6244 tried to do this but was not quite right. It treated a string like an array or a struct, which means create a global for it. But just creating a global isn't enough, as it needs to also be sorted in the right place etc. which requires changes in other places. But there is a much simpler solution here: string constants are just constants, which we can emit in-line, so do that.
* [Parser] Parse v128.const (#6275)Thomas Lively2024-02-055-1/+142
|
* [Parser] Templatize lexing of integers (#6272)Thomas Lively2024-02-054-108/+50
| | | | | | Have a single implementation for lexing each of unsigned, signed, and uninterpreted integers, each generic over the bit width of the integer. This reduces duplication in the existing code and it will make it much easier to support lexing more 8- and 16-bit integers.
* MemoryPacking: Handle non-empty trapping segments (#6261)Alon Zakai2024-02-011-9/+68
| | | Followup to #6243 which handled empty ones.
* JSON: Add simple printing and creation (#6265)Alon Zakai2024-02-013-0/+46
|
* C API: Use segment names (#6254)ericvergnaud2024-02-013-64/+74
| | | | | | | | | Move from segment indexes to names. This is a breaking change to make the API more capable and consistent. An effort has been made to reduce the burden on C API users where possible (specifically, you can avoid providing names and let Binaryen make them for you, which will basically be numbers that match the indexes from before). Fixes #6247
* Allow updating basic HeapTypes in GlobalTypeRewriter::mapTypes (#6266)Alon Zakai2024-02-011-3/+0
|
* GUFA: Propagate string literals (#6262)Alon Zakai2024-02-011-1/+2
| | | We only noted the type but not the literal value.
* Revert "Stop propagating/inlining string constants (#6234)" (#6258)Alon Zakai2024-01-312-22/+6
| | | | | | | | | | This reverts commit 9090ce56fcc67e15005aeedc59c6bc6773220f11. This has the effect of once more propagating string constants from globals to other places (and from non-globals too), which is useful for various optimizations even if it isn't useful in the final output. To fix the final output problem, #6257 added a pass that is run at the end to collect string.const to globals, which allows us to once more propagate strings in the optimizer, now without a downside.
* StringGathering pass (#6257)Alon Zakai2024-01-315-1/+190
| | | | | | | | | | | | | | | This pass finds all string.const and creates globals for them. After this transform, no string.const appears anywhere but in a global, and each string appears in one global which is then global.get-ed everywhere. This avoids overhead in VMs where executing a string.const is an allocation, and is also a good step towards imported strings. For that, this pass will be extended from gathering to a full lowering pass, which will first gather into globals as this pass does, and then turn each of those globals with a string.const into an imported externref. (For that reason this pass is in a file called StringLowering, as the two passes will share much of their code, and the larger pass should decide the name I think.) This pass runs in -O2 and above. Repeated executions have no downside (see details in code).
* [PostEmscripten] Fix calcSegmentOffsets for large offsets (#6260)Sam Clegg2024-01-311-4/+3
| | | | Specifically offsets larger than 2^32 which were being interpreted misinterpreted here as very large int64_t values.
* [EH] Change translator option name (#6259)Heejin Ahn2024-01-303-24/+7
| | | | | | The previous name feels too verbose and unwieldy. This also removes the "new-to-old EH" placeholder. I think it'd be better to add it back when it is actually added.
* [Parser] Parse start declarations (#6256)Thomas Lively2024-01-303-0/+37
|
* Directize: Handle overflows and out of bounds (#6255)Alon Zakai2024-01-301-1/+8
|
* [Parser] Parse pops (by doing nothing) (#6252)Thomas Lively2024-01-304-3/+33
| | | | | | | | | | | | | Parse pop expressions and check that they have the expected types, but do not actually create new Pop expressions or push anything onto the stack because we already create Pop expressions as necessary when visiting the beginning of catch blocks. Unlike the legacy text parser, the new text parser is not capable of parsing pops in invalid locations in the IR. This means that the new text parser will never be able to parse test/lit/catch-pop-fixup-eh-old.wast, which deliberately parses invalid IR to check that the pops can be fixed up and moved to the correct locations. It should be acceptable to delete that test when we turn on the new parser by default, though, so that won't be a problem.
* Update pop text syntax (#6251)Thomas Lively2024-01-292-9/+5
| | | | | | Rather than `(pop valtype*)`, use `(pop valtype)`, where `valtype` is now allowed to be a tuple. This will make it possible to parse un-folded multivalue pops in the new text parser. The alternative would have been to put an arity in the syntax like we have for other tuple instructions, but that's much uglier.
* [Parser] Parse local.set and global.set of tuple values correctly (#6250)Thomas Lively2024-01-292-0/+20
| | | | These instructions always pop a single value, except when tuples are involved, in which case they need special handling to know how many values to pop.
* [Parser] Parse tuple types (#6249)Thomas Lively2024-01-292-5/+45
| | | | | Use the new `(tuple ...)` syntax. Enforce that tuples have a valid number of elements and are not nested to avoid assertion failures when parsing invalid input.
* Update the text syntax for tuple types (#6246)Thomas Lively2024-01-264-9/+12
| | | | Instead of e.g. `(i32 i32)`, use `(tuple i32 i32)`. Having a keyword to introduce the s-expression is more consistent with the rest of the language.
* [EH] Support CFGWalker for new EH spec (#6235)Heejin Ahn2024-01-251-29/+71
| | | | | | | | This adds support `CFGWalker` for the new EH instructions (`try_table` and `throw_ref`). `CFGWalker` is used by many different passes, but in the same vein as #3494, this adds tests for `RedundantSetElimination` pass. `rse-eh.wast` file is created from translated and simplified version of `rse-eh-old.wast`, but many tests were removed because we don't have special `catch` block or `delegate` anymore.
* MemoryPacking: Ignore empty segments (#6243)Alon Zakai2024-01-251-0/+7
| | | | | | They might trap. Leave that for RemoveUnusedModuleElements. Fixes #6230
* RemoveUnusedModuleElements: Do not remove unused-but-trapping segments (#6242)Alon Zakai2024-01-251-6/+47
| | | | | | | | | | | | | | An out of bounds active segment traps during startup, which is an effect we must preserve. To avoid a regression here, ignore this in TNH mode (where the user assures us nothing will trap), and also check if a segment will trivially be in bounds and not trap (if so, it can be removed). Fixes the remove-unused-module-elements part of #6230 The small change to an existing testcase made a segment there be in bounds, to avoid this affecting it. Tests for this are in a new file.
* C API: Add BinaryenArrayNewData (#6236)ericvergnaud2024-01-252-2/+17
|
* [Parser] Parse throw_ref (#6238)Thomas Lively2024-01-255-3/+14
|
* wasm-ctor-eval: Eval strings (#6244)Alon Zakai2024-01-251-0/+6
|
* [Parser] Parse try_table (#6237)Thomas Lively2024-01-254-6/+190
|
* Memory flattening: Check for overflow (#6233)Alon Zakai2024-01-242-1/+49
| | | | | Fixes a fuzz testcase for wasm-ctor-eval. Add the beginnings of a polyfill for stdckdint.h to help that.
* [EH] Add translator from old to new EH instructions (#6210)Heejin Ahn2024-01-234-0/+826
| | | | | | | | | | | | | | | | | | | | This translates the old Phase 3 EH instructions, which include `try`, `catch`, `catch_all`, `delegate`, and `rethrow`, into the new EH instructions, which include `try_table` (with `catch` / `catch_ref` / `catch_all` / `catch_all_ref`) and `throw_ref`, passed at the Oct 2023 CG meeting. This translator can be used as a standalone tool by users of the previous EH toolchain to generate binaries for the new spec without recompiling, and also can be used at the end of the Binaryen pipeline to produce binaries for the new spec while the end-to-end toolchain implementation for the new spec is in progress. While the goal of this pass is not optimization, this tries to a little better than the most naive implementation, namely by omitting a few instructions where possible and trying to minimize the number of additional locals, because this can be used as a standalone translator or the last stage of the pipeline while we can't post-optimize the results because the whole pipeline (-On) is not ready for the new EH.
* Stop propagating/inlining string constants (#6234)Alon Zakai2024-01-232-6/+22
| | | | | This causes overhead atm since in VMs executing a string.const will actually allocate a string, and more copies means more allocations. For now, just do not add more. This required changes to two passes: SimplifyGlobals and Precompute.
* Rename stack variables in CFGWalker (NFC) (#6232)Heejin Ahn2024-01-221-26/+28
| | | | | | | This renames `***Stack` variables in `CFGWalker` to be consistent, as a preparation for adding another stack for the new EH. Currently `ifStack` and `loopStack` contains `BasicBlock*`s but `tryStack` contains `Expression*`, and `Try` expressions are rather contained in `unwindExprStack`, which to me is confusing.
* [EH] Support Stack IR for try_table (#6231)Heejin Ahn2024-01-224-27/+41
|
* Remove incorrect validation of segment sizes (#6228)Alon Zakai2024-01-221-9/+0
| | | | This should be a runtime error, not a validator error. It caused a fuzzer failure on wasm-ctor-eval.
* SimplifyGlobals: Apply constant globals to segment offsets (#6226)Alon Zakai2024-01-181-8/+32
| | | | | | | We already applied such globals to other globals, but can do the same to offsets of data and element segments. Suggested in #6220
* C API: Add BinaryenFunctionAppendVar (#6213)KinderGartenKiller2024-01-172-0/+8
|
* Make blockifyWithName correctly use name and type (#6223)Heejin Ahn2024-01-161-2/+5
| | | | | | | | - This passes `name` to `makeBlock` call, because `makeBlock` uses `BranchSeeker` when finalizing only when the block has a `name`. - This also refinalizes the block when an optional `type` is given. This was spun off from #6210, but I'm not sure how to add a standalone test for this.