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) {
}
namespace {
Node* CreateBuiltinContinuationFrameStateCommon(
JSGraph* js_graph, Builtins::Name name, Node* context, Node** parameters,
int parameter_count, Node* outer_frame_state, Handle<JSFunction> function) {
Isolate* isolate = js_graph->isolate();
Graph* graph = js_graph->graph();
CommonOperatorBuilder* common = js_graph->common();
JSGraph* jsgraph, FrameStateType frame_type, Builtins::Name name,
Node* closure, Node* context, Node** parameters, int parameter_count,
Node* outer_frame_state,
Handle<SharedFunctionInfo> shared = Handle<SharedFunctionInfo>()) {
Isolate* const isolate = jsgraph->isolate();
Graph* const graph = jsgraph->graph();
CommonOperatorBuilder* const common = jsgraph->common();
BailoutId bailout_id = Builtins::GetContinuationBailoutId(name);
Callable callable = Builtins::CallableFor(isolate, name);
......@@ -93,33 +96,26 @@ Node* CreateBuiltinContinuationFrameStateCommon(
common->StateValues(parameter_count, SparseInputMask::Dense());
Node* params_node = graph->NewNode(op_param, parameter_count, parameters);
FrameStateType frame_type =
function.is_null() ? FrameStateType::kBuiltinContinuation
: FrameStateType::kJavaScriptBuiltinContinuation;
const FrameStateFunctionInfo* state_info =
common->CreateFrameStateFunctionInfo(
frame_type, parameter_count, 0,
function.is_null() ? Handle<SharedFunctionInfo>()
: Handle<SharedFunctionInfo>(function->shared()));
common->CreateFrameStateFunctionInfo(frame_type, parameter_count, 0,
shared);
const Operator* op = common->FrameState(
bailout_id, OutputFrameStateCombine::Ignore(), state_info);
Node* function_node = function.is_null() ? js_graph->UndefinedConstant()
: js_graph->HeapConstant(function);
Node* frame_state = graph->NewNode(
op, params_node, js_graph->EmptyStateValues(),
js_graph->EmptyStateValues(), context, function_node, outer_frame_state);
op, params_node, jsgraph->EmptyStateValues(), jsgraph->EmptyStateValues(),
context, closure, outer_frame_state);
return frame_state;
}
} // namespace
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,
ContinuationFrameStateMode mode) {
Isolate* isolate = js_graph->isolate();
Isolate* isolate = jsgraph->isolate();
Callable callable = Builtins::CallableFor(isolate, name);
CallInterfaceDescriptor descriptor = callable.descriptor();
......@@ -140,18 +136,18 @@ Node* CreateStubBuiltinContinuationFrameState(
}
return CreateBuiltinContinuationFrameStateCommon(
js_graph, name, context, actual_parameters.data(),
static_cast<int>(actual_parameters.size()), outer_frame_state,
Handle<JSFunction>());
jsgraph, FrameStateType::kBuiltinContinuation, name,
jsgraph->UndefinedConstant(), context, actual_parameters.data(),
static_cast<int>(actual_parameters.size()), outer_frame_state);
}
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,
int stack_parameter_count, Node* outer_frame_state,
ContinuationFrameStateMode mode) {
Isolate* isolate = js_graph->isolate();
Callable callable = Builtins::CallableFor(isolate, name);
Isolate* const isolate = jsgraph->isolate();
Callable const callable = Builtins::CallableFor(isolate, name);
// 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
......@@ -163,8 +159,8 @@ Node* CreateJavaScriptBuiltinContinuationFrameState(
(mode == ContinuationFrameStateMode::EAGER ? 0 : 1));
Node* argc =
js_graph->Constant(stack_parameter_count -
(mode == ContinuationFrameStateMode::EAGER ? 1 : 0));
jsgraph->Constant(stack_parameter_count -
(mode == ContinuationFrameStateMode::EAGER ? 1 : 0));
// Stack parameters first. They must be first because the receiver is expected
// to be the second value in the translation when creating stack crawls
......@@ -177,12 +173,13 @@ Node* CreateJavaScriptBuiltinContinuationFrameState(
// Register parameters follow stack paraemters. The context will be added by
// instruction selector during FrameState translation.
actual_parameters.push_back(target);
actual_parameters.push_back(js_graph->UndefinedConstant());
actual_parameters.push_back(jsgraph->UndefinedConstant());
actual_parameters.push_back(argc);
return CreateBuiltinContinuationFrameStateCommon(
js_graph, name, context, &actual_parameters[0],
static_cast<int>(actual_parameters.size()), outer_frame_state, function);
jsgraph, FrameStateType::kJavaScriptBuiltinContinuation, name, target,
context, &actual_parameters[0],
static_cast<int>(actual_parameters.size()), outer_frame_state, shared);
}
} // namespace compiler
......
......@@ -151,7 +151,7 @@ Node* CreateStubBuiltinContinuationFrameState(
ContinuationFrameStateMode mode);
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,
int stack_parameter_count, Node* outer_frame_state,
ContinuationFrameStateMode mode);
......
This diff is collapsed.
......@@ -52,10 +52,10 @@ class V8_EXPORT_PRIVATE JSCallReducer final : public AdvancedReducer {
void Finalize() final;
private:
enum ArrayReduceDirection { kArrayReduceLeft, kArrayReduceRight };
Reduction ReduceArrayConstructor(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 ReduceFunctionPrototypeBind(Node* node);
Reduction ReduceFunctionPrototypeCall(Node* node);
......@@ -72,16 +72,17 @@ class V8_EXPORT_PRIVATE JSCallReducer final : public AdvancedReducer {
Reduction ReduceReflectGet(Node* node);
Reduction ReduceReflectGetPrototypeOf(Node* node);
Reduction ReduceReflectHas(Node* node);
Reduction ReduceArrayForEach(Handle<JSFunction> function, Node* node);
Reduction ReduceArrayReduce(Handle<JSFunction> function, Node* node,
ArrayReduceDirection direction);
Reduction ReduceArrayMap(Handle<JSFunction> function, Node* node);
Reduction ReduceArrayFilter(Handle<JSFunction> function, Node* node);
enum class ArrayFindVariant : uint8_t { kFind, kFindIndex };
Reduction ReduceArrayFind(ArrayFindVariant variant,
Handle<JSFunction> function, Node* node);
Reduction ReduceArrayEvery(Handle<JSFunction> function, Node* node);
Reduction ReduceArraySome(Handle<JSFunction> function, Node* node);
Reduction ReduceArrayForEach(Node* node, Handle<SharedFunctionInfo> shared);
enum class ArrayReduceDirection { kLeft, kRight };
Reduction ReduceArrayReduce(Node* node, ArrayReduceDirection direction,
Handle<SharedFunctionInfo> shared);
Reduction ReduceArrayMap(Node* node, Handle<SharedFunctionInfo> shared);
Reduction ReduceArrayFilter(Node* node, Handle<SharedFunctionInfo> shared);
enum class ArrayFindVariant { kFind, kFindIndex };
Reduction ReduceArrayFind(Node* node, ArrayFindVariant variant,
Handle<SharedFunctionInfo> shared);
Reduction ReduceArrayEvery(Node* node, Handle<SharedFunctionInfo> shared);
Reduction ReduceArraySome(Node* node, Handle<SharedFunctionInfo> shared);
Reduction ReduceArrayPrototypePush(Node* node);
Reduction ReduceArrayPrototypePop(Node* node);
Reduction ReduceArrayPrototypeShift(Node* node);
......@@ -92,11 +93,11 @@ class V8_EXPORT_PRIVATE JSCallReducer final : public AdvancedReducer {
Reduction ReduceJSConstructWithArrayLike(Node* node);
Reduction ReduceJSConstructWithSpread(Node* node);
Reduction ReduceJSCall(Node* node);
Reduction ReduceJSCall(Node* node, Handle<SharedFunctionInfo> shared);
Reduction ReduceJSCallWithArrayLike(Node* node);
Reduction ReduceJSCallWithSpread(Node* node);
Reduction ReduceReturnReceiver(Node* node);
Reduction ReduceStringPrototypeIndexOf(Handle<JSFunction> function,
Node* node);
Reduction ReduceStringPrototypeIndexOf(Node* node);
Reduction ReduceStringPrototypeStringAt(
const Operator* string_access_operator, Node* node);
Reduction ReduceAsyncFunctionPromiseCreate(Node* node);
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --opt
// Flags: --allow-natives-syntax
(function() {
var resolve, value;
......@@ -25,3 +25,23 @@
foo();
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