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

Side by Side Diff: src/compiler/machine-operator-reducer.cc

Issue 1513543003: [turbofan] Make MachineType a pair of enums. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Moar rebase Created 5 years 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/machine-operator.cc ('k') | src/compiler/mips/instruction-selector-mips.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 int32_t const divisor = Abs(m.right().Value()); 593 int32_t const divisor = Abs(m.right().Value());
594 if (base::bits::IsPowerOfTwo32(divisor)) { 594 if (base::bits::IsPowerOfTwo32(divisor)) {
595 uint32_t const mask = divisor - 1; 595 uint32_t const mask = divisor - 1;
596 Node* const zero = Int32Constant(0); 596 Node* const zero = Int32Constant(0);
597 node->ReplaceInput( 597 node->ReplaceInput(
598 0, graph()->NewNode(machine()->Int32LessThan(), dividend, zero)); 598 0, graph()->NewNode(machine()->Int32LessThan(), dividend, zero));
599 node->ReplaceInput( 599 node->ReplaceInput(
600 1, Int32Sub(zero, Word32And(Int32Sub(zero, dividend), mask))); 600 1, Int32Sub(zero, Word32And(Int32Sub(zero, dividend), mask)));
601 node->ReplaceInput(2, Word32And(dividend, mask)); 601 node->ReplaceInput(2, Word32And(dividend, mask));
602 NodeProperties::ChangeOp( 602 NodeProperties::ChangeOp(
603 node, common()->Select(kMachInt32, BranchHint::kFalse)); 603 node,
604 common()->Select(MachineRepresentation::kWord32, BranchHint::kFalse));
604 } else { 605 } else {
605 Node* quotient = Int32Div(dividend, divisor); 606 Node* quotient = Int32Div(dividend, divisor);
606 DCHECK_EQ(dividend, node->InputAt(0)); 607 DCHECK_EQ(dividend, node->InputAt(0));
607 node->ReplaceInput(1, Int32Mul(quotient, Int32Constant(divisor))); 608 node->ReplaceInput(1, Int32Mul(quotient, Int32Constant(divisor)));
608 node->TrimInputCount(2); 609 node->TrimInputCount(2);
609 NodeProperties::ChangeOp(node, machine()->Int32Sub()); 610 NodeProperties::ChangeOp(node, machine()->Int32Sub());
610 } 611 }
611 return Changed(node); 612 return Changed(node);
612 } 613 }
613 return NoChange(); 614 return NoChange();
(...skipping 29 matching lines...) Expand all
643 return NoChange(); 644 return NoChange();
644 } 645 }
645 646
646 647
647 Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32(Node* node) { 648 Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32(Node* node) {
648 Float64Matcher m(node->InputAt(0)); 649 Float64Matcher m(node->InputAt(0));
649 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value())); 650 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value()));
650 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0)); 651 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0));
651 if (m.IsPhi()) { 652 if (m.IsPhi()) {
652 Node* const phi = m.node(); 653 Node* const phi = m.node();
653 DCHECK_EQ(kRepFloat64, RepresentationOf(OpParameter<MachineType>(phi))); 654 DCHECK_EQ(MachineRepresentation::kFloat64, PhiRepresentationOf(phi->op()));
654 if (phi->OwnedBy(node)) { 655 if (phi->OwnedBy(node)) {
655 // TruncateFloat64ToInt32[mode](Phi[Float64](x1,...,xn)) 656 // TruncateFloat64ToInt32[mode](Phi[Float64](x1,...,xn))
656 // => Phi[Int32](TruncateFloat64ToInt32[mode](x1), 657 // => Phi[Int32](TruncateFloat64ToInt32[mode](x1),
657 // ..., 658 // ...,
658 // TruncateFloat64ToInt32[mode](xn)) 659 // TruncateFloat64ToInt32[mode](xn))
659 const int value_input_count = phi->InputCount() - 1; 660 const int value_input_count = phi->InputCount() - 1;
660 for (int i = 0; i < value_input_count; ++i) { 661 for (int i = 0; i < value_input_count; ++i) {
661 Node* input = graph()->NewNode(node->op(), phi->InputAt(i)); 662 Node* input = graph()->NewNode(node->op(), phi->InputAt(i));
662 // TODO(bmeurer): Reschedule input for reduction once we have Revisit() 663 // TODO(bmeurer): Reschedule input for reduction once we have Revisit()
663 // instead of recursing into ReduceTruncateFloat64ToInt32() here. 664 // instead of recursing into ReduceTruncateFloat64ToInt32() here.
664 Reduction reduction = ReduceTruncateFloat64ToInt32(input); 665 Reduction reduction = ReduceTruncateFloat64ToInt32(input);
665 if (reduction.Changed()) input = reduction.replacement(); 666 if (reduction.Changed()) input = reduction.replacement();
666 phi->ReplaceInput(i, input); 667 phi->ReplaceInput(i, input);
667 } 668 }
668 NodeProperties::ChangeOp(phi, 669 NodeProperties::ChangeOp(
669 common()->Phi(kMachInt32, value_input_count)); 670 phi,
671 common()->Phi(MachineRepresentation::kWord32, value_input_count));
670 return Replace(phi); 672 return Replace(phi);
671 } 673 }
672 } 674 }
673 return NoChange(); 675 return NoChange();
674 } 676 }
675 677
676 678
677 Reduction MachineOperatorReducer::ReduceStore(Node* node) { 679 Reduction MachineOperatorReducer::ReduceStore(Node* node) {
678 MachineType const rep = 680 MachineRepresentation const rep =
679 RepresentationOf(StoreRepresentationOf(node->op()).machine_type()); 681 StoreRepresentationOf(node->op()).machine_type().representation();
680 Node* const value = node->InputAt(2); 682 Node* const value = node->InputAt(2);
681 switch (value->opcode()) { 683 switch (value->opcode()) {
682 case IrOpcode::kWord32And: { 684 case IrOpcode::kWord32And: {
683 Uint32BinopMatcher m(value); 685 Uint32BinopMatcher m(value);
684 if (m.right().HasValue() && 686 if (m.right().HasValue() && ((rep == MachineRepresentation::kWord8 &&
685 ((rep == kRepWord8 && (m.right().Value() & 0xff) == 0xff) || 687 (m.right().Value() & 0xff) == 0xff) ||
686 (rep == kRepWord16 && (m.right().Value() & 0xffff) == 0xffff))) { 688 (rep == MachineRepresentation::kWord16 &&
689 (m.right().Value() & 0xffff) == 0xffff))) {
687 node->ReplaceInput(2, m.left().node()); 690 node->ReplaceInput(2, m.left().node());
688 return Changed(node); 691 return Changed(node);
689 } 692 }
690 break; 693 break;
691 } 694 }
692 case IrOpcode::kWord32Sar: { 695 case IrOpcode::kWord32Sar: {
693 Int32BinopMatcher m(value); 696 Int32BinopMatcher m(value);
694 if (m.left().IsWord32Shl() && 697 if (m.left().IsWord32Shl() && ((rep == MachineRepresentation::kWord8 &&
695 ((rep == kRepWord8 && m.right().IsInRange(1, 24)) || 698 m.right().IsInRange(1, 24)) ||
696 (rep == kRepWord16 && m.right().IsInRange(1, 16)))) { 699 (rep == MachineRepresentation::kWord16 &&
700 m.right().IsInRange(1, 16)))) {
697 Int32BinopMatcher mleft(m.left().node()); 701 Int32BinopMatcher mleft(m.left().node());
698 if (mleft.right().Is(m.right().Value())) { 702 if (mleft.right().Is(m.right().Value())) {
699 node->ReplaceInput(2, mleft.left().node()); 703 node->ReplaceInput(2, mleft.left().node());
700 return Changed(node); 704 return Changed(node);
701 } 705 }
702 } 706 }
703 break; 707 break;
704 } 708 }
705 default: 709 default:
706 break; 710 break;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 if (m.right().Is(31) && mleft.right().Is(31)) { 808 if (m.right().Is(31) && mleft.right().Is(31)) {
805 // Comparison << 31 >> 31 => 0 - Comparison 809 // Comparison << 31 >> 31 => 0 - Comparison
806 node->ReplaceInput(0, Int32Constant(0)); 810 node->ReplaceInput(0, Int32Constant(0));
807 node->ReplaceInput(1, mleft.left().node()); 811 node->ReplaceInput(1, mleft.left().node());
808 NodeProperties::ChangeOp(node, machine()->Int32Sub()); 812 NodeProperties::ChangeOp(node, machine()->Int32Sub());
809 Reduction const reduction = ReduceInt32Sub(node); 813 Reduction const reduction = ReduceInt32Sub(node);
810 return reduction.Changed() ? reduction : Changed(node); 814 return reduction.Changed() ? reduction : Changed(node);
811 } 815 }
812 } else if (mleft.left().IsLoad()) { 816 } else if (mleft.left().IsLoad()) {
813 LoadRepresentation const rep = 817 LoadRepresentation const rep =
814 OpParameter<LoadRepresentation>(mleft.left().node()); 818 LoadRepresentationOf(mleft.left().node()->op());
815 if (m.right().Is(24) && mleft.right().Is(24) && rep == kMachInt8) { 819 if (m.right().Is(24) && mleft.right().Is(24) &&
820 rep == MachineType::Int8()) {
816 // Load[kMachInt8] << 24 >> 24 => Load[kMachInt8] 821 // Load[kMachInt8] << 24 >> 24 => Load[kMachInt8]
817 return Replace(mleft.left().node()); 822 return Replace(mleft.left().node());
818 } 823 }
819 if (m.right().Is(16) && mleft.right().Is(16) && rep == kMachInt16) { 824 if (m.right().Is(16) && mleft.right().Is(16) &&
825 rep == MachineType::Int16()) {
820 // Load[kMachInt16] << 16 >> 16 => Load[kMachInt8] 826 // Load[kMachInt16] << 16 >> 16 => Load[kMachInt8]
821 return Replace(mleft.left().node()); 827 return Replace(mleft.left().node());
822 } 828 }
823 } 829 }
824 } 830 }
825 return ReduceWord32Shifts(node); 831 return ReduceWord32Shifts(node);
826 } 832 }
827 833
828 834
829 Reduction MachineOperatorReducer::ReduceWord32And(Node* node) { 835 Reduction MachineOperatorReducer::ReduceWord32And(Node* node) {
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 MachineOperatorBuilder* MachineOperatorReducer::machine() const { 1082 MachineOperatorBuilder* MachineOperatorReducer::machine() const {
1077 return jsgraph()->machine(); 1083 return jsgraph()->machine();
1078 } 1084 }
1079 1085
1080 1086
1081 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } 1087 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); }
1082 1088
1083 } // namespace compiler 1089 } // namespace compiler
1084 } // namespace internal 1090 } // namespace internal
1085 } // namespace v8 1091 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/machine-operator.cc ('k') | src/compiler/mips/instruction-selector-mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698