Commit 289aa11b authored by Deepti Gandluri's avatar Deepti Gandluri Committed by Commit Bot

Make atomic operations effectful.

Bug: v8:9536
Change-Id: Ie9c47493ab29f604d6e43ef318e08618ee527fc3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1728329Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Deepti Gandluri <gdeepti@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63012}
parent 195679de
......@@ -1081,7 +1081,11 @@ void InstructionSelector::VisitBlock(BasicBlock* block) {
node->opcode() == IrOpcode::kCallWithCallerSavedRegisters ||
node->opcode() == IrOpcode::kProtectedLoad ||
node->opcode() == IrOpcode::kProtectedStore ||
node->opcode() == IrOpcode::kMemoryBarrier) {
#define ADD_EFFECT_FOR_ATOMIC_OP(Opcode) \
node->opcode() == IrOpcode::k##Opcode ||
MACHINE_ATOMIC_OP_LIST(ADD_EFFECT_FOR_ATOMIC_OP)
#undef ADD_EFFECT_FOR_ATOMIC_OP
node->opcode() == IrOpcode::kMemoryBarrier) {
++effect_level;
}
}
......
......@@ -617,15 +617,33 @@
V(Float64Mod) \
V(Float64Pow)
#define MACHINE_WORD64_ATOMIC_OP_LIST(V) \
V(Word64AtomicLoad) \
V(Word64AtomicStore) \
V(Word64AtomicAdd) \
V(Word64AtomicSub) \
V(Word64AtomicAnd) \
V(Word64AtomicOr) \
V(Word64AtomicXor) \
V(Word64AtomicExchange) \
#define MACHINE_ATOMIC_OP_LIST(V) \
V(Word32AtomicLoad) \
V(Word32AtomicStore) \
V(Word32AtomicExchange) \
V(Word32AtomicCompareExchange) \
V(Word32AtomicAdd) \
V(Word32AtomicSub) \
V(Word32AtomicAnd) \
V(Word32AtomicOr) \
V(Word32AtomicXor) \
V(Word32AtomicPairLoad) \
V(Word32AtomicPairStore) \
V(Word32AtomicPairAdd) \
V(Word32AtomicPairSub) \
V(Word32AtomicPairAnd) \
V(Word32AtomicPairOr) \
V(Word32AtomicPairXor) \
V(Word32AtomicPairExchange) \
V(Word32AtomicPairCompareExchange) \
V(Word64AtomicLoad) \
V(Word64AtomicStore) \
V(Word64AtomicAdd) \
V(Word64AtomicSub) \
V(Word64AtomicAnd) \
V(Word64AtomicOr) \
V(Word64AtomicXor) \
V(Word64AtomicExchange) \
V(Word64AtomicCompareExchange)
#define MACHINE_OP_LIST(V) \
......@@ -637,7 +655,7 @@
MACHINE_FLOAT32_UNOP_LIST(V) \
MACHINE_FLOAT64_BINOP_LIST(V) \
MACHINE_FLOAT64_UNOP_LIST(V) \
MACHINE_WORD64_ATOMIC_OP_LIST(V) \
MACHINE_ATOMIC_OP_LIST(V) \
V(AbortCSAAssert) \
V(DebugBreak) \
V(Comment) \
......@@ -716,24 +734,6 @@
V(ProtectedLoad) \
V(ProtectedStore) \
V(MemoryBarrier) \
V(Word32AtomicLoad) \
V(Word32AtomicStore) \
V(Word32AtomicExchange) \
V(Word32AtomicCompareExchange) \
V(Word32AtomicAdd) \
V(Word32AtomicSub) \
V(Word32AtomicAnd) \
V(Word32AtomicOr) \
V(Word32AtomicXor) \
V(Word32AtomicPairLoad) \
V(Word32AtomicPairStore) \
V(Word32AtomicPairAdd) \
V(Word32AtomicPairSub) \
V(Word32AtomicPairAnd) \
V(Word32AtomicPairOr) \
V(Word32AtomicPairXor) \
V(Word32AtomicPairExchange) \
V(Word32AtomicPairCompareExchange) \
V(SignExtendWord8ToInt32) \
V(SignExtendWord16ToInt32) \
V(SignExtendWord8ToInt64) \
......
......@@ -317,6 +317,54 @@ WASM_EXEC_TEST(AtomicFence) {
CHECK_EQ(0, r.Call());
}
WASM_EXEC_TEST(AtomicStoreNoConsideredEffectful) {
EXPERIMENTAL_FLAG_SCOPE(threads);
FLAG_wasm_trap_handler = false; // To use {Load} instead of {ProtectedLoad}.
WasmRunner<uint32_t> r(execution_tier);
r.builder().AddMemoryElems<int32_t>(kWasmPageSize / sizeof(int32_t));
r.builder().SetHasSharedMemory();
BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_ZERO),
WASM_ATOMICS_STORE_OP(kExprI32AtomicStore, WASM_ZERO, WASM_I32V_1(20),
MachineRepresentation::kWord32),
kExprI64Eqz);
CHECK_EQ(1, r.Call());
}
void RunNoEffectTest(ExecutionTier execution_tier, WasmOpcode wasm_op) {
EXPERIMENTAL_FLAG_SCOPE(threads);
FLAG_wasm_trap_handler = false; // To use {Load} instead of {ProtectedLoad}.
WasmRunner<uint32_t> r(execution_tier);
r.builder().AddMemoryElems<int32_t>(kWasmPageSize / sizeof(int32_t));
r.builder().SetHasSharedMemory();
BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_ZERO),
WASM_ATOMICS_BINOP(wasm_op, WASM_ZERO, WASM_I32V_1(20),
MachineRepresentation::kWord32),
WASM_DROP, kExprI64Eqz);
CHECK_EQ(1, r.Call());
}
WASM_EXEC_TEST(AtomicAddNoConsideredEffectful) {
RunNoEffectTest(execution_tier, kExprI32AtomicAdd);
}
WASM_EXEC_TEST(AtomicExchangeNoConsideredEffectful) {
RunNoEffectTest(execution_tier, kExprI32AtomicExchange);
}
WASM_EXEC_TEST(AtomicCompareExchangeNoConsideredEffectful) {
EXPERIMENTAL_FLAG_SCOPE(threads);
FLAG_wasm_trap_handler = false; // To use {Load} instead of {ProtectedLoad}.
WasmRunner<uint32_t> r(execution_tier);
r.builder().AddMemoryElems<int32_t>(kWasmPageSize / sizeof(int32_t));
r.builder().SetHasSharedMemory();
BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO),
WASM_ATOMICS_TERNARY_OP(kExprI32AtomicCompareExchange, WASM_ZERO,
WASM_ZERO, WASM_I32V_1(30),
MachineRepresentation::kWord32),
WASM_DROP, kExprI32Eqz);
CHECK_EQ(1, r.Call());
}
} // namespace test_run_wasm_atomics
} // namespace wasm
} // namespace internal
......
......@@ -646,6 +646,54 @@ WASM_EXEC_TEST(I64AtomicCompareExchange32UFail) {
CHECK_EQ(initial, r.builder().ReadMemory(&memory[0]));
}
WASM_EXEC_TEST(AtomicStoreNoConsideredEffectful) {
EXPERIMENTAL_FLAG_SCOPE(threads);
FLAG_wasm_trap_handler = false; // To use {Load} instead of {ProtectedLoad}.
WasmRunner<uint32_t> r(execution_tier);
r.builder().AddMemoryElems<int64_t>(kWasmPageSize / sizeof(int64_t));
r.builder().SetHasSharedMemory();
BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_ZERO),
WASM_ATOMICS_STORE_OP(kExprI64AtomicStore, WASM_ZERO, WASM_I64V(20),
MachineRepresentation::kWord64),
kExprI64Eqz);
CHECK_EQ(1, r.Call());
}
void RunNoEffectTest(ExecutionTier execution_tier, WasmOpcode wasm_op) {
EXPERIMENTAL_FLAG_SCOPE(threads);
FLAG_wasm_trap_handler = false; // To use {Load} instead of {ProtectedLoad}.
WasmRunner<uint32_t> r(execution_tier);
r.builder().AddMemoryElems<int64_t>(kWasmPageSize / sizeof(int64_t));
r.builder().SetHasSharedMemory();
BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_ZERO),
WASM_ATOMICS_BINOP(wasm_op, WASM_ZERO, WASM_I64V(20),
MachineRepresentation::kWord64),
WASM_DROP, kExprI64Eqz);
CHECK_EQ(1, r.Call());
}
WASM_EXEC_TEST(AtomicAddNoConsideredEffectful) {
RunNoEffectTest(execution_tier, kExprI64AtomicAdd);
}
WASM_EXEC_TEST(AtomicExchangeNoConsideredEffectful) {
RunNoEffectTest(execution_tier, kExprI64AtomicExchange);
}
WASM_EXEC_TEST(AtomicCompareExchangeNoConsideredEffectful) {
EXPERIMENTAL_FLAG_SCOPE(threads);
FLAG_wasm_trap_handler = false; // To use {Load} instead of {ProtectedLoad}.
WasmRunner<uint32_t> r(execution_tier);
r.builder().AddMemoryElems<uint64_t>(kWasmPageSize / sizeof(uint64_t));
r.builder().SetHasSharedMemory();
BUILD(r, WASM_LOAD_MEM(MachineType::Int64(), WASM_ZERO),
WASM_ATOMICS_TERNARY_OP(kExprI64AtomicCompareExchange, WASM_ZERO,
WASM_I64V(0), WASM_I64V(30),
MachineRepresentation::kWord64),
WASM_DROP, kExprI64Eqz);
CHECK_EQ(1, r.Call());
}
} // namespace test_run_wasm_atomics_64
} // namespace wasm
} // namespace internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment