OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler/js-create-lowering.h" | 5 #include "src/compiler/js-create-lowering.h" |
6 | 6 |
7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/compilation-dependencies.h" | 9 #include "src/compilation-dependencies.h" |
10 #include "src/compiler/access-builder.h" | 10 #include "src/compiler/access-builder.h" |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 case IrOpcode::kJSCreateLiteralObject: | 221 case IrOpcode::kJSCreateLiteralObject: |
222 return ReduceJSCreateLiteral(node); | 222 return ReduceJSCreateLiteral(node); |
223 case IrOpcode::kJSCreateFunctionContext: | 223 case IrOpcode::kJSCreateFunctionContext: |
224 return ReduceJSCreateFunctionContext(node); | 224 return ReduceJSCreateFunctionContext(node); |
225 case IrOpcode::kJSCreateWithContext: | 225 case IrOpcode::kJSCreateWithContext: |
226 return ReduceJSCreateWithContext(node); | 226 return ReduceJSCreateWithContext(node); |
227 case IrOpcode::kJSCreateCatchContext: | 227 case IrOpcode::kJSCreateCatchContext: |
228 return ReduceJSCreateCatchContext(node); | 228 return ReduceJSCreateCatchContext(node); |
229 case IrOpcode::kJSCreateBlockContext: | 229 case IrOpcode::kJSCreateBlockContext: |
230 return ReduceJSCreateBlockContext(node); | 230 return ReduceJSCreateBlockContext(node); |
| 231 case IrOpcode::kJSCreateGeneratorObject: |
| 232 return ReduceJSCreateGeneratorObject(node); |
231 default: | 233 default: |
232 break; | 234 break; |
233 } | 235 } |
234 return NoChange(); | 236 return NoChange(); |
235 } | 237 } |
236 | 238 |
237 Reduction JSCreateLowering::ReduceJSCreate(Node* node) { | 239 Reduction JSCreateLowering::ReduceJSCreate(Node* node) { |
238 DCHECK_EQ(IrOpcode::kJSCreate, node->opcode()); | 240 DCHECK_EQ(IrOpcode::kJSCreate, node->opcode()); |
239 Node* const target = NodeProperties::GetValueInput(node, 0); | 241 Node* const target = NodeProperties::GetValueInput(node, 0); |
240 Type* const target_type = NodeProperties::GetType(target); | 242 Type* const target_type = NodeProperties::GetType(target); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 jsgraph()->Constant(length)); | 543 jsgraph()->Constant(length)); |
542 RelaxControls(node); | 544 RelaxControls(node); |
543 a.FinishAndChange(node); | 545 a.FinishAndChange(node); |
544 return Changed(node); | 546 return Changed(node); |
545 } | 547 } |
546 } | 548 } |
547 | 549 |
548 return NoChange(); | 550 return NoChange(); |
549 } | 551 } |
550 | 552 |
| 553 Reduction JSCreateLowering::ReduceJSCreateGeneratorObject(Node* node) { |
| 554 DCHECK_EQ(IrOpcode::kJSCreateGeneratorObject, node->opcode()); |
| 555 Node* const closure = NodeProperties::GetValueInput(node, 0); |
| 556 Node* const receiver = NodeProperties::GetValueInput(node, 1); |
| 557 Node* const context = NodeProperties::GetContextInput(node); |
| 558 Type* const closure_type = NodeProperties::GetType(closure); |
| 559 Node* effect = NodeProperties::GetEffectInput(node); |
| 560 Node* const control = NodeProperties::GetControlInput(node); |
| 561 // Extract constructor and original constructor function. |
| 562 if (closure_type->IsHeapConstant()) { |
| 563 DCHECK(closure_type->AsHeapConstant()->Value()->IsJSFunction()); |
| 564 Handle<JSFunction> js_function = |
| 565 Handle<JSFunction>::cast(closure_type->AsHeapConstant()->Value()); |
| 566 JSFunction::EnsureHasInitialMap(js_function); |
| 567 Handle<Map> initial_map(js_function->initial_map()); |
| 568 initial_map->CompleteInobjectSlackTracking(); |
| 569 DCHECK(initial_map->instance_type() == JS_GENERATOR_OBJECT_TYPE || |
| 570 initial_map->instance_type() == JS_ASYNC_GENERATOR_OBJECT_TYPE); |
| 571 |
| 572 // Add a dependency on the {initial_map} to make sure that this code is |
| 573 // deoptimized whenever the {initial_map} of the {original_constructor} |
| 574 // changes. |
| 575 dependencies()->AssumeInitialMapCantChange(initial_map); |
| 576 |
| 577 DCHECK(js_function->shared()->HasBytecodeArray()); |
| 578 int size = js_function->shared()->bytecode_array()->register_count(); |
| 579 Node* elements = effect = AllocateElements( |
| 580 effect, control, FAST_HOLEY_ELEMENTS, size, NOT_TENURED); |
| 581 |
| 582 AllocationBuilder a(jsgraph(), effect, control); |
| 583 a.Allocate(initial_map->instance_size()); |
| 584 Node* empty_fixed_array = jsgraph()->EmptyFixedArrayConstant(); |
| 585 Node* undefined = jsgraph()->UndefinedConstant(); |
| 586 a.Store(AccessBuilder::ForMap(), initial_map); |
| 587 a.Store(AccessBuilder::ForJSObjectProperties(), empty_fixed_array); |
| 588 a.Store(AccessBuilder::ForJSObjectElements(), empty_fixed_array); |
| 589 a.Store(AccessBuilder::ForJSGeneratorObjectContext(), context); |
| 590 a.Store(AccessBuilder::ForJSGeneratorObjectFunction(), closure); |
| 591 a.Store(AccessBuilder::ForJSGeneratorObjectReceiver(), receiver); |
| 592 a.Store(AccessBuilder::ForJSGeneratorObjectInputOrDebugPos(), undefined); |
| 593 a.Store(AccessBuilder::ForJSGeneratorObjectResumeMode(), |
| 594 jsgraph()->Constant(JSGeneratorObject::kNext)); |
| 595 a.Store(AccessBuilder::ForJSGeneratorObjectContinuation(), |
| 596 jsgraph()->Constant(JSGeneratorObject::kGeneratorExecuting)); |
| 597 a.Store(AccessBuilder::ForJSGeneratorObjectRegisterFile(), elements); |
| 598 |
| 599 if (initial_map->instance_type() == JS_ASYNC_GENERATOR_OBJECT_TYPE) { |
| 600 a.Store(AccessBuilder::ForJSAsyncGeneratorObjectQueue(), undefined); |
| 601 a.Store(AccessBuilder::ForJSAsyncGeneratorObjectAwaitInputOrDebugPos(), |
| 602 undefined); |
| 603 a.Store(AccessBuilder::ForJSAsyncGeneratorObjectAwaitedPromise(), |
| 604 undefined); |
| 605 } |
| 606 |
| 607 // Handle in-object properties, too. |
| 608 for (int i = 0; i < initial_map->GetInObjectProperties(); ++i) { |
| 609 a.Store(AccessBuilder::ForJSObjectInObjectProperty(initial_map, i), |
| 610 undefined); |
| 611 } |
| 612 a.FinishAndChange(node); |
| 613 return Changed(node); |
| 614 } |
| 615 return NoChange(); |
| 616 } |
| 617 |
551 Reduction JSCreateLowering::ReduceNewArray(Node* node, Node* length, | 618 Reduction JSCreateLowering::ReduceNewArray(Node* node, Node* length, |
552 int capacity, | 619 int capacity, |
553 Handle<AllocationSite> site) { | 620 Handle<AllocationSite> site) { |
554 DCHECK_EQ(IrOpcode::kJSCreateArray, node->opcode()); | 621 DCHECK_EQ(IrOpcode::kJSCreateArray, node->opcode()); |
555 Node* effect = NodeProperties::GetEffectInput(node); | 622 Node* effect = NodeProperties::GetEffectInput(node); |
556 Node* control = NodeProperties::GetControlInput(node); | 623 Node* control = NodeProperties::GetControlInput(node); |
557 | 624 |
558 // Extract transition and tenuring feedback from the {site} and add | 625 // Extract transition and tenuring feedback from the {site} and add |
559 // appropriate code dependencies on the {site} if deoptimization is | 626 // appropriate code dependencies on the {site} if deoptimization is |
560 // enabled. | 627 // enabled. |
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 return jsgraph()->simplified(); | 1510 return jsgraph()->simplified(); |
1444 } | 1511 } |
1445 | 1512 |
1446 MachineOperatorBuilder* JSCreateLowering::machine() const { | 1513 MachineOperatorBuilder* JSCreateLowering::machine() const { |
1447 return jsgraph()->machine(); | 1514 return jsgraph()->machine(); |
1448 } | 1515 } |
1449 | 1516 |
1450 } // namespace compiler | 1517 } // namespace compiler |
1451 } // namespace internal | 1518 } // namespace internal |
1452 } // namespace v8 | 1519 } // namespace v8 |
OLD | NEW |