| Index: src/compiler/js-typed-lowering.cc
|
| diff --git a/src/compiler/js-typed-lowering.cc b/src/compiler/js-typed-lowering.cc
|
| index f221577104c1d84679249ee2c81019a8d74749dc..5ad2f95fee6fdb7c5532670f022cd7828d1cc879 100644
|
| --- a/src/compiler/js-typed-lowering.cc
|
| +++ b/src/compiler/js-typed-lowering.cc
|
| @@ -1316,6 +1316,75 @@ Reduction JSTypedLowering::ReduceJSConvertReceiver(Node* node) {
|
|
|
| namespace {
|
|
|
| +// Maximum instance size for which allocations will be inlined.
|
| +const int kMaxInlineInstanceSize = 64 * kPointerSize;
|
| +
|
| +
|
| +// Checks whether allocation using the given constructor can be inlined.
|
| +bool IsAllocationInlineable(Handle<JSFunction> constructor) {
|
| + // TODO(bmeurer): Support inlining of class constructors.
|
| + if (IsClassConstructor(constructor->shared()->kind())) return false;
|
| + return constructor->has_initial_map() &&
|
| + constructor->initial_map()->instance_type() == JS_OBJECT_TYPE &&
|
| + constructor->initial_map()->instance_size() < kMaxInlineInstanceSize;
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +
|
| +Reduction JSTypedLowering::ReduceJSCreate(Node* node) {
|
| + DCHECK_EQ(IrOpcode::kJSCreate, node->opcode());
|
| + Node* const target = NodeProperties::GetValueInput(node, 0);
|
| + Type* const target_type = NodeProperties::GetType(target);
|
| + Node* const new_target = NodeProperties::GetValueInput(node, 1);
|
| + Node* const effect = NodeProperties::GetEffectInput(node);
|
| + // TODO(turbofan): Add support for NewTarget passed to JSCreate.
|
| + if (target != new_target) return NoChange();
|
| + // Extract constructor function.
|
| + if (target_type->IsConstant() &&
|
| + target_type->AsConstant()->Value()->IsJSFunction()) {
|
| + Handle<JSFunction> constructor =
|
| + Handle<JSFunction>::cast(target_type->AsConstant()->Value());
|
| + // Force completion of inobject slack tracking before
|
| + // generating code to finalize the instance size.
|
| + if (constructor->IsInobjectSlackTrackingInProgress()) {
|
| + constructor->CompleteInobjectSlackTracking();
|
| + }
|
| +
|
| + // TODO(bmeurer): We fall back to the runtime in case we cannot inline
|
| + // the allocation here, which is sort of expensive. We should think about
|
| + // a soft fallback to some NewObjectCodeStub.
|
| + if (IsAllocationInlineable(constructor)) {
|
| + // Compute instance size from initial map of {constructor}.
|
| + Handle<Map> initial_map(constructor->initial_map(), isolate());
|
| + int const instance_size = initial_map->instance_size();
|
| +
|
| + // Add a dependency on the {initial_map} to make sure that this code is
|
| + // deoptimized whenever the {initial_map} of the {constructor} changes.
|
| + dependencies()->AssumeInitialMapCantChange(initial_map);
|
| +
|
| + // Emit code to allocate the JSObject instance for the {constructor}.
|
| + AllocationBuilder a(jsgraph(), effect, graph()->start());
|
| + a.Allocate(instance_size);
|
| + a.Store(AccessBuilder::ForMap(), initial_map);
|
| + a.Store(AccessBuilder::ForJSObjectProperties(),
|
| + jsgraph()->EmptyFixedArrayConstant());
|
| + a.Store(AccessBuilder::ForJSObjectElements(),
|
| + jsgraph()->EmptyFixedArrayConstant());
|
| + for (int i = 0; i < initial_map->GetInObjectProperties(); ++i) {
|
| + a.Store(AccessBuilder::ForJSObjectInObjectProperty(initial_map, i),
|
| + jsgraph()->UndefinedConstant());
|
| + }
|
| + a.FinishAndChange(node);
|
| + return Changed(node);
|
| + }
|
| + }
|
| + return NoChange();
|
| +}
|
| +
|
| +
|
| +namespace {
|
| +
|
| // Retrieves the frame state holding actual argument values.
|
| Node* GetArgumentsFrameState(Node* frame_state) {
|
| Node* const outer_state = frame_state->InputAt(kFrameStateOuterStateInput);
|
| @@ -2153,6 +2222,8 @@ Reduction JSTypedLowering::Reduce(Node* node) {
|
| return ReduceJSStoreContext(node);
|
| case IrOpcode::kJSConvertReceiver:
|
| return ReduceJSConvertReceiver(node);
|
| + case IrOpcode::kJSCreate:
|
| + return ReduceJSCreate(node);
|
| case IrOpcode::kJSCreateArguments:
|
| return ReduceJSCreateArguments(node);
|
| case IrOpcode::kJSCreateClosure:
|
|
|