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 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 DCHECK_EQ(dividend, node->InputAt(0)); | 601 DCHECK_EQ(dividend, node->InputAt(0)); |
602 node->ReplaceInput(1, Int32Mul(quotient, Uint32Constant(divisor))); | 602 node->ReplaceInput(1, Int32Mul(quotient, Uint32Constant(divisor))); |
603 } | 603 } |
604 node->TrimInputCount(2); | 604 node->TrimInputCount(2); |
605 return Changed(node); | 605 return Changed(node); |
606 } | 606 } |
607 return NoChange(); | 607 return NoChange(); |
608 } | 608 } |
609 | 609 |
610 | 610 |
| 611 Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32Input( |
| 612 Node* input) { |
| 613 Float64Matcher m(input); |
| 614 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value())); |
| 615 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0)); |
| 616 return NoChange(); |
| 617 } |
| 618 |
| 619 |
611 Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32(Node* node) { | 620 Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32(Node* node) { |
612 Float64Matcher m(node->InputAt(0)); | 621 // Try to reduce the input first. |
613 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value())); | 622 Node* const input = node->InputAt(0); |
614 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0)); | 623 Reduction reduction = ReduceTruncateFloat64ToInt32Input(input); |
615 if (m.IsPhi()) { | 624 if (reduction.Changed()) return reduction; |
616 Node* const phi = m.node(); | 625 if (input->opcode() == IrOpcode::kPhi) { |
617 DCHECK_EQ(kRepFloat64, RepresentationOf(OpParameter<MachineType>(phi))); | 626 DCHECK_EQ(kRepFloat64, RepresentationOf(OpParameter<MachineType>(input))); |
618 if (phi->OwnedBy(node)) { | 627 // TruncateFloat64ToInt32(Phi[Float64](x1,...,xn)) |
619 // TruncateFloat64ToInt32(Phi[Float64](x1,...,xn)) | 628 // => Phi[Int32](TruncateFloat64ToInt32(x1), |
620 // => Phi[Int32](TruncateFloat64ToInt32(x1), | 629 // ..., |
621 // ..., | 630 // TruncateFloat64ToInt32(xn)) |
622 // TruncateFloat64ToInt32(xn)) | 631 int const input_count = input->InputCount() - 1; |
623 const int value_input_count = phi->InputCount() - 1; | 632 Node* const control = input->InputAt(input_count); |
624 for (int i = 0; i < value_input_count; ++i) { | 633 DCHECK_LE(0, input_count); |
625 Node* input = graph()->NewNode(machine()->TruncateFloat64ToInt32(), | 634 node->set_op(common()->Phi(kMachInt32, input_count)); |
626 phi->InputAt(i)); | 635 for (int i = 0; i < input_count; ++i) { |
627 // TODO(bmeurer): Reschedule input for reduction once we have Revisit() | 636 Node* value = input->InputAt(i); |
628 // instead of recursing into ReduceTruncateFloat64ToInt32() here. | 637 // Recursively try to reduce the value first. |
629 Reduction reduction = ReduceTruncateFloat64ToInt32(input); | 638 Reduction const reduction = ReduceTruncateFloat64ToInt32Input(value); |
630 if (reduction.Changed()) input = reduction.replacement(); | 639 if (reduction.Changed()) { |
631 phi->ReplaceInput(i, input); | 640 value = reduction.replacement(); |
| 641 } else { |
| 642 value = graph()->NewNode(machine()->TruncateFloat64ToInt32(), value); |
632 } | 643 } |
633 phi->set_op(common()->Phi(kMachInt32, value_input_count)); | 644 if (i < node->InputCount()) { |
634 return Replace(phi); | 645 node->ReplaceInput(i, value); |
| 646 } else { |
| 647 node->AppendInput(graph()->zone(), value); |
| 648 } |
635 } | 649 } |
| 650 if (input_count < node->InputCount()) { |
| 651 node->ReplaceInput(input_count, control); |
| 652 } else { |
| 653 node->AppendInput(graph()->zone(), control); |
| 654 } |
| 655 node->TrimInputCount(input_count + 1); |
| 656 return Changed(node); |
636 } | 657 } |
637 return NoChange(); | 658 return NoChange(); |
638 } | 659 } |
639 | 660 |
640 | 661 |
641 Reduction MachineOperatorReducer::ReduceStore(Node* node) { | 662 Reduction MachineOperatorReducer::ReduceStore(Node* node) { |
642 MachineType const rep = | 663 MachineType const rep = |
643 RepresentationOf(StoreRepresentationOf(node->op()).machine_type()); | 664 RepresentationOf(StoreRepresentationOf(node->op()).machine_type()); |
644 Node* const value = node->InputAt(2); | 665 Node* const value = node->InputAt(2); |
645 switch (value->opcode()) { | 666 switch (value->opcode()) { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 901 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
881 return jsgraph()->machine(); | 902 return jsgraph()->machine(); |
882 } | 903 } |
883 | 904 |
884 | 905 |
885 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 906 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
886 | 907 |
887 } // namespace compiler | 908 } // namespace compiler |
888 } // namespace internal | 909 } // namespace internal |
889 } // namespace v8 | 910 } // namespace v8 |
OLD | NEW |