OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/code-factory.h" | 5 #include "src/code-factory.h" |
6 #include "src/compilation-dependencies.h" | 6 #include "src/compilation-dependencies.h" |
7 #include "src/compiler/access-builder.h" | 7 #include "src/compiler/access-builder.h" |
8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
9 #include "src/compiler/js-typed-lowering.h" | 9 #include "src/compiler/js-typed-lowering.h" |
10 #include "src/compiler/linkage.h" | 10 #include "src/compiler/linkage.h" |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 type_cache_(TypeCache::Get()) { | 443 type_cache_(TypeCache::Get()) { |
444 for (size_t k = 0; k < arraysize(shifted_int32_ranges_); ++k) { | 444 for (size_t k = 0; k < arraysize(shifted_int32_ranges_); ++k) { |
445 double min = kMinInt / (1 << k); | 445 double min = kMinInt / (1 << k); |
446 double max = kMaxInt / (1 << k); | 446 double max = kMaxInt / (1 << k); |
447 shifted_int32_ranges_[k] = Type::Range(min, max, graph()->zone()); | 447 shifted_int32_ranges_[k] = Type::Range(min, max, graph()->zone()); |
448 } | 448 } |
449 } | 449 } |
450 | 450 |
451 | 451 |
452 Reduction JSTypedLowering::ReduceJSAdd(Node* node) { | 452 Reduction JSTypedLowering::ReduceJSAdd(Node* node) { |
| 453 if (flags() & kDisableBinaryOpReduction) return NoChange(); |
| 454 |
453 JSBinopReduction r(this, node); | 455 JSBinopReduction r(this, node); |
454 if (r.BothInputsAre(Type::Number())) { | 456 if (r.BothInputsAre(Type::Number())) { |
455 // JSAdd(x:number, y:number) => NumberAdd(x, y) | 457 // JSAdd(x:number, y:number) => NumberAdd(x, y) |
456 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); | 458 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); |
457 } | 459 } |
458 if (r.NeitherInputCanBe(Type::StringOrReceiver()) && !r.IsStrong()) { | 460 if (r.NeitherInputCanBe(Type::StringOrReceiver()) && !r.IsStrong()) { |
459 // JSAdd(x:-string, y:-string) => NumberAdd(ToNumber(x), ToNumber(y)) | 461 // JSAdd(x:-string, y:-string) => NumberAdd(ToNumber(x), ToNumber(y)) |
460 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); | 462 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); |
461 r.ConvertInputsToNumber(frame_state); | 463 r.ConvertInputsToNumber(frame_state); |
462 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); | 464 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); |
(...skipping 10 matching lines...) Expand all Loading... |
473 node->InsertInput(graph()->zone(), 0, | 475 node->InsertInput(graph()->zone(), 0, |
474 jsgraph()->HeapConstant(callable.code())); | 476 jsgraph()->HeapConstant(callable.code())); |
475 NodeProperties::ChangeOp(node, common()->Call(desc)); | 477 NodeProperties::ChangeOp(node, common()->Call(desc)); |
476 return Changed(node); | 478 return Changed(node); |
477 } | 479 } |
478 return NoChange(); | 480 return NoChange(); |
479 } | 481 } |
480 | 482 |
481 | 483 |
482 Reduction JSTypedLowering::ReduceJSModulus(Node* node) { | 484 Reduction JSTypedLowering::ReduceJSModulus(Node* node) { |
| 485 if (flags() & kDisableBinaryOpReduction) return NoChange(); |
| 486 |
483 JSBinopReduction r(this, node); | 487 JSBinopReduction r(this, node); |
484 if (r.BothInputsAre(Type::Number())) { | 488 if (r.BothInputsAre(Type::Number())) { |
485 // JSModulus(x:number, x:number) => NumberModulus(x, y) | 489 // JSModulus(x:number, x:number) => NumberModulus(x, y) |
486 return r.ChangeToPureOperator(simplified()->NumberModulus(), | 490 return r.ChangeToPureOperator(simplified()->NumberModulus(), |
487 Type::Number()); | 491 Type::Number()); |
488 } | 492 } |
489 return NoChange(); | 493 return NoChange(); |
490 } | 494 } |
491 | 495 |
492 | 496 |
493 Reduction JSTypedLowering::ReduceNumberBinop(Node* node, | 497 Reduction JSTypedLowering::ReduceNumberBinop(Node* node, |
494 const Operator* numberOp) { | 498 const Operator* numberOp) { |
| 499 if (flags() & kDisableBinaryOpReduction) return NoChange(); |
| 500 |
495 JSBinopReduction r(this, node); | 501 JSBinopReduction r(this, node); |
496 if (r.IsStrong() || numberOp == simplified()->NumberModulus()) { | 502 if (r.IsStrong() || numberOp == simplified()->NumberModulus()) { |
497 if (r.BothInputsAre(Type::Number())) { | 503 if (r.BothInputsAre(Type::Number())) { |
498 return r.ChangeToPureOperator(numberOp, Type::Number()); | 504 return r.ChangeToPureOperator(numberOp, Type::Number()); |
499 } | 505 } |
500 return NoChange(); | 506 return NoChange(); |
501 } | 507 } |
502 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); | 508 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); |
503 r.ConvertInputsToNumber(frame_state); | 509 r.ConvertInputsToNumber(frame_state); |
504 return r.ChangeToPureOperator(numberOp, Type::Number()); | 510 return r.ChangeToPureOperator(numberOp, Type::Number()); |
505 } | 511 } |
506 | 512 |
507 | 513 |
508 Reduction JSTypedLowering::ReduceInt32Binop(Node* node, const Operator* intOp) { | 514 Reduction JSTypedLowering::ReduceInt32Binop(Node* node, const Operator* intOp) { |
| 515 if (flags() & kDisableBinaryOpReduction) return NoChange(); |
| 516 |
509 JSBinopReduction r(this, node); | 517 JSBinopReduction r(this, node); |
510 if (r.IsStrong()) { | 518 if (r.IsStrong()) { |
511 if (r.BothInputsAre(Type::Number())) { | 519 if (r.BothInputsAre(Type::Number())) { |
512 r.ConvertInputsToUI32(kSigned, kSigned); | 520 r.ConvertInputsToUI32(kSigned, kSigned); |
513 return r.ChangeToPureOperator(intOp, Type::Integral32()); | 521 return r.ChangeToPureOperator(intOp, Type::Integral32()); |
514 } | 522 } |
515 return NoChange(); | 523 return NoChange(); |
516 } | 524 } |
517 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); | 525 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); |
518 r.ConvertInputsToNumber(frame_state); | 526 r.ConvertInputsToNumber(frame_state); |
519 r.ConvertInputsToUI32(kSigned, kSigned); | 527 r.ConvertInputsToUI32(kSigned, kSigned); |
520 return r.ChangeToPureOperator(intOp, Type::Integral32()); | 528 return r.ChangeToPureOperator(intOp, Type::Integral32()); |
521 } | 529 } |
522 | 530 |
523 | 531 |
524 Reduction JSTypedLowering::ReduceUI32Shift(Node* node, | 532 Reduction JSTypedLowering::ReduceUI32Shift(Node* node, |
525 Signedness left_signedness, | 533 Signedness left_signedness, |
526 const Operator* shift_op) { | 534 const Operator* shift_op) { |
| 535 if (flags() & kDisableBinaryOpReduction) return NoChange(); |
| 536 |
527 JSBinopReduction r(this, node); | 537 JSBinopReduction r(this, node); |
528 if (r.IsStrong()) { | 538 if (r.IsStrong()) { |
529 if (r.BothInputsAre(Type::Number())) { | 539 if (r.BothInputsAre(Type::Number())) { |
530 r.ConvertInputsToUI32(left_signedness, kUnsigned); | 540 r.ConvertInputsToUI32(left_signedness, kUnsigned); |
531 return r.ChangeToPureOperator(shift_op); | 541 return r.ChangeToPureOperator(shift_op); |
532 } | 542 } |
533 return NoChange(); | 543 return NoChange(); |
534 } | 544 } |
535 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); | 545 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); |
536 r.ConvertInputsToNumber(frame_state); | 546 r.ConvertInputsToNumber(frame_state); |
537 r.ConvertInputsToUI32(left_signedness, kUnsigned); | 547 r.ConvertInputsToUI32(left_signedness, kUnsigned); |
538 return r.ChangeToPureOperator(shift_op); | 548 return r.ChangeToPureOperator(shift_op); |
539 } | 549 } |
540 | 550 |
541 | 551 |
542 Reduction JSTypedLowering::ReduceJSComparison(Node* node) { | 552 Reduction JSTypedLowering::ReduceJSComparison(Node* node) { |
| 553 if (flags() & kDisableBinaryOpReduction) return NoChange(); |
| 554 |
543 JSBinopReduction r(this, node); | 555 JSBinopReduction r(this, node); |
544 if (r.BothInputsAre(Type::String())) { | 556 if (r.BothInputsAre(Type::String())) { |
545 // If both inputs are definitely strings, perform a string comparison. | 557 // If both inputs are definitely strings, perform a string comparison. |
546 const Operator* stringOp; | 558 const Operator* stringOp; |
547 switch (node->opcode()) { | 559 switch (node->opcode()) { |
548 case IrOpcode::kJSLessThan: | 560 case IrOpcode::kJSLessThan: |
549 stringOp = simplified()->StringLessThan(); | 561 stringOp = simplified()->StringLessThan(); |
550 break; | 562 break; |
551 case IrOpcode::kJSGreaterThan: | 563 case IrOpcode::kJSGreaterThan: |
552 stringOp = simplified()->StringLessThan(); | 564 stringOp = simplified()->StringLessThan(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 return NoChange(); | 616 return NoChange(); |
605 } | 617 } |
606 return r.ChangeToPureOperator(comparison); | 618 return r.ChangeToPureOperator(comparison); |
607 } | 619 } |
608 // TODO(turbofan): relax/remove effects of this operator in other cases. | 620 // TODO(turbofan): relax/remove effects of this operator in other cases. |
609 return NoChange(); // Keep a generic comparison. | 621 return NoChange(); // Keep a generic comparison. |
610 } | 622 } |
611 | 623 |
612 | 624 |
613 Reduction JSTypedLowering::ReduceJSEqual(Node* node, bool invert) { | 625 Reduction JSTypedLowering::ReduceJSEqual(Node* node, bool invert) { |
| 626 if (flags() & kDisableBinaryOpReduction) return NoChange(); |
| 627 |
614 JSBinopReduction r(this, node); | 628 JSBinopReduction r(this, node); |
615 | 629 |
616 if (r.BothInputsAre(Type::Number())) { | 630 if (r.BothInputsAre(Type::Number())) { |
617 return r.ChangeToPureOperator(simplified()->NumberEqual(), invert); | 631 return r.ChangeToPureOperator(simplified()->NumberEqual(), invert); |
618 } | 632 } |
619 if (r.BothInputsAre(Type::String())) { | 633 if (r.BothInputsAre(Type::String())) { |
620 return r.ChangeToStringComparisonOperator(simplified()->StringEqual(), | 634 return r.ChangeToStringComparisonOperator(simplified()->StringEqual(), |
621 invert); | 635 invert); |
622 } | 636 } |
623 if (r.BothInputsAre(Type::Boolean())) { | 637 if (r.BothInputsAre(Type::Boolean())) { |
(...skipping 21 matching lines...) Expand all Loading... |
645 value->ReplaceInput(0, node); | 659 value->ReplaceInput(0, node); |
646 return Replace(value); | 660 return Replace(value); |
647 } | 661 } |
648 return Changed(node); | 662 return Changed(node); |
649 } | 663 } |
650 return NoChange(); | 664 return NoChange(); |
651 } | 665 } |
652 | 666 |
653 | 667 |
654 Reduction JSTypedLowering::ReduceJSStrictEqual(Node* node, bool invert) { | 668 Reduction JSTypedLowering::ReduceJSStrictEqual(Node* node, bool invert) { |
| 669 if (flags() & kDisableBinaryOpReduction) return NoChange(); |
| 670 |
655 JSBinopReduction r(this, node); | 671 JSBinopReduction r(this, node); |
656 if (r.left() == r.right()) { | 672 if (r.left() == r.right()) { |
657 // x === x is always true if x != NaN | 673 // x === x is always true if x != NaN |
658 if (!r.left_type()->Maybe(Type::NaN())) { | 674 if (!r.left_type()->Maybe(Type::NaN())) { |
659 Node* replacement = jsgraph()->BooleanConstant(!invert); | 675 Node* replacement = jsgraph()->BooleanConstant(!invert); |
660 ReplaceWithValue(node, replacement); | 676 ReplaceWithValue(node, replacement); |
661 return Replace(replacement); | 677 return Replace(replacement); |
662 } | 678 } |
663 } | 679 } |
664 if (r.OneInputCannotBe(Type::NumberOrString())) { | 680 if (r.OneInputCannotBe(Type::NumberOrString())) { |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 return NoChange(); | 1113 return NoChange(); |
1098 } | 1114 } |
1099 | 1115 |
1100 | 1116 |
1101 Reduction JSTypedLowering::ReduceJSInstanceOf(Node* node) { | 1117 Reduction JSTypedLowering::ReduceJSInstanceOf(Node* node) { |
1102 DCHECK_EQ(IrOpcode::kJSInstanceOf, node->opcode()); | 1118 DCHECK_EQ(IrOpcode::kJSInstanceOf, node->opcode()); |
1103 Node* const context = NodeProperties::GetContextInput(node); | 1119 Node* const context = NodeProperties::GetContextInput(node); |
1104 Node* const frame_state = NodeProperties::GetFrameStateInput(node, 0); | 1120 Node* const frame_state = NodeProperties::GetFrameStateInput(node, 0); |
1105 | 1121 |
1106 // If deoptimization is disabled, we cannot optimize. | 1122 // If deoptimization is disabled, we cannot optimize. |
1107 if (!(flags() & kDeoptimizationEnabled)) return NoChange(); | 1123 if (!(flags() & kDeoptimizationEnabled) || |
| 1124 (flags() & kDisableBinaryOpReduction)) { |
| 1125 return NoChange(); |
| 1126 } |
1108 | 1127 |
1109 // If we are in a try block, don't optimize since the runtime call | 1128 // If we are in a try block, don't optimize since the runtime call |
1110 // in the proxy case can throw. | 1129 // in the proxy case can throw. |
1111 if (NodeProperties::IsExceptionalCall(node)) return NoChange(); | 1130 if (NodeProperties::IsExceptionalCall(node)) return NoChange(); |
1112 | 1131 |
1113 JSBinopReduction r(this, node); | 1132 JSBinopReduction r(this, node); |
1114 Node* effect = r.effect(); | 1133 Node* effect = r.effect(); |
1115 Node* control = r.control(); | 1134 Node* control = r.control(); |
1116 | 1135 |
1117 if (!r.right_type()->IsConstant() || | 1136 if (!r.right_type()->IsConstant() || |
(...skipping 1632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2750 } | 2769 } |
2751 | 2770 |
2752 | 2771 |
2753 CompilationDependencies* JSTypedLowering::dependencies() const { | 2772 CompilationDependencies* JSTypedLowering::dependencies() const { |
2754 return dependencies_; | 2773 return dependencies_; |
2755 } | 2774 } |
2756 | 2775 |
2757 } // namespace compiler | 2776 } // namespace compiler |
2758 } // namespace internal | 2777 } // namespace internal |
2759 } // namespace v8 | 2778 } // namespace v8 |
OLD | NEW |