OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 #if V8_TARGET_ARCH_X64 | 5 #if V8_TARGET_ARCH_X64 |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/codegen.h" | 8 #include "src/codegen.h" |
9 #include "src/deoptimizer.h" | 9 #include "src/deoptimizer.h" |
10 #include "src/full-codegen/full-codegen.h" | 10 #include "src/full-codegen/full-codegen.h" |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 __ Push(rdi); | 771 __ Push(rdi); |
772 __ CallRuntime(Runtime::kCompileBaseline); | 772 __ CallRuntime(Runtime::kCompileBaseline); |
773 | 773 |
774 // Restore return value. | 774 // Restore return value. |
775 __ Pop(rax); | 775 __ Pop(rax); |
776 } | 776 } |
777 __ ret(0); | 777 __ ret(0); |
778 } | 778 } |
779 | 779 |
780 static void Generate_InterpreterPushArgs(MacroAssembler* masm, | 780 static void Generate_InterpreterPushArgs(MacroAssembler* masm, |
781 bool push_receiver) { | 781 Register num_args, |
| 782 Register start_address, |
| 783 Register scratch, bool push_receiver) { |
782 // ----------- S t a t e ------------- | 784 // ----------- S t a t e ------------- |
783 // -- rax : the number of arguments (not including the receiver) | 785 // -- rax : the number of arguments (not including the receiver) |
784 // -- rbx : the address of the first argument to be pushed. Subsequent | 786 // -- rbx : the address of the first argument to be pushed. Subsequent |
785 // arguments should be consecutive above this, in the same order as | 787 // arguments should be consecutive above this, in the same order as |
786 // they are to be pushed onto the stack. | 788 // they are to be pushed onto the stack. |
787 // ----------------------------------- | 789 // ----------------------------------- |
788 | 790 |
789 // Find the address of the last argument. | 791 // Find the address of the last argument. |
790 __ movp(rcx, rax); | 792 __ movp(scratch, num_args); |
791 if (push_receiver) { | 793 if (push_receiver) { |
792 __ addp(rcx, Immediate(1)); // Add one for receiver. | 794 __ addp(scratch, Immediate(1)); // Add one for receiver. |
793 } | 795 } |
794 | 796 |
795 __ shlp(rcx, Immediate(kPointerSizeLog2)); | 797 __ shlp(scratch, Immediate(kPointerSizeLog2)); |
796 __ negp(rcx); | 798 __ negp(scratch); |
797 __ addp(rcx, rbx); | 799 __ addp(scratch, start_address); |
798 | 800 |
799 // Push the arguments. | 801 // Push the arguments. |
800 Label loop_header, loop_check; | 802 Label loop_header, loop_check; |
801 __ j(always, &loop_check); | 803 __ j(always, &loop_check); |
802 __ bind(&loop_header); | 804 __ bind(&loop_header); |
803 __ Push(Operand(rbx, 0)); | 805 __ Push(Operand(start_address, 0)); |
804 __ subp(rbx, Immediate(kPointerSize)); | 806 __ subp(start_address, Immediate(kPointerSize)); |
805 __ bind(&loop_check); | 807 __ bind(&loop_check); |
806 __ cmpp(rbx, rcx); | 808 __ cmpp(start_address, scratch); |
807 __ j(greater, &loop_header, Label::kNear); | 809 __ j(greater, &loop_header, Label::kNear); |
808 } | 810 } |
809 | 811 |
810 // static | 812 // static |
811 void Builtins::Generate_InterpreterPushArgsAndCallImpl( | 813 void Builtins::Generate_InterpreterPushArgsAndCallImpl( |
812 MacroAssembler* masm, TailCallMode tail_call_mode, | 814 MacroAssembler* masm, TailCallMode tail_call_mode, |
813 CallableType function_type) { | 815 CallableType function_type) { |
814 // ----------- S t a t e ------------- | 816 // ----------- S t a t e ------------- |
815 // -- rax : the number of arguments (not including the receiver) | 817 // -- rax : the number of arguments (not including the receiver) |
816 // -- rbx : the address of the first argument to be pushed. Subsequent | 818 // -- rbx : the address of the first argument to be pushed. Subsequent |
817 // arguments should be consecutive above this, in the same order as | 819 // arguments should be consecutive above this, in the same order as |
818 // they are to be pushed onto the stack. | 820 // they are to be pushed onto the stack. |
819 // -- rdi : the target to call (can be any Object). | 821 // -- rdi : the target to call (can be any Object). |
820 // ----------------------------------- | 822 // ----------------------------------- |
821 | 823 |
822 // Pop return address to allow tail-call after pushing arguments. | 824 // Pop return address to allow tail-call after pushing arguments. |
823 __ PopReturnAddressTo(kScratchRegister); | 825 __ PopReturnAddressTo(kScratchRegister); |
824 | 826 |
825 Generate_InterpreterPushArgs(masm, true); | 827 // rax is readonly rcx and r8 will be modified. |
| 828 Generate_InterpreterPushArgs(masm, rax, rbx, rcx, true); |
826 | 829 |
827 // Call the target. | 830 // Call the target. |
828 __ PushReturnAddressFrom(kScratchRegister); // Re-push return address. | 831 __ PushReturnAddressFrom(kScratchRegister); // Re-push return address. |
829 | 832 |
830 if (function_type == CallableType::kJSFunction) { | 833 if (function_type == CallableType::kJSFunction) { |
831 __ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny, | 834 __ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny, |
832 tail_call_mode), | 835 tail_call_mode), |
833 RelocInfo::CODE_TARGET); | 836 RelocInfo::CODE_TARGET); |
834 } else { | 837 } else { |
835 DCHECK_EQ(function_type, CallableType::kAny); | 838 DCHECK_EQ(function_type, CallableType::kAny); |
836 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny, | 839 __ Jump(masm->isolate()->builtins()->Call(ConvertReceiverMode::kAny, |
837 tail_call_mode), | 840 tail_call_mode), |
838 RelocInfo::CODE_TARGET); | 841 RelocInfo::CODE_TARGET); |
839 } | 842 } |
840 } | 843 } |
841 | 844 |
842 // static | 845 // static |
843 void Builtins::Generate_InterpreterPushArgsAndConstruct(MacroAssembler* masm) { | 846 void Builtins::Generate_InterpreterPushArgsAndConstructImpl( |
| 847 MacroAssembler* masm, CallableType construct_type) { |
844 // ----------- S t a t e ------------- | 848 // ----------- S t a t e ------------- |
845 // -- rax : the number of arguments (not including the receiver) | 849 // -- rax : the number of arguments (not including the receiver) |
846 // -- rdx : the new target (either the same as the constructor or | 850 // -- rdx : the new target (either the same as the constructor or |
847 // the JSFunction on which new was invoked initially) | 851 // the JSFunction on which new was invoked initially) |
848 // -- rdi : the constructor to call (can be any Object) | 852 // -- rdi : the constructor to call (can be any Object) |
849 // -- rbx : the address of the first argument to be pushed. Subsequent | 853 // -- rbx : the allocation site feedback if available, undefined otherwise |
| 854 // -- rcx : the address of the first argument to be pushed. Subsequent |
850 // arguments should be consecutive above this, in the same order as | 855 // arguments should be consecutive above this, in the same order as |
851 // they are to be pushed onto the stack. | 856 // they are to be pushed onto the stack. |
852 // ----------------------------------- | 857 // ----------------------------------- |
853 | 858 |
854 // Pop return address to allow tail-call after pushing arguments. | 859 // Pop return address to allow tail-call after pushing arguments. |
855 __ PopReturnAddressTo(kScratchRegister); | 860 __ PopReturnAddressTo(kScratchRegister); |
856 | 861 |
857 // Push slot for the receiver to be constructed. | 862 // Push slot for the receiver to be constructed. |
858 __ Push(Immediate(0)); | 863 __ Push(Immediate(0)); |
859 | 864 |
860 Generate_InterpreterPushArgs(masm, false); | 865 // rax is readonly rcx and r8 will be modified. |
| 866 Generate_InterpreterPushArgs(masm, rax, rcx, r8, false); |
861 | 867 |
862 // Push return address in preparation for the tail-call. | 868 // Push return address in preparation for the tail-call. |
863 __ PushReturnAddressFrom(kScratchRegister); | 869 __ PushReturnAddressFrom(kScratchRegister); |
864 | 870 |
865 // Call the constructor (rax, rdx, rdi passed on). | 871 __ AssertUndefinedOrAllocationSite(rbx); |
866 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); | 872 if (construct_type == CallableType::kJSFunction) { |
| 873 // Tail call to the function-specific construct stub (still in the caller |
| 874 // context at this point). |
| 875 __ AssertFunction(rdi); |
| 876 |
| 877 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
| 878 __ movp(rcx, FieldOperand(rcx, SharedFunctionInfo::kConstructStubOffset)); |
| 879 __ leap(rcx, FieldOperand(rcx, Code::kHeaderSize)); |
| 880 // Jump to the constructor function (rax, rbx, rdx passed on). |
| 881 __ jmp(rcx); |
| 882 } else { |
| 883 DCHECK_EQ(construct_type, CallableType::kAny); |
| 884 // Call the constructor (rax, rdx, rdi passed on). |
| 885 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); |
| 886 } |
867 } | 887 } |
868 | 888 |
869 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { | 889 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { |
870 // Set the return address to the correct point in the interpreter entry | 890 // Set the return address to the correct point in the interpreter entry |
871 // trampoline. | 891 // trampoline. |
872 Smi* interpreter_entry_return_pc_offset( | 892 Smi* interpreter_entry_return_pc_offset( |
873 masm->isolate()->heap()->interpreter_entry_return_pc_offset()); | 893 masm->isolate()->heap()->interpreter_entry_return_pc_offset()); |
874 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0)); | 894 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0)); |
875 __ Move(rbx, masm->isolate()->builtins()->InterpreterEntryTrampoline()); | 895 __ Move(rbx, masm->isolate()->builtins()->InterpreterEntryTrampoline()); |
876 __ addp(rbx, Immediate(interpreter_entry_return_pc_offset->value() + | 896 __ addp(rbx, Immediate(interpreter_entry_return_pc_offset->value() + |
(...skipping 2191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3068 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { | 3088 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { |
3069 Generate_OnStackReplacementHelper(masm, true); | 3089 Generate_OnStackReplacementHelper(masm, true); |
3070 } | 3090 } |
3071 | 3091 |
3072 #undef __ | 3092 #undef __ |
3073 | 3093 |
3074 } // namespace internal | 3094 } // namespace internal |
3075 } // namespace v8 | 3095 } // namespace v8 |
3076 | 3096 |
3077 #endif // V8_TARGET_ARCH_X64 | 3097 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |