Commit a3a024f0 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

Reland^2 "[wasm] [cleanup] Only pass information really needed"

This is a reland of fa18e78d.

Mips compile error is fixed.

Original change's description:
> [wasm] [cleanup] Only pass information really needed
>
> Instead of always passing the MachineType, we can often just pass the
> accessed memory size or the MachineRepresentation, which is less
> information to pass and will simplify the upcoming refactoring for
> memory operations in Liftoff.
>
> R=titzer@chromium.org
>
> Bug: v8:6600
> Change-Id: I8748f8e00dcfdbc4082893143fe88bdafde99053
> Reviewed-on: https://chromium-review.googlesource.com/822194
> Reviewed-by: Ben Titzer <titzer@chromium.org>
> Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#50041}

TBR=titzer@chromium.org

Bug: v8:6600
Change-Id: I3dff3072d6ceebd74873ace0c7dce7cccc3055d5
Reviewed-on: https://chromium-review.googlesource.com/822851Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50050}
parent 64d14553
...@@ -1010,9 +1010,8 @@ static bool ReverseBytesSupported(MachineOperatorBuilder* m, ...@@ -1010,9 +1010,8 @@ static bool ReverseBytesSupported(MachineOperatorBuilder* m,
return false; return false;
} }
Node* WasmGraphBuilder::BuildChangeEndiannessStore(Node* node, Node* WasmGraphBuilder::BuildChangeEndiannessStore(
MachineType memtype, Node* node, MachineRepresentation mem_rep, wasm::ValueType wasmtype) {
wasm::ValueType wasmtype) {
Node* result; Node* result;
Node* value = node; Node* value = node;
MachineOperatorBuilder* m = jsgraph()->machine(); MachineOperatorBuilder* m = jsgraph()->machine();
...@@ -1041,23 +1040,22 @@ Node* WasmGraphBuilder::BuildChangeEndiannessStore(Node* node, ...@@ -1041,23 +1040,22 @@ Node* WasmGraphBuilder::BuildChangeEndiannessStore(Node* node,
break; break;
} }
if (memtype.representation() == MachineRepresentation::kWord8) { if (mem_rep == MachineRepresentation::kWord8) {
// No need to change endianness for byte size, return original node // No need to change endianness for byte size, return original node
return node; return node;
} }
if (wasmtype == wasm::kWasmI64 && if (wasmtype == wasm::kWasmI64 && mem_rep < MachineRepresentation::kWord64) {
memtype.representation() < MachineRepresentation::kWord64) {
// In case we store lower part of WasmI64 expression, we can truncate // In case we store lower part of WasmI64 expression, we can truncate
// upper 32bits // upper 32bits
value = graph()->NewNode(m->TruncateInt64ToInt32(), value); value = graph()->NewNode(m->TruncateInt64ToInt32(), value);
valueSizeInBytes = 1 << ElementSizeLog2Of(wasm::kWasmI32); valueSizeInBytes = 1 << ElementSizeLog2Of(wasm::kWasmI32);
valueSizeInBits = 8 * valueSizeInBytes; valueSizeInBits = 8 * valueSizeInBytes;
if (memtype.representation() == MachineRepresentation::kWord16) { if (mem_rep == MachineRepresentation::kWord16) {
value = value =
graph()->NewNode(m->Word32Shl(), value, jsgraph()->Int32Constant(16)); graph()->NewNode(m->Word32Shl(), value, jsgraph()->Int32Constant(16));
} }
} else if (wasmtype == wasm::kWasmI32 && } else if (wasmtype == wasm::kWasmI32 &&
memtype.representation() == MachineRepresentation::kWord16) { mem_rep == MachineRepresentation::kWord16) {
value = value =
graph()->NewNode(m->Word32Shl(), value, jsgraph()->Int32Constant(16)); graph()->NewNode(m->Word32Shl(), value, jsgraph()->Int32Constant(16));
} }
...@@ -3485,7 +3483,7 @@ Node* WasmGraphBuilder::SetGlobal(uint32_t index, Node* val) { ...@@ -3485,7 +3483,7 @@ Node* WasmGraphBuilder::SetGlobal(uint32_t index, Node* val) {
return node; return node;
} }
void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index, void WasmGraphBuilder::BoundsCheckMem(uint8_t access_size, Node* index,
uint32_t offset, uint32_t offset,
wasm::WasmCodePosition position) { wasm::WasmCodePosition position) {
if (FLAG_wasm_no_bounds_checks) return; if (FLAG_wasm_no_bounds_checks) return;
...@@ -3499,8 +3497,6 @@ void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index, ...@@ -3499,8 +3497,6 @@ void WasmGraphBuilder::BoundsCheckMem(MachineType memtype, Node* index,
: wasm::kV8MaxWasmMemoryPages) * : wasm::kV8MaxWasmMemoryPages) *
wasm::WasmModule::kPageSize; wasm::WasmModule::kPageSize;
byte access_size = wasm::WasmOpcodes::MemSize(memtype);
if (access_size > max_size || offset > max_size - access_size) { if (access_size > max_size || offset > max_size - access_size) {
// The access will be out of bounds, even for the largest memory. // The access will be out of bounds, even for the largest memory.
TrapIfEq32(wasm::kTrapMemOutOfBounds, jsgraph()->Int32Constant(0), 0, TrapIfEq32(wasm::kTrapMemOutOfBounds, jsgraph()->Int32Constant(0), 0,
...@@ -3612,7 +3608,8 @@ Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype, ...@@ -3612,7 +3608,8 @@ Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype,
} }
// Wasm semantics throw on OOB. Introduce explicit bounds check. // Wasm semantics throw on OOB. Introduce explicit bounds check.
if (!use_trap_handler()) { if (!use_trap_handler()) {
BoundsCheckMem(memtype, index, offset, position); BoundsCheckMem(wasm::WasmOpcodes::MemSize(memtype), index, offset,
position);
} }
if (memtype.representation() == MachineRepresentation::kWord8 || if (memtype.representation() == MachineRepresentation::kWord8 ||
...@@ -3659,7 +3656,7 @@ Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype, ...@@ -3659,7 +3656,7 @@ Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype,
return load; return load;
} }
Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index, Node* WasmGraphBuilder::StoreMem(MachineRepresentation mem_rep, Node* index,
uint32_t offset, uint32_t alignment, Node* val, uint32_t offset, uint32_t alignment, Node* val,
wasm::WasmCodePosition position, wasm::WasmCodePosition position,
wasm::ValueType type) { wasm::ValueType type) {
...@@ -3671,22 +3668,23 @@ Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index, ...@@ -3671,22 +3668,23 @@ Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index,
} }
// Wasm semantics throw on OOB. Introduce explicit bounds check. // Wasm semantics throw on OOB. Introduce explicit bounds check.
if (!use_trap_handler()) { if (!use_trap_handler()) {
BoundsCheckMem(memtype, index, offset, position); BoundsCheckMem(wasm::WasmOpcodes::MemSize(mem_rep), index, offset,
position);
} }
#if defined(V8_TARGET_BIG_ENDIAN) #if defined(V8_TARGET_BIG_ENDIAN)
val = BuildChangeEndiannessStore(val, memtype, type); val = BuildChangeEndiannessStore(val, mem_rep, type);
#endif #endif
if (memtype.representation() == MachineRepresentation::kWord8 || if (mem_rep == MachineRepresentation::kWord8 ||
jsgraph()->machine()->UnalignedStoreSupported(memtype.representation())) { jsgraph()->machine()->UnalignedStoreSupported(mem_rep)) {
if (use_trap_handler()) { if (use_trap_handler()) {
store = graph()->NewNode( store =
jsgraph()->machine()->ProtectedStore(memtype.representation()), graph()->NewNode(jsgraph()->machine()->ProtectedStore(mem_rep),
MemBuffer(offset), index, val, *effect_, *control_); MemBuffer(offset), index, val, *effect_, *control_);
SetSourcePosition(store, position); SetSourcePosition(store, position);
} else { } else {
StoreRepresentation rep(memtype.representation(), kNoWriteBarrier); StoreRepresentation rep(mem_rep, kNoWriteBarrier);
store = store =
graph()->NewNode(jsgraph()->machine()->Store(rep), MemBuffer(offset), graph()->NewNode(jsgraph()->machine()->Store(rep), MemBuffer(offset),
index, val, *effect_, *control_); index, val, *effect_, *control_);
...@@ -3694,7 +3692,7 @@ Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index, ...@@ -3694,7 +3692,7 @@ Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index,
} else { } else {
// TODO(eholk): Support unaligned stores with trap handlers. // TODO(eholk): Support unaligned stores with trap handlers.
DCHECK(!use_trap_handler()); DCHECK(!use_trap_handler());
UnalignedStoreRepresentation rep(memtype.representation()); UnalignedStoreRepresentation rep(mem_rep);
store = store =
graph()->NewNode(jsgraph()->machine()->UnalignedStore(rep), graph()->NewNode(jsgraph()->machine()->UnalignedStore(rep),
MemBuffer(offset), index, val, *effect_, *control_); MemBuffer(offset), index, val, *effect_, *control_);
...@@ -3703,8 +3701,7 @@ Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index, ...@@ -3703,8 +3701,7 @@ Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index,
*effect_ = store; *effect_ = store;
if (FLAG_wasm_trace_memory) { if (FLAG_wasm_trace_memory) {
TraceMemoryOperation(true, memtype.representation(), index, offset, TraceMemoryOperation(true, mem_rep, index, offset, position);
position);
} }
return store; return store;
...@@ -4238,7 +4235,8 @@ Node* WasmGraphBuilder::AtomicOp(wasm::WasmOpcode opcode, Node* const* inputs, ...@@ -4238,7 +4235,8 @@ Node* WasmGraphBuilder::AtomicOp(wasm::WasmOpcode opcode, Node* const* inputs,
switch (opcode) { switch (opcode) {
#define BUILD_ATOMIC_BINOP(Name, Operation, Type) \ #define BUILD_ATOMIC_BINOP(Name, Operation, Type) \
case wasm::kExpr##Name: { \ case wasm::kExpr##Name: { \
BoundsCheckMem(MachineType::Type(), inputs[0], offset, position); \ BoundsCheckMem(wasm::WasmOpcodes::MemSize(MachineType::Type()), inputs[0], \
offset, position); \
node = graph()->NewNode( \ node = graph()->NewNode( \
jsgraph()->machine()->Atomic##Operation(MachineType::Type()), \ jsgraph()->machine()->Atomic##Operation(MachineType::Type()), \
MemBuffer(offset), inputs[0], inputs[1], *effect_, *control_); \ MemBuffer(offset), inputs[0], inputs[1], *effect_, *control_); \
...@@ -4249,7 +4247,8 @@ Node* WasmGraphBuilder::AtomicOp(wasm::WasmOpcode opcode, Node* const* inputs, ...@@ -4249,7 +4247,8 @@ Node* WasmGraphBuilder::AtomicOp(wasm::WasmOpcode opcode, Node* const* inputs,
#define BUILD_ATOMIC_TERNARY_OP(Name, Operation, Type) \ #define BUILD_ATOMIC_TERNARY_OP(Name, Operation, Type) \
case wasm::kExpr##Name: { \ case wasm::kExpr##Name: { \
BoundsCheckMem(MachineType::Type(), inputs[0], offset, position); \ BoundsCheckMem(wasm::WasmOpcodes::MemSize(MachineType::Type()), inputs[0], \
offset, position); \
node = graph()->NewNode( \ node = graph()->NewNode( \
jsgraph()->machine()->Atomic##Operation(MachineType::Type()), \ jsgraph()->machine()->Atomic##Operation(MachineType::Type()), \
MemBuffer(offset), inputs[0], inputs[1], inputs[2], *effect_, \ MemBuffer(offset), inputs[0], inputs[1], inputs[2], *effect_, \
...@@ -4261,7 +4260,8 @@ Node* WasmGraphBuilder::AtomicOp(wasm::WasmOpcode opcode, Node* const* inputs, ...@@ -4261,7 +4260,8 @@ Node* WasmGraphBuilder::AtomicOp(wasm::WasmOpcode opcode, Node* const* inputs,
#define BUILD_ATOMIC_LOAD_OP(Name, Type) \ #define BUILD_ATOMIC_LOAD_OP(Name, Type) \
case wasm::kExpr##Name: { \ case wasm::kExpr##Name: { \
BoundsCheckMem(MachineType::Type(), inputs[0], offset, position); \ BoundsCheckMem(wasm::WasmOpcodes::MemSize(MachineType::Type()), inputs[0], \
offset, position); \
node = graph()->NewNode( \ node = graph()->NewNode( \
jsgraph()->machine()->AtomicLoad(MachineType::Type()), \ jsgraph()->machine()->AtomicLoad(MachineType::Type()), \
MemBuffer(offset), inputs[0], *effect_, *control_); \ MemBuffer(offset), inputs[0], *effect_, *control_); \
...@@ -4272,7 +4272,8 @@ Node* WasmGraphBuilder::AtomicOp(wasm::WasmOpcode opcode, Node* const* inputs, ...@@ -4272,7 +4272,8 @@ Node* WasmGraphBuilder::AtomicOp(wasm::WasmOpcode opcode, Node* const* inputs,
#define BUILD_ATOMIC_STORE_OP(Name, Type, Rep) \ #define BUILD_ATOMIC_STORE_OP(Name, Type, Rep) \
case wasm::kExpr##Name: { \ case wasm::kExpr##Name: { \
BoundsCheckMem(MachineType::Type(), inputs[0], offset, position); \ BoundsCheckMem(wasm::WasmOpcodes::MemSize(MachineType::Type()), inputs[0], \
offset, position); \
node = graph()->NewNode( \ node = graph()->NewNode( \
jsgraph()->machine()->AtomicStore(MachineRepresentation::Rep), \ jsgraph()->machine()->AtomicStore(MachineRepresentation::Rep), \
MemBuffer(offset), inputs[0], inputs[1], *effect_, *control_); \ MemBuffer(offset), inputs[0], inputs[1], *effect_, *control_); \
......
...@@ -353,7 +353,7 @@ class WasmGraphBuilder { ...@@ -353,7 +353,7 @@ class WasmGraphBuilder {
Node* LoadMem(wasm::ValueType type, MachineType memtype, Node* index, Node* LoadMem(wasm::ValueType type, MachineType memtype, Node* index,
uint32_t offset, uint32_t alignment, uint32_t offset, uint32_t alignment,
wasm::WasmCodePosition position); wasm::WasmCodePosition position);
Node* StoreMem(MachineType memtype, Node* index, uint32_t offset, Node* StoreMem(MachineRepresentation mem_rep, Node* index, uint32_t offset,
uint32_t alignment, Node* val, wasm::WasmCodePosition position, uint32_t alignment, Node* val, wasm::WasmCodePosition position,
wasm::ValueType type); wasm::ValueType type);
static void PrintDebugName(Node* node); static void PrintDebugName(Node* node);
...@@ -457,11 +457,11 @@ class WasmGraphBuilder { ...@@ -457,11 +457,11 @@ class WasmGraphBuilder {
Node* String(const char* string); Node* String(const char* string);
Node* MemBuffer(uint32_t offset); Node* MemBuffer(uint32_t offset);
void BoundsCheckMem(MachineType memtype, Node* index, uint32_t offset, void BoundsCheckMem(uint8_t access_size, Node* index, uint32_t offset,
wasm::WasmCodePosition position); wasm::WasmCodePosition position);
const Operator* GetSafeLoadOperator(int offset, wasm::ValueType type); const Operator* GetSafeLoadOperator(int offset, wasm::ValueType type);
const Operator* GetSafeStoreOperator(int offset, wasm::ValueType type); const Operator* GetSafeStoreOperator(int offset, wasm::ValueType type);
Node* BuildChangeEndiannessStore(Node* node, MachineType type, Node* BuildChangeEndiannessStore(Node* node, MachineRepresentation rep,
wasm::ValueType wasmtype = wasm::kWasmStmt); wasm::ValueType wasmtype = wasm::kWasmStmt);
Node* BuildChangeEndiannessLoad(Node* node, MachineType type, Node* BuildChangeEndiannessLoad(Node* node, MachineType type,
wasm::ValueType wasmtype = wasm::kWasmStmt); wasm::ValueType wasmtype = wasm::kWasmStmt);
......
...@@ -528,7 +528,7 @@ class LiftoffCompiler { ...@@ -528,7 +528,7 @@ class LiftoffCompiler {
Value* result) { Value* result) {
unsupported(decoder, "memory load"); unsupported(decoder, "memory load");
} }
void StoreMem(Decoder* decoder, ValueType type, MachineType mem_type, void StoreMem(Decoder* decoder, ValueType type, MachineRepresentation mem_rep,
const MemoryAccessOperand<validate>& operand, const MemoryAccessOperand<validate>& operand,
const Value& index, const Value& value) { const Value& index, const Value& value) {
unsupported(decoder, "memory store"); unsupported(decoder, "memory store");
......
...@@ -581,7 +581,7 @@ struct ControlWithNamedConstructors : public ControlBase<Value> { ...@@ -581,7 +581,7 @@ struct ControlWithNamedConstructors : public ControlBase<Value> {
F(LoadMem, ValueType type, MachineType mem_type, \ F(LoadMem, ValueType type, MachineType mem_type, \
const MemoryAccessOperand<validate>& operand, const Value& index, \ const MemoryAccessOperand<validate>& operand, const Value& index, \
Value* result) \ Value* result) \
F(StoreMem, ValueType type, MachineType mem_type, \ F(StoreMem, ValueType type, MachineRepresentation mem_rep, \
const MemoryAccessOperand<validate>& operand, const Value& index, \ const MemoryAccessOperand<validate>& operand, const Value& index, \
const Value& value) \ const Value& value) \
F(CurrentMemoryPages, Value* result) \ F(CurrentMemoryPages, Value* result) \
...@@ -1997,8 +1997,8 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -1997,8 +1997,8 @@ class WasmFullDecoder : public WasmDecoder<validate> {
ElementSizeLog2Of(mem_type.representation())); ElementSizeLog2Of(mem_type.representation()));
auto value = Pop(1, type); auto value = Pop(1, type);
auto index = Pop(0, kWasmI32); auto index = Pop(0, kWasmI32);
CALL_INTERFACE_IF_REACHABLE(StoreMem, type, mem_type, operand, index, CALL_INTERFACE_IF_REACHABLE(StoreMem, type, mem_type.representation(),
value); operand, index, value);
return operand.length; return operand.length;
} }
......
...@@ -347,10 +347,10 @@ class WasmGraphBuildingInterface { ...@@ -347,10 +347,10 @@ class WasmGraphBuildingInterface {
operand.alignment, decoder->position()); operand.alignment, decoder->position());
} }
void StoreMem(Decoder* decoder, ValueType type, MachineType mem_type, void StoreMem(Decoder* decoder, ValueType type, MachineRepresentation mem_rep,
const MemoryAccessOperand<validate>& operand, const MemoryAccessOperand<validate>& operand,
const Value& index, const Value& value) { const Value& index, const Value& value) {
BUILD(StoreMem, mem_type, index.node, operand.offset, operand.alignment, BUILD(StoreMem, mem_rep, index.node, operand.offset, operand.alignment,
value.node, decoder->position(), type); value.node, decoder->position(), type);
} }
......
...@@ -551,7 +551,7 @@ class V8_EXPORT_PRIVATE WasmOpcodes { ...@@ -551,7 +551,7 @@ class V8_EXPORT_PRIVATE WasmOpcodes {
static const char* TrapReasonMessage(TrapReason reason); static const char* TrapReasonMessage(TrapReason reason);
static byte MemSize(MachineType type) { static byte MemSize(MachineType type) {
return 1 << ElementSizeLog2Of(type.representation()); return MemSize(type.representation());
} }
static byte MemSize(ValueType type) { return 1 << ElementSizeLog2Of(type); } static byte MemSize(ValueType type) { return 1 << ElementSizeLog2Of(type); }
......
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