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

Side by Side Diff: src/compiler/js-call-reducer.cc

Issue 2421923002: [turbofan] Inline Object.prototype.__proto__ getter. (Closed)
Patch Set: Created 4 years, 2 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/compiler/js-call-reducer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/compiler/js-call-reducer.h" 5 #include "src/compiler/js-call-reducer.h"
6 6
7 #include "src/compiler/js-graph.h" 7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/node-matchers.h" 8 #include "src/compiler/node-matchers.h"
9 #include "src/compiler/simplified-operator.h" 9 #include "src/compiler/simplified-operator.h"
10 #include "src/objects-inl.h" 10 #include "src/objects-inl.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 --arity; 182 --arity;
183 } 183 }
184 NodeProperties::ChangeOp( 184 NodeProperties::ChangeOp(
185 node, javascript()->CallFunction(arity, p.frequency(), VectorSlotPair(), 185 node, javascript()->CallFunction(arity, p.frequency(), VectorSlotPair(),
186 convert_mode, p.tail_call_mode())); 186 convert_mode, p.tail_call_mode()));
187 // Try to further reduce the JSCallFunction {node}. 187 // Try to further reduce the JSCallFunction {node}.
188 Reduction const reduction = ReduceJSCallFunction(node); 188 Reduction const reduction = ReduceJSCallFunction(node);
189 return reduction.Changed() ? reduction : Changed(node); 189 return reduction.Changed() ? reduction : Changed(node);
190 } 190 }
191 191
192 namespace {
193
194 // TODO(turbofan): Share with similar functionality in JSInliningHeuristic
195 // and JSNativeContextSpecialization, i.e. move to NodeProperties helper?!
196 MaybeHandle<Map> InferReceiverMap(Node* node) {
197 Node* receiver = NodeProperties::GetValueInput(node, 1);
198 Node* effect = NodeProperties::GetEffectInput(node);
199 // Check if the {node} is dominated by a CheckMaps with a single map
200 // for the {receiver}, and if so use that map for the lowering below.
201 for (Node* dominator = effect;;) {
202 if (dominator->opcode() == IrOpcode::kCheckMaps &&
203 dominator->InputAt(0) == receiver) {
204 if (dominator->op()->ValueInputCount() == 2) {
205 HeapObjectMatcher m(dominator->InputAt(1));
206 if (m.HasValue()) return Handle<Map>::cast(m.Value());
207 }
208 return MaybeHandle<Map>();
209 }
210 if (dominator->op()->EffectInputCount() != 1) {
211 // Didn't find any appropriate CheckMaps node.
212 return MaybeHandle<Map>();
213 }
214 dominator = NodeProperties::GetEffectInput(dominator);
215 }
216 }
217
218 } // namespace
219
220 // ES6 section B.2.2.1.1 get Object.prototype.__proto__
221 Reduction JSCallReducer::ReduceObjectPrototypeGetProto(Node* node) {
222 DCHECK_EQ(IrOpcode::kJSCallFunction, node->opcode());
223
224 // Try to determine the {receiver} map.
225 Handle<Map> receiver_map;
226 if (InferReceiverMap(node).ToHandle(&receiver_map)) {
227 // Check if we can constant-fold the {receiver} map.
228 if (!receiver_map->IsJSProxyMap() &&
229 !receiver_map->has_hidden_prototype() &&
230 !receiver_map->is_access_check_needed()) {
231 Handle<Object> receiver_prototype(receiver_map->prototype(), isolate());
232 Node* value = jsgraph()->Constant(receiver_prototype);
233 ReplaceWithValue(node, value);
234 return Replace(value);
235 }
236 }
237
238 return NoChange();
239 }
192 240
193 Reduction JSCallReducer::ReduceJSCallFunction(Node* node) { 241 Reduction JSCallReducer::ReduceJSCallFunction(Node* node) {
194 DCHECK_EQ(IrOpcode::kJSCallFunction, node->opcode()); 242 DCHECK_EQ(IrOpcode::kJSCallFunction, node->opcode());
195 CallFunctionParameters const& p = CallFunctionParametersOf(node->op()); 243 CallFunctionParameters const& p = CallFunctionParametersOf(node->op());
196 Node* target = NodeProperties::GetValueInput(node, 0); 244 Node* target = NodeProperties::GetValueInput(node, 0);
197 Node* control = NodeProperties::GetControlInput(node); 245 Node* control = NodeProperties::GetControlInput(node);
198 Node* effect = NodeProperties::GetEffectInput(node); 246 Node* effect = NodeProperties::GetEffectInput(node);
199 247
200 // Try to specialize JSCallFunction {node}s with constant {target}s. 248 // Try to specialize JSCallFunction {node}s with constant {target}s.
201 HeapObjectMatcher m(target); 249 HeapObjectMatcher m(target);
202 if (m.HasValue()) { 250 if (m.HasValue()) {
203 if (m.Value()->IsJSFunction()) { 251 if (m.Value()->IsJSFunction()) {
204 Handle<JSFunction> function = Handle<JSFunction>::cast(m.Value()); 252 Handle<JSFunction> function = Handle<JSFunction>::cast(m.Value());
205 Handle<SharedFunctionInfo> shared(function->shared(), isolate()); 253 Handle<SharedFunctionInfo> shared(function->shared(), isolate());
206 254
207 // Raise a TypeError if the {target} is a "classConstructor". 255 // Raise a TypeError if the {target} is a "classConstructor".
208 if (IsClassConstructor(shared->kind())) { 256 if (IsClassConstructor(shared->kind())) {
209 NodeProperties::ReplaceValueInputs(node, target); 257 NodeProperties::ReplaceValueInputs(node, target);
210 NodeProperties::ChangeOp( 258 NodeProperties::ChangeOp(
211 node, javascript()->CallRuntime( 259 node, javascript()->CallRuntime(
212 Runtime::kThrowConstructorNonCallableError, 1)); 260 Runtime::kThrowConstructorNonCallableError, 1));
213 return Changed(node); 261 return Changed(node);
214 } 262 }
215 263
216 // Check for known builtin functions. 264 // Check for known builtin functions.
217 if (shared->HasBuiltinFunctionId()) { 265 switch (shared->code()->builtin_index()) {
218 switch (shared->builtin_function_id()) { 266 case Builtins::kFunctionPrototypeApply:
219 case kFunctionApply: 267 return ReduceFunctionPrototypeApply(node);
220 return ReduceFunctionPrototypeApply(node); 268 case Builtins::kFunctionPrototypeCall:
221 case kFunctionCall: 269 return ReduceFunctionPrototypeCall(node);
222 return ReduceFunctionPrototypeCall(node); 270 case Builtins::kNumberConstructor:
223 default: 271 return ReduceNumberConstructor(node);
224 break; 272 case Builtins::kObjectPrototypeGetProto:
225 } 273 return ReduceObjectPrototypeGetProto(node);
274 default:
275 break;
226 } 276 }
227 277
228 // Check for the Array constructor. 278 // Check for the Array constructor.
229 if (*function == function->native_context()->array_function()) { 279 if (*function == function->native_context()->array_function()) {
230 return ReduceArrayConstructor(node); 280 return ReduceArrayConstructor(node);
231 } 281 }
232
233 // Check for the Number constructor.
234 if (*function == function->native_context()->number_function()) {
235 return ReduceNumberConstructor(node);
236 }
237 } else if (m.Value()->IsJSBoundFunction()) { 282 } else if (m.Value()->IsJSBoundFunction()) {
238 Handle<JSBoundFunction> function = 283 Handle<JSBoundFunction> function =
239 Handle<JSBoundFunction>::cast(m.Value()); 284 Handle<JSBoundFunction>::cast(m.Value());
240 Handle<JSReceiver> bound_target_function( 285 Handle<JSReceiver> bound_target_function(
241 function->bound_target_function(), isolate()); 286 function->bound_target_function(), isolate());
242 Handle<Object> bound_this(function->bound_this(), isolate()); 287 Handle<Object> bound_this(function->bound_this(), isolate());
243 Handle<FixedArray> bound_arguments(function->bound_arguments(), 288 Handle<FixedArray> bound_arguments(function->bound_arguments(),
244 isolate()); 289 isolate());
245 CallFunctionParameters const& p = CallFunctionParametersOf(node->op()); 290 CallFunctionParameters const& p = CallFunctionParametersOf(node->op());
246 ConvertReceiverMode const convert_mode = 291 ConvertReceiverMode const convert_mode =
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 return jsgraph()->javascript(); 502 return jsgraph()->javascript();
458 } 503 }
459 504
460 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { 505 SimplifiedOperatorBuilder* JSCallReducer::simplified() const {
461 return jsgraph()->simplified(); 506 return jsgraph()->simplified();
462 } 507 }
463 508
464 } // namespace compiler 509 } // namespace compiler
465 } // namespace internal 510 } // namespace internal
466 } // namespace v8 511 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/js-call-reducer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698