Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: src/builtins/ia32/builtins-ia32.cc

Issue 2571563004: [Turbofan] Implement super calls with spread bytecode in assembly code. (Closed)
Patch Set: MIPS64 port Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins/builtins-interpreter.cc ('k') | src/builtins/mips/builtins-mips.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_IA32 5 #if V8_TARGET_ARCH_IA32
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 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 __ sub(scratch1, Immediate(1)); 837 __ sub(scratch1, Immediate(1));
838 __ bind(&loop_check); 838 __ bind(&loop_check);
839 __ cmp(scratch1, Immediate(0)); 839 __ cmp(scratch1, Immediate(0));
840 __ j(greater, &loop_header, Label::kNear); 840 __ j(greater, &loop_header, Label::kNear);
841 } 841 }
842 842
843 } // end anonymous namespace 843 } // end anonymous namespace
844 844
845 // static 845 // static
846 void Builtins::Generate_InterpreterPushArgsAndConstructImpl( 846 void Builtins::Generate_InterpreterPushArgsAndConstructImpl(
847 MacroAssembler* masm, CallableType construct_type) { 847 MacroAssembler* masm, PushArgsConstructMode mode) {
848 // ----------- S t a t e ------------- 848 // ----------- S t a t e -------------
849 // -- eax : the number of arguments (not including the receiver) 849 // -- eax : the number of arguments (not including the receiver)
850 // -- edx : the new target 850 // -- edx : the new target
851 // -- edi : the constructor 851 // -- edi : the constructor
852 // -- ebx : allocation site feedback (if available or undefined) 852 // -- ebx : allocation site feedback (if available or undefined)
853 // -- ecx : the address of the first argument to be pushed. Subsequent 853 // -- ecx : the address of the first argument to be pushed. Subsequent
854 // arguments should be consecutive above this, in the same order as 854 // arguments should be consecutive above this, in the same order as
855 // they are to be pushed onto the stack. 855 // they are to be pushed onto the stack.
856 // ----------------------------------- 856 // -----------------------------------
857 Label stack_overflow; 857 Label stack_overflow;
858 // We need two scratch registers. Push edi and edx onto stack. 858 // We need two scratch registers. Push edi and edx onto stack.
859 __ Push(edi); 859 __ Push(edi);
860 __ Push(edx); 860 __ Push(edx);
861 861
862 // Push arguments and move return address to the top of stack. 862 // Push arguments and move return address to the top of stack.
863 // The eax register is readonly. The ecx register will be modified. The edx 863 // The eax register is readonly. The ecx register will be modified. The edx
864 // and edi registers will be modified but restored to their original values. 864 // and edi registers will be modified but restored to their original values.
865 Generate_InterpreterPushArgsAndReturnAddress(masm, eax, ecx, edx, edi, false, 865 Generate_InterpreterPushArgsAndReturnAddress(masm, eax, ecx, edx, edi, false,
866 2, &stack_overflow); 866 2, &stack_overflow);
867 867
868 // Restore edi and edx 868 // Restore edi and edx
869 __ Pop(edx); 869 __ Pop(edx);
870 __ Pop(edi); 870 __ Pop(edi);
871 871
872 __ AssertUndefinedOrAllocationSite(ebx); 872 __ AssertUndefinedOrAllocationSite(ebx);
873 if (construct_type == CallableType::kJSFunction) { 873 if (mode == PushArgsConstructMode::kJSFunction) {
874 // Tail call to the function-specific construct stub (still in the caller 874 // Tail call to the function-specific construct stub (still in the caller
875 // context at this point). 875 // context at this point).
876 __ AssertFunction(edi); 876 __ AssertFunction(edi);
877 877
878 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); 878 __ mov(ecx, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset));
879 __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset)); 879 __ mov(ecx, FieldOperand(ecx, SharedFunctionInfo::kConstructStubOffset));
880 __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize)); 880 __ lea(ecx, FieldOperand(ecx, Code::kHeaderSize));
881 __ jmp(ecx); 881 __ jmp(ecx);
882 } else if (mode == PushArgsConstructMode::kWithFinalSpread) {
883 // Call the constructor with unmodified eax, edi, edx values.
884 __ Jump(masm->isolate()->builtins()->ConstructWithSpread(),
885 RelocInfo::CODE_TARGET);
882 } else { 886 } else {
883 DCHECK_EQ(construct_type, CallableType::kAny); 887 DCHECK_EQ(PushArgsConstructMode::kOther, mode);
884
885 // Call the constructor with unmodified eax, edi, edx values. 888 // Call the constructor with unmodified eax, edi, edx values.
886 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET); 889 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
887 } 890 }
888 891
889 __ bind(&stack_overflow); 892 __ bind(&stack_overflow);
890 { 893 {
891 // Pop the temporary registers, so that return address is on top of stack. 894 // Pop the temporary registers, so that return address is on top of stack.
892 __ Pop(edx); 895 __ Pop(edx);
893 __ Pop(edi); 896 __ Pop(edi);
894 897
(...skipping 1881 matching lines...) Expand 10 before | Expand all | Expand 10 after
2776 } 2779 }
2777 2780
2778 // Called Construct on an Object that doesn't have a [[Construct]] internal 2781 // Called Construct on an Object that doesn't have a [[Construct]] internal
2779 // method. 2782 // method.
2780 __ bind(&non_constructor); 2783 __ bind(&non_constructor);
2781 __ Jump(masm->isolate()->builtins()->ConstructedNonConstructable(), 2784 __ Jump(masm->isolate()->builtins()->ConstructedNonConstructable(),
2782 RelocInfo::CODE_TARGET); 2785 RelocInfo::CODE_TARGET);
2783 } 2786 }
2784 2787
2785 // static 2788 // static
2789 void Builtins::Generate_ConstructWithSpread(MacroAssembler* masm) {
2790 // ----------- S t a t e -------------
2791 // -- eax : the number of arguments (not including the receiver)
2792 // -- edx : the new target (either the same as the constructor or
2793 // the JSFunction on which new was invoked initially)
2794 // -- edi : the constructor to call (can be any Object)
2795 // -----------------------------------
2796
2797 // Free up some registers.
2798 __ movd(xmm0, edx);
2799 __ movd(xmm1, edi);
2800
2801 Register argc = eax;
2802
2803 Register scratch = ecx;
2804 Register scratch2 = edi;
2805
2806 Register spread = ebx;
2807 Register spread_map = edx;
2808
2809 __ mov(spread, Operand(esp, kPointerSize));
2810 __ mov(spread_map, FieldOperand(spread, HeapObject::kMapOffset));
2811
2812 Label runtime_call, push_args;
2813 // Check that the spread is an array.
2814 __ CmpInstanceType(spread_map, JS_ARRAY_TYPE);
2815 __ j(not_equal, &runtime_call);
2816
2817 // Check that we have the original ArrayPrototype.
2818 __ mov(scratch, FieldOperand(spread_map, Map::kPrototypeOffset));
2819 __ mov(scratch2, NativeContextOperand());
2820 __ cmp(scratch,
2821 ContextOperand(scratch2, Context::INITIAL_ARRAY_PROTOTYPE_INDEX));
2822 __ j(not_equal, &runtime_call);
2823
2824 // Check that the ArrayPrototype hasn't been modified in a way that would
2825 // affect iteration.
2826 __ LoadRoot(scratch, Heap::kArrayIteratorProtectorRootIndex);
2827 __ cmp(FieldOperand(scratch, Cell::kValueOffset),
2828 Immediate(Smi::FromInt(Isolate::kProtectorValid)));
2829 __ j(not_equal, &runtime_call);
2830
2831 // Check that the map of the initial array iterator hasn't changed.
2832 __ mov(scratch2, NativeContextOperand());
2833 __ mov(scratch,
2834 ContextOperand(scratch2,
2835 Context::INITIAL_ARRAY_ITERATOR_PROTOTYPE_INDEX));
2836 __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset));
2837 __ cmp(scratch,
2838 ContextOperand(scratch2,
2839 Context::INITIAL_ARRAY_ITERATOR_PROTOTYPE_MAP_INDEX));
2840 __ j(not_equal, &runtime_call);
2841
2842 // For FastPacked kinds, iteration will have the same effect as simply
2843 // accessing each property in order.
2844 Label no_protector_check;
2845 __ mov(scratch, FieldOperand(spread_map, Map::kBitField2Offset));
2846 __ DecodeField<Map::ElementsKindBits>(scratch);
2847 __ cmp(scratch, Immediate(LAST_FAST_ELEMENTS_KIND));
2848 __ j(above, &runtime_call);
2849 // For non-FastHoley kinds, we can skip the protector check.
2850 __ cmp(scratch, Immediate(FAST_SMI_ELEMENTS));
2851 __ j(equal, &no_protector_check);
2852 __ cmp(scratch, Immediate(FAST_ELEMENTS));
2853 __ j(equal, &no_protector_check);
2854 __ cmp(scratch, Immediate(FAST_DOUBLE_ELEMENTS));
2855 __ j(equal, &no_protector_check);
2856 // Check the ArrayProtector cell.
2857 __ LoadRoot(scratch, Heap::kArrayProtectorRootIndex);
2858 __ cmp(FieldOperand(scratch, PropertyCell::kValueOffset),
2859 Immediate(Smi::FromInt(Isolate::kProtectorValid)));
2860 __ j(not_equal, &runtime_call);
2861
2862 __ bind(&no_protector_check);
2863 // Load the FixedArray backing store.
2864 __ mov(spread, FieldOperand(spread, JSArray::kElementsOffset));
2865 // Free up some registers.
2866 __ jmp(&push_args);
2867
2868 __ bind(&runtime_call);
2869 {
2870 // Call the builtin for the result of the spread.
2871 FrameScope scope(masm, StackFrame::INTERNAL);
2872 // Need to save these on the stack.
2873 __ movd(edi, xmm1);
2874 __ movd(edx, xmm0);
2875 __ Push(edi);
2876 __ Push(edx);
2877 __ SmiTag(argc);
2878 __ Push(argc);
2879 __ Push(spread);
2880 __ CallRuntime(Runtime::kSpreadIterableFixed);
2881 __ mov(spread, eax);
2882 __ Pop(argc);
2883 __ SmiUntag(argc);
2884 __ Pop(edx);
2885 __ Pop(edi);
2886 // Free up some registers.
2887 __ movd(xmm0, edx);
2888 __ movd(xmm1, edi);
2889 }
2890
2891 Register spread_len = edx;
2892 Register return_address = edi;
2893 __ bind(&push_args);
2894 {
2895 // Pop the return address and spread argument.
2896 __ PopReturnAddressTo(return_address);
2897 __ Pop(scratch);
2898
2899 // Calculate the new nargs including the result of the spread.
2900 __ mov(spread_len, FieldOperand(spread, FixedArray::kLengthOffset));
2901 __ SmiUntag(spread_len);
2902 // argc += spread_len - 1. Subtract 1 for the spread itself.
2903 __ lea(argc, Operand(argc, spread_len, times_1, -1));
2904 }
2905
2906 // Check for stack overflow.
2907 {
2908 // Check the stack for overflow. We are not trying to catch interruptions
2909 // (i.e. debug break and preemption) here, so check the "real stack limit".
2910 Label done;
2911 __ LoadRoot(scratch, Heap::kRealStackLimitRootIndex);
2912 // Make scratch the space we have left. The stack might already be
2913 // overflowed here which will cause scratch to become negative.
2914 __ neg(scratch);
2915 __ add(scratch, esp);
2916 __ sar(scratch, kPointerSizeLog2);
2917 // Check if the arguments will overflow the stack.
2918 __ cmp(scratch, spread_len);
2919 __ j(greater, &done, Label::kNear); // Signed comparison.
2920 __ TailCallRuntime(Runtime::kThrowStackOverflow);
2921 __ bind(&done);
2922 }
2923
2924 // Put the evaluated spread onto the stack as additional arguments.
2925 {
2926 Register scratch2 = esi;
2927 __ movd(xmm2, esi);
2928
2929 __ mov(scratch, Immediate(0));
2930 Label done, loop;
2931 __ bind(&loop);
2932 __ cmp(scratch, spread_len);
2933 __ j(equal, &done, Label::kNear);
2934 __ mov(scratch2, FieldOperand(spread, scratch, times_pointer_size,
2935 FixedArray::kHeaderSize));
2936 __ Push(scratch2);
2937 __ inc(scratch);
2938 __ jmp(&loop);
2939 __ bind(&done);
2940 __ PushReturnAddressFrom(return_address);
2941 __ movd(esi, xmm2);
2942 __ movd(edi, xmm1);
2943 __ movd(edx, xmm0);
2944 }
2945
2946 // Dispatch.
2947 __ Jump(masm->isolate()->builtins()->Construct(), RelocInfo::CODE_TARGET);
2948 }
2949
2950 // static
2786 void Builtins::Generate_AllocateInNewSpace(MacroAssembler* masm) { 2951 void Builtins::Generate_AllocateInNewSpace(MacroAssembler* masm) {
2787 // ----------- S t a t e ------------- 2952 // ----------- S t a t e -------------
2788 // -- edx : requested object size (untagged) 2953 // -- edx : requested object size (untagged)
2789 // -- esp[0] : return address 2954 // -- esp[0] : return address
2790 // ----------------------------------- 2955 // -----------------------------------
2791 __ SmiTag(edx); 2956 __ SmiTag(edx);
2792 __ PopReturnAddressTo(ecx); 2957 __ PopReturnAddressTo(ecx);
2793 __ Push(edx); 2958 __ Push(edx);
2794 __ PushReturnAddressFrom(ecx); 2959 __ PushReturnAddressFrom(ecx);
2795 __ Move(esi, Smi::kZero); 2960 __ Move(esi, Smi::kZero);
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
3097 3262
3098 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) { 3263 void Builtins::Generate_InterpreterOnStackReplacement(MacroAssembler* masm) {
3099 Generate_OnStackReplacementHelper(masm, true); 3264 Generate_OnStackReplacementHelper(masm, true);
3100 } 3265 }
3101 3266
3102 #undef __ 3267 #undef __
3103 } // namespace internal 3268 } // namespace internal
3104 } // namespace v8 3269 } // namespace v8
3105 3270
3106 #endif // V8_TARGET_ARCH_IA32 3271 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/builtins/builtins-interpreter.cc ('k') | src/builtins/mips/builtins-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698