Commit 10a8ae41 authored by Mike Stanton's avatar Mike Stanton Committed by Commit Bot

[TurboFan] Some refactoring in the inlined array builtins.

This code is highly repetitive, and while we've held off on large
refactorings (using "Builder" classes, templates or macros), it's
useful to find a few common points that don't change very much.

Bug: 
Change-Id: Ib0880558cf667f5d07c8343328461609ccb1e6b1
Reviewed-on: https://chromium-review.googlesource.com/848913Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
Commit-Queue: Michael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50338}
parent 94ef1148
......@@ -792,6 +792,24 @@ bool CanInlineArrayIteratingBuiltin(Handle<Map> receiver_map) {
isolate->IsAnyInitialArrayPrototype(receiver_prototype);
}
Node* JSCallReducer::WireInLoopStart(Node* k, Node** control, Node** effect) {
Node* loop = *control =
graph()->NewNode(common()->Loop(2), *control, *control);
Node* eloop = *effect =
graph()->NewNode(common()->EffectPhi(2), *effect, *effect, loop);
Node* terminate = graph()->NewNode(common()->Terminate(), eloop, loop);
NodeProperties::MergeControlToEnd(graph(), common(), terminate);
return graph()->NewNode(common()->Phi(MachineRepresentation::kTagged, 2), k,
k, loop);
}
void JSCallReducer::WireInLoopEnd(Node* loop, Node* eloop, Node* vloop, Node* k,
Node* control, Node* effect) {
loop->ReplaceInput(1, control);
vloop->ReplaceInput(1, k);
eloop->ReplaceInput(1, effect);
}
Reduction JSCallReducer::ReduceArrayForEach(Handle<JSFunction> function,
Node* node) {
if (!FLAG_turbo_inline_array_builtins) return NoChange();
......@@ -868,18 +886,10 @@ Reduction JSCallReducer::ReduceArrayForEach(Handle<JSFunction> function,
&control, &check_fail, &check_throw);
// Start the loop.
Node* loop = control = graph()->NewNode(common()->Loop(2), control, control);
Node* eloop = effect =
graph()->NewNode(common()->EffectPhi(2), effect, effect, loop);
Node* terminate = graph()->NewNode(common()->Terminate(), eloop, loop);
NodeProperties::MergeControlToEnd(graph(), common(), terminate);
Node* vloop = k = graph()->NewNode(
common()->Phi(MachineRepresentation::kTagged, 2), k, k, loop);
Node* vloop = k = WireInLoopStart(k, &control, &effect);
Node *loop = control, *eloop = effect;
checkpoint_params[3] = k;
control = loop;
effect = eloop;
Node* continue_test =
graph()->NewNode(simplified()->NumberLessThan(), k, original_length);
Node* continue_branch = graph()->NewNode(common()->Branch(BranchHint::kTrue),
......@@ -959,11 +969,7 @@ Reduction JSCallReducer::ReduceArrayForEach(Handle<JSFunction> function,
control);
}
k = next_k;
loop->ReplaceInput(1, control);
vloop->ReplaceInput(1, k);
eloop->ReplaceInput(1, effect);
WireInLoopEnd(loop, eloop, vloop, next_k, control, effect);
control = if_false;
effect = eloop;
......@@ -1529,18 +1535,10 @@ Reduction JSCallReducer::ReduceArrayMap(Handle<JSFunction> function,
&control, &check_fail, &check_throw);
// Start the loop.
Node* loop = control = graph()->NewNode(common()->Loop(2), control, control);
Node* eloop = effect =
graph()->NewNode(common()->EffectPhi(2), effect, effect, loop);
Node* terminate = graph()->NewNode(common()->Terminate(), eloop, loop);
NodeProperties::MergeControlToEnd(graph(), common(), terminate);
Node* vloop = k = graph()->NewNode(
common()->Phi(MachineRepresentation::kTagged, 2), k, k, loop);
Node* vloop = k = WireInLoopStart(k, &control, &effect);
Node *loop = control, *eloop = effect;
checkpoint_params[4] = k;
control = loop;
effect = eloop;
Node* continue_test =
graph()->NewNode(simplified()->NumberLessThan(), k, original_length);
Node* continue_branch = graph()->NewNode(common()->Branch(BranchHint::kTrue),
......@@ -1630,11 +1628,7 @@ Reduction JSCallReducer::ReduceArrayMap(Handle<JSFunction> function,
after_call_and_store_effect, control);
}
k = next_k;
loop->ReplaceInput(1, control);
vloop->ReplaceInput(1, k);
eloop->ReplaceInput(1, effect);
WireInLoopEnd(loop, eloop, vloop, next_k, control, effect);
control = if_false;
effect = eloop;
......@@ -1760,19 +1754,11 @@ Reduction JSCallReducer::ReduceArrayFilter(Handle<JSFunction> function,
}
// Start the loop.
Node* loop = control = graph()->NewNode(common()->Loop(2), control, control);
Node* eloop = effect =
graph()->NewNode(common()->EffectPhi(2), effect, effect, loop);
Node* terminate = graph()->NewNode(common()->Terminate(), eloop, loop);
NodeProperties::MergeControlToEnd(graph(), common(), terminate);
Node* vloop = k = graph()->NewNode(
common()->Phi(MachineRepresentation::kTagged, 2), k, k, loop);
Node* vloop = k = WireInLoopStart(k, &control, &effect);
Node *loop = control, *eloop = effect;
Node* v_to_loop = to = graph()->NewNode(
common()->Phi(MachineRepresentation::kTaggedSigned, 2), to, to, loop);
control = loop;
effect = eloop;
Node* continue_test =
graph()->NewNode(simplified()->NumberLessThan(), k, original_length);
Node* continue_branch = graph()->NewNode(common()->Branch(BranchHint::kTrue),
......@@ -1897,12 +1883,8 @@ Reduction JSCallReducer::ReduceArrayFilter(Handle<JSFunction> function,
hole_true_vto, to, control);
}
k = next_k;
loop->ReplaceInput(1, control);
vloop->ReplaceInput(1, k);
WireInLoopEnd(loop, eloop, vloop, next_k, control, effect);
v_to_loop->ReplaceInput(1, to);
eloop->ReplaceInput(1, effect);
control = if_false;
effect = eloop;
......@@ -2009,13 +1991,8 @@ Reduction JSCallReducer::ReduceArrayFind(ArrayFindVariant variant,
}
// Start the loop.
Node* loop = control = graph()->NewNode(common()->Loop(2), control, control);
Node* eloop = effect =
graph()->NewNode(common()->EffectPhi(2), effect, effect, loop);
Node* terminate = graph()->NewNode(common()->Terminate(), eloop, loop);
NodeProperties::MergeControlToEnd(graph(), common(), terminate);
Node* vloop = k = graph()->NewNode(
common()->Phi(MachineRepresentation::kTagged, 2), k, k, loop);
Node* vloop = k = WireInLoopStart(k, &control, &effect);
Node *loop = control, *eloop = effect;
checkpoint_params[3] = k;
// Check if we've iterated past the last element of the array.
......@@ -2103,9 +2080,7 @@ Reduction JSCallReducer::ReduceArrayFind(ArrayFindVariant variant,
control = if_notfound;
// Close the loop.
loop->ReplaceInput(1, control);
vloop->ReplaceInput(1, next_k);
eloop->ReplaceInput(1, effect);
WireInLoopEnd(loop, eloop, vloop, next_k, control, effect);
control = graph()->NewNode(common()->Merge(2), if_found, if_false);
effect =
......@@ -2339,13 +2314,8 @@ Reduction JSCallReducer::ReduceArrayEvery(Handle<JSFunction> function,
}
// Start the loop.
Node* loop = control = graph()->NewNode(common()->Loop(2), control, control);
Node* eloop = effect =
graph()->NewNode(common()->EffectPhi(2), effect, effect, loop);
Node* terminate = graph()->NewNode(common()->Terminate(), eloop, loop);
NodeProperties::MergeControlToEnd(graph(), common(), terminate);
Node* vloop = k = graph()->NewNode(
common()->Phi(MachineRepresentation::kTagged, 2), k, k, loop);
Node* vloop = k = WireInLoopStart(k, &control, &effect);
Node *loop = control, *eloop = effect;
Node* continue_test =
graph()->NewNode(simplified()->NumberLessThan(), k, original_length);
......@@ -2458,9 +2428,7 @@ Reduction JSCallReducer::ReduceArrayEvery(Handle<JSFunction> function,
control);
}
loop->ReplaceInput(1, control);
vloop->ReplaceInput(1, next_k);
eloop->ReplaceInput(1, effect);
WireInLoopEnd(loop, eloop, vloop, next_k, control, effect);
control = graph()->NewNode(common()->Merge(2), if_false, if_false_callback);
effect =
......
......@@ -117,6 +117,15 @@ class JSCallReducer final : public AdvancedReducer {
Node* effect, Node** check_fail,
Node** control);
// Begin the central loop of a higher-order array builtin. A Loop is wired
// into {control}, an EffectPhi into {effect}, and the array index {k} is
// threaded into a Phi, which is returned. It's helpful to save the
// value of {control} as the loop node, and of {effect} as the corresponding
// EffectPhi after function return.
Node* WireInLoopStart(Node* k, Node** control, Node** effect);
void WireInLoopEnd(Node* loop, Node* eloop, Node* vloop, Node* k,
Node* control, Node* effect);
// Load receiver[k], first bounding k by receiver array length.
// k is thusly changed, and the effect is changed as well.
Node* SafeLoadElement(ElementsKind kind, Node* receiver, Node* control,
......
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