Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2698,12 +2698,13 @@ void BinaryenLoadSetPtr(BinaryenExpressionRef expr,
bool BinaryenStoreIsAtomic(BinaryenExpressionRef expr) {
auto* expression = (Expression*)expr;
assert(expression->is<Store>());
return static_cast<Store*>(expression)->isAtomic;
return static_cast<Store*>(expression)->isAtomic();
}
void BinaryenStoreSetAtomic(BinaryenExpressionRef expr, bool isAtomic) {
auto* expression = (Expression*)expr;
assert(expression->is<Store>());
static_cast<Store*>(expression)->isAtomic = isAtomic != 0;
static_cast<Store*>(expression)->order =
isAtomic ? MemoryOrder::SeqCst : MemoryOrder::Unordered;
}
uint32_t BinaryenStoreGetBytes(BinaryenExpressionRef expr) {
auto* expression = (Expression*)expr;
Expand Down
2 changes: 1 addition & 1 deletion src/ir/cost.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct CostAnalyzer : public OverriddenVisitor<CostAnalyzer, CostType> {
}
CostType visitStore(Store* curr) {
return 2 + visit(curr->ptr) + visit(curr->value) +
AtomicCost * curr->isAtomic;
AtomicCost * curr->isAtomic();
}
CostType visitAtomicRMW(AtomicRMW* curr) {
return AtomicCost + visit(curr->ptr) + visit(curr->value);
Expand Down
2 changes: 1 addition & 1 deletion src/ir/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ class EffectAnalyzer {
}
void visitStore(Store* curr) {
parent.writesMemory = true;
parent.isAtomic |= curr->isAtomic;
parent.isAtomic |= curr->isAtomic();
parent.implicitTrap = true;
}
void visitAtomicRMW(AtomicRMW* curr) {
Expand Down
2 changes: 1 addition & 1 deletion src/ir/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ inline MemoryOrder getMemoryOrder(Expression* curr) {
return load->order;
}
if (auto* store = curr->dynCast<Store>()) {
return store->isAtomic ? MemoryOrder::SeqCst : MemoryOrder::Unordered;
return store->order;
}
if (curr->is<AtomicRMW>() || curr->is<AtomicWait>() ||
curr->is<AtomicNotify>() || curr->is<AtomicFence>()) {
Expand Down
2 changes: 1 addition & 1 deletion src/passes/I64ToI32Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {
return;
}
assert(curr->offset + 4 > curr->offset);
assert(!curr->isAtomic && "atomic store not implemented");
assert(!curr->isAtomic() && "atomic store not implemented");
TempVar highBits = fetchOutParam(curr->value);
uint8_t bytes = curr->bytes;
curr->bytes = std::min(curr->bytes, uint8_t(4));
Expand Down
2 changes: 1 addition & 1 deletion src/passes/OptimizeInstructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ struct OptimizeInstructions
// instead of wrapping to 32, just store some of the bits in the i64
curr->valueType = Type::i64;
curr->value = unary->value;
} else if (!curr->isAtomic && Abstract::hasAnyReinterpret(unary->op) &&
} else if (!curr->isAtomic() && Abstract::hasAnyReinterpret(unary->op) &&
curr->bytes == curr->valueType.getByteSize()) {
// f32.store(y, f32.reinterpret_i32(x)) => i32.store(y, x)
// f64.store(y, f64.reinterpret_i64(x)) => i64.store(y, x)
Expand Down
2 changes: 1 addition & 1 deletion src/passes/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ struct PrintExpressionContents
}
void visitStore(Store* curr) {
prepareColor(o) << forceConcrete(curr->valueType);
if (curr->isAtomic) {
if (curr->isAtomic()) {
o << ".atomic";
}
o << ".store";
Expand Down
10 changes: 6 additions & 4 deletions src/passes/SafeHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static Name getStoreName(Store* curr) {
std::string ret = "SAFE_HEAP_STORE_";
ret += curr->valueType.toString();
ret += "_" + std::to_string(curr->bytes) + "_";
if (curr->isAtomic) {
if (curr->isAtomic()) {
ret += "A";
} else {
ret += std::to_string(curr->align);
Expand Down Expand Up @@ -270,7 +270,8 @@ struct SafeHeap : public Pass {
continue;
}
for (auto isAtomic : {true, false}) {
store.isAtomic = isAtomic;
store.order =
isAtomic ? MemoryOrder::SeqCst : MemoryOrder::Unordered;
if (isAtomic &&
!isPossibleAtomicOperation(
align, bytes, module->memories[0]->shared, valueType)) {
Expand Down Expand Up @@ -411,8 +412,9 @@ struct SafeHeap : public Pass {
bool is64,
Name memory) {
bool lowMemUnused = getPassOptions().lowMemoryUnused;
auto upperOp = is64 ? lowMemUnused ? LtUInt64 : EqInt64
: lowMemUnused ? LtUInt32 : EqInt32;
auto upperOp = is64 ? lowMemUnused ? LtUInt64 : EqInt64
: lowMemUnused ? LtUInt32
: EqInt32;
auto upperBound = lowMemUnused ? PassOptions::LowMemoryBound : 0;
Expression* brkLocation;
if (sbrk.is()) {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/fuzzing/fuzzing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3358,7 +3358,7 @@ Expression* TranslateToFuzzReader::makeStore(Type type) {
}
// make it atomic
wasm.memories[0]->shared = true;
store->isAtomic = true;
store->order = MemoryOrder::SeqCst;
store->align = store->bytes;
return store;
}
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,14 @@ class Builder {
Type type,
Name memory) {
auto* ret = wasm.allocator.alloc<Store>();
ret->isAtomic = false;
ret->bytes = bytes;
ret->offset = offset;
ret->align = align;
ret->ptr = ptr;
ret->value = value;
ret->valueType = type;
ret->memory = memory;
ret->order = MemoryOrder::Unordered;
ret->finalize();
return ret;
}
Expand All @@ -446,7 +446,7 @@ class Builder {
Type type,
Name memory) {
Store* store = makeStore(bytes, offset, bytes, ptr, value, type, memory);
store->isAtomic = true;
store->order = MemoryOrder::SeqCst;
return store;
}
AtomicRMW* makeAtomicRMW(AtomicRMWOp op,
Expand Down
2 changes: 1 addition & 1 deletion src/wasm-delegations-fields.def
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ DELEGATE_FIELD_CHILD(Store, ptr)
DELEGATE_FIELD_INT(Store, bytes)
DELEGATE_FIELD_ADDRESS(Store, offset)
DELEGATE_FIELD_ADDRESS(Store, align)
DELEGATE_FIELD_INT(Store, isAtomic)
DELEGATE_FIELD_INT(Store, order)
DELEGATE_FIELD_TYPE(Store, valueType)
DELEGATE_FIELD_NAME_KIND(Store, memory, ModuleItemKind::Memory)
DELEGATE_FIELD_CASE_END(Store)
Expand Down
4 changes: 2 additions & 2 deletions src/wasm-interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -3966,7 +3966,7 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
auto memorySize = info.instance->getMemorySize(info.name);
auto addr =
info.instance->getFinalAddress(curr, ptr.getSingleValue(), memorySize);
if (curr->isAtomic) {
if (curr->isAtomic()) {
info.instance->checkAtomicAddress(addr, curr->bytes, memorySize);
}
info.interface()->store(curr, addr, value.getSingleValue(), info.name);
Expand Down Expand Up @@ -5136,7 +5136,7 @@ class ModuleRunnerBase : public ExpressionRunner<SubType> {
Store store;
store.bytes = bytes;
store.align = bytes;
store.isAtomic = true; // understatement
store.order = MemoryOrder::SeqCst; // understatement
store.ptr = &ptr;
store.value = &value;
store.valueType = value.type;
Expand Down
4 changes: 3 additions & 1 deletion src/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1012,11 +1012,13 @@ class Store : public SpecificExpression<Expression::StoreId> {
uint8_t bytes;
Address offset;
Address align;
bool isAtomic;
Expression* ptr;
Expression* value;
Type valueType;
Name memory;
MemoryOrder order;

bool isAtomic() const { return order != MemoryOrder::Unordered; }

void finalize();
};
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/wasm-stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void BinaryInstWriter::visitLoad(Load* curr) {
}

void BinaryInstWriter::visitStore(Store* curr) {
if (!curr->isAtomic) {
if (!curr->isAtomic()) {
switch (curr->valueType.getBasic()) {
case Type::i32: {
switch (curr->bytes) {
Expand Down
6 changes: 3 additions & 3 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ void FunctionValidator::visitLoad(Load* curr) {
void FunctionValidator::visitStore(Store* curr) {
auto* memory = getModule()->getMemoryOrNull(curr->memory);
shouldBeTrue(!!memory, curr, "memory.store memory must exist");
if (curr->isAtomic) {
if (curr->isAtomic()) {
shouldBeTrue(getModule()->features.hasAtomics(),
curr,
"Atomic operations require threads [--enable-threads]");
Expand All @@ -1145,7 +1145,7 @@ void FunctionValidator::visitStore(Store* curr) {
validateMemBytes(curr->bytes, curr->valueType, curr);
validateOffset(curr->offset, memory, curr);
validateAlignment(
curr->align, curr->valueType, curr->bytes, curr->isAtomic, curr);
curr->align, curr->valueType, curr->bytes, curr->isAtomic(), curr);
shouldBeEqualOrFirstIsUnreachable(
curr->ptr->type,
memory->addressType,
Expand All @@ -1157,7 +1157,7 @@ void FunctionValidator::visitStore(Store* curr) {
"store value type must not be none");
shouldBeEqualOrFirstIsUnreachable(
curr->value->type, curr->valueType, curr, "store value type must match");
if (curr->isAtomic) {
if (curr->isAtomic()) {
shouldBeIntOrUnreachable(
curr->valueType, curr, "atomic stores must be of integers");
}
Expand Down
2 changes: 1 addition & 1 deletion src/wasm2js.h
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ Ref Wasm2JSBuilder::processExpression(Expression* curr,
Fatal() << "Unhandled type in store: " << curr->valueType;
}
}
if (curr->isAtomic) {
if (curr->isAtomic()) {
Ref call = ValueBuilder::makeCall(
ValueBuilder::makeDot(ValueBuilder::makeName(ATOMICS), STORE));
ValueBuilder::appendToCall(call, ret[1]);
Expand Down
Loading