Skip to content

[Shared-Everything] ArrayRMW and ArrayCmpxchg #7632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
yolo
  • Loading branch information
kripken committed May 29, 2025
commit 8e66d70e881a503efe69fba8a9c3d68779281efe
39 changes: 39 additions & 0 deletions src/parser/parsers.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,10 @@ Result<> makeArrayInitData(Ctx&, Index, const std::vector<Annotation>&);
template<typename Ctx>
Result<> makeArrayInitElem(Ctx&, Index, const std::vector<Annotation>&);
template<typename Ctx>
template<typename Ctx>
Result<> makeArrayRMW(AtomicRMWOp, const std::vector<Annotation>&);
template<typename Ctx>
Result<> makeArrayCmpxchg(const std::vector<Annotation>&);
Result<> makeRefAs(Ctx&, Index, const std::vector<Annotation>&, RefAsOp op);
template<typename Ctx>
Result<>
Expand Down Expand Up @@ -2499,6 +2503,41 @@ Result<> makeArrayInitElem(Ctx& ctx,
return ctx.makeArrayInitElem(pos, annotations, *type, *elem);
}

template<typename Ctx>
Result<> makeArrayRMW(Ctx& ctx,
const std::vector<Annotation>& annotations,
AtomicRMWOp op) {
auto order1 = memorder(ctx);
CHECK_ERR(order1);
auto order2 = memorder(ctx);
CHECK_ERR(order2);
if (*order1 != *order2) {
return ctx.in.err(pos, "array.atomic.rmw memory orders must be identical");
}
auto type = typeidx(ctx);
CHECK_ERR(type);
auto field = fieldidx(ctx, *type);
CHECK_ERR(field);
return ctx.makeArrayRMW(annotations, op, *type, *field, *order1);
}

template<typename Ctx>
Result<> makeArrayCmpxchg(Ctx& ctx,
const std::vector<Annotation>& annotations) {
auto order1 = memorder(ctx);
CHECK_ERR(order1);
auto order2 = memorder(ctx);
CHECK_ERR(order2);
if (*order1 != *order2) {
return ctx.in.err(pos, "array.atomic.rmw memory orders must be identical");
}
auto type = typeidx(ctx);
CHECK_ERR(type);
auto field = fieldidx(ctx, *type);
CHECK_ERR(field);
return ctx.makeArrayCmpxchg(annotations, *type, *field, *order1);
}

template<typename Ctx>
Result<> makeRefAs(Ctx& ctx,
Index pos,
Expand Down
28 changes: 28 additions & 0 deletions src/wasm-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,34 @@ class Builder {
ret->finalize();
return ret;
}
ArrayRMW* makeArrayRMW(AtomicRMWOp op,
Expression* ref,
Expression* index,
Expression* value,
MemoryOrder order) {
auto* ret = wasm.allocator.alloc<ArrayRMW>();
ret->op = op;
ret->ref = ref;
ret->index = index;
ret->value = value;
ret->order = order;
ret->finalize();
return ret;
}
ArrayCmpxchg* makeArrayCmpxchg(Expression* ref,
Expression* index,
Expression* expected,
Expression* replacement,
MemoryOrder order) {
auto* ret = wasm.allocator.alloc<ArrayCmpxchg>();
ret->ref = ref;
ret->index = index;
ret->expected = expected;
ret->replacement = replacement;
ret->order = order;
ret->finalize();
return ret;
}
RefAs* makeRefAs(RefAsOp op, Expression* value) {
auto* ret = wasm.allocator.alloc<RefAs>();
ret->op = op;
Expand Down
3 changes: 3 additions & 0 deletions src/wasm-ir-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ class IRBuilder : public UnifiedExpressionVisitor<IRBuilder, Result<>> {
Result<> makeArrayFill(HeapType type);
Result<> makeArrayInitData(HeapType type, Name data);
Result<> makeArrayInitElem(HeapType type, Name elem);
Result<>
makeArrayRMW(AtomicRMWOp op, HeapType type, MemoryOrder order);
Result<> makeArrayCmpxchg(HeapType type, MemoryOrder order);
Result<> makeRefAs(RefAsOp op);
Result<> makeStringNew(StringNewOp op);
Result<> makeStringConst(Name string);
Expand Down