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

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

Issue 2930623002: [builtins] Start refactoring the Apply builtin. (Closed)
Patch Set: 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
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_Varargs(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_ForwardVarargs(masm, masm->isolate()->builtins()->Call());
87 } 94 }
88 95
89 void Builtins::Generate_CallFunctionForwardVarargs(MacroAssembler* masm) { 96 void Builtins::Generate_CallFunctionForwardVarargs(MacroAssembler* masm) {
90 Generate_ForwardVarargs(masm, masm->isolate()->builtins()->CallFunction()); 97 Generate_ForwardVarargs(masm, masm->isolate()->builtins()->CallFunction());
91 } 98 }
92 99
100 void CallOrConstructBuiltinsAssembler::CallOrConstructWithArrayLike(
101 Node* target, Node* new_target, Node* arguments_list, Node* context) {
102 Variable var_elements(this, MachineRepresentation::kTagged);
103 Variable var_length(this, MachineRepresentation::kWord32);
104 Label if_done(this), if_arguments(this), if_array(this),
105 if_holey_array(this, Label::kDeferred),
106 if_runtime(this, Label::kDeferred);
107
108 GotoIf(TaggedIsSmi(arguments_list), &if_runtime);
109 Node* arguments_list_map = LoadMap(arguments_list);
110 Node* native_context = LoadNativeContext(context);
111
112 // Check if {arguments_list} is an (unmodified) arguments object.
113 Node* sloppy_arguments_map =
114 LoadContextElement(native_context, Context::SLOPPY_ARGUMENTS_MAP_INDEX);
115 GotoIf(WordEqual(arguments_list_map, sloppy_arguments_map), &if_arguments);
116 Node* strict_arguments_map =
117 LoadContextElement(native_context, Context::STRICT_ARGUMENTS_MAP_INDEX);
118 GotoIf(WordEqual(arguments_list_map, strict_arguments_map), &if_arguments);
119
120 // Check if {arguments_list} is a fast JSArray.
121 Branch(IsJSArrayMap(arguments_list_map), &if_array, &if_runtime);
122
123 BIND(&if_array);
124 {
125 // Try to extract the elements from a JSArray object.
126 var_elements.Bind(
127 LoadObjectField(arguments_list, JSArray::kElementsOffset));
128 var_length.Bind(LoadAndUntagToWord32ObjectField(arguments_list,
petermarshall 2017/06/08 08:49:04 You can use LoadJSArrayLength
Benedikt Meurer 2017/06/08 18:02:58 That doesn't untag.
129 JSArray::kLengthOffset));
130
131 // Holey arrays and double backing stores need special treatment.
132 Node* kind = LoadMapElementsKind(arguments_list_map);
133 STATIC_ASSERT(FAST_SMI_ELEMENTS == 0);
134 STATIC_ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
135 STATIC_ASSERT(FAST_ELEMENTS == 2);
136 STATIC_ASSERT(FAST_HOLEY_ELEMENTS == 3);
137 GotoIf(Word32Equal(kind, Int32Constant(FAST_HOLEY_SMI_ELEMENTS)),
138 &if_holey_array);
139 GotoIf(Word32Equal(kind, Int32Constant(FAST_HOLEY_ELEMENTS)),
140 &if_holey_array);
141 Branch(Uint32LessThanOrEqual(kind, Int32Constant(FAST_HOLEY_ELEMENTS)),
142 &if_done, &if_runtime);
143 }
144
145 BIND(&if_holey_array);
146 {
147 // For holey JSArrays we need to check that the array prototype chain
148 // protector is intact and our prototype is the Array.prototype actually.
149 Node* arguments_list_prototype =
petermarshall 2017/06/08 08:49:04 LoadMapPrototype =]
Benedikt Meurer 2017/06/08 18:02:58 Done.
150 LoadObjectField(arguments_list_map, Map::kPrototypeOffset);
151 Node* initial_array_prototype = LoadContextElement(
152 native_context, Context::INITIAL_ARRAY_PROTOTYPE_INDEX);
153 GotoIfNot(WordEqual(arguments_list_prototype, initial_array_prototype),
154 &if_runtime);
155 Node* protector_cell = LoadRoot(Heap::kArrayProtectorRootIndex);
petermarshall 2017/06/08 08:49:04 Might be worth adding DCHECK(isolate()->heap()->a
Benedikt Meurer 2017/06/08 18:02:58 Done.
156 Branch(
157 WordEqual(LoadObjectField(protector_cell, PropertyCell::kValueOffset),
158 SmiConstant(Smi::FromInt(Isolate::kProtectorValid))),
159 &if_done, &if_runtime);
160 }
161
162 BIND(&if_arguments);
163 {
164 // Try to extract the elements from an JSArgumentsObject.
165 Node* length =
166 LoadObjectField(arguments_list, JSArgumentsObject::kLengthOffset);
167 Node* elements =
168 LoadObjectField(arguments_list, JSArgumentsObject::kElementsOffset);
169 Node* elements_length =
170 LoadObjectField(elements, FixedArray::kLengthOffset);
171 GotoIfNot(WordEqual(length, elements_length), &if_runtime);
172 var_elements.Bind(elements);
173 var_length.Bind(SmiToWord32(length));
174 Goto(&if_done);
175 }
176
177 BIND(&if_runtime);
178 {
179 // Ask the runtime to create the list (actually a FixedArray).
180 Node* elements =
181 CallRuntime(Runtime::kCreateListFromArrayLike, context, arguments_list);
182 var_elements.Bind(elements);
183 var_length.Bind(
184 LoadAndUntagToWord32ObjectField(elements, FixedArray::kLengthOffset));
185 Goto(&if_done);
186 }
187
188 // Tail call to the appropriate builtin (depending on whether we have
189 // a {new_target} passed).
190 BIND(&if_done);
191 {
192 Node* elements = var_elements.value();
193 Node* length = var_length.value();
194 if (new_target == nullptr) {
195 Callable callable = CodeFactory::CallVarargs(isolate());
196 TailCallStub(callable, context, target, Int32Constant(0), elements,
197 length);
198 } else {
199 Callable callable = CodeFactory::ConstructVarargs(isolate());
200 TailCallStub(callable, context, target, new_target, Int32Constant(0),
201 elements, length);
202 }
203 }
204 }
205
206 TF_BUILTIN(CallWithArrayLike, CallOrConstructBuiltinsAssembler) {
207 Node* target = Parameter(CallWithArrayLikeDescriptor::kTarget);
208 Node* new_target = nullptr;
209 Node* arguments_list = Parameter(CallWithArrayLikeDescriptor::kArgumentsList);
210 Node* context = Parameter(CallWithArrayLikeDescriptor::kContext);
211 CallOrConstructWithArrayLike(target, new_target, arguments_list, context);
212 }
213
93 } // namespace internal 214 } // namespace internal
94 } // namespace v8 215 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698