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
13 changes: 13 additions & 0 deletions src/ir/struct-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,19 @@ struct StructScanner : public WalkerPass<PostWalker<SubType>> {
functionSetGetInfos[this->getFunction()][ht][index]);
}

void visitStructWait(StructWait* curr) {
auto type = curr->ref->type;
if (type == Type::unreachable || type.isNull()) {
return;
}

auto ht = std::make_pair(type.getHeapType(), type.getExactness());
auto index = curr->index;
self().noteRead(type.getHeapType(),
index,
functionSetGetInfos[this->getFunction()][ht][index]);
}

void visitStructRMW(StructRMW* curr) {
auto type = curr->ref->type;
if (type == Type::unreachable || type.isNull()) {
Expand Down
12 changes: 11 additions & 1 deletion src/passes/GlobalTypeOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,17 @@ struct GlobalTypeOptimization : public Pass {
curr->index = newIndex;
}

// TODO: visitStructWait
void visitStructWait(StructWait* curr) {
if (curr->ref->type == Type::unreachable) {
return;
}

auto newIndex =
parent.getNewIndex(curr->ref->type.getHeapType(), curr->index);
// We must not remove a field that is read from.
assert(newIndex != RemovedField);
curr->index = newIndex;
}
};

PassRunner runner(getPassRunner());
Expand Down
13 changes: 12 additions & 1 deletion src/passes/TypeRefining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,18 @@ struct TypeRefining : public Pass {
curr->replacement = fixType(curr->replacement, fieldType);
}

// TODO: visitStructWait
void visitStructWait(StructWait* curr) {
if (curr->ref->type == Type::unreachable) {
return;
}
auto type = curr->ref->type.getHeapType();
if (type.isBottom()) {
return;
}

auto fieldType = type.getStruct().fields[curr->index].type;
curr->expected = fixType(curr->expected, fieldType);
}

bool refinalize = false;

Expand Down
20 changes: 18 additions & 2 deletions test/lit/passes/gto-removals.wast
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
;; A read *does* keep a field from being removed.

;; CHECK: (rec
;; CHECK-NEXT: (type $struct (sub (struct (field funcref))))
(type $struct (sub (struct (field (mut funcref)))))
;; CHECK-NEXT: (type $struct (sub (struct (field funcref) (field i32))))
(type $struct (sub (struct (field (mut funcref)) (field (mut i32)))))

;; CHECK: (type $1 (func (param (ref $struct))))

Expand All @@ -110,13 +110,29 @@
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (struct.wait $struct 1
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: (waitqueue.new)
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: (i64.const -1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $func (param $x (ref $struct))
(drop
(struct.get $struct 0
(local.get $x)
)
)
(drop
(struct.wait $struct 1
(local.get $x)
(waitqueue.new)
(i32.const 1)
(i64.const -1)
)
)
)
)

Expand Down
40 changes: 35 additions & 5 deletions test/lit/passes/type-refining-gufa-rmw.wast
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,10 @@
)

(module
;; NRML: (type $struct (sub (struct (field (mut (ref null $struct))))))
;; NRML: (type $struct (sub (shared (struct (field (mut (ref null $struct)))))))
;; GUFA: (rec
;; GUFA-NEXT: (type $struct (sub (struct (field (mut nullref)))))
(type $struct (sub (struct (field (mut (ref null $struct))))))
;; GUFA-NEXT: (type $struct (sub (shared (struct (field (mut (ref null (shared none))))))))
(type $struct (sub (shared (struct (field (mut (ref null $struct)))))))

;; NRML: (type $1 (func (param (ref null $struct))))

Expand All @@ -435,6 +435,14 @@
;; NRML-NEXT: (local.get $struct)
;; NRML-NEXT: )
;; NRML-NEXT: )
;; NRML-NEXT: (drop
;; NRML-NEXT: (struct.wait $struct 0
;; NRML-NEXT: (local.get $struct)
;; NRML-NEXT: (unreachable)
;; NRML-NEXT: (local.get $struct)
;; NRML-NEXT: (i64.const -1)
;; NRML-NEXT: )
;; NRML-NEXT: )
;; NRML-NEXT: )
;; GUFA: (type $1 (func (param (ref null $struct))))

Expand All @@ -446,12 +454,25 @@
;; GUFA-NEXT: (struct.atomic.rmw.cmpxchg acqrel acqrel $struct 0
;; GUFA-NEXT: (local.get $struct)
;; GUFA-NEXT: (unreachable)
;; GUFA-NEXT: (block (result nullref)
;; GUFA-NEXT: (block (result (ref null (shared none)))
;; GUFA-NEXT: (drop
;; GUFA-NEXT: (local.get $struct)
;; GUFA-NEXT: )
;; GUFA-NEXT: (ref.null none)
;; GUFA-NEXT: (ref.null (shared none))
;; GUFA-NEXT: )
;; GUFA-NEXT: )
;; GUFA-NEXT: )
;; GUFA-NEXT: (drop
;; GUFA-NEXT: (struct.wait $struct 0
;; GUFA-NEXT: (local.get $struct)
;; GUFA-NEXT: (unreachable)
;; GUFA-NEXT: (block (result (ref null (shared none)))
;; GUFA-NEXT: (drop
;; GUFA-NEXT: (local.get $struct)
;; GUFA-NEXT: )
;; GUFA-NEXT: (ref.null (shared none))
;; GUFA-NEXT: )
;; GUFA-NEXT: (i64.const -1)
;; GUFA-NEXT: )
;; GUFA-NEXT: )
;; GUFA-NEXT: )
Expand All @@ -471,6 +492,15 @@
(local.get $struct)
)
)
;; Likewise with struct.wait.
(drop
(struct.wait $struct 0
(local.get $struct)
(unreachable)
(local.get $struct)
(i64.const -1)
)
)
)
)

Loading