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 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 __ CallRuntime(Runtime::kCompileBaseline); | 777 __ CallRuntime(Runtime::kCompileBaseline); |
778 | 778 |
779 // Restore return value. | 779 // Restore return value. |
780 __ Pop(rax); | 780 __ Pop(rax); |
781 } | 781 } |
782 __ ret(0); | 782 __ ret(0); |
783 } | 783 } |
784 | 784 |
785 static void Generate_InterpreterPushArgs(MacroAssembler* masm, | 785 static void Generate_InterpreterPushArgs(MacroAssembler* masm, |
786 Register num_args, | 786 Register num_args, |
787 Register start_address, | 787 Register start_address) { |
788 Register scratch, bool push_receiver) { | 788 Register scratch = num_args; |
789 // ----------- S t a t e ------------- | |
790 // -- rax : the number of arguments (not including the receiver) | |
791 // -- rbx : the address of the first argument to be pushed. Subsequent | |
792 // arguments should be consecutive above this, in the same order as | |
793 // they are to be pushed onto the stack. | |
794 // ----------------------------------- | |
795 | |
796 // Find the address of the last argument. | 789 // Find the address of the last argument. |
797 __ movp(scratch, num_args); | |
798 if (push_receiver) { | |
799 __ addp(scratch, Immediate(1)); // Add one for receiver. | |
800 } | |
801 | |
802 __ shlp(scratch, Immediate(kPointerSizeLog2)); | 790 __ shlp(scratch, Immediate(kPointerSizeLog2)); |
803 __ negp(scratch); | 791 __ negp(scratch); |
804 __ addp(scratch, start_address); | 792 __ addp(scratch, start_address); |
805 | 793 |
| 794 // TODO(mythria): Add a stack check before pushing arguments. |
806 // Push the arguments. | 795 // Push the arguments. |
807 Label loop_header, loop_check; | 796 Label loop_header, loop_check; |
808 __ j(always, &loop_check); | 797 __ j(always, &loop_check); |
809 __ bind(&loop_header); | 798 __ bind(&loop_header); |
810 __ Push(Operand(start_address, 0)); | 799 __ Push(Operand(start_address, 0)); |
811 __ subp(start_address, Immediate(kPointerSize)); | 800 __ subp(start_address, Immediate(kPointerSize)); |
812 __ bind(&loop_check); | 801 __ bind(&loop_check); |
813 __ cmpp(start_address, scratch); | 802 __ cmpp(start_address, scratch); |
814 __ j(greater, &loop_header, Label::kNear); | 803 __ j(greater, &loop_header, Label::kNear); |
815 } | 804 } |
816 | 805 |
817 // static | 806 // static |
818 void Builtins::Generate_InterpreterPushArgsAndCallImpl( | 807 void Builtins::Generate_InterpreterPushArgsAndCallImpl( |
819 MacroAssembler* masm, TailCallMode tail_call_mode, | 808 MacroAssembler* masm, TailCallMode tail_call_mode, |
820 CallableType function_type) { | 809 CallableType function_type) { |
821 // ----------- S t a t e ------------- | 810 // ----------- S t a t e ------------- |
822 // -- rax : the number of arguments (not including the receiver) | 811 // -- rax : the number of arguments (not including the receiver) |
823 // -- rbx : the address of the first argument to be pushed. Subsequent | 812 // -- rbx : the address of the first argument to be pushed. Subsequent |
824 // arguments should be consecutive above this, in the same order as | 813 // arguments should be consecutive above this, in the same order as |
825 // they are to be pushed onto the stack. | 814 // they are to be pushed onto the stack. |
826 // -- rdi : the target to call (can be any Object). | 815 // -- rdi : the target to call (can be any Object). |
827 // ----------------------------------- | 816 // ----------------------------------- |
828 | 817 |
829 // Pop return address to allow tail-call after pushing arguments. | 818 // Pop return address to allow tail-call after pushing arguments. |
830 __ PopReturnAddressTo(kScratchRegister); | 819 __ PopReturnAddressTo(kScratchRegister); |
831 | 820 |
832 // TODO(mythria): Add a stack check before pushing arguments. | 821 // Number of values to be pushed. |
833 // rax is readonly rcx and r8 will be modified. | 822 __ Move(rcx, rax); |
834 Generate_InterpreterPushArgs(masm, rax, rbx, rcx, true); | 823 __ addp(rcx, Immediate(1)); // Add one for receiver. |
| 824 |
| 825 // rbx and rcx will be modified. |
| 826 Generate_InterpreterPushArgs(masm, rcx, rbx); |
835 | 827 |
836 // Call the target. | 828 // Call the target. |
837 __ PushReturnAddressFrom(kScratchRegister); // Re-push return address. | 829 __ PushReturnAddressFrom(kScratchRegister); // Re-push return address. |
838 | 830 |
839 if (function_type == CallableType::kJSFunction) { | 831 if (function_type == CallableType::kJSFunction) { |
840 __ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny, | 832 __ Jump(masm->isolate()->builtins()->CallFunction(ConvertReceiverMode::kAny, |
841 tail_call_mode), | 833 tail_call_mode), |
842 RelocInfo::CODE_TARGET); | 834 RelocInfo::CODE_TARGET); |
843 } else { | 835 } else { |
844 DCHECK_EQ(function_type, CallableType::kAny); | 836 DCHECK_EQ(function_type, CallableType::kAny); |
(...skipping 16 matching lines...) Expand all Loading... |
861 // arguments should be consecutive above this, in the same order as | 853 // arguments should be consecutive above this, in the same order as |
862 // they are to be pushed onto the stack. | 854 // they are to be pushed onto the stack. |
863 // ----------------------------------- | 855 // ----------------------------------- |
864 | 856 |
865 // Pop return address to allow tail-call after pushing arguments. | 857 // Pop return address to allow tail-call after pushing arguments. |
866 __ PopReturnAddressTo(kScratchRegister); | 858 __ PopReturnAddressTo(kScratchRegister); |
867 | 859 |
868 // Push slot for the receiver to be constructed. | 860 // Push slot for the receiver to be constructed. |
869 __ Push(Immediate(0)); | 861 __ Push(Immediate(0)); |
870 | 862 |
871 // TODO(mythria): Add a stack check before pushing arguments. | 863 // num_args will be modified by InterpreterPushArgs. So move it to a different |
872 // rax is readonly rcx and r8 will be modified. | 864 // register. |
873 Generate_InterpreterPushArgs(masm, rax, rcx, r8, false); | 865 __ Move(r8, rax); |
| 866 |
| 867 // rcx and r8 will be modified. |
| 868 Generate_InterpreterPushArgs(masm, r8, rcx); |
874 | 869 |
875 // Push return address in preparation for the tail-call. | 870 // Push return address in preparation for the tail-call. |
876 __ PushReturnAddressFrom(kScratchRegister); | 871 __ PushReturnAddressFrom(kScratchRegister); |
877 | 872 |
878 __ AssertUndefinedOrAllocationSite(rbx); | 873 __ AssertUndefinedOrAllocationSite(rbx); |
879 if (construct_type == CallableType::kJSFunction) { | 874 if (construct_type == CallableType::kJSFunction) { |
880 // Tail call to the function-specific construct stub (still in the caller | 875 // Tail call to the function-specific construct stub (still in the caller |
881 // context at this point). | 876 // context at this point). |
882 __ AssertFunction(rdi); | 877 __ AssertFunction(rdi); |
883 | 878 |
884 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); | 879 __ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset)); |
885 __ movp(rcx, FieldOperand(rcx, SharedFunctionInfo::kConstructStubOffset)); | 880 __ movp(rcx, FieldOperand(rcx, SharedFunctionInfo::kConstructStubOffset)); |
886 __ leap(rcx, FieldOperand(rcx, Code::kHeaderSize)); | 881 __ leap(rcx, FieldOperand(rcx, Code::kHeaderSize)); |
887 // Jump to the constructor function (rax, rbx, rdx passed on). | 882 // Jump to the constructor function (rax, rbx, rdx passed on). |
888 __ jmp(rcx); | 883 __ jmp(rcx); |
889 } else { | 884 } else { |
890 DCHECK_EQ(construct_type, CallableType::kAny); | 885 DCHECK_EQ(construct_type, CallableType::kAny); |
891 // Call the constructor (rax, rdx, rdi passed on). | 886 // Call the constructor (rax, rdx, rdi passed on). |
892 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); | 887 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); |
893 } | 888 } |
894 } | 889 } |
895 | 890 |
| 891 // static |
| 892 void Builtins::Generate_InterpreterPushArgsAndConstructArray( |
| 893 MacroAssembler* masm) { |
| 894 // ----------- S t a t e ------------- |
| 895 // -- rax : the number of arguments (not including the receiver) |
| 896 // -- rdx : the target to call checked to be Array function. |
| 897 // -- rbx : the allocation site feedback |
| 898 // -- rcx : the address of the first argument to be pushed. Subsequent |
| 899 // arguments should be consecutive above this, in the same order as |
| 900 // they are to be pushed onto the stack. |
| 901 // ----------------------------------- |
| 902 |
| 903 // Pop return address to allow tail-call after pushing arguments. |
| 904 __ PopReturnAddressTo(kScratchRegister); |
| 905 |
| 906 // Number of values to be pushed. |
| 907 __ Move(r8, rax); |
| 908 __ addp(r8, Immediate(1)); // Add one for receiver. |
| 909 |
| 910 // rcx and r8 will be modified. |
| 911 Generate_InterpreterPushArgs(masm, r8, rcx); |
| 912 |
| 913 // Push return address in preparation for the tail-call. |
| 914 __ PushReturnAddressFrom(kScratchRegister); |
| 915 |
| 916 // Array constructor expects constructor in rdi. It is same as rdx here. |
| 917 __ Move(rdi, rdx); |
| 918 |
| 919 ArrayConstructorStub stub(masm->isolate()); |
| 920 __ TailCallStub(&stub); |
| 921 } |
| 922 |
896 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { | 923 void Builtins::Generate_InterpreterEnterBytecodeDispatch(MacroAssembler* masm) { |
897 // Set the return address to the correct point in the interpreter entry | 924 // Set the return address to the correct point in the interpreter entry |
898 // trampoline. | 925 // trampoline. |
899 Smi* interpreter_entry_return_pc_offset( | 926 Smi* interpreter_entry_return_pc_offset( |
900 masm->isolate()->heap()->interpreter_entry_return_pc_offset()); | 927 masm->isolate()->heap()->interpreter_entry_return_pc_offset()); |
901 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0)); | 928 DCHECK_NE(interpreter_entry_return_pc_offset, Smi::FromInt(0)); |
902 __ Move(rbx, masm->isolate()->builtins()->InterpreterEntryTrampoline()); | 929 __ Move(rbx, masm->isolate()->builtins()->InterpreterEntryTrampoline()); |
903 __ addp(rbx, Immediate(interpreter_entry_return_pc_offset->value() + | 930 __ addp(rbx, Immediate(interpreter_entry_return_pc_offset->value() + |
904 Code::kHeaderSize - kHeapObjectTag)); | 931 Code::kHeaderSize - kHeapObjectTag)); |
905 __ Push(rbx); | 932 __ Push(rbx); |
(...skipping 2204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3110 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { | 3137 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { |
3111 Generate_OnStackReplacementHelper(masm, true); | 3138 Generate_OnStackReplacementHelper(masm, true); |
3112 } | 3139 } |
3113 | 3140 |
3114 #undef __ | 3141 #undef __ |
3115 | 3142 |
3116 } // namespace internal | 3143 } // namespace internal |
3117 } // namespace v8 | 3144 } // namespace v8 |
3118 | 3145 |
3119 #endif // V8_TARGET_ARCH_X64 | 3146 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |