Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/passes/GlobalTypeOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,9 @@ struct GlobalTypeOptimization : public Pass {
// Until we've created all the placeholders, create a placeholder
// describee type for the next descriptor that needs one.
if (placeholderIt != parent.descriptorsOfPlaceholders.end()) {
typeBuilder[i].descriptor(getTempHeapType(placeholderIt->first));
auto descriptor = placeholderIt->first;
typeBuilder[i].descriptor(getTempHeapType(descriptor));
typeBuilder[i].setShared(descriptor.getShared());
++placeholderIt;
return;
}
Expand Down
62 changes: 62 additions & 0 deletions test/lit/passes/gto-desc.wast
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,68 @@
)
)

;; Now we can optimize $A with a placeholder, but the placeholder must be
;; shared.
(module
(rec
;; CHECK: (rec
;; CHECK-NEXT: (type $0 (shared (descriptor $A.desc (struct))))

;; CHECK: (type $A (sub (shared (struct))))
(type $A (sub (shared (descriptor $A.desc (struct)))))
;; CHECK: (type $A.desc (sub (shared (describes $0 (struct)))))
(type $A.desc (sub (shared (describes $A (struct)))))

;; CHECK: (type $B (sub $A (shared (descriptor $B.desc (struct)))))
(type $B (sub $A (shared (descriptor $B.desc (struct)))))
;; CHECK: (type $B.desc (sub $A.desc (shared (describes $B (struct)))))
(type $B.desc (sub $A.desc (shared (describes $B (struct)))))
)

;; CHECK: (type $5 (func))

;; CHECK: (func $test (type $5)
;; CHECK-NEXT: (local $A (ref $A))
;; CHECK-NEXT: (local $A.desc (ref $A.desc))
;; CHECK-NEXT: (local $B (ref $B))
;; CHECK-NEXT: (local $B.desc (ref $B.desc))
;; CHECK-NEXT: (local.set $A
;; CHECK-NEXT: (struct.new_default $A)
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.set $B
;; CHECK-NEXT: (struct.new_default $B
;; CHECK-NEXT: (struct.new_default $B.desc)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (ref.get_desc $B
;; CHECK-NEXT: (local.get $B)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $test
(local $A (ref $A))
(local $A.desc (ref $A.desc))
(local $B (ref $B))
(local $B.desc (ref $B.desc))
(local.set $A
(struct.new $A
(struct.new $A.desc)
)
)
(local.set $B
(struct.new $B
(struct.new $B.desc)
)
)
(drop
(ref.get_desc $B
(local.get $B)
)
)
)
)

;; Sibling types $A and $B. The supertype that connects them should not stop us
;; from optimizing $B here, even though $A cannot be optimized.
(module
Expand Down
Loading