summaryrefslogtreecommitdiff
path: root/test/lit/passes
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2023-09-18 16:08:23 -0700
committerGitHub <noreply@github.com>2023-09-18 16:08:23 -0700
commit389fa79e63ff20fa1c6c24dfe26a28b2f487cac8 (patch)
treeae8f9fd92fbc723bff8652edd819d6573571470a /test/lit/passes
parent6d2364b55e4c81b0b2f7d15778619c40d1ded4d3 (diff)
downloadbinaryen-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/lit/passes')
-rw-r--r--test/lit/passes/type-finalizing.wast96
1 files changed, 96 insertions, 0 deletions
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))
+ )
+)