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

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

Issue 2803853005: Inline Array.prototype.forEach in TurboFan (Closed)
Patch Set: Cleanup Created 3 years, 7 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 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/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 #include "src/compilation-dependencies.h" 9 #include "src/compilation-dependencies.h"
10 #include "src/compiler/access-builder.h"
10 #include "src/compiler/js-graph.h" 11 #include "src/compiler/js-graph.h"
11 #include "src/compiler/linkage.h" 12 #include "src/compiler/linkage.h"
12 #include "src/compiler/node-matchers.h" 13 #include "src/compiler/node-matchers.h"
13 #include "src/compiler/simplified-operator.h" 14 #include "src/compiler/simplified-operator.h"
14 #include "src/feedback-vector-inl.h" 15 #include "src/feedback-vector-inl.h"
15 #include "src/ic/call-optimization.h" 16 #include "src/ic/call-optimization.h"
16 #include "src/objects-inl.h" 17 #include "src/objects-inl.h"
17 18
18 namespace v8 { 19 namespace v8 {
19 namespace internal { 20 namespace internal {
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 337
337 // ES6 section 26.1.7 Reflect.getPrototypeOf ( target ) 338 // ES6 section 26.1.7 Reflect.getPrototypeOf ( target )
338 Reduction JSCallReducer::ReduceReflectGetPrototypeOf(Node* node) { 339 Reduction JSCallReducer::ReduceReflectGetPrototypeOf(Node* node) {
339 DCHECK_EQ(IrOpcode::kJSCall, node->opcode()); 340 DCHECK_EQ(IrOpcode::kJSCall, node->opcode());
340 Node* target = (node->op()->ValueInputCount() >= 3) 341 Node* target = (node->op()->ValueInputCount() >= 3)
341 ? NodeProperties::GetValueInput(node, 2) 342 ? NodeProperties::GetValueInput(node, 2)
342 : jsgraph()->UndefinedConstant(); 343 : jsgraph()->UndefinedConstant();
343 return ReduceObjectGetPrototype(node, target); 344 return ReduceObjectGetPrototype(node, target);
344 } 345 }
345 346
347 Reduction JSCallReducer::ReduceArrayForEach(Handle<SharedFunctionInfo> shared,
348 Node* node) {
349 DCHECK_EQ(IrOpcode::kJSCall, node->opcode());
350 Node* outer_frame_state = NodeProperties::GetFrameStateInput(node);
351 Node* effect = NodeProperties::GetEffectInput(node);
352 Node* control = NodeProperties::GetControlInput(node);
353 Node* context = NodeProperties::GetContextInput(node);
354
355 // Try to determine the {receiver} map.
356 Node* receiver = NodeProperties::GetValueInput(node, 1);
357 Node* fncallback = node->op()->ValueInputCount() > 2
358 ? NodeProperties::GetValueInput(node, 2)
359 : jsgraph()->UndefinedConstant();
360 Node* this_arg = node->op()->ValueInputCount() > 3
361 ? NodeProperties::GetValueInput(node, 3)
362 : jsgraph()->UndefinedConstant();
363 ZoneHandleSet<Map> receiver_maps;
364 if (!NodeProperties::InferReceiverMaps(receiver, effect, &receiver_maps)) {
365 return NoChange();
366 }
367 if (receiver_maps.size() != 1) return NoChange();
368 Handle<Map> receiver_map(receiver_maps[0]);
369 ElementsKind kind = receiver_map->elements_kind();
370 // TODO(danno): Handle holey Smi and Object fast elements kinds and double
371 // packed.
372 if (!IsFastPackedElementsKind(kind) || IsFastDoubleElementsKind(kind)) {
373 return NoChange();
374 }
375
376 Node* k = jsgraph()->Constant(0);
377
378 Node* original_length = graph()->NewNode(
379 simplified()->LoadField(AccessBuilder::ForJSArrayLength(FAST_ELEMENTS)),
380 receiver, effect, control);
381
382 Node* loop = control = graph()->NewNode(common()->Loop(2), control, control);
383 Node* eloop = effect =
384 graph()->NewNode(common()->EffectPhi(2), effect, effect, loop);
385 Node* vloop = k = graph()->NewNode(
386 common()->Phi(MachineRepresentation::kTagged, 2), k, k, loop);
387
388 control = loop;
389 effect = eloop;
390
391 Node* continue_test =
392 graph()->NewNode(simplified()->NumberLessThan(), k, original_length);
393 Node* continue_branch = graph()->NewNode(common()->Branch(BranchHint::kTrue),
394 continue_test, control);
395
396 Node* if_true = graph()->NewNode(common()->IfTrue(), continue_branch);
397 Node* if_false = graph()->NewNode(common()->IfFalse(), continue_branch);
398 control = if_true;
399
400 std::vector<Node*> checkpoint_params(
401 {receiver, fncallback, this_arg, k, original_length});
402 const int stack_parameters = static_cast<int>(checkpoint_params.size());
403
404 Node* frame_state;
405 std::tie(frame_state, effect) = CreateJavaScriptBuiltinContinuationFrameState(
406 jsgraph(), shared, Builtins::kArrayForEachLoopEagerDeoptContinuation,
407 node->InputAt(0), context, &checkpoint_params[0], stack_parameters,
408 effect, control, outer_frame_state, CREATE_CHECKPOINT);
409
410 // Make sure the map hasn't changed during the iteration
411 Node* orig_map = jsgraph()->HeapConstant(receiver_map);
412 Node* array_map = effect =
413 graph()->NewNode(simplified()->LoadField(AccessBuilder::ForMap()),
414 receiver, effect, control);
415 Node* check_map =
416 graph()->NewNode(simplified()->ReferenceEqual(), array_map, orig_map);
417 effect =
418 graph()->NewNode(simplified()->CheckIf(), check_map, effect, control);
419
420 // Make sure that the access is still in bounds, since the callback could have
421 // changed the array's size.
422 Node* length = graph()->NewNode(
423 simplified()->LoadField(AccessBuilder::ForJSArrayLength(FAST_ELEMENTS)),
424 receiver, effect, control);
425 k = effect =
426 graph()->NewNode(simplified()->CheckBounds(), k, length, effect, control);
427 USE(length);
428
429 // Reload the elements pointer before calling the callback, since the previous
430 // callback might have resized the array causing the elements buffer to be
431 // re-allocated.
432 Node* elements = graph()->NewNode(
433 simplified()->LoadField(AccessBuilder::ForJSObjectElements()), receiver,
434 effect, control);
435
436 Node* element = graph()->NewNode(
437 simplified()->LoadElement(AccessBuilder::ForFixedArrayElement()),
438 elements, k, effect, control);
439
440 Node* next_k =
441 graph()->NewNode(simplified()->NumberAdd(), k, jsgraph()->Constant(1));
442 checkpoint_params[3] = next_k;
443 std::tie(frame_state, effect) = CreateJavaScriptBuiltinContinuationFrameState(
444 jsgraph(), shared, Builtins::kArrayForEachLoopLazyDeoptContinuation,
445 node->InputAt(0), context, &checkpoint_params[0], stack_parameters,
446 effect, control, outer_frame_state, DONT_CREATE_CHECKPOINT);
447
448 Node* call_back = control = effect =
449 graph()->NewNode(javascript()->Call(5, 1), fncallback, this_arg, element,
450 k, receiver, context, frame_state, effect, control);
451 USE(call_back);
452 USE(this_arg);
453
454 k = next_k;
455
456 loop->ReplaceInput(1, control);
457 vloop->ReplaceInput(1, k);
458 eloop->ReplaceInput(1, effect);
459
460 control = if_false;
461 effect = eloop;
462
463 NodeProperties::ReplaceUses(node, jsgraph()->UndefinedConstant(), effect,
464 control);
465
466 node->TrimInputCount(0);
467 NodeProperties::ChangeOp(node, common()->Dead());
468 return Changed(node);
469 }
470
346 Reduction JSCallReducer::ReduceCallApiFunction( 471 Reduction JSCallReducer::ReduceCallApiFunction(
347 Node* node, Handle<FunctionTemplateInfo> function_template_info) { 472 Node* node, Handle<FunctionTemplateInfo> function_template_info) {
348 DCHECK_EQ(IrOpcode::kJSCall, node->opcode()); 473 DCHECK_EQ(IrOpcode::kJSCall, node->opcode());
349 CallParameters const& p = CallParametersOf(node->op()); 474 CallParameters const& p = CallParametersOf(node->op());
350 int const argc = static_cast<int>(p.arity()) - 2; 475 int const argc = static_cast<int>(p.arity()) - 2;
351 Node* receiver = (p.convert_mode() == ConvertReceiverMode::kNullOrUndefined) 476 Node* receiver = (p.convert_mode() == ConvertReceiverMode::kNullOrUndefined)
352 ? jsgraph()->HeapConstant(global_proxy()) 477 ? jsgraph()->HeapConstant(global_proxy())
353 : NodeProperties::GetValueInput(node, 1); 478 : NodeProperties::GetValueInput(node, 1);
354 Node* effect = NodeProperties::GetEffectInput(node); 479 Node* effect = NodeProperties::GetEffectInput(node);
355 480
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 case Builtins::kFunctionPrototypeHasInstance: 693 case Builtins::kFunctionPrototypeHasInstance:
569 return ReduceFunctionPrototypeHasInstance(node); 694 return ReduceFunctionPrototypeHasInstance(node);
570 case Builtins::kNumberConstructor: 695 case Builtins::kNumberConstructor:
571 return ReduceNumberConstructor(node); 696 return ReduceNumberConstructor(node);
572 case Builtins::kObjectGetPrototypeOf: 697 case Builtins::kObjectGetPrototypeOf:
573 return ReduceObjectGetPrototypeOf(node); 698 return ReduceObjectGetPrototypeOf(node);
574 case Builtins::kObjectPrototypeGetProto: 699 case Builtins::kObjectPrototypeGetProto:
575 return ReduceObjectPrototypeGetProto(node); 700 return ReduceObjectPrototypeGetProto(node);
576 case Builtins::kReflectGetPrototypeOf: 701 case Builtins::kReflectGetPrototypeOf:
577 return ReduceReflectGetPrototypeOf(node); 702 return ReduceReflectGetPrototypeOf(node);
703 case Builtins::kArrayForEach:
704 return ReduceArrayForEach(shared, node);
578 default: 705 default:
579 break; 706 break;
580 } 707 }
581 708
582 // Check for the Array constructor. 709 // Check for the Array constructor.
583 if (*function == function->native_context()->array_function()) { 710 if (*function == function->native_context()->array_function()) {
584 return ReduceArrayConstructor(node); 711 return ReduceArrayConstructor(node);
585 } 712 }
586 713
587 if (!FLAG_runtime_stats && shared->IsApiFunction()) { 714 if (!FLAG_runtime_stats && shared->IsApiFunction()) {
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 return jsgraph()->javascript(); 978 return jsgraph()->javascript();
852 } 979 }
853 980
854 SimplifiedOperatorBuilder* JSCallReducer::simplified() const { 981 SimplifiedOperatorBuilder* JSCallReducer::simplified() const {
855 return jsgraph()->simplified(); 982 return jsgraph()->simplified();
856 } 983 }
857 984
858 } // namespace compiler 985 } // namespace compiler
859 } // namespace internal 986 } // namespace internal
860 } // namespace v8 987 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698