Commit e465a4f3 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[turbofan] Support inlining of builtins based on SharedFunctionInfo.

This makes the inlining of the default resolve/reject closures generated
by the Promise constructor effective. To be really useful we still need
to have the Promise constructor inlined (work-in-progress) and eventually
track SharedFunctionInfo feedback in the CALL_IC.

Bug: v8:2206, v8:7253
Change-Id: I08fa8ca72754f459ae36027a55377ef57d411cdc
Reviewed-on: https://chromium-review.googlesource.com/926103
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51390}
parent 46c199a5
...@@ -79,12 +79,15 @@ std::ostream& operator<<(std::ostream& os, FrameStateInfo const& info) { ...@@ -79,12 +79,15 @@ std::ostream& operator<<(std::ostream& os, FrameStateInfo const& info) {
} }
namespace { namespace {
Node* CreateBuiltinContinuationFrameStateCommon( Node* CreateBuiltinContinuationFrameStateCommon(
JSGraph* js_graph, Builtins::Name name, Node* context, Node** parameters, JSGraph* jsgraph, FrameStateType frame_type, Builtins::Name name,
int parameter_count, Node* outer_frame_state, Handle<JSFunction> function) { Node* closure, Node* context, Node** parameters, int parameter_count,
Isolate* isolate = js_graph->isolate(); Node* outer_frame_state,
Graph* graph = js_graph->graph(); Handle<SharedFunctionInfo> shared = Handle<SharedFunctionInfo>()) {
CommonOperatorBuilder* common = js_graph->common(); Isolate* const isolate = jsgraph->isolate();
Graph* const graph = jsgraph->graph();
CommonOperatorBuilder* const common = jsgraph->common();
BailoutId bailout_id = Builtins::GetContinuationBailoutId(name); BailoutId bailout_id = Builtins::GetContinuationBailoutId(name);
Callable callable = Builtins::CallableFor(isolate, name); Callable callable = Builtins::CallableFor(isolate, name);
...@@ -93,33 +96,26 @@ Node* CreateBuiltinContinuationFrameStateCommon( ...@@ -93,33 +96,26 @@ Node* CreateBuiltinContinuationFrameStateCommon(
common->StateValues(parameter_count, SparseInputMask::Dense()); common->StateValues(parameter_count, SparseInputMask::Dense());
Node* params_node = graph->NewNode(op_param, parameter_count, parameters); Node* params_node = graph->NewNode(op_param, parameter_count, parameters);
FrameStateType frame_type =
function.is_null() ? FrameStateType::kBuiltinContinuation
: FrameStateType::kJavaScriptBuiltinContinuation;
const FrameStateFunctionInfo* state_info = const FrameStateFunctionInfo* state_info =
common->CreateFrameStateFunctionInfo( common->CreateFrameStateFunctionInfo(frame_type, parameter_count, 0,
frame_type, parameter_count, 0, shared);
function.is_null() ? Handle<SharedFunctionInfo>()
: Handle<SharedFunctionInfo>(function->shared()));
const Operator* op = common->FrameState( const Operator* op = common->FrameState(
bailout_id, OutputFrameStateCombine::Ignore(), state_info); bailout_id, OutputFrameStateCombine::Ignore(), state_info);
Node* function_node = function.is_null() ? js_graph->UndefinedConstant()
: js_graph->HeapConstant(function);
Node* frame_state = graph->NewNode( Node* frame_state = graph->NewNode(
op, params_node, js_graph->EmptyStateValues(), op, params_node, jsgraph->EmptyStateValues(), jsgraph->EmptyStateValues(),
js_graph->EmptyStateValues(), context, function_node, outer_frame_state); context, closure, outer_frame_state);
return frame_state; return frame_state;
} }
} // namespace } // namespace
Node* CreateStubBuiltinContinuationFrameState( Node* CreateStubBuiltinContinuationFrameState(
JSGraph* js_graph, Builtins::Name name, Node* context, JSGraph* jsgraph, Builtins::Name name, Node* context,
Node* const* parameters, int parameter_count, Node* outer_frame_state, Node* const* parameters, int parameter_count, Node* outer_frame_state,
ContinuationFrameStateMode mode) { ContinuationFrameStateMode mode) {
Isolate* isolate = js_graph->isolate(); Isolate* isolate = jsgraph->isolate();
Callable callable = Builtins::CallableFor(isolate, name); Callable callable = Builtins::CallableFor(isolate, name);
CallInterfaceDescriptor descriptor = callable.descriptor(); CallInterfaceDescriptor descriptor = callable.descriptor();
...@@ -140,18 +136,18 @@ Node* CreateStubBuiltinContinuationFrameState( ...@@ -140,18 +136,18 @@ Node* CreateStubBuiltinContinuationFrameState(
} }
return CreateBuiltinContinuationFrameStateCommon( return CreateBuiltinContinuationFrameStateCommon(
js_graph, name, context, actual_parameters.data(), jsgraph, FrameStateType::kBuiltinContinuation, name,
static_cast<int>(actual_parameters.size()), outer_frame_state, jsgraph->UndefinedConstant(), context, actual_parameters.data(),
Handle<JSFunction>()); static_cast<int>(actual_parameters.size()), outer_frame_state);
} }
Node* CreateJavaScriptBuiltinContinuationFrameState( Node* CreateJavaScriptBuiltinContinuationFrameState(
JSGraph* js_graph, Handle<JSFunction> function, Builtins::Name name, JSGraph* jsgraph, Handle<SharedFunctionInfo> shared, Builtins::Name name,
Node* target, Node* context, Node* const* 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* const isolate = jsgraph->isolate();
Callable callable = Builtins::CallableFor(isolate, name); Callable const callable = Builtins::CallableFor(isolate, name);
// Lazy deopt points where the frame state is assocated with a call get an // Lazy deopt points where the frame state is assocated with a call get an
// additional parameter for the return result from the call that's added by // additional parameter for the return result from the call that's added by
...@@ -163,8 +159,8 @@ Node* CreateJavaScriptBuiltinContinuationFrameState( ...@@ -163,8 +159,8 @@ Node* CreateJavaScriptBuiltinContinuationFrameState(
(mode == ContinuationFrameStateMode::EAGER ? 0 : 1)); (mode == ContinuationFrameStateMode::EAGER ? 0 : 1));
Node* argc = Node* argc =
js_graph->Constant(stack_parameter_count - jsgraph->Constant(stack_parameter_count -
(mode == ContinuationFrameStateMode::EAGER ? 1 : 0)); (mode == ContinuationFrameStateMode::EAGER ? 1 : 0));
// Stack parameters first. They must be first because the receiver is expected // Stack parameters first. They must be first because the receiver is expected
// to be the second value in the translation when creating stack crawls // to be the second value in the translation when creating stack crawls
...@@ -177,12 +173,13 @@ Node* CreateJavaScriptBuiltinContinuationFrameState( ...@@ -177,12 +173,13 @@ Node* CreateJavaScriptBuiltinContinuationFrameState(
// Register parameters follow stack paraemters. The context will be added by // Register parameters follow stack paraemters. The context will be added by
// instruction selector during FrameState translation. // instruction selector during FrameState translation.
actual_parameters.push_back(target); actual_parameters.push_back(target);
actual_parameters.push_back(js_graph->UndefinedConstant()); actual_parameters.push_back(jsgraph->UndefinedConstant());
actual_parameters.push_back(argc); actual_parameters.push_back(argc);
return CreateBuiltinContinuationFrameStateCommon( return CreateBuiltinContinuationFrameStateCommon(
js_graph, name, context, &actual_parameters[0], jsgraph, FrameStateType::kJavaScriptBuiltinContinuation, name, target,
static_cast<int>(actual_parameters.size()), outer_frame_state, function); context, &actual_parameters[0],
static_cast<int>(actual_parameters.size()), outer_frame_state, shared);
} }
} // namespace compiler } // namespace compiler
......
...@@ -151,7 +151,7 @@ Node* CreateStubBuiltinContinuationFrameState( ...@@ -151,7 +151,7 @@ Node* CreateStubBuiltinContinuationFrameState(
ContinuationFrameStateMode mode); ContinuationFrameStateMode mode);
Node* CreateJavaScriptBuiltinContinuationFrameState( Node* CreateJavaScriptBuiltinContinuationFrameState(
JSGraph* graph, Handle<JSFunction> function, Builtins::Name name, JSGraph* graph, Handle<SharedFunctionInfo> shared, Builtins::Name name,
Node* target, Node* context, Node* const* 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);
......
This diff is collapsed.
...@@ -52,10 +52,10 @@ class V8_EXPORT_PRIVATE JSCallReducer final : public AdvancedReducer { ...@@ -52,10 +52,10 @@ class V8_EXPORT_PRIVATE JSCallReducer final : public AdvancedReducer {
void Finalize() final; void Finalize() final;
private: private:
enum ArrayReduceDirection { kArrayReduceLeft, kArrayReduceRight };
Reduction ReduceArrayConstructor(Node* node); Reduction ReduceArrayConstructor(Node* node);
Reduction ReduceBooleanConstructor(Node* node); Reduction ReduceBooleanConstructor(Node* node);
Reduction ReduceCallApiFunction(Node* node, Handle<JSFunction> function); Reduction ReduceCallApiFunction(Node* node,
Handle<SharedFunctionInfo> shared);
Reduction ReduceFunctionPrototypeApply(Node* node); Reduction ReduceFunctionPrototypeApply(Node* node);
Reduction ReduceFunctionPrototypeBind(Node* node); Reduction ReduceFunctionPrototypeBind(Node* node);
Reduction ReduceFunctionPrototypeCall(Node* node); Reduction ReduceFunctionPrototypeCall(Node* node);
...@@ -72,16 +72,17 @@ class V8_EXPORT_PRIVATE JSCallReducer final : public AdvancedReducer { ...@@ -72,16 +72,17 @@ class V8_EXPORT_PRIVATE JSCallReducer final : public AdvancedReducer {
Reduction ReduceReflectGet(Node* node); Reduction ReduceReflectGet(Node* node);
Reduction ReduceReflectGetPrototypeOf(Node* node); Reduction ReduceReflectGetPrototypeOf(Node* node);
Reduction ReduceReflectHas(Node* node); Reduction ReduceReflectHas(Node* node);
Reduction ReduceArrayForEach(Handle<JSFunction> function, Node* node); Reduction ReduceArrayForEach(Node* node, Handle<SharedFunctionInfo> shared);
Reduction ReduceArrayReduce(Handle<JSFunction> function, Node* node, enum class ArrayReduceDirection { kLeft, kRight };
ArrayReduceDirection direction); Reduction ReduceArrayReduce(Node* node, ArrayReduceDirection direction,
Reduction ReduceArrayMap(Handle<JSFunction> function, Node* node); Handle<SharedFunctionInfo> shared);
Reduction ReduceArrayFilter(Handle<JSFunction> function, Node* node); Reduction ReduceArrayMap(Node* node, Handle<SharedFunctionInfo> shared);
enum class ArrayFindVariant : uint8_t { kFind, kFindIndex }; Reduction ReduceArrayFilter(Node* node, Handle<SharedFunctionInfo> shared);
Reduction ReduceArrayFind(ArrayFindVariant variant, enum class ArrayFindVariant { kFind, kFindIndex };
Handle<JSFunction> function, Node* node); Reduction ReduceArrayFind(Node* node, ArrayFindVariant variant,
Reduction ReduceArrayEvery(Handle<JSFunction> function, Node* node); Handle<SharedFunctionInfo> shared);
Reduction ReduceArraySome(Handle<JSFunction> function, Node* node); Reduction ReduceArrayEvery(Node* node, Handle<SharedFunctionInfo> shared);
Reduction ReduceArraySome(Node* node, Handle<SharedFunctionInfo> shared);
Reduction ReduceArrayPrototypePush(Node* node); Reduction ReduceArrayPrototypePush(Node* node);
Reduction ReduceArrayPrototypePop(Node* node); Reduction ReduceArrayPrototypePop(Node* node);
Reduction ReduceArrayPrototypeShift(Node* node); Reduction ReduceArrayPrototypeShift(Node* node);
...@@ -92,11 +93,11 @@ class V8_EXPORT_PRIVATE JSCallReducer final : public AdvancedReducer { ...@@ -92,11 +93,11 @@ class V8_EXPORT_PRIVATE JSCallReducer final : public AdvancedReducer {
Reduction ReduceJSConstructWithArrayLike(Node* node); Reduction ReduceJSConstructWithArrayLike(Node* node);
Reduction ReduceJSConstructWithSpread(Node* node); Reduction ReduceJSConstructWithSpread(Node* node);
Reduction ReduceJSCall(Node* node); Reduction ReduceJSCall(Node* node);
Reduction ReduceJSCall(Node* node, Handle<SharedFunctionInfo> shared);
Reduction ReduceJSCallWithArrayLike(Node* node); Reduction ReduceJSCallWithArrayLike(Node* node);
Reduction ReduceJSCallWithSpread(Node* node); Reduction ReduceJSCallWithSpread(Node* node);
Reduction ReduceReturnReceiver(Node* node); Reduction ReduceReturnReceiver(Node* node);
Reduction ReduceStringPrototypeIndexOf(Handle<JSFunction> function, Reduction ReduceStringPrototypeIndexOf(Node* node);
Node* node);
Reduction ReduceStringPrototypeStringAt( Reduction ReduceStringPrototypeStringAt(
const Operator* string_access_operator, Node* node); const Operator* string_access_operator, Node* node);
Reduction ReduceAsyncFunctionPromiseCreate(Node* node); Reduction ReduceAsyncFunctionPromiseCreate(Node* node);
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Flags: --allow-natives-syntax --opt // Flags: --allow-natives-syntax
(function() { (function() {
var resolve, value; var resolve, value;
...@@ -25,3 +25,23 @@ ...@@ -25,3 +25,23 @@
foo(); foo();
setTimeout(_ => assertEquals(1, value)); setTimeout(_ => assertEquals(1, value));
})(); })();
(function() {
var value;
function foo(x) { return new Promise((resolve, reject) => resolve(x)); }
foo(1);
foo(1);
%OptimizeFunctionOnNextCall(foo);
foo(1).then(v => value = v);
setTimeout(_ => assertEquals(1, value));
})();
(function() {
var value;
function foo(x) { return new Promise((resolve, reject) => reject(x)); }
foo(1);
foo(1);
%OptimizeFunctionOnNextCall(foo);
foo(1).catch(v => value = v);
setTimeout(_ => assertEquals(1, value));
})();
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