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 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 460 |
461 Variable return_value(this, MachineRepresentation::kTagged); | 461 Variable return_value(this, MachineRepresentation::kTagged); |
462 Label handle_monomorphic(this), extra_checks(this), end(this), call(this); | 462 Label handle_monomorphic(this), extra_checks(this), end(this), call(this); |
463 | 463 |
464 // Slot id of 0 is used to indicate no typefeedback is available. Call using | 464 // Slot id of 0 is used to indicate no typefeedback is available. Call using |
465 // call builtin. | 465 // call builtin. |
466 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); | 466 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); |
467 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); | 467 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); |
468 GotoIf(is_feedback_unavailable, &call); | 468 GotoIf(is_feedback_unavailable, &call); |
469 | 469 |
470 // The checks. First, does function match the recorded monomorphic target? | 470 // The checks. First, does rdi match the recorded monomorphic target? |
471 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); | 471 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); |
472 Node* feedback_value = LoadWeakCellValue(feedback_element); | 472 Node* feedback_value = LoadWeakCellValue(feedback_element); |
473 Node* is_monomorphic = WordEqual(function, feedback_value); | 473 Node* is_monomorphic = WordEqual(function, feedback_value); |
474 BranchIf(is_monomorphic, &handle_monomorphic, &extra_checks); | 474 BranchIf(is_monomorphic, &handle_monomorphic, &extra_checks); |
475 | 475 |
476 Bind(&handle_monomorphic); | 476 Bind(&handle_monomorphic); |
477 { | 477 { |
478 // The compare above could have been a SMI/SMI comparison. Guard against | 478 // The compare above could have been a SMI/SMI comparison. Guard against |
479 // this convincing us that we have a monomorphic JSFunction. | 479 // this convincing us that we have a monomorphic JSFunction. |
480 Node* is_smi = WordIsSmi(function); | 480 Node* is_smi = WordIsSmi(function); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 Node* is_same_native_context = | 539 Node* is_same_native_context = |
540 WordEqual(native_context, LoadNativeContext(context)); | 540 WordEqual(native_context, LoadNativeContext(context)); |
541 GotoUnless(is_same_native_context, &mark_megamorphic); | 541 GotoUnless(is_same_native_context, &mark_megamorphic); |
542 | 542 |
543 // Initialize it to a monomorphic target. | 543 // Initialize it to a monomorphic target. |
544 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | 544 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); |
545 // Count is Smi, so we don't need a write barrier. | 545 // Count is Smi, so we don't need a write barrier. |
546 StoreFixedArrayElement(type_feedback_vector, call_count_slot, | 546 StoreFixedArrayElement(type_feedback_vector, call_count_slot, |
547 SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); | 547 SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); |
548 | 548 |
549 // TODO(mythria): Inline the weak cell creation/registration. | |
550 CreateWeakCellStub weak_cell_stub(isolate()); | 549 CreateWeakCellStub weak_cell_stub(isolate()); |
551 CallStub(weak_cell_stub.GetCallInterfaceDescriptor(), | 550 CallStub(weak_cell_stub.GetCallInterfaceDescriptor(), |
552 HeapConstant(weak_cell_stub.GetCode()), context, | 551 HeapConstant(weak_cell_stub.GetCode()), context, |
553 type_feedback_vector, SmiTag(slot_id), function); | 552 type_feedback_vector, SmiTag(slot_id), function); |
554 | 553 |
555 // Call using call function builtin. | 554 // Call using call function builtin. |
556 Callable callable = CodeFactory::InterpreterPushArgsAndCall( | 555 Callable callable = CodeFactory::InterpreterPushArgsAndCall( |
557 isolate(), tail_call_mode, CallableType::kJSFunction); | 556 isolate(), tail_call_mode, CallableType::kJSFunction); |
558 Node* code_target = HeapConstant(callable.code()); | 557 Node* code_target = HeapConstant(callable.code()); |
559 Node* ret_value = CallStub(callable.descriptor(), code_target, context, | 558 Node* ret_value = CallStub(callable.descriptor(), code_target, context, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
597 TailCallMode tail_call_mode) { | 596 TailCallMode tail_call_mode) { |
598 Callable callable = CodeFactory::InterpreterPushArgsAndCall( | 597 Callable callable = CodeFactory::InterpreterPushArgsAndCall( |
599 isolate(), tail_call_mode, CallableType::kAny); | 598 isolate(), tail_call_mode, CallableType::kAny); |
600 Node* code_target = HeapConstant(callable.code()); | 599 Node* code_target = HeapConstant(callable.code()); |
601 return CallStub(callable.descriptor(), code_target, context, arg_count, | 600 return CallStub(callable.descriptor(), code_target, context, arg_count, |
602 first_arg, function); | 601 first_arg, function); |
603 } | 602 } |
604 | 603 |
605 Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context, | 604 Node* InterpreterAssembler::CallConstruct(Node* constructor, Node* context, |
606 Node* new_target, Node* first_arg, | 605 Node* new_target, Node* first_arg, |
607 Node* arg_count, Node* slot_id, | 606 Node* arg_count) { |
608 Node* type_feedback_vector) { | 607 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct(isolate()); |
609 Label call_construct(this), js_function(this), end(this); | 608 Node* code_target = HeapConstant(callable.code()); |
610 Variable return_value(this, MachineRepresentation::kTagged); | 609 return CallStub(callable.descriptor(), code_target, context, arg_count, |
611 | 610 new_target, constructor, first_arg); |
612 // Slot id of 0 is used to indicate no typefeedback is available. | |
613 STATIC_ASSERT(TypeFeedbackVector::kReservedIndexCount > 0); | |
614 Node* is_feedback_unavailable = Word32Equal(slot_id, Int32Constant(0)); | |
615 GotoIf(is_feedback_unavailable, &call_construct); | |
616 | |
617 // Check that the constructor is not a smi. | |
618 Node* is_smi = WordIsSmi(constructor); | |
619 GotoIf(is_smi, &call_construct); | |
620 | |
621 // Check that constructor is a JSFunction. | |
622 Node* instance_type = LoadInstanceType(constructor); | |
623 Node* is_js_function = | |
624 WordEqual(instance_type, Int32Constant(JS_FUNCTION_TYPE)); | |
625 BranchIf(is_js_function, &js_function, &call_construct); | |
626 | |
627 Bind(&js_function); | |
628 // Cache the called function in a feedback vector slot. Cache states | |
629 // are uninitialized, monomorphic (indicated by a JSFunction), and | |
630 // megamorphic. | |
631 // TODO(mythria/v8:5210): Check if it is better to mark extra_checks as a | |
632 // deferred block so that call_construct_function will be scheduled just | |
633 // after increment_count and in the fast path we can reduce one branch in the | |
634 // fast path. | |
635 Label increment_count(this), extra_checks(this), | |
636 call_construct_function(this); | |
637 | |
638 Node* feedback_element = LoadFixedArrayElement(type_feedback_vector, slot_id); | |
639 Node* feedback_value = LoadWeakCellValue(feedback_element); | |
640 Node* is_monomorphic = WordEqual(constructor, feedback_value); | |
641 BranchIf(is_monomorphic, &increment_count, &extra_checks); | |
642 | |
643 Bind(&increment_count); | |
644 { | |
645 // Increment the call count. | |
646 Comment("increment call count"); | |
647 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
648 Node* call_count = | |
649 LoadFixedArrayElement(type_feedback_vector, call_count_slot); | |
650 Node* new_count = SmiAdd(call_count, SmiTag(Int32Constant(1))); | |
651 // Count is Smi, so we don't need a write barrier. | |
652 StoreFixedArrayElement(type_feedback_vector, call_count_slot, new_count, | |
653 SKIP_WRITE_BARRIER); | |
654 Goto(&call_construct_function); | |
655 } | |
656 | |
657 Bind(&extra_checks); | |
658 { | |
659 Label mark_megamorphic(this), initialize(this), | |
660 check_weak_cell_cleared(this); | |
661 // Check if it is a megamorphic target | |
662 Comment("check if megamorphic"); | |
663 Node* is_megamorphic = WordEqual( | |
664 feedback_element, | |
665 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate()))); | |
666 GotoIf(is_megamorphic, &call_construct_function); | |
667 | |
668 // Check if it is uninitialized. | |
669 Comment("check if uninitialized"); | |
670 Node* is_uninitialized = WordEqual( | |
671 feedback_element, LoadRoot(Heap::kuninitialized_symbolRootIndex)); | |
672 BranchIf(is_uninitialized, &initialize, &check_weak_cell_cleared); | |
673 | |
674 Bind(&check_weak_cell_cleared); | |
675 { | |
676 Comment("check if weak cell"); | |
677 Node* is_weak_cell = WordEqual(LoadMap(feedback_element), | |
678 LoadRoot(Heap::kWeakCellMapRootIndex)); | |
679 GotoUnless(is_weak_cell, &mark_megamorphic); | |
680 | |
681 // If the weak cell is cleared, we have a new chance to become | |
682 // monomorphic. | |
683 Comment("check if weak cell is not cleared"); | |
684 Node* is_smi = WordIsSmi(feedback_value); | |
685 BranchIf(is_smi, &initialize, &mark_megamorphic); | |
686 } | |
687 | |
688 Bind(&initialize); | |
689 { | |
690 // Check that it is not the Array() function. | |
691 Comment("check it is not Array()"); | |
692 Node* context_slot = | |
693 LoadFixedArrayElement(LoadNativeContext(context), | |
694 Int32Constant(Context::ARRAY_FUNCTION_INDEX)); | |
695 Node* is_array_function = WordEqual(context_slot, constructor); | |
696 GotoIf(is_array_function, &mark_megamorphic); | |
697 | |
698 Node* call_count_slot = IntPtrAdd(slot_id, IntPtrConstant(1)); | |
699 // Count is Smi, so we don't need a write barrier. | |
700 StoreFixedArrayElement(type_feedback_vector, call_count_slot, | |
701 SmiTag(Int32Constant(1)), SKIP_WRITE_BARRIER); | |
702 | |
703 // TODO(mythria): Inline the weak cell creation/registration. | |
704 CreateWeakCellStub weak_cell_stub(isolate()); | |
705 CallStub(weak_cell_stub.GetCallInterfaceDescriptor(), | |
706 HeapConstant(weak_cell_stub.GetCode()), context, | |
707 type_feedback_vector, SmiTag(slot_id), constructor); | |
708 Goto(&call_construct_function); | |
709 } | |
710 | |
711 Bind(&mark_megamorphic); | |
712 { | |
713 // MegamorphicSentinel is an immortal immovable object so no write-barrier | |
714 // is needed. | |
715 Comment("transition to megamorphic"); | |
716 DCHECK(Heap::RootIsImmortalImmovable(Heap::kmegamorphic_symbolRootIndex)); | |
717 StoreFixedArrayElement( | |
718 type_feedback_vector, slot_id, | |
719 HeapConstant(TypeFeedbackVector::MegamorphicSentinel(isolate())), | |
720 SKIP_WRITE_BARRIER); | |
721 Goto(&call_construct_function); | |
722 } | |
723 } | |
724 | |
725 Bind(&call_construct_function); | |
726 { | |
727 // TODO(mythria): Get allocation site feedback if available. Currently | |
728 // we do not collect allocation site feedback. | |
729 Comment("call using callConstructFunction"); | |
730 Callable callable_function = CodeFactory::InterpreterPushArgsAndConstruct( | |
731 isolate(), CallableType::kJSFunction); | |
732 return_value.Bind(CallStub(callable_function.descriptor(), | |
733 HeapConstant(callable_function.code()), context, | |
734 arg_count, new_target, constructor, first_arg)); | |
735 Goto(&end); | |
736 } | |
737 | |
738 Bind(&call_construct); | |
739 { | |
740 Comment("call using callConstruct builtin"); | |
741 Callable callable = CodeFactory::InterpreterPushArgsAndConstruct( | |
742 isolate(), CallableType::kAny); | |
743 Node* code_target = HeapConstant(callable.code()); | |
744 return_value.Bind(CallStub(callable.descriptor(), code_target, context, | |
745 arg_count, new_target, constructor, first_arg)); | |
746 Goto(&end); | |
747 } | |
748 | |
749 Bind(&end); | |
750 return return_value.value(); | |
751 } | 611 } |
752 | 612 |
753 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, | 613 Node* InterpreterAssembler::CallRuntimeN(Node* function_id, Node* context, |
754 Node* first_arg, Node* arg_count, | 614 Node* first_arg, Node* arg_count, |
755 int result_size) { | 615 int result_size) { |
756 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size); | 616 Callable callable = CodeFactory::InterpreterCEntry(isolate(), result_size); |
757 Node* code_target = HeapConstant(callable.code()); | 617 Node* code_target = HeapConstant(callable.code()); |
758 | 618 |
759 // Get the function entry from the function id. | 619 // Get the function entry from the function id. |
760 Node* function_table = ExternalConstant( | 620 Node* function_table = ExternalConstant( |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 Goto(&loop); | 932 Goto(&loop); |
1073 } | 933 } |
1074 Bind(&done_loop); | 934 Bind(&done_loop); |
1075 | 935 |
1076 return array; | 936 return array; |
1077 } | 937 } |
1078 | 938 |
1079 } // namespace interpreter | 939 } // namespace interpreter |
1080 } // namespace internal | 940 } // namespace internal |
1081 } // namespace v8 | 941 } // namespace v8 |
OLD | NEW |