OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/interpreter/interpreter-assembler.h" | 5 #include "src/interpreter/interpreter-assembler.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <ostream> | 8 #include <ostream> |
9 | 9 |
10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 462 |
463 Variable return_value(this, MachineRepresentation::kTagged); | 463 Variable return_value(this, MachineRepresentation::kTagged); |
464 Label handle_monomorphic(this), extra_checks(this), end(this), call(this); | 464 Label handle_monomorphic(this), extra_checks(this), end(this), call(this); |
465 | 465 |
466 // Slot id of 0 is used to indicate no typefeedback is available. Call using | 466 // Slot id of 0 is used to indicate no typefeedback is available. Call using |
467 // call builtin. | 467 // call builtin. |
468 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); | 468 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); |
469 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); | 469 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); |
470 GotoIf(is_feedback_unavailable, &call); | 470 GotoIf(is_feedback_unavailable, &call); |
471 | 471 |
472 // The checks. First, does function match the recorded monomorphic target? | 472 // The checks. First, does rdi match the recorded monomorphic target? |
473 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); | 473 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); |
474 Node* feedback_value = LoadWeakCellValue(feedback_element); | 474 Node* feedback_value = LoadWeakCellValue(feedback_element); |
475 Node* is_monomorphic = WordEqual(function, feedback_value); | 475 Node* is_monomorphic = WordEqual(function, feedback_value); |
476 BranchIf(is_monomorphic, &handle_monomorphic, &extra_checks); | 476 BranchIf(is_monomorphic, &handle_monomorphic, &extra_checks); |
477 | 477 |
478 Bind(&handle_monomorphic); | 478 Bind(&handle_monomorphic); |
479 { | 479 { |
480 // The compare above could have been a SMI/SMI comparison. Guard against | 480 // The compare above could have been a SMI/SMI comparison. Guard against |
481 // this convincing us that we have a monomorphic JSFunction. | 481 // this convincing us that we have a monomorphic JSFunction. |
482 Node* is_smi = WordIsSmi(function); | 482 Node* is_smi = WordIsSmi(function); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 TailCallMode tail_call_mode) { | 596 TailCallMode tail_call_mode) { |
597 Callable callable = CodeFactory::InterpreterPushArgsAndCall( | 597 Callable callable = CodeFactory::InterpreterPushArgsAndCall( |
598 isolate(), tail_call_mode, CallableType::kAny); | 598 isolate(), tail_call_mode, CallableType::kAny); |
599 Node* code_target = HeapConstant(callable.code()); | 599 Node* code_target = HeapConstant(callable.code()); |
600 return CallStub(callable.descriptor(), code_target, context, arg_count, | 600 return CallStub(callable.descriptor(), code_target, context, arg_count, |
601 first_arg, function); | 601 first_arg, function); |
602 } | 602 } |
603 | 603 |
604 Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context, | 604 Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context, |
605 Node* new_target, Node* first_arg, | 605 Node* new_target, Node* first_arg, |
606 Node* arg_count, Node* slot_id, | 606 Node* arg_count) { |
607 Node* type_feedback_vector) { | 607 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct(isolate()); |
608 Label call_construct(this), js_function(this), end(this); | 608 Node* code_target = HeapConstant(callable.code()); |
609 Variable return_value(this, MachineRepresentation::kTagged); | 609 return CallStub(callable.descriptor(), code_target, context, arg_count, |
610 Variable allocation_feedback(this, MachineRepresentation::kTagged); | 610 new_target, constructor, first_arg); |
611 allocation_feedback.Bind(UndefinedConstant()); | |
612 | |
613 // Slot id of 0 is used to indicate no type feedback is available. | |
614 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); | |
615 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); | |
616 GotoIf(is_feedback_unavailable, &call_construct); | |
617 | |
618 // Check that the constructor is not a smi. | |
619 Node* is_smi = WordIsSmi(constructor); | |
620 GotoIf(is_smi, &call_construct); | |
621 | |
622 // Check that constructor is a JSFunction. | |
623 Node* instance_type = LoadInstanceType(constructor); | |
624 Node* is_js_function = | |
625 WordEqual(instance_type, Int32Constant(JS_FUNCTION_TYPE)); | |
626 BranchIf(is_js_function, &js_function, &call_construct); | |
627 | |
628 Bind(&js_function); | |
629 { | |
630 // Cache the called function in a feedback vector slot. Cache states | |
631 // are uninitialized, monomorphic (indicated by a JSFunction), and | |
632 // megamorphic. | |
633 // TODO(mythria/v8:5210): Check if it is better to mark extra_checks as a | |
634 // deferred block so that call_construct_function will be scheduled just | |
635 // after increment_count and in the fast path we can reduce one branch in | |
636 // the | |
637 // fast path. | |
638 Label increment_count(this), extra_checks(this), | |
639 call_construct_function(this); | |
640 | |
641 Node* feedback_element = | |
642 LoadFixedArrayElement(type_feedback_vector, slot_id); | |
643 Node* feedback_value = LoadWeakCellValue(feedback_element); | |
644 Node* is_monomorphic = WordEqual(constructor, feedback_value); | |
645 BranchIf(is_monomorphic, &increment_count, &extra_checks); | |
646 | |
647 Bind(&extra_checks); | |
648 { | |
649 Label mark_megamorphic(this), initialize(this), | |
650 check_allocation_site(this), check_initialized(this), | |
651 set_alloc_feedback_and_inc_count(this); | |
652 { | |
653 // Check if it is a megamorphic target | |
654 Comment("check if megamorphic"); | |
655 Node* is_megamorphic = WordEqual( | |
656 feedback_element, | |
657 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate()))); | |
658 GotoIf(is_megamorphic, &call_construct_function); | |
659 | |
660 Comment("check if weak cell"); | |
661 Node* is_weak_cell = WordEqual(LoadMap(feedback_element), | |
662 LoadRoot(Heap::kWeakCellMapRootIndex)); | |
663 GotoUnless(is_weak_cell, &check_allocation_site); | |
664 // If the weak cell is cleared, we have a new chance to become | |
665 // monomorphic. | |
666 Comment("check if weak cell is cleared"); | |
667 Node* is_smi = WordIsSmi(feedback_value); | |
668 BranchIf(is_smi, &initialize, &mark_megamorphic); | |
669 } | |
670 | |
671 Bind(&check_allocation_site); | |
672 { | |
673 Comment("check if it is an allocation site"); | |
674 Node* is_allocation_site = | |
675 WordEqual(LoadObjectField(feedback_element, 0), | |
676 LoadRoot(Heap::kAllocationSiteMapRootIndex)); | |
677 GotoUnless(is_allocation_site, &check_initialized); | |
678 | |
679 // Make sure the function is the Array() function | |
680 Node* context_slot = | |
681 LoadFixedArrayElement(LoadNativeContext(context), | |
682 Int32Constant(Context::ARRAY_FUNCTION_INDEX)); | |
683 Node* is_array_function = WordEqual(context_slot, constructor); | |
684 BranchIf(is_array_function, &set_alloc_feedback_and_inc_count, | |
685 &mark_megamorphic); | |
686 } | |
687 | |
688 Bind(&set_alloc_feedback_and_inc_count); | |
689 { | |
690 allocation_feedback.Bind(feedback_element); | |
691 Goto(&increment_count); | |
692 } | |
693 | |
694 Bind(&check_initialized); | |
695 { | |
696 // Check if it is uninitialized. | |
697 Comment("check if uninitialized"); | |
698 Node* is_uninitialized = WordEqual( | |
699 feedback_element, LoadRoot(Heap::kuninitialized_symbolRootIndex)); | |
700 BranchIf(is_uninitialized, &initialize, &mark_megamorphic); | |
701 } | |
702 | |
703 Bind(&initialize); | |
704 { | |
705 Label initialize_count(this), create_weak_cell(this), | |
706 create_allocation_site(this); | |
707 Comment("initialize the feedback element"); | |
708 // Check that it is the Array() function. | |
709 Node* context_slot = | |
710 LoadFixedArrayElement(LoadNativeContext(context), | |
711 Int32Constant(Context::ARRAY_FUNCTION_INDEX)); | |
712 Node* is_array_function = WordEqual(context_slot, constructor); | |
713 BranchIf(is_array_function, &create_allocation_site, &create_weak_cell); | |
714 | |
715 Bind(&create_allocation_site); | |
716 { | |
717 // TODO(mythria): Inline the creation of allocation site. | |
718 CreateAllocationSiteStub create_stub(isolate()); | |
719 CallStub(create_stub.GetCallInterfaceDescriptor(), | |
720 HeapConstant(create_stub.GetCode()), context, | |
721 type_feedback_vector, SmiTag(slot_id)); | |
722 Node* feedback_element = | |
723 LoadFixedArrayElement(type_feedback_vector, slot_id); | |
724 allocation_feedback.Bind(feedback_element); | |
725 Goto(&initialize_count); | |
726 } | |
727 | |
728 Bind(&create_weak_cell); | |
729 { | |
730 CreateWeakCellInFeedbackVector(type_feedback_vector, SmiTag(slot_id), | |
731 constructor); | |
732 Goto(&initialize_count); | |
733 } | |
734 | |
735 Bind(&initialize_count); | |
736 { | |
737 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
738 // Count is Smi, so we don't need a write barrier. | |
739 StoreFixedArrayElement(type_feedback_vector, call_count_slot, | |
740 SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); | |
741 Goto(&call_construct_function); | |
742 } | |
743 } | |
744 | |
745 Bind(&mark_megamorphic); | |
746 { | |
747 // MegamorphicSentinel is an immortal immovable object so no | |
748 // write-barrier | |
749 // is needed. | |
750 Comment("transition to megamorphic"); | |
751 DCHECK( | |
752 Heap::RootIsImmortalImmovable(Heap::kmegamorphic_symbolRootIndex)); | |
753 StoreFixedArrayElement( | |
754 type_feedback_vector, slot_id, | |
755 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate())), | |
756 SKIP_WRITE_BARRIER); | |
757 Goto(&call_construct_function); | |
758 } | |
759 } | |
760 | |
761 Bind(&increment_count); | |
762 { | |
763 // Increment the call count. | |
764 Comment("increment call count"); | |
765 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
766 Node* call_count = | |
767 LoadFixedArrayElement(type_feedback_vector, call_count_slot); | |
768 Node* new_count = SmiAdd(call_count, SmiTag(Int32Constant(1))); | |
769 // Count is Smi, so we don't need a write barrier. | |
770 StoreFixedArrayElement(type_feedback_vector, call_count_slot, new_count, | |
771 SKIP_WRITE_BARRIER); | |
772 Goto(&call_construct_function); | |
773 } | |
774 | |
775 Bind(&call_construct_function); | |
776 { | |
777 Comment("call using callConstructFunction"); | |
778 Callable callable_function = CodeFactory::InterpreterPushArgsAndConstruct( | |
779 isolate(), CallableType::kJSFunction); | |
780 return_value.Bind(CallStub(callable_function.descriptor(), | |
781 HeapConstant(callable_function.code()), | |
782 context, arg_count, new_target, constructor, | |
783 allocation_feedback.value(), first_arg)); | |
784 Goto(&end); | |
785 } | |
786 } | |
787 | |
788 Bind(&call_construct); | |
789 { | |
790 Comment("call using callConstruct builtin"); | |
791 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct( | |
792 isolate(), CallableType::kAny); | |
793 Node* code_target = HeapConstant(callable.code()); | |
794 return_value.Bind(CallStub(callable.descriptor(), code_target, context, | |
795 arg_count, new_target, constructor, | |
796 UndefinedConstant(), first_arg)); | |
797 Goto(&end); | |
798 } | |
799 | |
800 Bind(&end); | |
801 return return_value.value(); | |
802 } | 611 } |
803 | 612 |
804 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, | 613 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, |
805 Node* first_arg, Node* arg_count, | 614 Node* first_arg, Node* arg_count, |
806 int result_size) { | 615 int result_size) { |
807 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size); | 616 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size); |
808 Node* code_target = HeapConstant(callable.code()); | 617 Node* code_target = HeapConstant(callable.code()); |
809 | 618 |
810 // Get the function entry from the function id. | 619 // Get the function entry from the function id. |
811 Node* function_table = ExternalConstant( | 620 Node* function_table = ExternalConstant( |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 Goto(&loop); | 992 Goto(&loop); |
1184 } | 993 } |
1185 Bind(&done_loop); | 994 Bind(&done_loop); |
1186 | 995 |
1187 return array; | 996 return array; |
1188 } | 997 } |
1189 | 998 |
1190 } // namespace interpreter | 999 } // namespace interpreter |
1191 } // namespace internal | 1000 } // namespace internal |
1192 } // namespace v8 | 1001 } // namespace v8 |
OLD | NEW |