diff options
author | Thomas Lively <tlively@google.com> | 2023-10-18 20:37:48 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-18 18:37:48 +0000 |
commit | f50e933f639c24f3a5814980fb20e6f7e1435184 (patch) | |
tree | c118bfbfbb54a5c0e1879af650131503ad59bd97 /test/lit/passes | |
parent | 89c02aad305474aea1d413e110aadd68278a13d6 (diff) | |
download | binaryen-f50e933f639c24f3a5814980fb20e6f7e1435184.tar.gz binaryen-f50e933f639c24f3a5814980fb20e6f7e1435184.tar.bz2 binaryen-f50e933f639c24f3a5814980fb20e6f7e1435184.zip |
Reuse existing function types for blocks (#6022)
Type annotations on multivalue blocks (and loops, ifs, and trys) are type
indices that refer to function types in the type section. For these type
annotations, the identities of the function types does not matter. As long as
the referenced type has the correct parameters and results, it will be valid to
use.
Previously, when collecting module types, we always used the "default" function
type for multivalue control flow, i.e. we used a final function type with no
supertypes in a singleton rec group. However, in cases where the program already
contains another function type with the expected signature, using the default
type is unnecessary and bloats the type section.
Update the type collecting code to reuse existing function types for multivalue
control flow where possible rather than unconditionally adding the default
function type. Similarly, update the binary writer to use the first heap type
with the required signature when emitting annotations on multivalue control flow
structures. To make this all testable, update the printer to print the type
annotations as well, rather than just the result types. Since the parser was not
able to parse those newly emitted type annotations, update the parser as well.
Diffstat (limited to 'test/lit/passes')
-rw-r--r-- | test/lit/passes/coalesce-locals-gc.wast | 10 | ||||
-rw-r--r-- | test/lit/passes/optimize-instructions-multivalue.wast | 2 | ||||
-rw-r--r-- | test/lit/passes/poppify.wast | 2 | ||||
-rw-r--r-- | test/lit/passes/remove-unused-brs.wast | 6 | ||||
-rw-r--r-- | test/lit/passes/roundtrip.wast | 2 | ||||
-rw-r--r-- | test/lit/passes/tuple-optimization.wast | 2 | ||||
-rw-r--r-- | test/lit/passes/type-merging.wast | 6 |
7 files changed, 13 insertions, 17 deletions
diff --git a/test/lit/passes/coalesce-locals-gc.wast b/test/lit/passes/coalesce-locals-gc.wast index 3706dc61f..5122fc23b 100644 --- a/test/lit/passes/coalesce-locals-gc.wast +++ b/test/lit/passes/coalesce-locals-gc.wast @@ -79,7 +79,7 @@ ) ) - ;; CHECK: (func $nn-dead (type $2) + ;; CHECK: (func $nn-dead (type $3) ;; CHECK-NEXT: (local $0 funcref) ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (ref.func $nn-dead) @@ -118,7 +118,7 @@ ) ) - ;; CHECK: (func $nn-dead-nameless (type $2) + ;; CHECK: (func $nn-dead-nameless (type $3) ;; CHECK-NEXT: (local $0 (ref func)) ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (ref.func $nn-dead) @@ -149,7 +149,7 @@ ) ) - ;; CHECK: (func $unreachable-get-null (type $2) + ;; CHECK: (func $unreachable-get-null (type $3) ;; CHECK-NEXT: (local $0 anyref) ;; CHECK-NEXT: (local $1 i31ref) ;; CHECK-NEXT: (unreachable) @@ -307,9 +307,9 @@ ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) ;; CHECK-NEXT: (global.set $nn-tuple-global - ;; CHECK-NEXT: (block (result (ref any) i32) + ;; CHECK-NEXT: (block (type $1) (result (ref any) i32) ;; CHECK-NEXT: (local.set $1 - ;; CHECK-NEXT: (if (result (ref any) i32) + ;; CHECK-NEXT: (if (type $1) (result (ref any) i32) ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: (tuple.make ;; CHECK-NEXT: (ref.as_non_null diff --git a/test/lit/passes/optimize-instructions-multivalue.wast b/test/lit/passes/optimize-instructions-multivalue.wast index 0e7938417..1e456f20f 100644 --- a/test/lit/passes/optimize-instructions-multivalue.wast +++ b/test/lit/passes/optimize-instructions-multivalue.wast @@ -6,7 +6,7 @@ ;; CHECK-NEXT: (local $tuple (i32 i32)) ;; CHECK-NEXT: (local $tuple2 (i32 i32)) ;; CHECK-NEXT: (tuple.extract 0 - ;; CHECK-NEXT: (if (result i32 i32) + ;; CHECK-NEXT: (if (type $2) (result i32 i32) ;; CHECK-NEXT: (local.get $x) ;; CHECK-NEXT: (local.get $tuple) ;; CHECK-NEXT: (local.get $tuple2) diff --git a/test/lit/passes/poppify.wast b/test/lit/passes/poppify.wast index 9432cbd28..4aa44a3d5 100644 --- a/test/lit/passes/poppify.wast +++ b/test/lit/passes/poppify.wast @@ -466,7 +466,7 @@ ) ;; CHECK: (func $break-tuple (type $1) (result i32 i64) - ;; CHECK-NEXT: (block $l (result i32 i64) + ;; CHECK-NEXT: (block $l (type $1) (result i32 i64) ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: (i64.const 1) ;; CHECK-NEXT: (br $l diff --git a/test/lit/passes/remove-unused-brs.wast b/test/lit/passes/remove-unused-brs.wast index 93cf4cbd2..8392dfe86 100644 --- a/test/lit/passes/remove-unused-brs.wast +++ b/test/lit/passes/remove-unused-brs.wast @@ -5,7 +5,7 @@ (module ;; Regression test in which we need to calculate a proper LUB. - ;; CHECK: (func $selectify-fresh-lub (type $2) (param $x i32) (result anyref) + ;; CHECK: (func $selectify-fresh-lub (type $3) (param $x i32) (result anyref) ;; CHECK-NEXT: (select (result i31ref) ;; CHECK-NEXT: (ref.null none) ;; CHECK-NEXT: (ref.i31 @@ -211,7 +211,7 @@ ) ) - ;; CHECK: (func $get-i32 (type $3) (result i32) + ;; CHECK: (func $get-i32 (type $4) (result i32) ;; CHECK-NEXT: (i32.const 400) ;; CHECK-NEXT: ) (func $get-i32 (result i32) @@ -327,7 +327,7 @@ ;; CHECK: (func $restructure-select-no-multivalue (type $1) ;; CHECK-NEXT: (drop - ;; CHECK-NEXT: (block $block (result i32 i32) + ;; CHECK-NEXT: (block $block (type $2) (result i32 i32) ;; CHECK-NEXT: (drop ;; CHECK-NEXT: (br_if $block ;; CHECK-NEXT: (tuple.make diff --git a/test/lit/passes/roundtrip.wast b/test/lit/passes/roundtrip.wast index f41761c2e..2f3fd4009 100644 --- a/test/lit/passes/roundtrip.wast +++ b/test/lit/passes/roundtrip.wast @@ -8,7 +8,7 @@ ;; CHECK-NEXT: (local $0 (funcref (ref $none))) ;; CHECK-NEXT: (local $1 funcref) ;; CHECK-NEXT: (local.set $0 - ;; CHECK-NEXT: (block $label$1 (result funcref (ref $none)) + ;; CHECK-NEXT: (block $label$1 (type $1) (result funcref (ref $none)) ;; CHECK-NEXT: (tuple.make ;; CHECK-NEXT: (ref.null nofunc) ;; CHECK-NEXT: (ref.func $foo) diff --git a/test/lit/passes/tuple-optimization.wast b/test/lit/passes/tuple-optimization.wast index 766f51e81..6884f95c5 100644 --- a/test/lit/passes/tuple-optimization.wast +++ b/test/lit/passes/tuple-optimization.wast @@ -546,7 +546,7 @@ ;; CHECK: (func $set-of-block (type $0) ;; CHECK-NEXT: (local $tuple (i32 i32)) ;; CHECK-NEXT: (local.set $tuple - ;; CHECK-NEXT: (block (result i32 i32) + ;; CHECK-NEXT: (block (type $1) (result i32 i32) ;; CHECK-NEXT: (tuple.make ;; CHECK-NEXT: (i32.const 1) ;; CHECK-NEXT: (i32.const 2) diff --git a/test/lit/passes/type-merging.wast b/test/lit/passes/type-merging.wast index 7c44fe8e2..34f156a2b 100644 --- a/test/lit/passes/type-merging.wast +++ b/test/lit/passes/type-merging.wast @@ -929,8 +929,6 @@ ;; CHECK: (rec ;; CHECK-NEXT: (type $B (sub (func))) - ;; CHECK: (type $1 (func (result (ref any) (ref $B)))) - ;; CHECK: (type $A (sub (func (result (ref any) (ref $B))))) (type $A (sub (func (result (ref any) (ref $C))))) (type $B (sub (func))) @@ -939,10 +937,8 @@ (type $D (sub final $A (func (result (ref any) (ref $C))))) ) - ;; CHECK: (type $4 (func (result (ref any) (ref $B)))) - ;; CHECK: (func $test (type $D) (result (ref any) (ref $B)) - ;; CHECK-NEXT: (block $l (result (ref any) (ref $B)) + ;; CHECK-NEXT: (block $l (type $A) (result (ref any) (ref $B)) ;; CHECK-NEXT: (unreachable) ;; CHECK-NEXT: ) ;; CHECK-NEXT: ) |