diff options
author | Thomas Lively <tlively@google.com> | 2024-02-29 10:37:41 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-29 10:37:41 -0800 |
commit | 7cd00ad485d9bcb68a4a36d4b1291439349e4f5c (patch) | |
tree | f48a4edf82f1d70a3b014f2e5a3c7f35d399e15e | |
parent | a9418461ef5188d2b2dea32b3047cc7bb3b173b3 (diff) | |
download | binaryen-7cd00ad485d9bcb68a4a36d4b1291439349e4f5c.tar.gz binaryen-7cd00ad485d9bcb68a4a36d4b1291439349e4f5c.tar.bz2 binaryen-7cd00ad485d9bcb68a4a36d4b1291439349e4f5c.zip |
[Parser] Do not require a memory for GC string ops (#6363)
We previously required a memory to exist while parsing all `StringNew` and
`StringEncode` instructions, even though some variants of the instructions use
GC arrays instead. Require a memory only for those instructions that use one.
-rw-r--r-- | src/parser/contexts.h | 36 | ||||
-rw-r--r-- | src/parser/parsers.h | 30 | ||||
-rw-r--r-- | test/lit/passes/string-lowering-instructions.wast | 1 |
3 files changed, 55 insertions, 12 deletions
diff --git a/src/parser/contexts.h b/src/parser/contexts.h index 6505d11a4..4c15c0308 100644 --- a/src/parser/contexts.h +++ b/src/parser/contexts.h @@ -2448,9 +2448,21 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> { StringNewOp op, bool try_, Name* mem) { - auto m = getMemory(pos, mem); - CHECK_ERR(m); - return withLoc(pos, irBuilder.makeStringNew(op, try_, *m)); + Name memName; + switch (op) { + case StringNewUTF8: + case StringNewWTF8: + case StringNewLossyUTF8: + case StringNewWTF16: { + auto m = getMemory(pos, mem); + CHECK_ERR(m); + memName = *m; + break; + } + default: + break; + } + return withLoc(pos, irBuilder.makeStringNew(op, try_, memName)); } Result<> makeStringConst(Index pos, @@ -2469,9 +2481,21 @@ struct ParseDefsCtx : TypeParserCtx<ParseDefsCtx> { const std::vector<Annotation>& annotations, StringEncodeOp op, Name* mem) { - auto m = getMemory(pos, mem); - CHECK_ERR(m); - return withLoc(pos, irBuilder.makeStringEncode(op, *m)); + Name memName; + switch (op) { + case StringEncodeUTF8: + case StringEncodeLossyUTF8: + case StringEncodeWTF8: + case StringEncodeWTF16: { + auto m = getMemory(pos, mem); + CHECK_ERR(m); + memName = *m; + break; + } + default: + break; + } + return withLoc(pos, irBuilder.makeStringEncode(op, memName)); } Result<> makeStringConcat(Index pos, diff --git a/src/parser/parsers.h b/src/parser/parsers.h index 987f0f5aa..4c210624f 100644 --- a/src/parser/parsers.h +++ b/src/parser/parsers.h @@ -2330,9 +2330,18 @@ Result<> makeStringNew(Ctx& ctx, const std::vector<Annotation>& annotations, StringNewOp op, bool try_) { - auto mem = maybeMemidx(ctx); - CHECK_ERR(mem); - return ctx.makeStringNew(pos, annotations, op, try_, mem.getPtr()); + switch (op) { + case StringNewUTF8: + case StringNewWTF8: + case StringNewLossyUTF8: + case StringNewWTF16: { + auto mem = maybeMemidx(ctx); + CHECK_ERR(mem); + return ctx.makeStringNew(pos, annotations, op, try_, mem.getPtr()); + } + default: + return ctx.makeStringNew(pos, annotations, op, try_, nullptr); + } } template<typename Ctx> @@ -2359,9 +2368,18 @@ Result<> makeStringEncode(Ctx& ctx, Index pos, const std::vector<Annotation>& annotations, StringEncodeOp op) { - auto mem = maybeMemidx(ctx); - CHECK_ERR(mem); - return ctx.makeStringEncode(pos, annotations, op, mem.getPtr()); + switch (op) { + case StringEncodeUTF8: + case StringEncodeLossyUTF8: + case StringEncodeWTF8: + case StringEncodeWTF16: { + auto mem = maybeMemidx(ctx); + CHECK_ERR(mem); + return ctx.makeStringEncode(pos, annotations, op, mem.getPtr()); + } + default: + return ctx.makeStringEncode(pos, annotations, op, nullptr); + } } template<typename Ctx> diff --git a/test/lit/passes/string-lowering-instructions.wast b/test/lit/passes/string-lowering-instructions.wast index d1b8172e2..97186fba7 100644 --- a/test/lit/passes/string-lowering-instructions.wast +++ b/test/lit/passes/string-lowering-instructions.wast @@ -1,6 +1,7 @@ ;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. ;; RUN: foreach %s %t wasm-opt --string-lowering -all -S -o - | filecheck %s +;; RUN: foreach %s %t wasm-opt --new-wat-parser --string-lowering -all -S -o - | filecheck %s (module (rec |