diff options
author | Alon Zakai <azakai@google.com> | 2023-09-18 16:08:23 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-18 16:08:23 -0700 |
commit | 389fa79e63ff20fa1c6c24dfe26a28b2f487cac8 (patch) | |
tree | ae8f9fd92fbc723bff8652edd819d6573571470a /test | |
parent | 6d2364b55e4c81b0b2f7d15778619c40d1ded4d3 (diff) | |
download | binaryen-389fa79e63ff20fa1c6c24dfe26a28b2f487cac8.tar.gz binaryen-389fa79e63ff20fa1c6c24dfe26a28b2f487cac8.tar.bz2 binaryen-389fa79e63ff20fa1c6c24dfe26a28b2f487cac8.zip |
Add passes to finalize or unfinalize types (#5944)
TypeFinalization finalizes all types that we can, that is, all private types that have no
children. TypeUnFinalization unfinalizes (opens) all (private) types.
These could be used by first opening all types, optimizing, and then finalizing, as that
might find more opportunities.
Fixes #5933
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/help/wasm-opt.test | 5 | ||||
-rw-r--r-- | test/lit/help/wasm2js.test | 5 | ||||
-rw-r--r-- | test/lit/passes/type-finalizing.wast | 96 |
3 files changed, 106 insertions, 0 deletions
diff --git a/test/lit/help/wasm-opt.test b/test/lit/help/wasm-opt.test index 563a885f0..77974d4b2 100644 --- a/test/lit/help/wasm-opt.test +++ b/test/lit/help/wasm-opt.test @@ -478,6 +478,8 @@ ;; CHECK-NEXT: ;; CHECK-NEXT: --tuple-optimization optimize trivial tuples away ;; CHECK-NEXT: +;; CHECK-NEXT: --type-finalizing mark all leaf types as final +;; CHECK-NEXT: ;; CHECK-NEXT: --type-merging merge types to their supertypes ;; CHECK-NEXT: where possible ;; CHECK-NEXT: @@ -487,6 +489,9 @@ ;; CHECK-NEXT: --type-ssa create new nominal types to help ;; CHECK-NEXT: other optimizations ;; CHECK-NEXT: +;; CHECK-NEXT: --type-unfinalizing mark all types as non-final +;; CHECK-NEXT: (open) +;; CHECK-NEXT: ;; CHECK-NEXT: --untee removes local.tees, replacing ;; CHECK-NEXT: them with sets and gets ;; CHECK-NEXT: diff --git a/test/lit/help/wasm2js.test b/test/lit/help/wasm2js.test index 54a593b75..b896730a3 100644 --- a/test/lit/help/wasm2js.test +++ b/test/lit/help/wasm2js.test @@ -437,6 +437,8 @@ ;; CHECK-NEXT: ;; CHECK-NEXT: --tuple-optimization optimize trivial tuples away ;; CHECK-NEXT: +;; CHECK-NEXT: --type-finalizing mark all leaf types as final +;; CHECK-NEXT: ;; CHECK-NEXT: --type-merging merge types to their supertypes ;; CHECK-NEXT: where possible ;; CHECK-NEXT: @@ -446,6 +448,9 @@ ;; CHECK-NEXT: --type-ssa create new nominal types to help ;; CHECK-NEXT: other optimizations ;; CHECK-NEXT: +;; CHECK-NEXT: --type-unfinalizing mark all types as non-final +;; CHECK-NEXT: (open) +;; CHECK-NEXT: ;; CHECK-NEXT: --untee removes local.tees, replacing ;; CHECK-NEXT: them with sets and gets ;; CHECK-NEXT: diff --git a/test/lit/passes/type-finalizing.wast b/test/lit/passes/type-finalizing.wast new file mode 100644 index 000000000..d8265fe04 --- /dev/null +++ b/test/lit/passes/type-finalizing.wast @@ -0,0 +1,96 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. +;; RUN: foreach %s %t wasm-opt -all --type-unfinalizing -S -o - | filecheck %s --check-prefix UNFINAL +;; RUN: foreach %s %t wasm-opt -all --type-finalizing -S -o - | filecheck %s --check-prefix DOFINAL + +;; The public types should never be modified. The private ones should become +;; final or not depending on what we do. +(module + ;; Types. + + ;; UNFINAL: (type $open-public (sub (struct (field i32)))) + ;; DOFINAL: (type $open-public (sub (struct (field i32)))) + (type $open-public (sub (struct (field i32)))) + + ;; UNFINAL: (type $final-public (struct (field i64))) + ;; DOFINAL: (type $final-public (struct (field i64))) + (type $final-public (sub final (struct (field i64)))) + + ;; UNFINAL: (rec + ;; UNFINAL-NEXT: (type $final-private (sub (struct (field f64)))) + ;; DOFINAL: (rec + ;; DOFINAL-NEXT: (type $final-private (struct (field f64))) + (type $final-private (sub final (struct (field f64)))) + + ;; UNFINAL: (type $open-private (sub (struct (field f32)))) + ;; DOFINAL: (type $open-private (struct (field f32))) + (type $open-private (sub (struct (field f32)))) + + ;; Globals. + + ;; UNFINAL: (global $open-public (ref null $open-public) (ref.null none)) + ;; DOFINAL: (global $open-public (ref null $open-public) (ref.null none)) + (global $open-public (ref null $open-public) (ref.null $open-public)) + + ;; UNFINAL: (global $final-public (ref null $final-public) (ref.null none)) + ;; DOFINAL: (global $final-public (ref null $final-public) (ref.null none)) + (global $final-public (ref null $final-public) (ref.null $final-public)) + + ;; UNFINAL: (global $open-private (ref null $open-private) (ref.null none)) + ;; DOFINAL: (global $open-private (ref null $open-private) (ref.null none)) + (global $open-private (ref null $open-private) (ref.null $open-private)) + + ;; UNFINAL: (global $final-private (ref null $final-private) (ref.null none)) + ;; DOFINAL: (global $final-private (ref null $final-private) (ref.null none)) + (global $final-private (ref null $final-private) (ref.null $final-private)) + + ;; Exports. + + ;; UNFINAL: (export "a" (global $open-public)) + ;; DOFINAL: (export "a" (global $open-public)) + (export "a" (global $open-public)) + ;; UNFINAL: (export "b" (global $final-public)) + ;; DOFINAL: (export "b" (global $final-public)) + (export "b" (global $final-public)) +) + +;; Test we do not make a type with a subtype final. $parent should always +;; remain open, while the children can be modified. +(module + (rec + ;; UNFINAL: (rec + ;; UNFINAL-NEXT: (type $parent (sub (struct ))) + ;; DOFINAL: (rec + ;; DOFINAL-NEXT: (type $parent (sub (struct ))) + (type $parent (sub (struct))) + + ;; UNFINAL: (type $child-open (sub $parent (struct ))) + ;; DOFINAL: (type $child-open (sub final $parent (struct ))) + (type $child-open (sub $parent (struct))) + + ;; UNFINAL: (type $child-final (sub $parent (struct ))) + ;; DOFINAL: (type $child-final (sub final $parent (struct ))) + (type $child-final (sub final $parent (struct))) + ) + + ;; UNFINAL: (type $3 (sub (func))) + + ;; UNFINAL: (func $keepalive (type $3) + ;; UNFINAL-NEXT: (local $parent (ref $parent)) + ;; UNFINAL-NEXT: (local $child-final (ref $child-final)) + ;; UNFINAL-NEXT: (local $child-open (ref $child-open)) + ;; UNFINAL-NEXT: (nop) + ;; UNFINAL-NEXT: ) + ;; DOFINAL: (type $3 (func)) + + ;; DOFINAL: (func $keepalive (type $3) + ;; DOFINAL-NEXT: (local $parent (ref $parent)) + ;; DOFINAL-NEXT: (local $child-final (ref $child-final)) + ;; DOFINAL-NEXT: (local $child-open (ref $child-open)) + ;; DOFINAL-NEXT: (nop) + ;; DOFINAL-NEXT: ) + (func $keepalive + (local $parent (ref $parent)) + (local $child-final (ref $child-final)) + (local $child-open (ref $child-open)) + ) +) |