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/compiler/machine-operator-reducer.h" | 5 #include "src/compiler/machine-operator-reducer.h" |
6 | 6 |
7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
8 #include "src/base/division-by-constant.h" | 8 #include "src/base/division-by-constant.h" |
9 #include "src/codegen.h" | 9 #include "src/codegen.h" |
10 #include "src/compiler/diamond.h" | 10 #include "src/compiler/diamond.h" |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 case IrOpcode::kChangeUint32ToFloat64: { | 516 case IrOpcode::kChangeUint32ToFloat64: { |
517 Uint32Matcher m(node->InputAt(0)); | 517 Uint32Matcher m(node->InputAt(0)); |
518 if (m.HasValue()) return ReplaceFloat64(FastUI2D(m.Value())); | 518 if (m.HasValue()) return ReplaceFloat64(FastUI2D(m.Value())); |
519 break; | 519 break; |
520 } | 520 } |
521 case IrOpcode::kChangeUint32ToUint64: { | 521 case IrOpcode::kChangeUint32ToUint64: { |
522 Uint32Matcher m(node->InputAt(0)); | 522 Uint32Matcher m(node->InputAt(0)); |
523 if (m.HasValue()) return ReplaceInt64(static_cast<uint64_t>(m.Value())); | 523 if (m.HasValue()) return ReplaceInt64(static_cast<uint64_t>(m.Value())); |
524 break; | 524 break; |
525 } | 525 } |
526 case IrOpcode::kTruncateFloat64ToInt32: { | 526 case IrOpcode::kTruncateFloat64ToInt32: |
527 Float64Matcher m(node->InputAt(0)); | 527 return ReduceTruncateFloat64ToInt32(node); |
528 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value())); | |
529 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0)); | |
530 break; | |
531 } | |
532 case IrOpcode::kTruncateInt64ToInt32: { | 528 case IrOpcode::kTruncateInt64ToInt32: { |
533 Int64Matcher m(node->InputAt(0)); | 529 Int64Matcher m(node->InputAt(0)); |
534 if (m.HasValue()) return ReplaceInt32(static_cast<int32_t>(m.Value())); | 530 if (m.HasValue()) return ReplaceInt32(static_cast<int32_t>(m.Value())); |
535 if (m.IsChangeInt32ToInt64()) return Replace(m.node()->InputAt(0)); | 531 if (m.IsChangeInt32ToInt64()) return Replace(m.node()->InputAt(0)); |
536 break; | 532 break; |
537 } | 533 } |
538 case IrOpcode::kTruncateFloat64ToFloat32: { | 534 case IrOpcode::kTruncateFloat64ToFloat32: { |
539 Float64Matcher m(node->InputAt(0)); | 535 Float64Matcher m(node->InputAt(0)); |
540 if (m.HasValue()) return ReplaceFloat32(DoubleToFloat32(m.Value())); | 536 if (m.HasValue()) return ReplaceFloat32(DoubleToFloat32(m.Value())); |
541 if (m.IsChangeFloat32ToFloat64()) return Replace(m.node()->InputAt(0)); | 537 if (m.IsChangeFloat32ToFloat64()) return Replace(m.node()->InputAt(0)); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 DCHECK_EQ(dividend, node->InputAt(0)); | 681 DCHECK_EQ(dividend, node->InputAt(0)); |
686 node->ReplaceInput(1, Int32Mul(quotient, Uint32Constant(divisor))); | 682 node->ReplaceInput(1, Int32Mul(quotient, Uint32Constant(divisor))); |
687 } | 683 } |
688 node->TrimInputCount(2); | 684 node->TrimInputCount(2); |
689 return Changed(node); | 685 return Changed(node); |
690 } | 686 } |
691 return NoChange(); | 687 return NoChange(); |
692 } | 688 } |
693 | 689 |
694 | 690 |
| 691 Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32(Node* node) { |
| 692 Float64Matcher m(node->InputAt(0)); |
| 693 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value())); |
| 694 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0)); |
| 695 if (m.IsPhi()) { |
| 696 Node* const phi = m.node(); |
| 697 DCHECK_EQ(kRepFloat64, RepresentationOf(OpParameter<MachineType>(phi))); |
| 698 if (phi->OwnedBy(node)) { |
| 699 // TruncateFloat64ToInt32(Phi[Float64](x1,...,xn)) |
| 700 // => Phi[Int32](TruncateFloat64ToInt32(x1), |
| 701 // ..., |
| 702 // TruncateFloat64ToInt32(xn)) |
| 703 const int value_input_count = phi->InputCount() - 1; |
| 704 for (int i = 0; i < value_input_count; ++i) { |
| 705 Node* input = graph()->NewNode(machine()->TruncateFloat64ToInt32(), |
| 706 phi->InputAt(i)); |
| 707 // TODO(bmeurer): Reschedule input for reduction once we have Revisit() |
| 708 // instead of recursing into ReduceTruncateFloat64ToInt32() here. |
| 709 Reduction reduction = ReduceTruncateFloat64ToInt32(input); |
| 710 if (reduction.Changed()) input = reduction.replacement(); |
| 711 phi->ReplaceInput(i, input); |
| 712 } |
| 713 phi->set_op(common()->Phi(kMachInt32, value_input_count)); |
| 714 return Replace(phi); |
| 715 } |
| 716 } |
| 717 return NoChange(); |
| 718 } |
| 719 |
| 720 |
695 Reduction MachineOperatorReducer::ReduceStore(Node* node) { | 721 Reduction MachineOperatorReducer::ReduceStore(Node* node) { |
696 MachineType const rep = | 722 MachineType const rep = |
697 RepresentationOf(StoreRepresentationOf(node->op()).machine_type()); | 723 RepresentationOf(StoreRepresentationOf(node->op()).machine_type()); |
698 Node* const value = node->InputAt(2); | 724 Node* const value = node->InputAt(2); |
699 switch (value->opcode()) { | 725 switch (value->opcode()) { |
700 case IrOpcode::kWord32And: { | 726 case IrOpcode::kWord32And: { |
701 Uint32BinopMatcher m(value); | 727 Uint32BinopMatcher m(value); |
702 if (m.right().HasValue() && | 728 if (m.right().HasValue() && |
703 ((rep == kRepWord8 && (m.right().Value() & 0xff) == 0xff) || | 729 ((rep == kRepWord8 && (m.right().Value() & 0xff) == 0xff) || |
704 (rep == kRepWord16 && (m.right().Value() & 0xffff) == 0xffff))) { | 730 (rep == kRepWord16 && (m.right().Value() & 0xffff) == 0xffff))) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 798 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
773 return jsgraph()->machine(); | 799 return jsgraph()->machine(); |
774 } | 800 } |
775 | 801 |
776 | 802 |
777 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 803 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
778 | 804 |
779 } // namespace compiler | 805 } // namespace compiler |
780 } // namespace internal | 806 } // namespace internal |
781 } // namespace v8 | 807 } // namespace v8 |
OLD | NEW |