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

Side by Side Diff: src/builtins/builtins-call-gen.cc

Issue 2930623002: [builtins] Start refactoring the Apply builtin. (Closed)
Patch Set: Address feedback. Created 3 years, 6 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-call-gen.h ('k') | src/builtins/builtins-constructor-gen.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 2017 the V8 project authors. All rights reserved. 1 // Copyright 2017 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/builtins/builtins-call-gen.h"
6
7 #include "src/builtins/builtins-utils-gen.h"
5 #include "src/builtins/builtins.h" 8 #include "src/builtins/builtins.h"
6 #include "src/globals.h" 9 #include "src/globals.h"
7 #include "src/isolate.h" 10 #include "src/isolate.h"
8 #include "src/macro-assembler.h" 11 #include "src/macro-assembler.h"
9 12
10 namespace v8 { 13 namespace v8 {
11 namespace internal { 14 namespace internal {
12 15
13 void Builtins::Generate_CallFunction_ReceiverIsNullOrUndefined( 16 void Builtins::Generate_CallFunction_ReceiverIsNullOrUndefined(
14 MacroAssembler* masm) { 17 MacroAssembler* masm) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 void Builtins::Generate_TailCall_ReceiverIsNotNullOrUndefined( 78 void Builtins::Generate_TailCall_ReceiverIsNotNullOrUndefined(
76 MacroAssembler* masm) { 79 MacroAssembler* masm) {
77 Generate_Call(masm, ConvertReceiverMode::kNotNullOrUndefined, 80 Generate_Call(masm, ConvertReceiverMode::kNotNullOrUndefined,
78 TailCallMode::kAllow); 81 TailCallMode::kAllow);
79 } 82 }
80 83
81 void Builtins::Generate_TailCall_ReceiverIsAny(MacroAssembler* masm) { 84 void Builtins::Generate_TailCall_ReceiverIsAny(MacroAssembler* masm) {
82 Generate_Call(masm, ConvertReceiverMode::kAny, TailCallMode::kAllow); 85 Generate_Call(masm, ConvertReceiverMode::kAny, TailCallMode::kAllow);
83 } 86 }
84 87
88 void Builtins::Generate_CallVarargs(MacroAssembler* masm) {
89 Generate_CallOrConstructVarargs(masm, masm->isolate()->builtins()->Call());
90 }
91
85 void Builtins::Generate_CallForwardVarargs(MacroAssembler* masm) { 92 void Builtins::Generate_CallForwardVarargs(MacroAssembler* masm) {
86 Generate_ForwardVarargs(masm, masm->isolate()->builtins()->Call()); 93 Generate_CallOrConstructForwardVarargs(masm,
94 masm->isolate()->builtins()->Call());
87 } 95 }
88 96
89 void Builtins::Generate_CallFunctionForwardVarargs(MacroAssembler* masm) { 97 void Builtins::Generate_CallFunctionForwardVarargs(MacroAssembler* masm) {
90 Generate_ForwardVarargs(masm, masm->isolate()->builtins()->CallFunction()); 98 Generate_CallOrConstructForwardVarargs(
99 masm, masm->isolate()->builtins()->CallFunction());
100 }
101
102 void CallOrConstructBuiltinsAssembler::CallOrConstructWithArrayLike(
103 Node* target, Node* new_target, Node* arguments_list, Node* context) {
104 Variable var_elements(this, MachineRepresentation::kTagged);
105 Variable var_length(this, MachineRepresentation::kWord32);
106 Label if_done(this), if_arguments(this), if_array(this),
107 if_holey_array(this, Label::kDeferred),
108 if_runtime(this, Label::kDeferred);
109
110 GotoIf(TaggedIsSmi(arguments_list), &if_runtime);
111 Node* arguments_list_map = LoadMap(arguments_list);
112 Node* native_context = LoadNativeContext(context);
113
114 // Check if {arguments_list} is an (unmodified) arguments object.
115 Node* sloppy_arguments_map =
116 LoadContextElement(native_context, Context::SLOPPY_ARGUMENTS_MAP_INDEX);
117 GotoIf(WordEqual(arguments_list_map, sloppy_arguments_map), &if_arguments);
118 Node* strict_arguments_map =
119 LoadContextElement(native_context, Context::STRICT_ARGUMENTS_MAP_INDEX);
120 GotoIf(WordEqual(arguments_list_map, strict_arguments_map), &if_arguments);
121
122 // Check if {arguments_list} is a fast JSArray.
123 Branch(IsJSArrayMap(arguments_list_map), &if_array, &if_runtime);
124
125 BIND(&if_array);
126 {
127 // Try to extract the elements from a JSArray object.
128 var_elements.Bind(
129 LoadObjectField(arguments_list, JSArray::kElementsOffset));
130 var_length.Bind(LoadAndUntagToWord32ObjectField(arguments_list,
131 JSArray::kLengthOffset));
132
133 // Holey arrays and double backing stores need special treatment.
134 Node* kind = LoadMapElementsKind(arguments_list_map);
135 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
136 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
137 STATIC_ASSERT(FAST_ELEMENTS == 2);
138 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
139 GotoIf(Word32Equal(kind, Int32Constant(FAST_HOLEY_SMI_ELEMENTS)),
140 &if_holey_array);
141 GotoIf(Word32Equal(kind, Int32Constant(FAST_HOLEY_ELEMENTS)),
142 &if_holey_array);
143 Branch(Uint32LessThanOrEqual(kind, Int32Constant(FAST_HOLEY_ELEMENTS)),
144 &if_done, &if_runtime);
145 }
146
147 BIND(&if_holey_array);
148 {
149 // For holey JSArrays we need to check that the array prototype chain
150 // protector is intact and our prototype is the Array.prototype actually.
151 Node* arguments_list_prototype = LoadMapPrototype(arguments_list_map);
152 Node* initial_array_prototype = LoadContextElement(
153 native_context, Context::INITIAL_ARRAY_PROTOTYPE_INDEX);
154 GotoIfNot(WordEqual(arguments_list_prototype, initial_array_prototype),
155 &if_runtime);
156 Node* protector_cell = LoadRoot(Heap::kArrayProtectorRootIndex);
157 DCHECK(isolate()->heap()->array_protector()->IsPropertyCell());
158 Branch(
159 WordEqual(LoadObjectField(protector_cell, PropertyCell::kValueOffset),
160 SmiConstant(Smi::FromInt(Isolate::kProtectorValid))),
161 &if_done, &if_runtime);
162 }
163
164 BIND(&if_arguments);
165 {
166 // Try to extract the elements from an JSArgumentsObject.
167 Node* length =
168 LoadObjectField(arguments_list, JSArgumentsObject::kLengthOffset);
169 Node* elements =
170 LoadObjectField(arguments_list, JSArgumentsObject::kElementsOffset);
171 Node* elements_length =
172 LoadObjectField(elements, FixedArray::kLengthOffset);
173 GotoIfNot(WordEqual(length, elements_length), &if_runtime);
174 var_elements.Bind(elements);
175 var_length.Bind(SmiToWord32(length));
176 Goto(&if_done);
177 }
178
179 BIND(&if_runtime);
180 {
181 // Ask the runtime to create the list (actually a FixedArray).
182 Node* elements =
183 CallRuntime(Runtime::kCreateListFromArrayLike, context, arguments_list);
184 var_elements.Bind(elements);
185 var_length.Bind(
186 LoadAndUntagToWord32ObjectField(elements, FixedArray::kLengthOffset));
187 Goto(&if_done);
188 }
189
190 // Tail call to the appropriate builtin (depending on whether we have
191 // a {new_target} passed).
192 BIND(&if_done);
193 {
194 Node* elements = var_elements.value();
195 Node* length = var_length.value();
196 if (new_target == nullptr) {
197 Callable callable = CodeFactory::CallVarargs(isolate());
198 TailCallStub(callable, context, target, Int32Constant(0), elements,
199 length);
200 } else {
201 Callable callable = CodeFactory::ConstructVarargs(isolate());
202 TailCallStub(callable, context, target, new_target, Int32Constant(0),
203 elements, length);
204 }
205 }
206 }
207
208 TF_BUILTIN(CallWithArrayLike, CallOrConstructBuiltinsAssembler) {
209 Node* target = Parameter(CallWithArrayLikeDescriptor::kTarget);
210 Node* new_target = nullptr;
211 Node* arguments_list = Parameter(CallWithArrayLikeDescriptor::kArgumentsList);
212 Node* context = Parameter(CallWithArrayLikeDescriptor::kContext);
213 CallOrConstructWithArrayLike(target, new_target, arguments_list, context);
91 } 214 }
92 215
93 } // namespace internal 216 } // namespace internal
94 } // namespace v8 217 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins-call-gen.h ('k') | src/builtins/builtins-constructor-gen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698