Commit e2c7eba4 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[turbofan] Refactor handling of framestates in A.p.reduce[Right]

Bug: v8:7340
Change-Id: I7f4df794a57bf5db6a3b611ad76b5ef5c4edba9c
Reviewed-on: https://chromium-review.googlesource.com/878264Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50785}
parent 0998eda9
...@@ -115,12 +115,10 @@ Node* CreateBuiltinContinuationFrameStateCommon( ...@@ -115,12 +115,10 @@ Node* CreateBuiltinContinuationFrameStateCommon(
} }
} // namespace } // namespace
Node* CreateStubBuiltinContinuationFrameState(JSGraph* js_graph, Node* CreateStubBuiltinContinuationFrameState(
Builtins::Name name, JSGraph* js_graph, Builtins::Name name, Node* context,
Node* context, Node** parameters, Node* const* parameters, int parameter_count, Node* outer_frame_state,
int parameter_count, ContinuationFrameStateMode mode) {
Node* outer_frame_state,
ContinuationFrameStateMode mode) {
Isolate* isolate = js_graph->isolate(); Isolate* isolate = js_graph->isolate();
Callable callable = Builtins::CallableFor(isolate, name); Callable callable = Builtins::CallableFor(isolate, name);
CallInterfaceDescriptor descriptor = callable.descriptor(); CallInterfaceDescriptor descriptor = callable.descriptor();
...@@ -149,7 +147,7 @@ Node* CreateStubBuiltinContinuationFrameState(JSGraph* js_graph, ...@@ -149,7 +147,7 @@ Node* CreateStubBuiltinContinuationFrameState(JSGraph* js_graph,
Node* CreateJavaScriptBuiltinContinuationFrameState( Node* CreateJavaScriptBuiltinContinuationFrameState(
JSGraph* js_graph, Handle<JSFunction> function, Builtins::Name name, JSGraph* js_graph, Handle<JSFunction> function, Builtins::Name name,
Node* target, Node* context, Node** stack_parameters, Node* target, Node* context, Node* const* stack_parameters,
int stack_parameter_count, Node* outer_frame_state, int stack_parameter_count, Node* outer_frame_state,
ContinuationFrameStateMode mode) { ContinuationFrameStateMode mode) {
Isolate* isolate = js_graph->isolate(); Isolate* isolate = js_graph->isolate();
......
...@@ -145,16 +145,14 @@ static const int kFrameStateInputCount = kFrameStateOuterStateInput + 1; ...@@ -145,16 +145,14 @@ static const int kFrameStateInputCount = kFrameStateOuterStateInput + 1;
enum class ContinuationFrameStateMode { EAGER, LAZY }; enum class ContinuationFrameStateMode { EAGER, LAZY };
Node* CreateStubBuiltinContinuationFrameState(JSGraph* graph, Node* CreateStubBuiltinContinuationFrameState(
Builtins::Name name, JSGraph* graph, Builtins::Name name, Node* context, Node* const* parameters,
Node* context, Node** parameters, int parameter_count, Node* outer_frame_state,
int parameter_count, ContinuationFrameStateMode mode);
Node* outer_frame_state,
ContinuationFrameStateMode mode);
Node* CreateJavaScriptBuiltinContinuationFrameState( Node* CreateJavaScriptBuiltinContinuationFrameState(
JSGraph* graph, Handle<JSFunction> function, Builtins::Name name, JSGraph* graph, Handle<JSFunction> function, Builtins::Name name,
Node* target, Node* context, Node** stack_parameters, Node* target, Node* context, Node* const* stack_parameters,
int stack_parameter_count, Node* outer_frame_state, int stack_parameter_count, Node* outer_frame_state,
ContinuationFrameStateMode mode); ContinuationFrameStateMode mode);
......
...@@ -1065,11 +1065,6 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function, ...@@ -1065,11 +1065,6 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function,
left ? simplified()->NumberAdd() : simplified()->NumberSubtract(); left ? simplified()->NumberAdd() : simplified()->NumberSubtract();
Node* k = initial_index; Node* k = initial_index;
std::vector<Node*> checkpoint_params({receiver, fncallback, k,
original_length,
jsgraph()->UndefinedConstant()});
const int stack_parameters = static_cast<int>(checkpoint_params.size());
Builtins::Name builtin_lazy = Builtins::Name builtin_lazy =
left ? Builtins::kArrayReduceLoopLazyDeoptContinuation left ? Builtins::kArrayReduceLoopLazyDeoptContinuation
: Builtins::kArrayReduceRightLoopLazyDeoptContinuation; : Builtins::kArrayReduceRightLoopLazyDeoptContinuation;
...@@ -1078,15 +1073,19 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function, ...@@ -1078,15 +1073,19 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function,
left ? Builtins::kArrayReduceLoopEagerDeoptContinuation left ? Builtins::kArrayReduceLoopEagerDeoptContinuation
: Builtins::kArrayReduceRightLoopEagerDeoptContinuation; : Builtins::kArrayReduceRightLoopEagerDeoptContinuation;
// Check whether the given callback function is callable. Note that const std::vector<Node*> checkpoint_params({receiver, fncallback, k,
// this has to happen outside the loop to make sure we also throw on original_length,
// empty arrays. jsgraph()->UndefinedConstant()});
const int stack_parameters = static_cast<int>(checkpoint_params.size());
Node* check_frame_state = CreateJavaScriptBuiltinContinuationFrameState( Node* check_frame_state = CreateJavaScriptBuiltinContinuationFrameState(
jsgraph(), function, builtin_lazy, node->InputAt(0), context, jsgraph(), function, builtin_lazy, node->InputAt(0), context,
&checkpoint_params[0], stack_parameters - 1, outer_frame_state, checkpoint_params.data(), stack_parameters - 1, outer_frame_state,
ContinuationFrameStateMode::LAZY); ContinuationFrameStateMode::LAZY);
Node* check_fail = nullptr; Node* check_fail = nullptr;
Node* check_throw = nullptr; Node* check_throw = nullptr;
// Check whether the given callback function is callable. Note that
// this has to happen outside the loop to make sure we also throw on
// empty arrays.
WireInCallbackIsCallableCheck(fncallback, context, check_frame_state, effect, WireInCallbackIsCallableCheck(fncallback, context, check_frame_state, effect,
&control, &check_fail, &check_throw); &control, &check_fail, &check_throw);
...@@ -1096,7 +1095,7 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function, ...@@ -1096,7 +1095,7 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function,
Node* initial_element_frame_state = Node* initial_element_frame_state =
CreateJavaScriptBuiltinContinuationFrameState( CreateJavaScriptBuiltinContinuationFrameState(
jsgraph(), function, builtin_eager, node->InputAt(0), context, jsgraph(), function, builtin_eager, node->InputAt(0), context,
&checkpoint_params[0], stack_parameters, outer_frame_state, checkpoint_params.data(), stack_parameters, outer_frame_state,
ContinuationFrameStateMode::EAGER); ContinuationFrameStateMode::EAGER);
if (node->op()->ValueInputCount() > 3) { if (node->op()->ValueInputCount() > 3) {
...@@ -1140,8 +1139,6 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function, ...@@ -1140,8 +1139,6 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function,
common()->Phi(MachineRepresentation::kTagged, 2), k, k, loop); common()->Phi(MachineRepresentation::kTagged, 2), k, k, loop);
Node* curloop = cur = graph()->NewNode( Node* curloop = cur = graph()->NewNode(
common()->Phi(MachineRepresentation::kTagged, 2), cur, cur, loop); common()->Phi(MachineRepresentation::kTagged, 2), cur, cur, loop);
checkpoint_params[2] = k;
checkpoint_params[4] = curloop;
control = loop; control = loop;
effect = eloop; effect = eloop;
...@@ -1159,13 +1156,17 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function, ...@@ -1159,13 +1156,17 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function,
Node* if_false = graph()->NewNode(common()->IfFalse(), continue_branch); Node* if_false = graph()->NewNode(common()->IfFalse(), continue_branch);
control = if_true; control = if_true;
Node* frame_state = CreateJavaScriptBuiltinContinuationFrameState( {
jsgraph(), function, builtin_eager, node->InputAt(0), context, const std::vector<Node*> checkpoint_params(
&checkpoint_params[0], stack_parameters, outer_frame_state, {receiver, fncallback, k, original_length, curloop});
ContinuationFrameStateMode::EAGER); const int stack_parameters = static_cast<int>(checkpoint_params.size());
Node* frame_state = CreateJavaScriptBuiltinContinuationFrameState(
effect = jsgraph(), function, builtin_eager, node->InputAt(0), context,
graph()->NewNode(common()->Checkpoint(), frame_state, effect, control); checkpoint_params.data(), stack_parameters, outer_frame_state,
ContinuationFrameStateMode::EAGER);
effect =
graph()->NewNode(common()->Checkpoint(), frame_state, effect, control);
}
// Make sure the map hasn't changed during the iteration // Make sure the map hasn't changed during the iteration
effect = graph()->NewNode( effect = graph()->NewNode(
...@@ -1176,7 +1177,6 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function, ...@@ -1176,7 +1177,6 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function,
SafeLoadElement(kind, receiver, control, &effect, &k, p.feedback()); SafeLoadElement(kind, receiver, control, &effect, &k, p.feedback());
Node* next_k = graph()->NewNode(next_op, k, jsgraph()->OneConstant()); Node* next_k = graph()->NewNode(next_op, k, jsgraph()->OneConstant());
checkpoint_params[2] = next_k;
Node* hole_true = nullptr; Node* hole_true = nullptr;
Node* hole_false = nullptr; Node* hole_false = nullptr;
...@@ -1198,15 +1198,21 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function, ...@@ -1198,15 +1198,21 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function,
common()->TypeGuard(Type::NonInternal()), element, effect, control); common()->TypeGuard(Type::NonInternal()), element, effect, control);
} }
frame_state = CreateJavaScriptBuiltinContinuationFrameState( Node* next_cur;
jsgraph(), function, builtin_lazy, node->InputAt(0), context, {
&checkpoint_params[0], stack_parameters - 1, outer_frame_state, const std::vector<Node*> checkpoint_params(
ContinuationFrameStateMode::LAZY); {receiver, fncallback, next_k, original_length, curloop});
const int stack_parameters = static_cast<int>(checkpoint_params.size());
Node* frame_state = CreateJavaScriptBuiltinContinuationFrameState(
jsgraph(), function, builtin_lazy, node->InputAt(0), context,
checkpoint_params.data(), stack_parameters - 1, outer_frame_state,
ContinuationFrameStateMode::LAZY);
Node* next_cur = control = effect = next_cur = control = effect =
graph()->NewNode(javascript()->Call(6, p.frequency()), fncallback, graph()->NewNode(javascript()->Call(6, p.frequency()), fncallback,
jsgraph()->UndefinedConstant(), cur, element, k, jsgraph()->UndefinedConstant(), cur, element, k,
receiver, context, frame_state, effect, control); receiver, context, frame_state, effect, control);
}
// Rewire potential exception edges. // Rewire potential exception edges.
Node* on_exception = nullptr; Node* on_exception = nullptr;
......
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