diff options
author | Thomas Lively <tlively@google.com> | 2024-07-16 16:30:36 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-16 13:30:36 -0700 |
commit | 53b7dd1f0f129f0304a045ea00ce92334c01fb75 (patch) | |
tree | c23e8f057a7863291d897b30b497a18f39ed6b39 | |
parent | 9de9d05de2f6780ac6d1394528b7e38223edf22b (diff) | |
download | binaryen-53b7dd1f0f129f0304a045ea00ce92334c01fb75.tar.gz binaryen-53b7dd1f0f129f0304a045ea00ce92334c01fb75.tar.bz2 binaryen-53b7dd1f0f129f0304a045ea00ce92334c01fb75.zip |
[threads] Update TypeSSA for shared types (#6753)
When creating a new subtype, make sure to copy the supertype's
shareability.
-rw-r--r-- | src/passes/TypeSSA.cpp | 5 | ||||
-rw-r--r-- | test/lit/passes/type-ssa-shared.wast | 72 |
2 files changed, 76 insertions, 1 deletions
diff --git a/src/passes/TypeSSA.cpp b/src/passes/TypeSSA.cpp index 3736f3ccf..dcd56f5d6 100644 --- a/src/passes/TypeSSA.cpp +++ b/src/passes/TypeSSA.cpp @@ -251,10 +251,13 @@ struct TypeSSA : public Pass { auto oldType = curr->type.getHeapType(); if (oldType.isStruct()) { builder[i] = oldType.getStruct(); - } else { + } else if (oldType.isArray()) { builder[i] = oldType.getArray(); + } else { + WASM_UNREACHABLE("unexpected type kind"); } builder[i].subTypeOf(oldType); + builder[i].setShared(oldType.getShared()); builder[i].setOpen(); } builder.createRecGroup(0, num); diff --git a/test/lit/passes/type-ssa-shared.wast b/test/lit/passes/type-ssa-shared.wast new file mode 100644 index 000000000..d6266f7d9 --- /dev/null +++ b/test/lit/passes/type-ssa-shared.wast @@ -0,0 +1,72 @@ +;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited. + +;; RUN: foreach %s %t wasm-opt --type-ssa -all -S -o - | filecheck %s + +;; TypeSSA should not fail on shared types. +(module + ;; CHECK: (type $struct (sub (shared (struct (field i32))))) + (type $struct (sub (shared (struct (field i32))))) + + ;; CHECK: (type $1 (func)) + + ;; CHECK: (rec + ;; CHECK-NEXT: (type $struct_1 (sub $struct (shared (struct (field i32))))) + + ;; CHECK: (type $struct_2 (sub $struct (shared (struct (field i32))))) + + ;; CHECK: (type $struct_3 (sub $struct (shared (struct (field i32))))) + + ;; CHECK: (type $struct_4 (sub $struct (shared (struct (field i32))))) + + ;; CHECK: (type $struct_5 (sub $struct (shared (struct (field i32))))) + + ;; CHECK: (global $g (ref $struct) (struct.new $struct_4 + ;; CHECK-NEXT: (i32.const 42) + ;; CHECK-NEXT: )) + (global $g (ref $struct) (struct.new $struct + (i32.const 42) + )) + + ;; CHECK: (global $h (ref $struct) (struct.new $struct_5 + ;; CHECK-NEXT: (i32.const 42) + ;; CHECK-NEXT: )) + (global $h (ref $struct) (struct.new $struct + (i32.const 42) + )) + + ;; CHECK: (func $foo (type $1) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (struct.new_default $struct_1) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (struct.new $struct_2 + ;; CHECK-NEXT: (i32.const 10) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $foo + (drop + (struct.new_default $struct) + ) + (drop + (struct.new $struct + (i32.const 10) + ) + ) + ) + + ;; CHECK: (func $another-func (type $1) + ;; CHECK-NEXT: (drop + ;; CHECK-NEXT: (struct.new $struct_3 + ;; CHECK-NEXT: (i32.const 100) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + ;; CHECK-NEXT: ) + (func $another-func + (drop + (struct.new $struct + (i32.const 100) + ) + ) + ) +) |