Skip to content

Commit 577f9ed

Browse files
waitqueue notify
1 parent 0979bd4 commit 577f9ed

29 files changed

+195
-7
lines changed

scripts/gen-s-parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
# atomic instructions
208208
("memory.atomic.notify", "makeAtomicNotify()"),
209209
("waitqueue.wait", "makeWaitQueueWait()"),
210+
("waitqueue.notify", "makeWaitQueueNotify()"),
210211
("memory.atomic.wait32", "makeAtomicWait(Type::i32)"),
211212
("memory.atomic.wait64", "makeAtomicWait(Type::i64)"),
212213
("atomic.fence", "makeAtomicFence()"),

src/gen-s-parser.inc

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5784,12 +5784,23 @@ switch (buf[0]) {
57845784
default: goto parse_error;
57855785
}
57865786
}
5787-
case 'w':
5788-
if (op == "waitqueue.wait"sv) {
5789-
CHECK_ERR(makeWaitQueueWait(ctx, pos, annotations));
5790-
return Ok{};
5787+
case 'w': {
5788+
switch (buf[10]) {
5789+
case 'n':
5790+
if (op == "waitqueue.notify"sv) {
5791+
CHECK_ERR(makeWaitQueueNotify(ctx, pos, annotations));
5792+
return Ok{};
5793+
}
5794+
goto parse_error;
5795+
case 'w':
5796+
if (op == "waitqueue.wait"sv) {
5797+
CHECK_ERR(makeWaitQueueWait(ctx, pos, annotations));
5798+
return Ok{};
5799+
}
5800+
goto parse_error;
5801+
default: goto parse_error;
57915802
}
5792-
goto parse_error;
5803+
}
57935804
default: goto parse_error;
57945805
}
57955806
parse_error:

src/interpreter/interpreter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ struct ExpressionInterpreter : OverriddenVisitor<ExpressionInterpreter, Flow> {
284284
Flow visitResumeThrow(ResumeThrow* curr) { WASM_UNREACHABLE("TODO"); }
285285
Flow visitStackSwitch(StackSwitch* curr) { WASM_UNREACHABLE("TODO"); }
286286
Flow visitWaitQueueWait(WaitQueueWait* curr) { WASM_UNREACHABLE("TODO"); }
287+
Flow visitWaitQueueNotify(WaitQueueNotify* curr) { WASM_UNREACHABLE("TODO"); }
287288
};
288289

289290
} // anonymous namespace

src/ir/ReFinalize.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ void ReFinalize::visitResumeThrow(ResumeThrow* curr) {
203203
}
204204
void ReFinalize::visitStackSwitch(StackSwitch* curr) { curr->finalize(); }
205205
void ReFinalize::visitWaitQueueWait(WaitQueueWait* curr) { curr->finalize(); }
206+
void ReFinalize::visitWaitQueueNotify(WaitQueueNotify* curr) {
207+
curr->finalize();
208+
}
206209

207210
void ReFinalize::visitExport(Export* curr) { WASM_UNREACHABLE("unimp"); }
208211
void ReFinalize::visitGlobal(Global* curr) { WASM_UNREACHABLE("unimp"); }

src/ir/child-typer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,14 @@ template<typename Subtype> struct ChildTyper : OverriddenVisitor<Subtype> {
13661366
note(&curr->value, Type(Type::BasicType::i32));
13671367
note(&curr->timeout, Type(Type::BasicType::i64));
13681368
}
1369+
1370+
void visitWaitQueueNotify(WaitQueueNotify* curr) {
1371+
note(&curr->waitqueue,
1372+
Type(HeapType(Struct(std::vector{
1373+
Field(Field::PackedType::WaitQueue, Mutability::Immutable)})),
1374+
NonNullable));
1375+
note(&curr->count, Type(Type::BasicType::i32));
1376+
}
13691377
};
13701378

13711379
} // namespace wasm

src/ir/cost.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ struct CostAnalyzer : public OverriddenVisitor<CostAnalyzer, CostType> {
122122
return AtomicCost + visit(curr->waitqueue) + visit(curr->value) +
123123
visit(curr->timeout);
124124
}
125+
CostType visitWaitQueueNotify(WaitQueueNotify* curr) {
126+
return AtomicCost + visit(curr->waitqueue) + visit(curr->count);
127+
}
125128
CostType visitAtomicNotify(AtomicNotify* curr) {
126129
return AtomicCost + visit(curr->ptr) + visit(curr->notifyCount);
127130
}

src/ir/effects.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,18 @@ class EffectAnalyzer {
11721172
parent.readsMutableStruct = true;
11731173
}
11741174
}
1175+
1176+
void visitWaitQueueNotify(WaitQueueNotify* curr) {
1177+
parent.isAtomic = true;
1178+
1179+
// field 0 must exist and be a packed waitqueue if this is valid Wasm.
1180+
if (curr->waitqueue->type.getHeapType()
1181+
.getStruct()
1182+
.fields.at(0)
1183+
.mutable_ == Mutable) {
1184+
parent.readsMutableStruct = true;
1185+
}
1186+
}
11751187
};
11761188

11771189
public:

src/ir/module-utils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ struct CodeScanner : PostWalker<CodeScanner> {
449449
void visitWaitQueueWait(WaitQueueWait* curr) {
450450
info.note(curr->waitqueue->type);
451451
}
452+
void visitWaitQueueNotify(WaitQueueNotify* curr) {
453+
info.note(curr->waitqueue->type);
454+
}
452455
void visitBlock(Block* curr) {
453456
info.noteControlFlow(Signature(Type::none, curr->type));
454457
}

src/ir/possible-contents.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,7 @@ struct InfoCollector
14021402
addRoot(curr);
14031403
}
14041404
void visitWaitQueueWait(WaitQueueWait* curr) { addRoot(curr); }
1405+
void visitWaitQueueNotify(WaitQueueNotify* curr) { addRoot(curr); }
14051406

14061407
void visitFunction(Function* func) {
14071408
// Functions with a result can flow a value out from their body.

src/ir/subtype-exprs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,12 @@ struct SubtypingDiscoverer : public OverriddenVisitor<SubType> {
604604
Field::PackedType::WaitQueue, Immutable)})),
605605
NonNullable));
606606
}
607+
void visitWaitQueueNotify(WaitQueueNotify* curr) {
608+
self()->noteSubtype(curr->waitqueue,
609+
Type(HeapType(Struct(std::vector{Field(
610+
Field::PackedType::WaitQueue, Immutable)})),
611+
NonNullable));
612+
}
607613
};
608614

609615
} // namespace wasm

0 commit comments

Comments
 (0)