Commit b2733d75 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[wasm] Implement i32 to tagged conversion in GraphAssembler

This makes the code more readable, and allows for easier future
performance optimizations.

R=jkummerow@chromium.org

Bug: v8:10123, v8:10070
Change-Id: Ifd27f0c888da21bb7f5729c550e8993e793ae7d2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2037438Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66136}
parent 8c8af291
...@@ -5148,7 +5148,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -5148,7 +5148,7 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
: GetBuiltinPointerTarget(builtin_id); : GetBuiltinPointerTarget(builtin_id);
} }
Node* BuildAllocateHeapNumberWithValue(Node* value, Node* control) { Node* BuildAllocateHeapNumberWithValue(Node* value) {
MachineOperatorBuilder* machine = mcgraph()->machine(); MachineOperatorBuilder* machine = mcgraph()->machine();
CommonOperatorBuilder* common = mcgraph()->common(); CommonOperatorBuilder* common = mcgraph()->common();
Node* target = GetTargetForBuiltinCall(wasm::WasmCode::kAllocateHeapNumber, Node* target = GetTargetForBuiltinCall(wasm::WasmCode::kAllocateHeapNumber,
...@@ -5160,12 +5160,12 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -5160,12 +5160,12 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
allocate_heap_number_operator_.set(common->Call(call_descriptor)); allocate_heap_number_operator_.set(common->Call(call_descriptor));
} }
Node* heap_number = graph()->NewNode(allocate_heap_number_operator_.get(), Node* heap_number = graph()->NewNode(allocate_heap_number_operator_.get(),
target, effect(), control); target, effect(), control());
SetEffect( SetEffect(
graph()->NewNode(machine->Store(StoreRepresentation( graph()->NewNode(machine->Store(StoreRepresentation(
MachineRepresentation::kFloat64, kNoWriteBarrier)), MachineRepresentation::kFloat64, kNoWriteBarrier)),
heap_number, BuildHeapNumberValueIndexConstant(), heap_number, BuildHeapNumberValueIndexConstant(),
value, heap_number, control)); value, heap_number, control()));
return heap_number; return heap_number;
} }
...@@ -5212,37 +5212,31 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -5212,37 +5212,31 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
} }
Node* BuildChangeInt32ToTagged(Node* value) { Node* BuildChangeInt32ToTagged(Node* value) {
MachineOperatorBuilder* machine = mcgraph()->machine();
CommonOperatorBuilder* common = mcgraph()->common();
if (SmiValuesAre32Bits()) { if (SmiValuesAre32Bits()) {
return BuildChangeInt32ToSmi(value); return BuildChangeInt32ToSmi(value);
} }
DCHECK(SmiValuesAre31Bits()); DCHECK(SmiValuesAre31Bits());
Node* old_effect = effect(); auto allocate_heap_number = gasm_->MakeDeferredLabel();
Node* old_control = control(); auto done = gasm_->MakeLabel(MachineRepresentation::kTagged);
Node* add = graph()->NewNode(machine->Int32AddWithOverflow(), value, value,
graph()->start());
Node* ovf = graph()->NewNode(common->Projection(1), add, graph()->start()); // The smi value is {2 * value}. If that overflows, we need to allocate a
Node* branch = // heap number.
graph()->NewNode(common->Branch(BranchHint::kFalse), ovf, old_control); Node* add = gasm_->Int32AddWithOverflow(value, value);
Node* ovf = gasm_->Projection(1, add);
gasm_->GotoIf(ovf, &allocate_heap_number);
Node* if_true = graph()->NewNode(common->IfTrue(), branch); // If it didn't overflow, the result is {2 * value} as pointer-sized value.
Node* vtrue = BuildAllocateHeapNumberWithValue( Node* smi_tagged = BuildChangeInt32ToIntPtr(gasm_->Projection(0, add));
graph()->NewNode(machine->ChangeInt32ToFloat64(), value), if_true); gasm_->Goto(&done, smi_tagged);
Node* etrue = effect();
Node* if_false = graph()->NewNode(common->IfFalse(), branch); gasm_->Bind(&allocate_heap_number);
Node* vfalse = graph()->NewNode(common->Projection(0), add, if_false); Node* heap_number =
vfalse = BuildChangeInt32ToIntPtr(vfalse); BuildAllocateHeapNumberWithValue(gasm_->ChangeInt32ToFloat64(value));
gasm_->Goto(&done, heap_number);
Node* merge = gasm_->Bind(&done);
SetControl(graph()->NewNode(common->Merge(2), if_true, if_false)); return done.PhiAt(0);
SetEffect(graph()->NewNode(common->EffectPhi(2), etrue, old_effect, merge));
return graph()->NewNode(common->Phi(MachineRepresentation::kTagged, 2),
vtrue, vfalse, merge);
} }
Node* BuildChangeFloat64ToTagged(Node* value) { Node* BuildChangeFloat64ToTagged(Node* value) {
...@@ -5323,7 +5317,8 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder { ...@@ -5323,7 +5317,8 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
} }
// Allocate the box for the {value}. // Allocate the box for the {value}.
Node* vbox = BuildAllocateHeapNumberWithValue(value, if_box); SetControl(if_box);
Node* vbox = BuildAllocateHeapNumberWithValue(value);
Node* ebox = effect(); Node* ebox = effect();
Node* merge = Node* merge =
......
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