Commit 825cb671 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm][cleanup] Increase GraphAssembler infra usage in WasmGraphBuilder

WasmGraphBuilder often failed to use GraphAssembler infrastructure and
went with directly invoking graph()->NewNode(). This made the code more
verbose, especially in cases where effect() and control() had to be
passes directly to NewNode().
This CL eliminates these invocations in obvious cases. It does not try
to refactor complicated code with branches, diamond patterns, etc.

Additional changes:
- Define a few more operators in GraphAssembler.
- Move Branch() helper in WasmGraphAssembler.
- Define NumberConstant() helper in WasmGraphAssembler.
- Define Merge() helper with varargs in WasmGraphBuilder.
- Omit IntPtrConstant() wrapper for constant offsets of Load and Store.

Change-Id: I571d5286be8881504cb2060195fbd181d1fce67d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2712804Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72975}
parent 4b37f202
...@@ -48,6 +48,7 @@ class BasicBlock; ...@@ -48,6 +48,7 @@ class BasicBlock;
V(Float64ExtractLowWord32) \ V(Float64ExtractLowWord32) \
V(Float64SilenceNaN) \ V(Float64SilenceNaN) \
V(RoundFloat64ToInt32) \ V(RoundFloat64ToInt32) \
V(RoundInt32ToFloat32) \
V(TruncateFloat64ToFloat32) \ V(TruncateFloat64ToFloat32) \
V(TruncateFloat64ToWord32) \ V(TruncateFloat64ToWord32) \
V(TruncateInt64ToInt32) \ V(TruncateInt64ToInt32) \
...@@ -90,6 +91,9 @@ class BasicBlock; ...@@ -90,6 +91,9 @@ class BasicBlock;
V(Word64And) \ V(Word64And) \
V(Word64Equal) \ V(Word64Equal) \
V(Word64Or) \ V(Word64Or) \
V(Word64Sar) \
V(Word64SarShiftOutZeros) \
V(Word64Shl) \
V(Word64Shr) \ V(Word64Shr) \
V(WordAnd) \ V(WordAnd) \
V(WordEqual) \ V(WordEqual) \
...@@ -106,8 +110,12 @@ class BasicBlock; ...@@ -106,8 +110,12 @@ class BasicBlock;
V(Int32Mod) \ V(Int32Mod) \
V(Int32MulWithOverflow) \ V(Int32MulWithOverflow) \
V(Int32SubWithOverflow) \ V(Int32SubWithOverflow) \
V(Int64Div) \
V(Int64Mod) \
V(Uint32Div) \ V(Uint32Div) \
V(Uint32Mod) V(Uint32Mod) \
V(Uint64Div) \
V(Uint64Mod)
#define JSGRAPH_SINGLETON_CONSTANT_LIST(V) \ #define JSGRAPH_SINGLETON_CONSTANT_LIST(V) \
V(AllocateInOldGenerationStub, Code) \ V(AllocateInOldGenerationStub, Code) \
......
...@@ -238,6 +238,20 @@ class WasmGraphAssembler : public GraphAssembler { ...@@ -238,6 +238,20 @@ class WasmGraphAssembler : public GraphAssembler {
return call; return call;
} }
Node* Branch(Node* cond, Node** true_node, Node** false_node,
BranchHint hint) {
DCHECK_NOT_NULL(cond);
Node* branch =
graph()->NewNode(mcgraph()->common()->Branch(hint), cond, control());
*true_node = graph()->NewNode(mcgraph()->common()->IfTrue(), branch);
*false_node = graph()->NewNode(mcgraph()->common()->IfFalse(), branch);
return branch;
}
Node* NumberConstant(volatile double value) {
return graph()->NewNode(mcgraph()->common()->NumberConstant(value));
}
// Helper functions for dealing with HeapObjects. // Helper functions for dealing with HeapObjects.
// Rule of thumb: if access to a given field in an object is required in // Rule of thumb: if access to a given field in an object is required in
// at least two places, put a helper function here. // at least two places, put a helper function here.
...@@ -445,8 +459,7 @@ Node* WasmGraphBuilder::Start(unsigned params) { ...@@ -445,8 +459,7 @@ Node* WasmGraphBuilder::Start(unsigned params) {
} }
Node* WasmGraphBuilder::Param(unsigned index) { Node* WasmGraphBuilder::Param(unsigned index) {
return graph()->NewNode(mcgraph()->common()->Parameter(index), return gasm_->Parameter(index);
graph()->start());
} }
Node* WasmGraphBuilder::Loop(Node* entry) { Node* WasmGraphBuilder::Loop(Node* entry) {
...@@ -518,6 +531,12 @@ void WasmGraphBuilder::AppendToPhi(Node* phi, Node* from) { ...@@ -518,6 +531,12 @@ void WasmGraphBuilder::AppendToPhi(Node* phi, Node* from) {
phi, mcgraph()->common()->ResizeMergeOrPhi(phi->op(), new_size)); phi, mcgraph()->common()->ResizeMergeOrPhi(phi->op(), new_size));
} }
template <typename... Nodes>
Node* WasmGraphBuilder::Merge(Node* fst, Nodes*... args) {
return graph()->NewNode(this->mcgraph()->common()->Merge(1 + sizeof...(args)),
fst, args...);
}
Node* WasmGraphBuilder::Merge(unsigned count, Node** controls) { Node* WasmGraphBuilder::Merge(unsigned count, Node** controls) {
return graph()->NewNode(mcgraph()->common()->Merge(count), count, controls); return graph()->NewNode(mcgraph()->common()->Merge(count), count, controls);
} }
...@@ -594,9 +613,7 @@ void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position) { ...@@ -594,9 +613,7 @@ void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position) {
Node* limit_address = Node* limit_address =
LOAD_INSTANCE_FIELD(StackLimitAddress, MachineType::Pointer()); LOAD_INSTANCE_FIELD(StackLimitAddress, MachineType::Pointer());
Node* limit = SetEffect(graph()->NewNode( Node* limit = gasm_->Load(MachineType::Pointer(), limit_address, 0);
mcgraph()->machine()->Load(MachineType::Pointer()), limit_address,
mcgraph()->IntPtrConstant(0), limit_address, control()));
Node* check = SetEffect(graph()->NewNode( Node* check = SetEffect(graph()->NewNode(
mcgraph()->machine()->StackPointerGreaterThan(StackCheckKind::kWasm), mcgraph()->machine()->StackPointerGreaterThan(StackCheckKind::kWasm),
...@@ -942,8 +959,7 @@ Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input, ...@@ -942,8 +959,7 @@ Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input,
MachineOperatorBuilder* m = mcgraph()->machine(); MachineOperatorBuilder* m = mcgraph()->machine();
switch (opcode) { switch (opcode) {
case wasm::kExprI32Eqz: case wasm::kExprI32Eqz:
op = m->Word32Equal(); return gasm_->Word32Equal(input, mcgraph()->Int32Constant(0));
return graph()->NewNode(op, input, mcgraph()->Int32Constant(0));
case wasm::kExprF32Abs: case wasm::kExprF32Abs:
op = m->Float32Abs(); op = m->Float32Abs();
break; break;
...@@ -1144,8 +1160,7 @@ Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input, ...@@ -1144,8 +1160,7 @@ Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input,
break; break;
} }
case wasm::kExprI64Eqz: case wasm::kExprI64Eqz:
op = m->Word64Equal(); return gasm_->Word64Equal(input, mcgraph()->Int64Constant(0));
return graph()->NewNode(op, input, mcgraph()->Int64Constant(0));
case wasm::kExprF32SConvertI64: case wasm::kExprF32SConvertI64:
if (m->Is32()) { if (m->Is32()) {
return BuildF32SConvertI64(input); return BuildF32SConvertI64(input);
...@@ -1197,7 +1212,7 @@ Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input, ...@@ -1197,7 +1212,7 @@ Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input,
? BuildCcallConvertFloat(input, position, opcode) ? BuildCcallConvertFloat(input, position, opcode)
: BuildIntConvertFloat(input, position, opcode); : BuildIntConvertFloat(input, position, opcode);
case wasm::kExprRefIsNull: case wasm::kExprRefIsNull:
return graph()->NewNode(m->WordEqual(), input, RefNull()); return gasm_->WordEqual(input, RefNull());
case wasm::kExprI32AsmjsLoadMem8S: case wasm::kExprI32AsmjsLoadMem8S:
return BuildAsmjsLoadMem(MachineType::Int8(), input); return BuildAsmjsLoadMem(MachineType::Int8(), input);
case wasm::kExprI32AsmjsLoadMem8U: case wasm::kExprI32AsmjsLoadMem8U:
...@@ -1231,29 +1246,14 @@ Node* WasmGraphBuilder::Simd128Constant(const uint8_t value[16]) { ...@@ -1231,29 +1246,14 @@ Node* WasmGraphBuilder::Simd128Constant(const uint8_t value[16]) {
return graph()->NewNode(mcgraph()->machine()->S128Const(value)); return graph()->NewNode(mcgraph()->machine()->S128Const(value));
} }
namespace {
Node* Branch(MachineGraph* mcgraph, Node* cond, Node** true_node,
Node** false_node, Node* control, BranchHint hint) {
DCHECK_NOT_NULL(cond);
DCHECK_NOT_NULL(control);
Node* branch =
mcgraph->graph()->NewNode(mcgraph->common()->Branch(hint), cond, control);
*true_node = mcgraph->graph()->NewNode(mcgraph->common()->IfTrue(), branch);
*false_node = mcgraph->graph()->NewNode(mcgraph->common()->IfFalse(), branch);
return branch;
}
} // namespace
Node* WasmGraphBuilder::BranchNoHint(Node* cond, Node** true_node, Node* WasmGraphBuilder::BranchNoHint(Node* cond, Node** true_node,
Node** false_node) { Node** false_node) {
return Branch(mcgraph(), cond, true_node, false_node, control(), return gasm_->Branch(cond, true_node, false_node, BranchHint::kNone);
BranchHint::kNone);
} }
Node* WasmGraphBuilder::BranchExpectFalse(Node* cond, Node** true_node, Node* WasmGraphBuilder::BranchExpectFalse(Node* cond, Node** true_node,
Node** false_node) { Node** false_node) {
return Branch(mcgraph(), cond, true_node, false_node, control(), return gasm_->Branch(cond, true_node, false_node, BranchHint::kFalse);
BranchHint::kFalse);
} }
TrapId WasmGraphBuilder::GetTrapIdForTrap(wasm::TrapReason reason) { TrapId WasmGraphBuilder::GetTrapIdForTrap(wasm::TrapReason reason) {
...@@ -1308,8 +1308,7 @@ Node* WasmGraphBuilder::TrapIfEq32(wasm::TrapReason reason, Node* node, ...@@ -1308,8 +1308,7 @@ Node* WasmGraphBuilder::TrapIfEq32(wasm::TrapReason reason, Node* node,
return TrapIfFalse(reason, node, position); return TrapIfFalse(reason, node, position);
} else { } else {
return TrapIfTrue(reason, return TrapIfTrue(reason,
graph()->NewNode(mcgraph()->machine()->Word32Equal(), gasm_->Word32Equal(node, mcgraph()->Int32Constant(val)),
node, mcgraph()->Int32Constant(val)),
position); position);
} }
} }
...@@ -1327,8 +1326,7 @@ Node* WasmGraphBuilder::TrapIfEq64(wasm::TrapReason reason, Node* node, ...@@ -1327,8 +1326,7 @@ Node* WasmGraphBuilder::TrapIfEq64(wasm::TrapReason reason, Node* node,
Int64Matcher m(node); Int64Matcher m(node);
if (m.HasResolvedValue() && !m.Is(val)) return graph()->start(); if (m.HasResolvedValue() && !m.Is(val)) return graph()->start();
return TrapIfTrue(reason, return TrapIfTrue(reason,
graph()->NewNode(mcgraph()->machine()->Word64Equal(), node, gasm_->Word64Equal(node, mcgraph()->Int64Constant(val)),
mcgraph()->Int64Constant(val)),
position); position);
} }
...@@ -1390,8 +1388,7 @@ Node* WasmGraphBuilder::MaskShiftCount32(Node* node) { ...@@ -1390,8 +1388,7 @@ Node* WasmGraphBuilder::MaskShiftCount32(Node* node) {
if (match.ResolvedValue() != masked) if (match.ResolvedValue() != masked)
node = mcgraph()->Int32Constant(masked); node = mcgraph()->Int32Constant(masked);
} else { } else {
node = graph()->NewNode(mcgraph()->machine()->Word32And(), node, node = gasm_->Word32And(node, mcgraph()->Int32Constant(kMask32));
mcgraph()->Int32Constant(kMask32));
} }
} }
return node; return node;
...@@ -1407,8 +1404,7 @@ Node* WasmGraphBuilder::MaskShiftCount64(Node* node) { ...@@ -1407,8 +1404,7 @@ Node* WasmGraphBuilder::MaskShiftCount64(Node* node) {
if (match.ResolvedValue() != masked) if (match.ResolvedValue() != masked)
node = mcgraph()->Int64Constant(masked); node = mcgraph()->Int64Constant(masked);
} else { } else {
node = graph()->NewNode(mcgraph()->machine()->Word64And(), node, node = gasm_->Word64And(node, mcgraph()->Int64Constant(kMask64));
mcgraph()->Int64Constant(kMask64));
} }
} }
return node; return node;
...@@ -1442,14 +1438,14 @@ Node* WasmGraphBuilder::BuildChangeEndiannessStore( ...@@ -1442,14 +1438,14 @@ Node* WasmGraphBuilder::BuildChangeEndiannessStore(
switch (wasmtype.kind()) { switch (wasmtype.kind()) {
case wasm::kF64: case wasm::kF64:
value = graph()->NewNode(m->BitcastFloat64ToInt64(), node); value = gasm_->BitcastFloat64ToInt64(node);
isFloat = true; isFloat = true;
V8_FALLTHROUGH; V8_FALLTHROUGH;
case wasm::kI64: case wasm::kI64:
result = mcgraph()->Int64Constant(0); result = mcgraph()->Int64Constant(0);
break; break;
case wasm::kF32: case wasm::kF32:
value = graph()->NewNode(m->BitcastFloat32ToInt32(), node); value = gasm_->BitcastFloat32ToInt32(node);
isFloat = true; isFloat = true;
V8_FALLTHROUGH; V8_FALLTHROUGH;
case wasm::kI32: case wasm::kI32:
...@@ -1469,17 +1465,15 @@ Node* WasmGraphBuilder::BuildChangeEndiannessStore( ...@@ -1469,17 +1465,15 @@ Node* WasmGraphBuilder::BuildChangeEndiannessStore(
if (wasmtype == wasm::kWasmI64 && mem_rep < MachineRepresentation::kWord64) { if (wasmtype == wasm::kWasmI64 && mem_rep < 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 = gasm_->TruncateInt64ToInt32(value);
valueSizeInBytes = wasm::kWasmI32.element_size_bytes(); valueSizeInBytes = wasm::kWasmI32.element_size_bytes();
valueSizeInBits = 8 * valueSizeInBytes; valueSizeInBits = 8 * valueSizeInBytes;
if (mem_rep == MachineRepresentation::kWord16) { if (mem_rep == MachineRepresentation::kWord16) {
value = value = gasm_->Word32Shl(value, mcgraph()->Int32Constant(16));
graph()->NewNode(m->Word32Shl(), value, mcgraph()->Int32Constant(16));
} }
} else if (wasmtype == wasm::kWasmI32 && } else if (wasmtype == wasm::kWasmI32 &&
mem_rep == MachineRepresentation::kWord16) { mem_rep == MachineRepresentation::kWord16) {
value = value = gasm_->Word32Shl(value, mcgraph()->Int32Constant(16));
graph()->NewNode(m->Word32Shl(), value, mcgraph()->Int32Constant(16));
} }
int i; int i;
...@@ -1488,10 +1482,10 @@ Node* WasmGraphBuilder::BuildChangeEndiannessStore( ...@@ -1488,10 +1482,10 @@ Node* WasmGraphBuilder::BuildChangeEndiannessStore(
if (ReverseBytesSupported(m, valueSizeInBytes)) { if (ReverseBytesSupported(m, valueSizeInBytes)) {
switch (valueSizeInBytes) { switch (valueSizeInBytes) {
case 4: case 4:
result = graph()->NewNode(m->Word32ReverseBytes(), value); result = gasm_->Word32ReverseBytes(value);
break; break;
case 8: case 8:
result = graph()->NewNode(m->Word64ReverseBytes(), value); result = gasm_->Word64ReverseBytes(value);
break; break;
case 16: case 16:
result = graph()->NewNode(m->Simd128ReverseBytes(), value); result = graph()->NewNode(m->Simd128ReverseBytes(), value);
...@@ -1512,33 +1506,31 @@ Node* WasmGraphBuilder::BuildChangeEndiannessStore( ...@@ -1512,33 +1506,31 @@ Node* WasmGraphBuilder::BuildChangeEndiannessStore(
DCHECK_EQ(0, (shiftCount + 8) % 16); DCHECK_EQ(0, (shiftCount + 8) % 16);
if (valueSizeInBits > 32) { if (valueSizeInBits > 32) {
shiftLower = graph()->NewNode(m->Word64Shl(), value, shiftLower =
mcgraph()->Int64Constant(shiftCount)); gasm_->Word64Shl(value, mcgraph()->Int64Constant(shiftCount));
shiftHigher = graph()->NewNode(m->Word64Shr(), value, shiftHigher =
mcgraph()->Int64Constant(shiftCount)); gasm_->Word64Shr(value, mcgraph()->Int64Constant(shiftCount));
lowerByte = graph()->NewNode( lowerByte = gasm_->Word64And(
m->Word64And(), shiftLower, shiftLower, mcgraph()->Int64Constant(static_cast<uint64_t>(0xFF)
mcgraph()->Int64Constant(static_cast<uint64_t>(0xFF) << (valueSizeInBits - 8 - i)));
<< (valueSizeInBits - 8 - i))); higherByte = gasm_->Word64And(
higherByte = graph()->NewNode( shiftHigher,
m->Word64And(), shiftHigher,
mcgraph()->Int64Constant(static_cast<uint64_t>(0xFF) << i)); mcgraph()->Int64Constant(static_cast<uint64_t>(0xFF) << i));
result = graph()->NewNode(m->Word64Or(), result, lowerByte); result = gasm_->Word64Or(result, lowerByte);
result = graph()->NewNode(m->Word64Or(), result, higherByte); result = gasm_->Word64Or(result, higherByte);
} else { } else {
shiftLower = graph()->NewNode(m->Word32Shl(), value, shiftLower =
mcgraph()->Int32Constant(shiftCount)); gasm_->Word32Shl(value, mcgraph()->Int32Constant(shiftCount));
shiftHigher = graph()->NewNode(m->Word32Shr(), value, shiftHigher =
mcgraph()->Int32Constant(shiftCount)); gasm_->Word32Shr(value, mcgraph()->Int32Constant(shiftCount));
lowerByte = graph()->NewNode( lowerByte = gasm_->Word32And(
m->Word32And(), shiftLower, shiftLower, mcgraph()->Int32Constant(static_cast<uint32_t>(0xFF)
mcgraph()->Int32Constant(static_cast<uint32_t>(0xFF) << (valueSizeInBits - 8 - i)));
<< (valueSizeInBits - 8 - i))); higherByte = gasm_->Word32And(
higherByte = graph()->NewNode( shiftHigher,
m->Word32And(), shiftHigher,
mcgraph()->Int32Constant(static_cast<uint32_t>(0xFF) << i)); mcgraph()->Int32Constant(static_cast<uint32_t>(0xFF) << i));
result = graph()->NewNode(m->Word32Or(), result, lowerByte); result = gasm_->Word32Or(result, lowerByte);
result = graph()->NewNode(m->Word32Or(), result, higherByte); result = gasm_->Word32Or(result, higherByte);
} }
} }
} }
...@@ -1546,10 +1538,10 @@ Node* WasmGraphBuilder::BuildChangeEndiannessStore( ...@@ -1546,10 +1538,10 @@ Node* WasmGraphBuilder::BuildChangeEndiannessStore(
if (isFloat) { if (isFloat) {
switch (wasmtype.kind()) { switch (wasmtype.kind()) {
case wasm::kF64: case wasm::kF64:
result = graph()->NewNode(m->BitcastInt64ToFloat64(), result); result = gasm_->BitcastInt64ToFloat64(result);
break; break;
case wasm::kF32: case wasm::kF32:
result = graph()->NewNode(m->BitcastInt32ToFloat32(), result); result = gasm_->BitcastInt32ToFloat32(result);
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -1572,14 +1564,14 @@ Node* WasmGraphBuilder::BuildChangeEndiannessLoad(Node* node, ...@@ -1572,14 +1564,14 @@ Node* WasmGraphBuilder::BuildChangeEndiannessLoad(Node* node,
switch (memtype.representation()) { switch (memtype.representation()) {
case MachineRepresentation::kFloat64: case MachineRepresentation::kFloat64:
value = graph()->NewNode(m->BitcastFloat64ToInt64(), node); value = gasm_->BitcastFloat64ToInt64(node);
isFloat = true; isFloat = true;
V8_FALLTHROUGH; V8_FALLTHROUGH;
case MachineRepresentation::kWord64: case MachineRepresentation::kWord64:
result = mcgraph()->Int64Constant(0); result = mcgraph()->Int64Constant(0);
break; break;
case MachineRepresentation::kFloat32: case MachineRepresentation::kFloat32:
value = graph()->NewNode(m->BitcastFloat32ToInt32(), node); value = gasm_->BitcastFloat32ToInt32(node);
isFloat = true; isFloat = true;
V8_FALLTHROUGH; V8_FALLTHROUGH;
case MachineRepresentation::kWord32: case MachineRepresentation::kWord32:
...@@ -1603,16 +1595,14 @@ Node* WasmGraphBuilder::BuildChangeEndiannessLoad(Node* node, ...@@ -1603,16 +1595,14 @@ Node* WasmGraphBuilder::BuildChangeEndiannessLoad(Node* node,
if (ReverseBytesSupported(m, valueSizeInBytes < 4 ? 4 : valueSizeInBytes)) { if (ReverseBytesSupported(m, valueSizeInBytes < 4 ? 4 : valueSizeInBytes)) {
switch (valueSizeInBytes) { switch (valueSizeInBytes) {
case 2: case 2:
result = result = gasm_->Word32ReverseBytes(
graph()->NewNode(m->Word32ReverseBytes(), gasm_->Word32Shl(value, mcgraph()->Int32Constant(16)));
graph()->NewNode(m->Word32Shl(), value,
mcgraph()->Int32Constant(16)));
break; break;
case 4: case 4:
result = graph()->NewNode(m->Word32ReverseBytes(), value); result = gasm_->Word32ReverseBytes(value);
break; break;
case 8: case 8:
result = graph()->NewNode(m->Word64ReverseBytes(), value); result = gasm_->Word64ReverseBytes(value);
break; break;
case 16: case 16:
result = graph()->NewNode(m->Simd128ReverseBytes(), value); result = graph()->NewNode(m->Simd128ReverseBytes(), value);
...@@ -1632,33 +1622,31 @@ Node* WasmGraphBuilder::BuildChangeEndiannessLoad(Node* node, ...@@ -1632,33 +1622,31 @@ Node* WasmGraphBuilder::BuildChangeEndiannessLoad(Node* node,
DCHECK_EQ(0, (shiftCount + 8) % 16); DCHECK_EQ(0, (shiftCount + 8) % 16);
if (valueSizeInBits > 32) { if (valueSizeInBits > 32) {
shiftLower = graph()->NewNode(m->Word64Shl(), value, shiftLower =
mcgraph()->Int64Constant(shiftCount)); gasm_->Word64Shl(value, mcgraph()->Int64Constant(shiftCount));
shiftHigher = graph()->NewNode(m->Word64Shr(), value, shiftHigher =
mcgraph()->Int64Constant(shiftCount)); gasm_->Word64Shr(value, mcgraph()->Int64Constant(shiftCount));
lowerByte = graph()->NewNode( lowerByte = gasm_->Word64And(
m->Word64And(), shiftLower, shiftLower, mcgraph()->Int64Constant(static_cast<uint64_t>(0xFF)
mcgraph()->Int64Constant(static_cast<uint64_t>(0xFF) << (valueSizeInBits - 8 - i)));
<< (valueSizeInBits - 8 - i))); higherByte = gasm_->Word64And(
higherByte = graph()->NewNode( shiftHigher,
m->Word64And(), shiftHigher,
mcgraph()->Int64Constant(static_cast<uint64_t>(0xFF) << i)); mcgraph()->Int64Constant(static_cast<uint64_t>(0xFF) << i));
result = graph()->NewNode(m->Word64Or(), result, lowerByte); result = gasm_->Word64Or(result, lowerByte);
result = graph()->NewNode(m->Word64Or(), result, higherByte); result = gasm_->Word64Or(result, higherByte);
} else { } else {
shiftLower = graph()->NewNode(m->Word32Shl(), value, shiftLower =
mcgraph()->Int32Constant(shiftCount)); gasm_->Word32Shl(value, mcgraph()->Int32Constant(shiftCount));
shiftHigher = graph()->NewNode(m->Word32Shr(), value, shiftHigher =
mcgraph()->Int32Constant(shiftCount)); gasm_->Word32Shr(value, mcgraph()->Int32Constant(shiftCount));
lowerByte = graph()->NewNode( lowerByte = gasm_->Word32And(
m->Word32And(), shiftLower, shiftLower, mcgraph()->Int32Constant(static_cast<uint32_t>(0xFF)
mcgraph()->Int32Constant(static_cast<uint32_t>(0xFF) << (valueSizeInBits - 8 - i)));
<< (valueSizeInBits - 8 - i))); higherByte = gasm_->Word32And(
higherByte = graph()->NewNode( shiftHigher,
m->Word32And(), shiftHigher,
mcgraph()->Int32Constant(static_cast<uint32_t>(0xFF) << i)); mcgraph()->Int32Constant(static_cast<uint32_t>(0xFF) << i));
result = graph()->NewNode(m->Word32Or(), result, lowerByte); result = gasm_->Word32Or(result, lowerByte);
result = graph()->NewNode(m->Word32Or(), result, higherByte); result = gasm_->Word32Or(result, higherByte);
} }
} }
} }
...@@ -1666,10 +1654,10 @@ Node* WasmGraphBuilder::BuildChangeEndiannessLoad(Node* node, ...@@ -1666,10 +1654,10 @@ Node* WasmGraphBuilder::BuildChangeEndiannessLoad(Node* node,
if (isFloat) { if (isFloat) {
switch (memtype.representation()) { switch (memtype.representation()) {
case MachineRepresentation::kFloat64: case MachineRepresentation::kFloat64:
result = graph()->NewNode(m->BitcastInt64ToFloat64(), result); result = gasm_->BitcastInt64ToFloat64(result);
break; break;
case MachineRepresentation::kFloat32: case MachineRepresentation::kFloat32:
result = graph()->NewNode(m->BitcastInt32ToFloat32(), result); result = gasm_->BitcastInt32ToFloat32(result);
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -1687,18 +1675,13 @@ Node* WasmGraphBuilder::BuildChangeEndiannessLoad(Node* node, ...@@ -1687,18 +1675,13 @@ Node* WasmGraphBuilder::BuildChangeEndiannessLoad(Node* node,
// type_width) // type_width)
if (wasmtype == wasm::kWasmI64) { if (wasmtype == wasm::kWasmI64) {
shiftBitCount = mcgraph()->Int32Constant(64 - valueSizeInBits); shiftBitCount = mcgraph()->Int32Constant(64 - valueSizeInBits);
result = graph()->NewNode( result = gasm_->Word64Sar(
m->Word64Sar(), gasm_->Word64Shl(gasm_->ChangeInt32ToInt64(result), shiftBitCount),
graph()->NewNode(m->Word64Shl(),
graph()->NewNode(m->ChangeInt32ToInt64(), result),
shiftBitCount),
shiftBitCount); shiftBitCount);
} else if (wasmtype == wasm::kWasmI32) { } else if (wasmtype == wasm::kWasmI32) {
shiftBitCount = mcgraph()->Int32Constant(32 - valueSizeInBits); shiftBitCount = mcgraph()->Int32Constant(32 - valueSizeInBits);
result = graph()->NewNode( result = gasm_->Word32Sar(gasm_->Word32Shl(result, shiftBitCount),
m->Word32Sar(), shiftBitCount);
graph()->NewNode(m->Word32Shl(), result, shiftBitCount),
shiftBitCount);
} }
} }
} }
...@@ -2026,29 +2009,23 @@ Node* WasmGraphBuilder::BuildIntConvertFloat(Node* input, ...@@ -2026,29 +2009,23 @@ Node* WasmGraphBuilder::BuildIntConvertFloat(Node* input,
} }
Node* WasmGraphBuilder::BuildI32AsmjsSConvertF32(Node* input) { Node* WasmGraphBuilder::BuildI32AsmjsSConvertF32(Node* input) {
MachineOperatorBuilder* m = mcgraph()->machine();
// asm.js must use the wacky JS semantics. // asm.js must use the wacky JS semantics.
input = graph()->NewNode(m->ChangeFloat32ToFloat64(), input); return gasm_->TruncateFloat64ToWord32(gasm_->ChangeFloat32ToFloat64(input));
return graph()->NewNode(m->TruncateFloat64ToWord32(), input);
} }
Node* WasmGraphBuilder::BuildI32AsmjsSConvertF64(Node* input) { Node* WasmGraphBuilder::BuildI32AsmjsSConvertF64(Node* input) {
MachineOperatorBuilder* m = mcgraph()->machine();
// asm.js must use the wacky JS semantics. // asm.js must use the wacky JS semantics.
return graph()->NewNode(m->TruncateFloat64ToWord32(), input); return gasm_->TruncateFloat64ToWord32(input);
} }
Node* WasmGraphBuilder::BuildI32AsmjsUConvertF32(Node* input) { Node* WasmGraphBuilder::BuildI32AsmjsUConvertF32(Node* input) {
MachineOperatorBuilder* m = mcgraph()->machine();
// asm.js must use the wacky JS semantics. // asm.js must use the wacky JS semantics.
input = graph()->NewNode(m->ChangeFloat32ToFloat64(), input); return gasm_->TruncateFloat64ToWord32(gasm_->ChangeFloat32ToFloat64(input));
return graph()->NewNode(m->TruncateFloat64ToWord32(), input);
} }
Node* WasmGraphBuilder::BuildI32AsmjsUConvertF64(Node* input) { Node* WasmGraphBuilder::BuildI32AsmjsUConvertF64(Node* input) {
MachineOperatorBuilder* m = mcgraph()->machine();
// asm.js must use the wacky JS semantics. // asm.js must use the wacky JS semantics.
return graph()->NewNode(m->TruncateFloat64ToWord32(), input); return gasm_->TruncateFloat64ToWord32(input);
} }
Node* WasmGraphBuilder::BuildBitCountingCall(Node* input, ExternalReference ref, Node* WasmGraphBuilder::BuildBitCountingCall(Node* input, ExternalReference ref,
...@@ -2058,7 +2035,7 @@ Node* WasmGraphBuilder::BuildBitCountingCall(Node* input, ExternalReference ref, ...@@ -2058,7 +2035,7 @@ Node* WasmGraphBuilder::BuildBitCountingCall(Node* input, ExternalReference ref,
MachineType sig_types[] = {MachineType::Int32(), MachineType::Pointer()}; MachineType sig_types[] = {MachineType::Int32(), MachineType::Pointer()};
MachineSignature sig(1, 1, sig_types); MachineSignature sig(1, 1, sig_types);
Node* function = graph()->NewNode(mcgraph()->common()->ExternalConstant(ref)); Node* function = gasm_->ExternalConstant(ref);
return BuildCCall(&sig, function, stack_slot_param); return BuildCCall(&sig, function, stack_slot_param);
} }
...@@ -2178,12 +2155,10 @@ Node* WasmGraphBuilder::BuildCFuncInstruction(ExternalReference ref, ...@@ -2178,12 +2155,10 @@ Node* WasmGraphBuilder::BuildCFuncInstruction(ExternalReference ref,
MachineType sig_types[] = {MachineType::Pointer()}; MachineType sig_types[] = {MachineType::Pointer()};
MachineSignature sig(0, 1, sig_types); MachineSignature sig(0, 1, sig_types);
Node* function = graph()->NewNode(mcgraph()->common()->ExternalConstant(ref)); Node* function = gasm_->ExternalConstant(ref);
BuildCCall(&sig, function, stack_slot); BuildCCall(&sig, function, stack_slot);
return SetEffect(graph()->NewNode(mcgraph()->machine()->Load(type), return gasm_->Load(type, stack_slot, 0);
stack_slot, mcgraph()->Int32Constant(0),
effect(), control()));
} }
Node* WasmGraphBuilder::BuildF32SConvertI64(Node* input) { Node* WasmGraphBuilder::BuildF32SConvertI64(Node* input) {
...@@ -2218,17 +2193,14 @@ Node* WasmGraphBuilder::BuildIntToFloatConversionInstruction( ...@@ -2218,17 +2193,14 @@ Node* WasmGraphBuilder::BuildIntToFloatConversionInstruction(
ElementSizeInBytes(result_type.representation())); ElementSizeInBytes(result_type.representation()));
Node* stack_slot = Node* stack_slot =
graph()->NewNode(mcgraph()->machine()->StackSlot(stack_slot_size)); graph()->NewNode(mcgraph()->machine()->StackSlot(stack_slot_size));
const Operator* store_op = mcgraph()->machine()->Store( auto store_rep =
StoreRepresentation(parameter_representation, kNoWriteBarrier)); StoreRepresentation(parameter_representation, kNoWriteBarrier);
SetEffect(graph()->NewNode(store_op, stack_slot, mcgraph()->Int32Constant(0), gasm_->Store(store_rep, stack_slot, 0, input);
input, effect(), control()));
MachineType sig_types[] = {MachineType::Pointer()}; MachineType sig_types[] = {MachineType::Pointer()};
MachineSignature sig(0, 1, sig_types); MachineSignature sig(0, 1, sig_types);
Node* function = graph()->NewNode(mcgraph()->common()->ExternalConstant(ref)); Node* function = gasm_->ExternalConstant(ref);
BuildCCall(&sig, function, stack_slot); BuildCCall(&sig, function, stack_slot);
return SetEffect(graph()->NewNode(mcgraph()->machine()->Load(result_type), return gasm_->Load(result_type, stack_slot, 0);
stack_slot, mcgraph()->Int32Constant(0),
effect(), control()));
} }
namespace { namespace {
...@@ -2265,20 +2237,16 @@ Node* WasmGraphBuilder::BuildCcallConvertFloat(Node* input, ...@@ -2265,20 +2237,16 @@ Node* WasmGraphBuilder::BuildCcallConvertFloat(Node* input,
ElementSizeInBytes(float_ty.representation())); ElementSizeInBytes(float_ty.representation()));
Node* stack_slot = Node* stack_slot =
graph()->NewNode(mcgraph()->machine()->StackSlot(stack_slot_size)); graph()->NewNode(mcgraph()->machine()->StackSlot(stack_slot_size));
const Operator* store_op = mcgraph()->machine()->Store( auto store_rep =
StoreRepresentation(float_ty.representation(), kNoWriteBarrier)); StoreRepresentation(float_ty.representation(), kNoWriteBarrier);
SetEffect(graph()->NewNode(store_op, stack_slot, Int32Constant(0), input, gasm_->Store(store_rep, stack_slot, 0, input);
effect(), control()));
MachineType sig_types[] = {MachineType::Int32(), MachineType::Pointer()}; MachineType sig_types[] = {MachineType::Int32(), MachineType::Pointer()};
MachineSignature sig(1, 1, sig_types); MachineSignature sig(1, 1, sig_types);
Node* function = Node* function = gasm_->ExternalConstant(call_ref);
graph()->NewNode(mcgraph()->common()->ExternalConstant(call_ref));
Node* overflow = BuildCCall(&sig, function, stack_slot); Node* overflow = BuildCCall(&sig, function, stack_slot);
if (IsTrappingConvertOp(opcode)) { if (IsTrappingConvertOp(opcode)) {
ZeroCheck32(wasm::kTrapFloatUnrepresentable, overflow, position); ZeroCheck32(wasm::kTrapFloatUnrepresentable, overflow, position);
return SetEffect(graph()->NewNode(mcgraph()->machine()->Load(int_ty), return gasm_->Load(int_ty, stack_slot, 0);
stack_slot, Int32Constant(0), effect(),
control()));
} }
Node* test = Binop(wasm::kExprI32Eq, overflow, Int32Constant(0), position); Node* test = Binop(wasm::kExprI32Eq, overflow, Int32Constant(0), position);
Diamond tl_d(graph(), mcgraph()->common(), test, BranchHint::kFalse); Diamond tl_d(graph(), mcgraph()->common(), test, BranchHint::kFalse);
...@@ -2291,9 +2259,7 @@ Node* WasmGraphBuilder::BuildCcallConvertFloat(Node* input, ...@@ -2291,9 +2259,7 @@ Node* WasmGraphBuilder::BuildCcallConvertFloat(Node* input,
sat_d.Nest(nan_d, false); sat_d.Nest(nan_d, false);
Node* sat_val = Node* sat_val =
sat_d.Phi(int_ty.representation(), Min(this, int_ty), Max(this, int_ty)); sat_d.Phi(int_ty.representation(), Min(this, int_ty), Max(this, int_ty));
Node* load = Node* load = gasm_->Load(int_ty, stack_slot, 0);
SetEffect(graph()->NewNode(mcgraph()->machine()->Load(int_ty), stack_slot,
Int32Constant(0), effect(), control()));
Node* nan_val = Node* nan_val =
nan_d.Phi(int_ty.representation(), Zero(this, int_ty), sat_val); nan_d.Phi(int_ty.representation(), Zero(this, int_ty), sat_val);
return tl_d.Phi(int_ty.representation(), nan_val, load); return tl_d.Phi(int_ty.representation(), nan_val, load);
...@@ -2323,20 +2289,19 @@ Node* WasmGraphBuilder::Throw(uint32_t exception_index, ...@@ -2323,20 +2289,19 @@ Node* WasmGraphBuilder::Throw(uint32_t exception_index,
Node* value = values[i]; Node* value = values[i];
switch (sig->GetParam(i).kind()) { switch (sig->GetParam(i).kind()) {
case wasm::kF32: case wasm::kF32:
value = graph()->NewNode(m->BitcastFloat32ToInt32(), value); value = gasm_->BitcastFloat32ToInt32(value);
V8_FALLTHROUGH; V8_FALLTHROUGH;
case wasm::kI32: case wasm::kI32:
BuildEncodeException32BitValue(values_array, &index, value); BuildEncodeException32BitValue(values_array, &index, value);
break; break;
case wasm::kF64: case wasm::kF64:
value = graph()->NewNode(m->BitcastFloat64ToInt64(), value); value = gasm_->BitcastFloat64ToInt64(value);
V8_FALLTHROUGH; V8_FALLTHROUGH;
case wasm::kI64: { case wasm::kI64: {
Node* upper32 = graph()->NewNode( Node* upper32 = gasm_->TruncateInt64ToInt32(
m->TruncateInt64ToInt32(),
Binop(wasm::kExprI64ShrU, value, Int64Constant(32))); Binop(wasm::kExprI64ShrU, value, Int64Constant(32)));
BuildEncodeException32BitValue(values_array, &index, upper32); BuildEncodeException32BitValue(values_array, &index, upper32);
Node* lower32 = graph()->NewNode(m->TruncateInt64ToInt32(), value); Node* lower32 = gasm_->TruncateInt64ToInt32(value);
BuildEncodeException32BitValue(values_array, &index, lower32); BuildEncodeException32BitValue(values_array, &index, lower32);
break; break;
} }
...@@ -2381,28 +2346,26 @@ Node* WasmGraphBuilder::Throw(uint32_t exception_index, ...@@ -2381,28 +2346,26 @@ Node* WasmGraphBuilder::Throw(uint32_t exception_index,
void WasmGraphBuilder::BuildEncodeException32BitValue(Node* values_array, void WasmGraphBuilder::BuildEncodeException32BitValue(Node* values_array,
uint32_t* index, uint32_t* index,
Node* value) { Node* value) {
MachineOperatorBuilder* machine = mcgraph()->machine(); Node* upper_halfword_as_smi =
Node* upper_halfword_as_smi = BuildChangeUint31ToSmi( BuildChangeUint31ToSmi(gasm_->Word32Shr(value, Int32Constant(16)));
graph()->NewNode(machine->Word32Shr(), value, Int32Constant(16)));
STORE_FIXED_ARRAY_SLOT_SMI(values_array, *index, upper_halfword_as_smi); STORE_FIXED_ARRAY_SLOT_SMI(values_array, *index, upper_halfword_as_smi);
++(*index); ++(*index);
Node* lower_halfword_as_smi = BuildChangeUint31ToSmi( Node* lower_halfword_as_smi =
graph()->NewNode(machine->Word32And(), value, Int32Constant(0xFFFFu))); BuildChangeUint31ToSmi(gasm_->Word32And(value, Int32Constant(0xFFFFu)));
STORE_FIXED_ARRAY_SLOT_SMI(values_array, *index, lower_halfword_as_smi); STORE_FIXED_ARRAY_SLOT_SMI(values_array, *index, lower_halfword_as_smi);
++(*index); ++(*index);
} }
Node* WasmGraphBuilder::BuildDecodeException32BitValue(Node* values_array, Node* WasmGraphBuilder::BuildDecodeException32BitValue(Node* values_array,
uint32_t* index) { uint32_t* index) {
MachineOperatorBuilder* machine = mcgraph()->machine();
Node* upper = Node* upper =
BuildChangeSmiToInt32(LOAD_FIXED_ARRAY_SLOT_SMI(values_array, *index)); BuildChangeSmiToInt32(LOAD_FIXED_ARRAY_SLOT_SMI(values_array, *index));
(*index)++; (*index)++;
upper = graph()->NewNode(machine->Word32Shl(), upper, Int32Constant(16)); upper = gasm_->Word32Shl(upper, Int32Constant(16));
Node* lower = Node* lower =
BuildChangeSmiToInt32(LOAD_FIXED_ARRAY_SLOT_SMI(values_array, *index)); BuildChangeSmiToInt32(LOAD_FIXED_ARRAY_SLOT_SMI(values_array, *index));
(*index)++; (*index)++;
Node* value = graph()->NewNode(machine->Word32Or(), upper, lower); Node* value = gasm_->Word32Or(upper, lower);
return value; return value;
} }
...@@ -2426,8 +2389,7 @@ Node* WasmGraphBuilder::Rethrow(Node* except_obj) { ...@@ -2426,8 +2389,7 @@ Node* WasmGraphBuilder::Rethrow(Node* except_obj) {
Node* WasmGraphBuilder::ExceptionTagEqual(Node* caught_tag, Node* WasmGraphBuilder::ExceptionTagEqual(Node* caught_tag,
Node* expected_tag) { Node* expected_tag) {
MachineOperatorBuilder* machine = mcgraph()->machine(); return gasm_->WordEqual(caught_tag, expected_tag);
return graph()->NewNode(machine->WordEqual(), caught_tag, expected_tag);
} }
Node* WasmGraphBuilder::LoadExceptionTagFromTable(uint32_t exception_index) { Node* WasmGraphBuilder::LoadExceptionTagFromTable(uint32_t exception_index) {
...@@ -2512,23 +2474,20 @@ Node* WasmGraphBuilder::GetExceptionValues(Node* except_obj, ...@@ -2512,23 +2474,20 @@ Node* WasmGraphBuilder::GetExceptionValues(Node* except_obj,
Node* WasmGraphBuilder::BuildI32DivS(Node* left, Node* right, Node* WasmGraphBuilder::BuildI32DivS(Node* left, Node* right,
wasm::WasmCodePosition position) { wasm::WasmCodePosition position) {
MachineOperatorBuilder* m = mcgraph()->machine();
ZeroCheck32(wasm::kTrapDivByZero, right, position); ZeroCheck32(wasm::kTrapDivByZero, right, position);
Node* before = control(); Node* before = control();
Node* denom_is_m1; Node* denom_is_m1;
Node* denom_is_not_m1; Node* denom_is_not_m1;
BranchExpectFalse( BranchExpectFalse(gasm_->Word32Equal(right, mcgraph()->Int32Constant(-1)),
graph()->NewNode(m->Word32Equal(), right, mcgraph()->Int32Constant(-1)), &denom_is_m1, &denom_is_not_m1);
&denom_is_m1, &denom_is_not_m1);
SetControl(denom_is_m1); SetControl(denom_is_m1);
TrapIfEq32(wasm::kTrapDivUnrepresentable, left, kMinInt, position); TrapIfEq32(wasm::kTrapDivUnrepresentable, left, kMinInt, position);
if (control() != denom_is_m1) { if (control() != denom_is_m1) {
SetControl(graph()->NewNode(mcgraph()->common()->Merge(2), denom_is_not_m1, SetControl(Merge(denom_is_not_m1, control()));
control()));
} else { } else {
SetControl(before); SetControl(before);
} }
return graph()->NewNode(m->Int32Div(), left, right, control()); return gasm_->Int32Div(left, right);
} }
Node* WasmGraphBuilder::BuildI32RemS(Node* left, Node* right, Node* WasmGraphBuilder::BuildI32RemS(Node* left, Node* right,
...@@ -2537,10 +2496,9 @@ Node* WasmGraphBuilder::BuildI32RemS(Node* left, Node* right, ...@@ -2537,10 +2496,9 @@ Node* WasmGraphBuilder::BuildI32RemS(Node* left, Node* right,
ZeroCheck32(wasm::kTrapRemByZero, right, position); ZeroCheck32(wasm::kTrapRemByZero, right, position);
Diamond d( Diamond d(graph(), mcgraph()->common(),
graph(), mcgraph()->common(), gasm_->Word32Equal(right, mcgraph()->Int32Constant(-1)),
graph()->NewNode(m->Word32Equal(), right, mcgraph()->Int32Constant(-1)), BranchHint::kFalse);
BranchHint::kFalse);
d.Chain(control()); d.Chain(control());
return d.Phi(MachineRepresentation::kWord32, mcgraph()->Int32Constant(0), return d.Phi(MachineRepresentation::kWord32, mcgraph()->Int32Constant(0),
...@@ -2549,16 +2507,14 @@ Node* WasmGraphBuilder::BuildI32RemS(Node* left, Node* right, ...@@ -2549,16 +2507,14 @@ Node* WasmGraphBuilder::BuildI32RemS(Node* left, Node* right,
Node* WasmGraphBuilder::BuildI32DivU(Node* left, Node* right, Node* WasmGraphBuilder::BuildI32DivU(Node* left, Node* right,
wasm::WasmCodePosition position) { wasm::WasmCodePosition position) {
MachineOperatorBuilder* m = mcgraph()->machine(); ZeroCheck32(wasm::kTrapDivByZero, right, position);
return graph()->NewNode(m->Uint32Div(), left, right, return gasm_->Uint32Div(left, right);
ZeroCheck32(wasm::kTrapDivByZero, right, position));
} }
Node* WasmGraphBuilder::BuildI32RemU(Node* left, Node* right, Node* WasmGraphBuilder::BuildI32RemU(Node* left, Node* right,
wasm::WasmCodePosition position) { wasm::WasmCodePosition position) {
MachineOperatorBuilder* m = mcgraph()->machine(); ZeroCheck32(wasm::kTrapRemByZero, right, position);
return graph()->NewNode(m->Uint32Mod(), left, right, return gasm_->Uint32Mod(left, right);
ZeroCheck32(wasm::kTrapRemByZero, right, position));
} }
Node* WasmGraphBuilder::BuildI32AsmjsDivS(Node* left, Node* right) { Node* WasmGraphBuilder::BuildI32AsmjsDivS(Node* left, Node* right) {
...@@ -2570,35 +2526,32 @@ Node* WasmGraphBuilder::BuildI32AsmjsDivS(Node* left, Node* right) { ...@@ -2570,35 +2526,32 @@ Node* WasmGraphBuilder::BuildI32AsmjsDivS(Node* left, Node* right) {
return mcgraph()->Int32Constant(0); return mcgraph()->Int32Constant(0);
} else if (mr.ResolvedValue() == -1) { } else if (mr.ResolvedValue() == -1) {
// The result is the negation of the left input. // The result is the negation of the left input.
return graph()->NewNode(m->Int32Sub(), mcgraph()->Int32Constant(0), left); return gasm_->Int32Sub(mcgraph()->Int32Constant(0), left);
} }
return graph()->NewNode(m->Int32Div(), left, right, control()); return gasm_->Int32Div(left, right);
} }
// asm.js semantics return 0 on divide or mod by zero. // asm.js semantics return 0 on divide or mod by zero.
if (m->Int32DivIsSafe()) { if (m->Int32DivIsSafe()) {
// The hardware instruction does the right thing (e.g. arm). // The hardware instruction does the right thing (e.g. arm).
return graph()->NewNode(m->Int32Div(), left, right, control()); return gasm_->Int32Div(left, right);
} }
// Check denominator for zero. // Check denominator for zero.
Diamond z( Diamond z(graph(), mcgraph()->common(),
graph(), mcgraph()->common(), gasm_->Word32Equal(right, mcgraph()->Int32Constant(0)),
graph()->NewNode(m->Word32Equal(), right, mcgraph()->Int32Constant(0)), BranchHint::kFalse);
BranchHint::kFalse);
z.Chain(control()); z.Chain(control());
// Check denominator for -1. (avoid minint / -1 case). // Check denominator for -1. (avoid minint / -1 case).
Diamond n( Diamond n(graph(), mcgraph()->common(),
graph(), mcgraph()->common(), gasm_->Word32Equal(right, mcgraph()->Int32Constant(-1)),
graph()->NewNode(m->Word32Equal(), right, mcgraph()->Int32Constant(-1)), BranchHint::kFalse);
BranchHint::kFalse);
n.Chain(z.if_false); n.Chain(z.if_false);
Node* div = graph()->NewNode(m->Int32Div(), left, right, n.if_false); Node* div = graph()->NewNode(m->Int32Div(), left, right, n.if_false);
Node* neg = Node* neg = gasm_->Int32Sub(mcgraph()->Int32Constant(0), left);
graph()->NewNode(m->Int32Sub(), mcgraph()->Int32Constant(0), left);
return z.Phi(MachineRepresentation::kWord32, mcgraph()->Int32Constant(0), return z.Phi(MachineRepresentation::kWord32, mcgraph()->Int32Constant(0),
n.Phi(MachineRepresentation::kWord32, neg, div)); n.Phi(MachineRepresentation::kWord32, neg, div));
...@@ -2614,7 +2567,7 @@ Node* WasmGraphBuilder::BuildI32AsmjsRemS(Node* left, Node* right) { ...@@ -2614,7 +2567,7 @@ Node* WasmGraphBuilder::BuildI32AsmjsRemS(Node* left, Node* right) {
if (mr.ResolvedValue() == 0 || mr.ResolvedValue() == -1) { if (mr.ResolvedValue() == 0 || mr.ResolvedValue() == -1) {
return zero; return zero;
} }
return graph()->NewNode(m->Int32Mod(), left, right, control()); return gasm_->Int32Mod(left, right);
} }
// General case for signed integer modulus, with optimization for (unknown) // General case for signed integer modulus, with optimization for (unknown)
...@@ -2642,7 +2595,7 @@ Node* WasmGraphBuilder::BuildI32AsmjsRemS(Node* left, Node* right) { ...@@ -2642,7 +2595,7 @@ Node* WasmGraphBuilder::BuildI32AsmjsRemS(Node* left, Node* right) {
const Operator* const merge_op = c->Merge(2); const Operator* const merge_op = c->Merge(2);
const Operator* const phi_op = c->Phi(MachineRepresentation::kWord32, 2); const Operator* const phi_op = c->Phi(MachineRepresentation::kWord32, 2);
Node* check0 = graph()->NewNode(m->Int32LessThan(), zero, right); Node* check0 = gasm_->Int32LessThan(zero, right);
Node* branch0 = Node* branch0 =
graph()->NewNode(c->Branch(BranchHint::kTrue), check0, control()); graph()->NewNode(c->Branch(BranchHint::kTrue), check0, control());
...@@ -2707,14 +2660,13 @@ Node* WasmGraphBuilder::BuildI32AsmjsDivU(Node* left, Node* right) { ...@@ -2707,14 +2660,13 @@ Node* WasmGraphBuilder::BuildI32AsmjsDivU(Node* left, Node* right) {
// asm.js semantics return 0 on divide or mod by zero. // asm.js semantics return 0 on divide or mod by zero.
if (m->Uint32DivIsSafe()) { if (m->Uint32DivIsSafe()) {
// The hardware instruction does the right thing (e.g. arm). // The hardware instruction does the right thing (e.g. arm).
return graph()->NewNode(m->Uint32Div(), left, right, control()); return gasm_->Uint32Div(left, right);
} }
// Explicit check for x % 0. // Explicit check for x % 0.
Diamond z( Diamond z(graph(), mcgraph()->common(),
graph(), mcgraph()->common(), gasm_->Word32Equal(right, mcgraph()->Int32Constant(0)),
graph()->NewNode(m->Word32Equal(), right, mcgraph()->Int32Constant(0)), BranchHint::kFalse);
BranchHint::kFalse);
z.Chain(control()); z.Chain(control());
return z.Phi(MachineRepresentation::kWord32, mcgraph()->Int32Constant(0), return z.Phi(MachineRepresentation::kWord32, mcgraph()->Int32Constant(0),
...@@ -2723,13 +2675,11 @@ Node* WasmGraphBuilder::BuildI32AsmjsDivU(Node* left, Node* right) { ...@@ -2723,13 +2675,11 @@ Node* WasmGraphBuilder::BuildI32AsmjsDivU(Node* left, Node* right) {
} }
Node* WasmGraphBuilder::BuildI32AsmjsRemU(Node* left, Node* right) { Node* WasmGraphBuilder::BuildI32AsmjsRemU(Node* left, Node* right) {
MachineOperatorBuilder* m = mcgraph()->machine();
// asm.js semantics return 0 on divide or mod by zero. // asm.js semantics return 0 on divide or mod by zero.
// Explicit check for x % 0. // Explicit check for x % 0.
Diamond z( Diamond z(graph(), mcgraph()->common(),
graph(), mcgraph()->common(), gasm_->Word32Equal(right, mcgraph()->Int32Constant(0)),
graph()->NewNode(m->Word32Equal(), right, mcgraph()->Int32Constant(0)), BranchHint::kFalse);
BranchHint::kFalse);
z.Chain(control()); z.Chain(control());
Node* rem = graph()->NewNode(mcgraph()->machine()->Uint32Mod(), left, right, Node* rem = graph()->NewNode(mcgraph()->machine()->Uint32Mod(), left, right,
...@@ -2748,20 +2698,17 @@ Node* WasmGraphBuilder::BuildI64DivS(Node* left, Node* right, ...@@ -2748,20 +2698,17 @@ Node* WasmGraphBuilder::BuildI64DivS(Node* left, Node* right,
Node* before = control(); Node* before = control();
Node* denom_is_m1; Node* denom_is_m1;
Node* denom_is_not_m1; Node* denom_is_not_m1;
BranchExpectFalse(graph()->NewNode(mcgraph()->machine()->Word64Equal(), right, BranchExpectFalse(gasm_->Word64Equal(right, mcgraph()->Int64Constant(-1)),
mcgraph()->Int64Constant(-1)),
&denom_is_m1, &denom_is_not_m1); &denom_is_m1, &denom_is_not_m1);
SetControl(denom_is_m1); SetControl(denom_is_m1);
TrapIfEq64(wasm::kTrapDivUnrepresentable, left, TrapIfEq64(wasm::kTrapDivUnrepresentable, left,
std::numeric_limits<int64_t>::min(), position); std::numeric_limits<int64_t>::min(), position);
if (control() != denom_is_m1) { if (control() != denom_is_m1) {
SetControl(graph()->NewNode(mcgraph()->common()->Merge(2), denom_is_not_m1, SetControl(Merge(denom_is_not_m1, control()));
control()));
} else { } else {
SetControl(before); SetControl(before);
} }
return graph()->NewNode(mcgraph()->machine()->Int64Div(), left, right, return gasm_->Int64Div(left, right);
control());
} }
Node* WasmGraphBuilder::BuildI64RemS(Node* left, Node* right, Node* WasmGraphBuilder::BuildI64RemS(Node* left, Node* right,
...@@ -2772,8 +2719,7 @@ Node* WasmGraphBuilder::BuildI64RemS(Node* left, Node* right, ...@@ -2772,8 +2719,7 @@ Node* WasmGraphBuilder::BuildI64RemS(Node* left, Node* right,
} }
ZeroCheck64(wasm::kTrapRemByZero, right, position); ZeroCheck64(wasm::kTrapRemByZero, right, position);
Diamond d(mcgraph()->graph(), mcgraph()->common(), Diamond d(mcgraph()->graph(), mcgraph()->common(),
graph()->NewNode(mcgraph()->machine()->Word64Equal(), right, gasm_->Word64Equal(right, mcgraph()->Int64Constant(-1)));
mcgraph()->Int64Constant(-1)));
d.Chain(control()); d.Chain(control());
...@@ -2790,8 +2736,8 @@ Node* WasmGraphBuilder::BuildI64DivU(Node* left, Node* right, ...@@ -2790,8 +2736,8 @@ Node* WasmGraphBuilder::BuildI64DivU(Node* left, Node* right,
return BuildDiv64Call(left, right, ExternalReference::wasm_uint64_div(), return BuildDiv64Call(left, right, ExternalReference::wasm_uint64_div(),
MachineType::Int64(), wasm::kTrapDivByZero, position); MachineType::Int64(), wasm::kTrapDivByZero, position);
} }
return graph()->NewNode(mcgraph()->machine()->Uint64Div(), left, right, ZeroCheck64(wasm::kTrapDivByZero, right, position);
ZeroCheck64(wasm::kTrapDivByZero, right, position)); return gasm_->Uint64Div(left, right);
} }
Node* WasmGraphBuilder::BuildI64RemU(Node* left, Node* right, Node* WasmGraphBuilder::BuildI64RemU(Node* left, Node* right,
wasm::WasmCodePosition position) { wasm::WasmCodePosition position) {
...@@ -2799,8 +2745,8 @@ Node* WasmGraphBuilder::BuildI64RemU(Node* left, Node* right, ...@@ -2799,8 +2745,8 @@ Node* WasmGraphBuilder::BuildI64RemU(Node* left, Node* right,
return BuildDiv64Call(left, right, ExternalReference::wasm_uint64_mod(), return BuildDiv64Call(left, right, ExternalReference::wasm_uint64_mod(),
MachineType::Int64(), wasm::kTrapRemByZero, position); MachineType::Int64(), wasm::kTrapRemByZero, position);
} }
return graph()->NewNode(mcgraph()->machine()->Uint64Mod(), left, right, ZeroCheck64(wasm::kTrapRemByZero, right, position);
ZeroCheck64(wasm::kTrapRemByZero, right, position)); return gasm_->Uint64Mod(left, right);
} }
Node* WasmGraphBuilder::BuildDiv64Call(Node* left, Node* right, Node* WasmGraphBuilder::BuildDiv64Call(Node* left, Node* right,
...@@ -2815,14 +2761,12 @@ Node* WasmGraphBuilder::BuildDiv64Call(Node* left, Node* right, ...@@ -2815,14 +2761,12 @@ Node* WasmGraphBuilder::BuildDiv64Call(Node* left, Node* right,
MachineType sig_types[] = {MachineType::Int32(), MachineType::Pointer()}; MachineType sig_types[] = {MachineType::Int32(), MachineType::Pointer()};
MachineSignature sig(1, 1, sig_types); MachineSignature sig(1, 1, sig_types);
Node* function = graph()->NewNode(mcgraph()->common()->ExternalConstant(ref)); Node* function = gasm_->ExternalConstant(ref);
Node* call = BuildCCall(&sig, function, stack_slot); Node* call = BuildCCall(&sig, function, stack_slot);
ZeroCheck32(trap_zero, call, position); ZeroCheck32(trap_zero, call, position);
TrapIfEq32(wasm::kTrapDivUnrepresentable, call, -1, position); TrapIfEq32(wasm::kTrapDivUnrepresentable, call, -1, position);
return SetEffect(graph()->NewNode(mcgraph()->machine()->Load(result_type), return gasm_->Load(result_type, stack_slot, 0);
stack_slot, mcgraph()->Int32Constant(0),
effect(), control()));
} }
template <typename... Args> template <typename... Args>
...@@ -2830,13 +2774,12 @@ Node* WasmGraphBuilder::BuildCCall(MachineSignature* sig, Node* function, ...@@ -2830,13 +2774,12 @@ Node* WasmGraphBuilder::BuildCCall(MachineSignature* sig, Node* function,
Args... args) { Args... args) {
DCHECK_LE(sig->return_count(), 1); DCHECK_LE(sig->return_count(), 1);
DCHECK_EQ(sizeof...(args), sig->parameter_count()); DCHECK_EQ(sizeof...(args), sig->parameter_count());
Node* const call_args[] = {function, args..., effect(), control()}; Node* call_args[] = {function, args..., effect(), control()};
auto call_descriptor = auto call_descriptor =
Linkage::GetSimplifiedCDescriptor(mcgraph()->zone(), sig); Linkage::GetSimplifiedCDescriptor(mcgraph()->zone(), sig);
const Operator* op = mcgraph()->common()->Call(call_descriptor); return gasm_->Call(call_descriptor, arraysize(call_args), call_args);
return SetEffect(graph()->NewNode(op, arraysize(call_args), call_args));
} }
Node* WasmGraphBuilder::BuildCallNode(const wasm::FunctionSig* sig, Node* WasmGraphBuilder::BuildCallNode(const wasm::FunctionSig* sig,
...@@ -2937,10 +2880,8 @@ Node* WasmGraphBuilder::BuildImportCall(const wasm::FunctionSig* sig, ...@@ -2937,10 +2880,8 @@ Node* WasmGraphBuilder::BuildImportCall(const wasm::FunctionSig* sig,
// Load the target from the imported_targets array at a known offset. // Load the target from the imported_targets array at a known offset.
Node* imported_targets = Node* imported_targets =
LOAD_INSTANCE_FIELD(ImportedFunctionTargets, MachineType::Pointer()); LOAD_INSTANCE_FIELD(ImportedFunctionTargets, MachineType::Pointer());
Node* target_node = SetEffect(graph()->NewNode( Node* target_node = gasm_->Load(MachineType::Pointer(), imported_targets,
mcgraph()->machine()->Load(MachineType::Pointer()), imported_targets, func_index * kSystemPointerSize);
mcgraph()->Int32Constant(func_index * kSystemPointerSize), effect(),
control()));
args[0] = target_node; args[0] = target_node;
const UseRetpoline use_retpoline = const UseRetpoline use_retpoline =
untrusted_code_mitigations_ ? kRetpoline : kNoRetpoline; untrusted_code_mitigations_ ? kRetpoline : kNoRetpoline;
...@@ -2973,9 +2914,8 @@ Node* WasmGraphBuilder::BuildImportCall(const wasm::FunctionSig* sig, ...@@ -2973,9 +2914,8 @@ Node* WasmGraphBuilder::BuildImportCall(const wasm::FunctionSig* sig,
func_index_intptr, gasm_->IntPtrConstant(kSystemPointerSize)); func_index_intptr, gasm_->IntPtrConstant(kSystemPointerSize));
Node* imported_targets = Node* imported_targets =
LOAD_INSTANCE_FIELD(ImportedFunctionTargets, MachineType::Pointer()); LOAD_INSTANCE_FIELD(ImportedFunctionTargets, MachineType::Pointer());
Node* target_node = SetEffect(graph()->NewNode( Node* target_node = gasm_->Load(MachineType::Pointer(), imported_targets,
mcgraph()->machine()->Load(MachineType::Pointer()), imported_targets, func_index_times_pointersize);
func_index_times_pointersize, effect(), control()));
args[0] = target_node; args[0] = target_node;
const UseRetpoline use_retpoline = const UseRetpoline use_retpoline =
untrusted_code_mitigations_ ? kRetpoline : kNoRetpoline; untrusted_code_mitigations_ ? kRetpoline : kNoRetpoline;
...@@ -3072,32 +3012,27 @@ Node* WasmGraphBuilder::BuildIndirectCall(uint32_t table_index, ...@@ -3072,32 +3012,27 @@ Node* WasmGraphBuilder::BuildIndirectCall(uint32_t table_index,
const wasm::FunctionSig* sig = env_->module->signature(sig_index); const wasm::FunctionSig* sig = env_->module->signature(sig_index);
MachineOperatorBuilder* machine = mcgraph()->machine();
Node* key = args[0]; Node* key = args[0];
// Bounds check against the table size. // Bounds check against the table size.
Node* in_bounds = graph()->NewNode(machine->Uint32LessThan(), key, ift_size); Node* in_bounds = gasm_->Uint32LessThan(key, ift_size);
TrapIfFalse(wasm::kTrapTableOutOfBounds, in_bounds, position); TrapIfFalse(wasm::kTrapTableOutOfBounds, in_bounds, position);
// Mask the key to prevent SSCA. // Mask the key to prevent SSCA.
if (untrusted_code_mitigations_) { if (untrusted_code_mitigations_) {
// mask = ((key - size) & ~key) >> 31 // mask = ((key - size) & ~key) >> 31
Node* neg_key = Node* neg_key = gasm_->Word32Xor(key, Int32Constant(-1));
graph()->NewNode(machine->Word32Xor(), key, Int32Constant(-1)); Node* masked_diff =
Node* masked_diff = graph()->NewNode( gasm_->Word32And(gasm_->Int32Sub(key, ift_size), neg_key);
machine->Word32And(), Node* mask = gasm_->Word32Sar(masked_diff, Int32Constant(31));
graph()->NewNode(machine->Int32Sub(), key, ift_size), neg_key); key = gasm_->Word32And(key, mask);
Node* mask = }
graph()->NewNode(machine->Word32Sar(), masked_diff, Int32Constant(31));
key = graph()->NewNode(machine->Word32And(), key, mask); Node* int32_scaled_key =
} Uint32ToUintptr(gasm_->Word32Shl(key, Int32Constant(2)));
Node* int32_scaled_key = Uint32ToUintptr( Node* loaded_sig =
graph()->NewNode(machine->Word32Shl(), key, Int32Constant(2))); gasm_->Load(MachineType::Int32(), ift_sig_ids, int32_scaled_key);
Node* loaded_sig = SetEffect(
graph()->NewNode(machine->Load(MachineType::Int32()), ift_sig_ids,
int32_scaled_key, effect(), control()));
// Check that the dynamic type of the function is a subtype of its static // Check that the dynamic type of the function is a subtype of its static
// (table) type. Currently, the only subtyping between function types is // (table) type. Currently, the only subtyping between function types is
// $t <: funcref for all $t: function_type. // $t <: funcref for all $t: function_type.
...@@ -3106,15 +3041,14 @@ Node* WasmGraphBuilder::BuildIndirectCall(uint32_t table_index, ...@@ -3106,15 +3041,14 @@ Node* WasmGraphBuilder::BuildIndirectCall(uint32_t table_index,
env_->module->tables[table_index].type == wasm::kWasmFuncRef; env_->module->tables[table_index].type == wasm::kWasmFuncRef;
if (needs_typechecking) { if (needs_typechecking) {
int32_t expected_sig_id = env_->module->canonicalized_type_ids[sig_index]; int32_t expected_sig_id = env_->module->canonicalized_type_ids[sig_index];
Node* sig_match = graph()->NewNode(machine->Word32Equal(), loaded_sig, Node* sig_match =
Int32Constant(expected_sig_id)); gasm_->Word32Equal(loaded_sig, Int32Constant(expected_sig_id));
TrapIfFalse(wasm::kTrapFuncSigMismatch, sig_match, position); TrapIfFalse(wasm::kTrapFuncSigMismatch, sig_match, position);
} else { } else {
// We still have to check that the entry is initialized. // We still have to check that the entry is initialized.
// TODO(9495): Skip this check for non-nullable tables when they are // TODO(9495): Skip this check for non-nullable tables when they are
// allowed. // allowed.
Node* function_is_null = Node* function_is_null = gasm_->Word32Equal(loaded_sig, Int32Constant(-1));
graph()->NewNode(machine->Word32Equal(), loaded_sig, Int32Constant(-1));
TrapIfTrue(wasm::kTrapNullDereference, function_is_null, position); TrapIfTrue(wasm::kTrapNullDereference, function_is_null, position);
} }
...@@ -3126,9 +3060,8 @@ Node* WasmGraphBuilder::BuildIndirectCall(uint32_t table_index, ...@@ -3126,9 +3060,8 @@ Node* WasmGraphBuilder::BuildIndirectCall(uint32_t table_index,
Node* intptr_scaled_key = Node* intptr_scaled_key =
gasm_->IntMul(key_intptr, gasm_->IntPtrConstant(kSystemPointerSize)); gasm_->IntMul(key_intptr, gasm_->IntPtrConstant(kSystemPointerSize));
Node* target = SetEffect( Node* target =
graph()->NewNode(machine->Load(MachineType::Pointer()), ift_targets, gasm_->Load(MachineType::Pointer(), ift_targets, intptr_scaled_key);
intptr_scaled_key, effect(), control()));
args[0] = target; args[0] = target;
const UseRetpoline use_retpoline = const UseRetpoline use_retpoline =
...@@ -3379,9 +3312,8 @@ Node* WasmGraphBuilder::BuildChangeInt32ToSmi(Node* value) { ...@@ -3379,9 +3312,8 @@ Node* WasmGraphBuilder::BuildChangeInt32ToSmi(Node* value) {
Node* WasmGraphBuilder::BuildChangeUint31ToSmi(Node* value) { Node* WasmGraphBuilder::BuildChangeUint31ToSmi(Node* value) {
return COMPRESS_POINTERS_BOOL return COMPRESS_POINTERS_BOOL
? gasm_->Word32Shl(value, BuildSmiShiftBitsConstant32()) ? gasm_->Word32Shl(value, BuildSmiShiftBitsConstant32())
: graph()->NewNode(mcgraph()->machine()->WordShl(), : gasm_->WordShl(Uint32ToUintptr(value),
Uint32ToUintptr(value), BuildSmiShiftBitsConstant());
BuildSmiShiftBitsConstant());
} }
Node* WasmGraphBuilder::BuildSmiShiftBitsConstant() { Node* WasmGraphBuilder::BuildSmiShiftBitsConstant() {
...@@ -3404,18 +3336,16 @@ Node* WasmGraphBuilder::BuildChangeSmiToIntPtr(Node* value) { ...@@ -3404,18 +3336,16 @@ Node* WasmGraphBuilder::BuildChangeSmiToIntPtr(Node* value) {
value = BuildChangeSmiToInt32(value); value = BuildChangeSmiToInt32(value);
return BuildChangeInt32ToIntPtr(value); return BuildChangeInt32ToIntPtr(value);
} }
return graph()->NewNode(mcgraph()->machine()->WordSar(), value, return gasm_->WordSar(value, BuildSmiShiftBitsConstant());
BuildSmiShiftBitsConstant());
} }
Node* WasmGraphBuilder::BuildConvertUint32ToSmiWithSaturation(Node* value, Node* WasmGraphBuilder::BuildConvertUint32ToSmiWithSaturation(Node* value,
uint32_t maxval) { uint32_t maxval) {
DCHECK(Smi::IsValid(maxval)); DCHECK(Smi::IsValid(maxval));
Node* max = mcgraph()->Uint32Constant(maxval); Node* max = mcgraph()->Uint32Constant(maxval);
Node* check = graph()->NewNode(mcgraph()->machine()->Uint32LessThanOrEqual(), Node* check = gasm_->Uint32LessThanOrEqual(value, max);
value, max);
Node* valsmi = BuildChangeUint31ToSmi(value); Node* valsmi = BuildChangeUint31ToSmi(value);
Node* maxsmi = graph()->NewNode(mcgraph()->common()->NumberConstant(maxval)); Node* maxsmi = gasm_->NumberConstant(maxval);
Diamond d(graph(), mcgraph()->common(), check, BranchHint::kTrue); Diamond d(graph(), mcgraph()->common(), check, BranchHint::kTrue);
d.Chain(control()); d.Chain(control());
return d.Phi(MachineRepresentation::kTagged, valsmi, maxsmi); return d.Phi(MachineRepresentation::kTagged, valsmi, maxsmi);
...@@ -3563,11 +3493,9 @@ void WasmGraphBuilder::GetGlobalBaseAndOffset(MachineType mem_type, ...@@ -3563,11 +3493,9 @@ void WasmGraphBuilder::GetGlobalBaseAndOffset(MachineType mem_type,
Node** offset_node) { Node** offset_node) {
DCHECK_NOT_NULL(instance_node_); DCHECK_NOT_NULL(instance_node_);
if (global.mutability && global.imported) { if (global.mutability && global.imported) {
*base_node = SetEffect(graph()->NewNode( *base_node =
mcgraph()->machine()->Load(MachineType::UintPtr()), gasm_->Load(MachineType::UintPtr(), GetImportedMutableGlobals(),
GetImportedMutableGlobals(), mcgraph()->Int32Constant(global.index * sizeof(Address)));
mcgraph()->Int32Constant(global.index * sizeof(Address)), effect(),
control()));
*offset_node = mcgraph()->Int32Constant(0); *offset_node = mcgraph()->Int32Constant(0);
} else { } else {
if (globals_start_ == nullptr) { if (globals_start_ == nullptr) {
...@@ -3591,8 +3519,7 @@ void WasmGraphBuilder::GetGlobalBaseAndOffset(MachineType mem_type, ...@@ -3591,8 +3519,7 @@ void WasmGraphBuilder::GetGlobalBaseAndOffset(MachineType mem_type,
if (mem_type == MachineType::Simd128() && global.offset != 0) { if (mem_type == MachineType::Simd128() && global.offset != 0) {
// TODO(titzer,bbudge): code generation for SIMD memory offsets is broken. // TODO(titzer,bbudge): code generation for SIMD memory offsets is broken.
*base_node = graph()->NewNode(mcgraph()->machine()->IntAdd(), *base_node, *base_node = gasm_->IntAdd(*base_node, *offset_node);
*offset_node);
*offset_node = mcgraph()->Int32Constant(0); *offset_node = mcgraph()->Int32Constant(0);
} }
} }
...@@ -3608,20 +3535,17 @@ void WasmGraphBuilder::GetBaseAndOffsetForImportedMutableExternRefGlobal( ...@@ -3608,20 +3535,17 @@ void WasmGraphBuilder::GetBaseAndOffsetForImportedMutableExternRefGlobal(
// For the offset we need the index of the global in the buffer, and then // For the offset we need the index of the global in the buffer, and then
// calculate the actual offset from the index. Load the index from the // calculate the actual offset from the index. Load the index from the
// ImportedMutableGlobals array of the instance. // ImportedMutableGlobals array of the instance.
Node* index = SetEffect( Node* index =
graph()->NewNode(mcgraph()->machine()->Load(MachineType::UintPtr()), gasm_->Load(MachineType::UintPtr(), GetImportedMutableGlobals(),
GetImportedMutableGlobals(), mcgraph()->Int32Constant(global.index * sizeof(Address)));
mcgraph()->Int32Constant(global.index * sizeof(Address)),
effect(), control()));
// From the index, calculate the actual offset in the FixedArray. This // From the index, calculate the actual offset in the FixedArray. This
// is kHeaderSize + (index * kTaggedSize). kHeaderSize can be acquired with // is kHeaderSize + (index * kTaggedSize). kHeaderSize can be acquired with
// wasm::ObjectAccess::ElementOffsetInTaggedFixedArray(0). // wasm::ObjectAccess::ElementOffsetInTaggedFixedArray(0).
Node* index_times_tagged_size = Node* index_times_tagged_size = gasm_->IntMul(
graph()->NewNode(mcgraph()->machine()->IntMul(), Uint32ToUintptr(index), Uint32ToUintptr(index), mcgraph()->Int32Constant(kTaggedSize));
mcgraph()->Int32Constant(kTaggedSize)); *offset = gasm_->IntAdd(
*offset = graph()->NewNode( index_times_tagged_size,
mcgraph()->machine()->IntAdd(), index_times_tagged_size,
mcgraph()->IntPtrConstant( mcgraph()->IntPtrConstant(
wasm::ObjectAccess::ElementOffsetInTaggedFixedArray(0))); wasm::ObjectAccess::ElementOffsetInTaggedFixedArray(0)));
} }
...@@ -3683,10 +3607,7 @@ Node* WasmGraphBuilder::BuildCallToRuntimeWithContext(Runtime::FunctionId f, ...@@ -3683,10 +3607,7 @@ Node* WasmGraphBuilder::BuildCallToRuntimeWithContext(Runtime::FunctionId f,
inputs[count++] = effect(); inputs[count++] = effect();
inputs[count++] = control(); inputs[count++] = control();
Node* call = mcgraph()->graph()->NewNode( return gasm_->Call(call_descriptor, count, inputs);
mcgraph()->common()->Call(call_descriptor), count, inputs);
SetEffect(call);
return call;
} }
Node* WasmGraphBuilder::BuildCallToRuntime(Runtime::FunctionId f, Node* WasmGraphBuilder::BuildCallToRuntime(Runtime::FunctionId f,
...@@ -3717,8 +3638,7 @@ Node* WasmGraphBuilder::GlobalGet(uint32_t index) { ...@@ -3717,8 +3638,7 @@ Node* WasmGraphBuilder::GlobalGet(uint32_t index) {
Node* base = nullptr; Node* base = nullptr;
Node* offset = nullptr; Node* offset = nullptr;
GetGlobalBaseAndOffset(mem_type, global, &base, &offset); GetGlobalBaseAndOffset(mem_type, global, &base, &offset);
Node* result = SetEffect(graph()->NewNode( Node* result = gasm_->Load(mem_type, base, offset);
mcgraph()->machine()->Load(mem_type), base, offset, effect(), control()));
#if defined(V8_TARGET_BIG_ENDIAN) #if defined(V8_TARGET_BIG_ENDIAN)
result = BuildChangeEndiannessLoad(result, mem_type, global.type); result = BuildChangeEndiannessLoad(result, mem_type, global.type);
#endif #endif
...@@ -3748,13 +3668,13 @@ Node* WasmGraphBuilder::GlobalSet(uint32_t index, Node* val) { ...@@ -3748,13 +3668,13 @@ Node* WasmGraphBuilder::GlobalSet(uint32_t index, Node* val) {
Node* base = nullptr; Node* base = nullptr;
Node* offset = nullptr; Node* offset = nullptr;
GetGlobalBaseAndOffset(mem_type, global, &base, &offset); GetGlobalBaseAndOffset(mem_type, global, &base, &offset);
const Operator* op = mcgraph()->machine()->Store( auto store_rep =
StoreRepresentation(mem_type.representation(), kNoWriteBarrier)); StoreRepresentation(mem_type.representation(), kNoWriteBarrier);
#if defined(V8_TARGET_BIG_ENDIAN) #if defined(V8_TARGET_BIG_ENDIAN)
val = BuildChangeEndiannessStore(val, mem_type.representation(), global.type); val = BuildChangeEndiannessStore(val, mem_type.representation(), global.type);
#endif #endif
return SetEffect(
graph()->NewNode(op, base, offset, val, effect(), control())); return gasm_->Store(store_rep, base, offset, val);
} }
Node* WasmGraphBuilder::TableGet(uint32_t table_index, Node* index, Node* WasmGraphBuilder::TableGet(uint32_t table_index, Node* index,
...@@ -4410,17 +4330,15 @@ Node* WasmGraphBuilder::BuildAsmjsLoadMem(MachineType type, Node* index) { ...@@ -4410,17 +4330,15 @@ Node* WasmGraphBuilder::BuildAsmjsLoadMem(MachineType type, Node* index) {
// stored value, which is conservative if misaligned. Technically, asm.js // stored value, which is conservative if misaligned. Technically, asm.js
// should never have misaligned accesses. // should never have misaligned accesses.
index = Uint32ToUintptr(index); index = Uint32ToUintptr(index);
Diamond bounds_check( Diamond bounds_check(graph(), mcgraph()->common(),
graph(), mcgraph()->common(), gasm_->UintLessThan(index, mem_size), BranchHint::kTrue);
graph()->NewNode(mcgraph()->machine()->UintLessThan(), index, mem_size),
BranchHint::kTrue);
bounds_check.Chain(control()); bounds_check.Chain(control());
if (untrusted_code_mitigations_) { if (untrusted_code_mitigations_) {
// Condition the index with the memory mask. // Condition the index with the memory mask.
Node* mem_mask = instance_cache_->mem_mask; Node* mem_mask = instance_cache_->mem_mask;
DCHECK_NOT_NULL(mem_mask); DCHECK_NOT_NULL(mem_mask);
index = graph()->NewNode(mcgraph()->machine()->WordAnd(), index, mem_mask); index = gasm_->WordAnd(index, mem_mask);
} }
Node* load = graph()->NewNode(mcgraph()->machine()->Load(type), mem_start, Node* load = graph()->NewNode(mcgraph()->machine()->Load(type), mem_start,
...@@ -4438,7 +4356,7 @@ Node* WasmGraphBuilder::Uint32ToUintptr(Node* node) { ...@@ -4438,7 +4356,7 @@ Node* WasmGraphBuilder::Uint32ToUintptr(Node* node) {
uintptr_t value = matcher.ResolvedValue(); uintptr_t value = matcher.ResolvedValue();
return mcgraph()->IntPtrConstant(bit_cast<intptr_t>(value)); return mcgraph()->IntPtrConstant(bit_cast<intptr_t>(value));
} }
return graph()->NewNode(mcgraph()->machine()->ChangeUint32ToUint64(), node); return gasm_->ChangeUint32ToUint64(node);
} }
Node* WasmGraphBuilder::BuildAsmjsStoreMem(MachineType type, Node* index, Node* WasmGraphBuilder::BuildAsmjsStoreMem(MachineType type, Node* index,
...@@ -4453,18 +4371,16 @@ Node* WasmGraphBuilder::BuildAsmjsStoreMem(MachineType type, Node* index, ...@@ -4453,18 +4371,16 @@ Node* WasmGraphBuilder::BuildAsmjsStoreMem(MachineType type, Node* index,
// Note that we check against the memory size ignoring the size of the // Note that we check against the memory size ignoring the size of the
// stored value, which is conservative if misaligned. Technically, asm.js // stored value, which is conservative if misaligned. Technically, asm.js
// should never have misaligned accesses. // should never have misaligned accesses.
Diamond bounds_check( Diamond bounds_check(graph(), mcgraph()->common(),
graph(), mcgraph()->common(), gasm_->Uint32LessThan(index, mem_size),
graph()->NewNode(mcgraph()->machine()->Uint32LessThan(), index, mem_size), BranchHint::kTrue);
BranchHint::kTrue);
bounds_check.Chain(control()); bounds_check.Chain(control());
if (untrusted_code_mitigations_) { if (untrusted_code_mitigations_) {
// Condition the index with the memory mask. // Condition the index with the memory mask.
Node* mem_mask = instance_cache_->mem_mask; Node* mem_mask = instance_cache_->mem_mask;
DCHECK_NOT_NULL(mem_mask); DCHECK_NOT_NULL(mem_mask);
index = index = gasm_->Word32And(index, mem_mask);
graph()->NewNode(mcgraph()->machine()->Word32And(), index, mem_mask);
} }
index = Uint32ToUintptr(index); index = Uint32ToUintptr(index);
...@@ -5525,8 +5441,8 @@ Node* WasmGraphBuilder::MemoryInit(uint32_t data_segment_index, Node* dst, ...@@ -5525,8 +5441,8 @@ Node* WasmGraphBuilder::MemoryInit(uint32_t data_segment_index, Node* dst,
// validation. // validation.
DCHECK_LT(data_segment_index, env_->module->num_declared_data_segments); DCHECK_LT(data_segment_index, env_->module->num_declared_data_segments);
Node* function = graph()->NewNode(mcgraph()->common()->ExternalConstant( Node* function =
ExternalReference::wasm_memory_init())); gasm_->ExternalConstant(ExternalReference::wasm_memory_init());
Node* stack_slot = StoreArgsInStackSlot( Node* stack_slot = StoreArgsInStackSlot(
{{MachineType::PointerRepresentation(), instance_node_.get()}, {{MachineType::PointerRepresentation(), instance_node_.get()},
...@@ -5549,12 +5465,11 @@ Node* WasmGraphBuilder::DataDrop(uint32_t data_segment_index, ...@@ -5549,12 +5465,11 @@ Node* WasmGraphBuilder::DataDrop(uint32_t data_segment_index,
Node* seg_size_array = Node* seg_size_array =
LOAD_INSTANCE_FIELD(DataSegmentSizes, MachineType::Pointer()); LOAD_INSTANCE_FIELD(DataSegmentSizes, MachineType::Pointer());
STATIC_ASSERT(wasm::kV8MaxWasmDataSegments <= kMaxUInt32 >> 2); STATIC_ASSERT(wasm::kV8MaxWasmDataSegments <= kMaxUInt32 >> 2);
const Operator* store_op = mcgraph()->machine()->Store( auto store_rep =
StoreRepresentation(MachineRepresentation::kWord32, kNoWriteBarrier)); StoreRepresentation(MachineRepresentation::kWord32, kNoWriteBarrier);
return SetEffect( return gasm_->Store(store_rep, seg_size_array,
graph()->NewNode(store_op, seg_size_array, mcgraph()->IntPtrConstant(data_segment_index << 2),
mcgraph()->IntPtrConstant(data_segment_index << 2), mcgraph()->Int32Constant(0));
mcgraph()->Int32Constant(0), effect(), control()));
} }
Node* WasmGraphBuilder::StoreArgsInStackSlot( Node* WasmGraphBuilder::StoreArgsInStackSlot(
...@@ -5580,8 +5495,8 @@ Node* WasmGraphBuilder::StoreArgsInStackSlot( ...@@ -5580,8 +5495,8 @@ Node* WasmGraphBuilder::StoreArgsInStackSlot(
Node* WasmGraphBuilder::MemoryCopy(Node* dst, Node* src, Node* size, Node* WasmGraphBuilder::MemoryCopy(Node* dst, Node* src, Node* size,
wasm::WasmCodePosition position) { wasm::WasmCodePosition position) {
Node* function = graph()->NewNode(mcgraph()->common()->ExternalConstant( Node* function =
ExternalReference::wasm_memory_copy())); gasm_->ExternalConstant(ExternalReference::wasm_memory_copy());
Node* stack_slot = StoreArgsInStackSlot( Node* stack_slot = StoreArgsInStackSlot(
{{MachineType::PointerRepresentation(), instance_node_.get()}, {{MachineType::PointerRepresentation(), instance_node_.get()},
...@@ -5597,8 +5512,8 @@ Node* WasmGraphBuilder::MemoryCopy(Node* dst, Node* src, Node* size, ...@@ -5597,8 +5512,8 @@ Node* WasmGraphBuilder::MemoryCopy(Node* dst, Node* src, Node* size,
Node* WasmGraphBuilder::MemoryFill(Node* dst, Node* value, Node* size, Node* WasmGraphBuilder::MemoryFill(Node* dst, Node* value, Node* size,
wasm::WasmCodePosition position) { wasm::WasmCodePosition position) {
Node* function = graph()->NewNode(mcgraph()->common()->ExternalConstant( Node* function =
ExternalReference::wasm_memory_fill())); gasm_->ExternalConstant(ExternalReference::wasm_memory_fill());
Node* stack_slot = StoreArgsInStackSlot( Node* stack_slot = StoreArgsInStackSlot(
{{MachineType::PointerRepresentation(), instance_node_.get()}, {{MachineType::PointerRepresentation(), instance_node_.get()},
...@@ -5616,11 +5531,9 @@ Node* WasmGraphBuilder::TableInit(uint32_t table_index, ...@@ -5616,11 +5531,9 @@ Node* WasmGraphBuilder::TableInit(uint32_t table_index,
uint32_t elem_segment_index, Node* dst, uint32_t elem_segment_index, Node* dst,
Node* src, Node* size, Node* src, Node* size,
wasm::WasmCodePosition position) { wasm::WasmCodePosition position) {
return gasm_->CallRuntimeStub( return gasm_->CallRuntimeStub(wasm::WasmCode::kWasmTableInit, dst, src, size,
wasm::WasmCode::kWasmTableInit, dst, src, size, gasm_->NumberConstant(table_index),
graph()->NewNode(mcgraph()->common()->NumberConstant(table_index)), gasm_->NumberConstant(elem_segment_index));
graph()->NewNode(
mcgraph()->common()->NumberConstant(elem_segment_index)));
} }
Node* WasmGraphBuilder::ElemDrop(uint32_t elem_segment_index, Node* WasmGraphBuilder::ElemDrop(uint32_t elem_segment_index,
...@@ -5631,28 +5544,25 @@ Node* WasmGraphBuilder::ElemDrop(uint32_t elem_segment_index, ...@@ -5631,28 +5544,25 @@ Node* WasmGraphBuilder::ElemDrop(uint32_t elem_segment_index,
Node* dropped_elem_segments = Node* dropped_elem_segments =
LOAD_INSTANCE_FIELD(DroppedElemSegments, MachineType::Pointer()); LOAD_INSTANCE_FIELD(DroppedElemSegments, MachineType::Pointer());
const Operator* store_op = mcgraph()->machine()->Store( auto store_rep =
StoreRepresentation(MachineRepresentation::kWord8, kNoWriteBarrier)); StoreRepresentation(MachineRepresentation::kWord8, kNoWriteBarrier);
return SetEffect( return gasm_->Store(store_rep, dropped_elem_segments, elem_segment_index,
graph()->NewNode(store_op, dropped_elem_segments, mcgraph()->Int32Constant(1));
mcgraph()->IntPtrConstant(elem_segment_index),
mcgraph()->Int32Constant(1), effect(), control()));
} }
Node* WasmGraphBuilder::TableCopy(uint32_t table_dst_index, Node* WasmGraphBuilder::TableCopy(uint32_t table_dst_index,
uint32_t table_src_index, Node* dst, uint32_t table_src_index, Node* dst,
Node* src, Node* size, Node* src, Node* size,
wasm::WasmCodePosition position) { wasm::WasmCodePosition position) {
return gasm_->CallRuntimeStub( return gasm_->CallRuntimeStub(wasm::WasmCode::kWasmTableCopy, dst, src, size,
wasm::WasmCode::kWasmTableCopy, dst, src, size, gasm_->NumberConstant(table_dst_index),
graph()->NewNode(mcgraph()->common()->NumberConstant(table_dst_index)), gasm_->NumberConstant(table_src_index));
graph()->NewNode(mcgraph()->common()->NumberConstant(table_src_index)));
} }
Node* WasmGraphBuilder::TableGrow(uint32_t table_index, Node* value, Node* WasmGraphBuilder::TableGrow(uint32_t table_index, Node* value,
Node* delta) { Node* delta) {
Node* args[] = { Node* args[] = {
graph()->NewNode(mcgraph()->common()->NumberConstant(table_index)), value, gasm_->NumberConstant(table_index), value,
BuildConvertUint32ToSmiWithSaturation(delta, FLAG_wasm_max_table_size)}; BuildConvertUint32ToSmiWithSaturation(delta, FLAG_wasm_max_table_size)};
Node* result = Node* result =
BuildCallToRuntime(Runtime::kWasmTableGrow, args, arraysize(args)); BuildCallToRuntime(Runtime::kWasmTableGrow, args, arraysize(args));
...@@ -5675,7 +5585,7 @@ Node* WasmGraphBuilder::TableSize(uint32_t table_index) { ...@@ -5675,7 +5585,7 @@ Node* WasmGraphBuilder::TableSize(uint32_t table_index) {
Node* WasmGraphBuilder::TableFill(uint32_t table_index, Node* start, Node* WasmGraphBuilder::TableFill(uint32_t table_index, Node* start,
Node* value, Node* count) { Node* value, Node* count) {
Node* args[] = { Node* args[] = {
graph()->NewNode(mcgraph()->common()->NumberConstant(table_index)), gasm_->NumberConstant(table_index),
BuildConvertUint32ToSmiWithSaturation(start, FLAG_wasm_max_table_size), BuildConvertUint32ToSmiWithSaturation(start, FLAG_wasm_max_table_size),
value, value,
BuildConvertUint32ToSmiWithSaturation(count, FLAG_wasm_max_table_size)}; BuildConvertUint32ToSmiWithSaturation(count, FLAG_wasm_max_table_size)};
...@@ -5703,10 +5613,9 @@ Node* WasmGraphBuilder::ArrayNewWithRtt(uint32_t array_index, ...@@ -5703,10 +5613,9 @@ Node* WasmGraphBuilder::ArrayNewWithRtt(uint32_t array_index,
length, gasm_->Uint32Constant(wasm::kV8MaxWasmArrayLength)), length, gasm_->Uint32Constant(wasm::kV8MaxWasmArrayLength)),
position); position);
wasm::ValueType element_type = type->element_type(); wasm::ValueType element_type = type->element_type();
Node* a = Node* a = gasm_->CallBuiltin(
gasm_->CallBuiltin(Builtins::kWasmAllocateArrayWithRtt, rtt, length, Builtins::kWasmAllocateArrayWithRtt, rtt, length,
graph()->NewNode(mcgraph()->common()->Int32Constant( gasm_->Int32Constant(element_type.element_size_bytes()));
element_type.element_size_bytes())));
auto loop = gasm_->MakeLoopLabel(MachineRepresentation::kWord32); auto loop = gasm_->MakeLoopLabel(MachineRepresentation::kWord32);
auto done = gasm_->MakeLabel(); auto done = gasm_->MakeLabel();
Node* start_offset = gasm_->Int32Constant( Node* start_offset = gasm_->Int32Constant(
...@@ -5738,10 +5647,8 @@ Node* WasmGraphBuilder::RttCanon(uint32_t type_index) { ...@@ -5738,10 +5647,8 @@ Node* WasmGraphBuilder::RttCanon(uint32_t type_index) {
} }
Node* WasmGraphBuilder::RttSub(uint32_t type_index, Node* parent_rtt) { Node* WasmGraphBuilder::RttSub(uint32_t type_index, Node* parent_rtt) {
return gasm_->CallBuiltin( return gasm_->CallBuiltin(Builtins::kWasmAllocateRtt,
Builtins::kWasmAllocateRtt, gasm_->Int32Constant(type_index), parent_rtt);
graph()->NewNode(mcgraph()->common()->Int32Constant(type_index)),
parent_rtt);
} }
void AssertFalse(MachineGraph* mcgraph, GraphAssembler* gasm, Node* condition) { void AssertFalse(MachineGraph* mcgraph, GraphAssembler* gasm, Node* condition) {
...@@ -6013,18 +5920,11 @@ Node* WasmGraphBuilder::BrOnI31(Node* object, Node* /* rtt */, ...@@ -6013,18 +5920,11 @@ Node* WasmGraphBuilder::BrOnI31(Node* object, Node* /* rtt */,
Node** match_control, Node** match_effect, Node** match_control, Node** match_effect,
Node** no_match_control, Node** no_match_control,
Node** no_match_effect) { Node** no_match_effect) {
Node* branch = gasm_->Branch(gasm_->IsI31(object), match_control, no_match_control,
graph()->NewNode(mcgraph()->common()->Branch(BranchHint::kTrue), BranchHint::kTrue);
gasm_->IsI31(object), control());
Node* if_true = graph()->NewNode(mcgraph()->common()->IfTrue(), branch);
Node* if_false = graph()->NewNode(mcgraph()->common()->IfFalse(), branch);
SetControl(if_false);
*match_control = if_true; SetControl(*no_match_control);
*match_effect = effect(); *match_effect = effect();
*no_match_control = if_false;
*no_match_effect = effect(); *no_match_effect = effect();
// Unused return value, needed for typing of BUILD in graph-builder-interface. // Unused return value, needed for typing of BUILD in graph-builder-interface.
...@@ -6448,9 +6348,6 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6448,9 +6348,6 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
} }
Node* BuildChangeInt64ToBigInt(Node* input) { Node* BuildChangeInt64ToBigInt(Node* input) {
const Operator* call =
mcgraph()->common()->Call(GetI64ToBigIntCallDescriptor());
Node* target; Node* target;
if (mcgraph()->machine()->Is64()) { if (mcgraph()->machine()->Is64()) {
target = GetTargetForBuiltinCall(wasm::WasmCode::kI64ToBigInt, target = GetTargetForBuiltinCall(wasm::WasmCode::kI64ToBigInt,
...@@ -6463,16 +6360,11 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6463,16 +6360,11 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
target = GetTargetForBuiltinCall(wasm::WasmCode::kI32PairToBigInt, target = GetTargetForBuiltinCall(wasm::WasmCode::kI32PairToBigInt,
Builtins::kI32PairToBigInt); Builtins::kI32PairToBigInt);
} }
return gasm_->Call(GetI64ToBigIntCallDescriptor(), target, input);
return SetEffectControl(
graph()->NewNode(call, target, input, effect(), control()));
} }
Node* BuildChangeBigIntToInt64(Node* input, Node* context, Node* BuildChangeBigIntToInt64(Node* input, Node* context,
Node* frame_state) { Node* frame_state) {
const Operator* call = mcgraph()->common()->Call(
GetBigIntToI64CallDescriptor(frame_state != nullptr));
Node* target; Node* target;
if (mcgraph()->machine()->Is64()) { if (mcgraph()->machine()->Is64()) {
target = GetTargetForBuiltinCall(wasm::WasmCode::kBigIntToI64, target = GetTargetForBuiltinCall(wasm::WasmCode::kBigIntToI64,
...@@ -6486,11 +6378,10 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6486,11 +6378,10 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
Builtins::kBigIntToI32Pair); Builtins::kBigIntToI32Pair);
} }
if (frame_state) return frame_state ? gasm_->Call(GetBigIntToI64CallDescriptor(true), target,
return SetEffectControl(graph()->NewNode( input, context, frame_state)
call, target, input, context, frame_state, effect(), control())); : gasm_->Call(GetBigIntToI64CallDescriptor(false),
return SetEffectControl( target, input, context);
graph()->NewNode(call, target, input, context, effect(), control()));
} }
void BuildCheckValidRefValue(Node* input, Node* js_context, void BuildCheckValidRefValue(Node* input, Node* js_context,
...@@ -6551,8 +6442,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6551,8 +6442,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
} }
} }
case wasm::kF32: case wasm::kF32:
return graph()->NewNode( return gasm_->TruncateFloat64ToFloat32(
mcgraph()->machine()->TruncateFloat64ToFloat32(),
BuildChangeTaggedToFloat64(input, js_context, frame_state)); BuildChangeTaggedToFloat64(input, js_context, frame_state));
case wasm::kF64: case wasm::kF64:
...@@ -6578,13 +6468,11 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6578,13 +6468,11 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
} }
Node* SmiToFloat32(Node* input) { Node* SmiToFloat32(Node* input) {
return graph()->NewNode(mcgraph()->machine()->RoundInt32ToFloat32(), return gasm_->RoundInt32ToFloat32(BuildChangeSmiToInt32(input));
BuildChangeSmiToInt32(input));
} }
Node* SmiToFloat64(Node* input) { Node* SmiToFloat64(Node* input) {
return graph()->NewNode(mcgraph()->machine()->ChangeInt32ToFloat64(), return gasm_->ChangeInt32ToFloat64(BuildChangeSmiToInt32(input));
BuildChangeSmiToInt32(input));
} }
Node* HeapNumberToFloat64(Node* input) { Node* HeapNumberToFloat64(Node* input) {
...@@ -6603,8 +6491,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6603,8 +6491,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
gasm_->Goto(&done, SmiToFloat32(input)); gasm_->Goto(&done, SmiToFloat32(input));
gasm_->Bind(&heap_number); gasm_->Bind(&heap_number);
Node* value = Node* value =
graph()->NewNode(mcgraph()->machine()->TruncateFloat64ToFloat32(), gasm_->TruncateFloat64ToFloat32(HeapNumberToFloat64(input));
HeapNumberToFloat64(input));
gasm_->Goto(&done, value); gasm_->Goto(&done, value);
gasm_->Bind(&done); gasm_->Bind(&done);
return done.PhiAt(0); return done.PhiAt(0);
...@@ -6637,22 +6524,18 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6637,22 +6524,18 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
void BuildModifyThreadInWasmFlagHelper(Node* thread_in_wasm_flag_address, void BuildModifyThreadInWasmFlagHelper(Node* thread_in_wasm_flag_address,
bool new_value) { bool new_value) {
if (FLAG_debug_code) { if (FLAG_debug_code) {
Node* flag_value = SetEffect( Node* flag_value =
graph()->NewNode(mcgraph()->machine()->Load(MachineType::Pointer()), gasm_->Load(MachineType::Pointer(), thread_in_wasm_flag_address, 0);
thread_in_wasm_flag_address, Node* check = gasm_->Word32Equal(
mcgraph()->Int32Constant(0), effect(), control())); flag_value, mcgraph()->Int32Constant(new_value ? 0 : 1));
Node* check =
graph()->NewNode(mcgraph()->machine()->Word32Equal(), flag_value,
mcgraph()->Int32Constant(new_value ? 0 : 1));
Diamond flag_check(graph(), mcgraph()->common(), check, Diamond flag_check(graph(), mcgraph()->common(), check,
BranchHint::kTrue); BranchHint::kTrue);
flag_check.Chain(control()); flag_check.Chain(control());
SetControl(flag_check.if_false); SetControl(flag_check.if_false);
Node* message_id = graph()->NewNode( Node* message_id = gasm_->NumberConstant(static_cast<int32_t>(
mcgraph()->common()->NumberConstant(static_cast<int32_t>( new_value ? AbortReason::kUnexpectedThreadInWasmSet
new_value ? AbortReason::kUnexpectedThreadInWasmSet : AbortReason::kUnexpectedThreadInWasmUnset));
: AbortReason::kUnexpectedThreadInWasmUnset)));
Node* old_effect = effect(); Node* old_effect = effect();
Node* call = BuildCallToRuntimeWithContext( Node* call = BuildCallToRuntimeWithContext(
...@@ -6662,11 +6545,10 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6662,11 +6545,10 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
flag_check.merge); flag_check.merge);
} }
SetEffect(graph()->NewNode( gasm_->Store(
mcgraph()->machine()->Store(StoreRepresentation( StoreRepresentation(MachineRepresentation::kWord32, kNoWriteBarrier),
MachineRepresentation::kWord32, kNoWriteBarrier)), thread_in_wasm_flag_address, 0,
thread_in_wasm_flag_address, mcgraph()->Int32Constant(0), mcgraph()->Int32Constant(new_value ? 1 : 0));
mcgraph()->Int32Constant(new_value ? 1 : 0), effect(), control()));
} }
void BuildModifyThreadInWasmFlag(bool new_value) { void BuildModifyThreadInWasmFlag(bool new_value) {
...@@ -6755,8 +6637,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6755,8 +6637,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
Node* jump_table_offset = Node* jump_table_offset =
BuildLoadJumpTableOffsetFromExportedFunctionData(function_data); BuildLoadJumpTableOffsetFromExportedFunctionData(function_data);
Node* jump_table_slot = Node* jump_table_slot =
graph()->NewNode(mcgraph()->machine()->IntAdd(), jump_table_start, gasm_->IntAdd(jump_table_start, jump_table_offset);
jump_table_offset);
args[0] = jump_table_slot; args[0] = jump_table_slot;
BuildWasmCall(sig_, VectorOf(args), VectorOf(rets), BuildWasmCall(sig_, VectorOf(args), VectorOf(rets),
...@@ -6773,16 +6654,14 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6773,16 +6654,14 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
LOAD_INSTANCE_FIELD(IsolateRoot, MachineType::Pointer()); LOAD_INSTANCE_FIELD(IsolateRoot, MachineType::Pointer());
jsval = gasm_->Load( jsval = gasm_->Load(
MachineType::Pointer(), isolate_root, MachineType::Pointer(), isolate_root,
mcgraph()->Int32Constant( IsolateData::root_slot_offset(RootIndex::kUndefinedValue));
IsolateData::root_slot_offset(RootIndex::kUndefinedValue)));
} else if (sig_->return_count() == 1) { } else if (sig_->return_count() == 1) {
jsval = js_wasm_call_data && !js_wasm_call_data->result_needs_conversion() jsval = js_wasm_call_data && !js_wasm_call_data->result_needs_conversion()
? rets[0] ? rets[0]
: ToJS(rets[0], sig_->GetReturn()); : ToJS(rets[0], sig_->GetReturn());
} else { } else {
int32_t return_count = static_cast<int32_t>(sig_->return_count()); int32_t return_count = static_cast<int32_t>(sig_->return_count());
Node* size = Node* size = gasm_->NumberConstant(return_count);
graph()->NewNode(mcgraph()->common()->NumberConstant(return_count));
jsval = BuildCallAllocateJSArray(size, js_context); jsval = BuildCallAllocateJSArray(size, js_context);
...@@ -6955,8 +6834,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -6955,8 +6834,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
// simplified-lowering and we need to add here a conversion from Float64 // simplified-lowering and we need to add here a conversion from Float64
// to Float32. // to Float32.
if (sig_->GetParam(i).kind() == wasm::kF32) { if (sig_->GetParam(i).kind() == wasm::kF32) {
wasm_param = graph()->NewNode( wasm_param = gasm_->TruncateFloat64ToFloat32(wasm_param);
mcgraph()->machine()->TruncateFloat64ToFloat32(), wasm_param);
} }
args[i + 1] = wasm_param; args[i + 1] = wasm_param;
...@@ -7060,8 +6938,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -7060,8 +6938,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
args[pos++] = control(); args[pos++] = control();
DCHECK_EQ(pos, args.size()); DCHECK_EQ(pos, args.size());
call = graph()->NewNode(mcgraph()->common()->Call(call_descriptor), pos, call = gasm_->Call(call_descriptor, pos, args.begin());
args.begin());
break; break;
} }
// ======================================================================= // =======================================================================
...@@ -7094,8 +6971,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -7094,8 +6971,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
auto call_descriptor = Linkage::GetJSCallDescriptor( auto call_descriptor = Linkage::GetJSCallDescriptor(
graph()->zone(), false, pushed_count + 1, CallDescriptor::kNoFlags); graph()->zone(), false, pushed_count + 1, CallDescriptor::kNoFlags);
call = graph()->NewNode(mcgraph()->common()->Call(call_descriptor), pos, call = gasm_->Call(call_descriptor, pos, args.begin());
args.begin());
break; break;
} }
// ======================================================================= // =======================================================================
...@@ -7128,8 +7004,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -7128,8 +7004,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
args[pos++] = control(); args[pos++] = control();
DCHECK_EQ(pos, args.size()); DCHECK_EQ(pos, args.size());
call = graph()->NewNode(mcgraph()->common()->Call(call_descriptor), pos, call = gasm_->Call(call_descriptor, pos, args.begin());
args.begin());
break; break;
} }
default: default:
...@@ -7137,7 +7012,6 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -7137,7 +7012,6 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
} }
DCHECK_NOT_NULL(call); DCHECK_NOT_NULL(call);
SetEffect(call);
SetSourcePosition(call, 0); SetSourcePosition(call, 0);
// Convert the return value(s) back. // Convert the return value(s) back.
...@@ -7209,8 +7083,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -7209,8 +7083,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
// TODO(jkummerow): Load the address from the {host_data}, and cache // TODO(jkummerow): Load the address from the {host_data}, and cache
// wrappers per signature. // wrappers per signature.
const ExternalReference ref = ExternalReference::Create(address); const ExternalReference ref = ExternalReference::Create(address);
Node* function = Node* function = gasm_->ExternalConstant(ref);
graph()->NewNode(mcgraph()->common()->ExternalConstant(ref));
// Parameters: Address host_data_foreign, Address arguments. // Parameters: Address host_data_foreign, Address arguments.
MachineType host_sig_types[] = { MachineType host_sig_types[] = {
...@@ -7223,8 +7096,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -7223,8 +7096,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
Node* exception_branch = graph()->NewNode( Node* exception_branch = graph()->NewNode(
mcgraph()->common()->Branch(BranchHint::kTrue), mcgraph()->common()->Branch(BranchHint::kTrue),
graph()->NewNode(mcgraph()->machine()->WordEqual(), return_value, gasm_->WordEqual(return_value, mcgraph()->IntPtrConstant(0)),
mcgraph()->IntPtrConstant(0)),
control()); control());
SetControl( SetControl(
graph()->NewNode(mcgraph()->common()->IfFalse(), exception_branch)); graph()->NewNode(mcgraph()->common()->IfFalse(), exception_branch));
...@@ -7235,12 +7107,11 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -7235,12 +7107,11 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
Operator::kNoProperties, StubCallMode::kCallWasmRuntimeStub); Operator::kNoProperties, StubCallMode::kCallWasmRuntimeStub);
Node* call_target = mcgraph()->RelocatableIntPtrConstant( Node* call_target = mcgraph()->RelocatableIntPtrConstant(
wasm::WasmCode::kWasmRethrow, RelocInfo::WASM_STUB_CALL); wasm::WasmCode::kWasmRethrow, RelocInfo::WASM_STUB_CALL);
Node* throw_effect = gasm_->Call(call_descriptor, call_target, return_value);
graph()->NewNode(mcgraph()->common()->Call(call_descriptor), TerminateThrow(effect(), control());
call_target, return_value, effect(), control());
TerminateThrow(throw_effect, control());
SetControl( SetEffectControl(
return_value,
graph()->NewNode(mcgraph()->common()->IfTrue(), exception_branch)); graph()->NewNode(mcgraph()->common()->IfTrue(), exception_branch));
DCHECK_LT(sig_->return_count(), wasm::kV8MaxWasmFunctionMultiReturns); DCHECK_LT(sig_->return_count(), wasm::kV8MaxWasmFunctionMultiReturns);
size_t return_count = sig_->return_count(); size_t return_count = sig_->return_count();
...@@ -7319,8 +7190,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -7319,8 +7190,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
args[pos++] = control(); args[pos++] = control();
DCHECK_EQ(pos, args.size()); DCHECK_EQ(pos, args.size());
Node* call = SetEffect(graph()->NewNode( Node* call = gasm_->Call(call_descriptor, pos, args.begin());
mcgraph()->common()->Call(call_descriptor), pos, args.begin()));
// Convert return JS values to wasm numbers and back to JS values. // Convert return JS values to wasm numbers and back to JS values.
Node* jsval; Node* jsval;
...@@ -7332,8 +7202,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -7332,8 +7202,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
Node* fixed_array = Node* fixed_array =
BuildMultiReturnFixedArrayFromIterable(sig_, call, context); BuildMultiReturnFixedArrayFromIterable(sig_, call, context);
int32_t return_count = static_cast<int32_t>(sig_->return_count()); int32_t return_count = static_cast<int32_t>(sig_->return_count());
Node* size = Node* size = gasm_->NumberConstant(return_count);
graph()->NewNode(mcgraph()->common()->NumberConstant(return_count));
jsval = BuildCallAllocateJSArray(size, context); jsval = BuildCallAllocateJSArray(size, context);
Node* result_fixed_array = gasm_->LoadJSArrayElements(jsval); Node* result_fixed_array = gasm_->LoadJSArrayElements(jsval);
for (unsigned i = 0; i < sig_->return_count(); ++i) { for (unsigned i = 0; i < sig_->return_count(); ++i) {
...@@ -7383,8 +7252,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -7383,8 +7252,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
auto call_descriptor = GetWasmCallDescriptor(mcgraph()->zone(), sig_); auto call_descriptor = GetWasmCallDescriptor(mcgraph()->zone(), sig_);
DCHECK_EQ(pos, args.size()); DCHECK_EQ(pos, args.size());
Node* call = SetEffect(graph()->NewNode( Node* call = gasm_->Call(call_descriptor, pos, args.begin());
mcgraph()->common()->Call(call_descriptor), pos, args.begin()));
Node* if_success = graph()->NewNode(mcgraph()->common()->IfSuccess(), call); Node* if_success = graph()->NewNode(mcgraph()->common()->IfSuccess(), call);
Node* if_exception = Node* if_exception =
......
...@@ -222,6 +222,8 @@ class WasmGraphBuilder { ...@@ -222,6 +222,8 @@ class WasmGraphBuilder {
Node* LoopExitValue(Node* value, MachineRepresentation representation); Node* LoopExitValue(Node* value, MachineRepresentation representation);
Node* TerminateThrow(Node* effect, Node* control); Node* TerminateThrow(Node* effect, Node* control);
Node* Merge(unsigned count, Node** controls); Node* Merge(unsigned count, Node** controls);
template <typename... Nodes>
Node* Merge(Node* fst, Nodes*... args);
Node* Phi(wasm::ValueType type, unsigned count, Node** vals_and_control); Node* Phi(wasm::ValueType type, unsigned count, Node** vals_and_control);
Node* CreateOrMergeIntoPhi(MachineRepresentation rep, Node* merge, Node* CreateOrMergeIntoPhi(MachineRepresentation rep, Node* merge,
Node* tnode, Node* fnode); Node* tnode, Node* fnode);
......
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