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

Side by Side Diff: src/compiler/mips/instruction-selector-mips.cc

Issue 931263002: MIPS: [turbofan] Optimize certain chains of Branch into a Switch. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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 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/base/bits.h" 5 #include "src/base/bits.h"
6 #include "src/compiler/instruction-selector-impl.h" 6 #include "src/compiler/instruction-selector-impl.h"
7 #include "src/compiler/node-matchers.h" 7 #include "src/compiler/node-matchers.h"
8 #include "src/compiler/node-properties.h" 8 #include "src/compiler/node-properties.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 } 739 }
740 740
741 741
742 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, 742 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
743 BasicBlock* fbranch) { 743 BasicBlock* fbranch) {
744 FlagsContinuation cont(kNotEqual, tbranch, fbranch); 744 FlagsContinuation cont(kNotEqual, tbranch, fbranch);
745 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont); 745 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont);
746 } 746 }
747 747
748 748
749 void InstructionSelector::VisitSwitch(Node* node, BasicBlock* default_branch,
750 BasicBlock** case_branches,
751 int32_t* case_values, size_t case_count,
752 int32_t min_value, int32_t max_value) {
753 MipsOperandGenerator g(this);
754 InstructionOperand value_operand = g.UseRegister(node->InputAt(0));
755 InstructionOperand default_operand = g.Label(default_branch);
756
757 // Note that {value_range} can be 0 if {min_value} is -2^31 and {max_value}
758 // is 2^31-1, so don't assume that it's non-zero below.
759 size_t value_range =
760 1u + bit_cast<uint32_t>(max_value) - bit_cast<uint32_t>(min_value);
761
762 // Determine whether to issue an ArchTableSwitch or an ArchLookupSwitch
763 // instruction.
764 size_t table_space_cost = 4 + value_range;
paul.l... 2015/02/17 19:33:59 The cost numbers here are incorrect for MIPS, sinc
765 size_t table_time_cost = 3;
766 size_t lookup_space_cost = 3 + 2 * case_count;
767 size_t lookup_time_cost = case_count;
768 if (case_count > 0 &&
769 table_space_cost + 3 * table_time_cost <=
770 lookup_space_cost + 3 * lookup_time_cost &&
771 min_value > std::numeric_limits<int32_t>::min()) {
772 InstructionOperand index_operand = value_operand;
773 if (min_value) {
774 index_operand = g.TempRegister();
775 Emit(kMipsSub, index_operand, value_operand, g.TempImmediate(min_value));
776 }
777 size_t input_count = 2 + value_range;
778 auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
779 inputs[0] = index_operand;
780 std::fill(&inputs[1], &inputs[input_count], default_operand);
781 for (size_t index = 0; index < case_count; ++index) {
782 size_t value = case_values[index] - min_value;
783 BasicBlock* branch = case_branches[index];
784 DCHECK_LE(0u, value);
785 DCHECK_LT(value + 2, input_count);
786 inputs[value + 2] = g.Label(branch);
787 }
788 Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr)
789 ->MarkAsControl();
790 return;
791 }
792
793 // Generate a sequence of conditional jumps.
794 size_t input_count = 2 + case_count * 2;
795 auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
796 inputs[0] = value_operand;
797 inputs[1] = default_operand;
798 for (size_t index = 0; index < case_count; ++index) {
799 int32_t value = case_values[index];
800 BasicBlock* branch = case_branches[index];
801 inputs[index * 2 + 2 + 0] = g.TempImmediate(value);
802 inputs[index * 2 + 2 + 1] = g.Label(branch);
803 }
804 Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr)
805 ->MarkAsControl();
806 }
807
808
749 void InstructionSelector::VisitWord32Equal(Node* const node) { 809 void InstructionSelector::VisitWord32Equal(Node* const node) {
750 FlagsContinuation cont(kEqual, node); 810 FlagsContinuation cont(kEqual, node);
751 Int32BinopMatcher m(node); 811 Int32BinopMatcher m(node);
752 if (m.right().Is(0)) { 812 if (m.right().Is(0)) {
753 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont); 813 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont);
754 } 814 }
755 VisitWordCompare(this, node, &cont); 815 VisitWordCompare(this, node, &cont);
756 } 816 }
757 817
758 818
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 return MachineOperatorBuilder::kFloat64Floor | 885 return MachineOperatorBuilder::kFloat64Floor |
826 MachineOperatorBuilder::kFloat64Ceil | 886 MachineOperatorBuilder::kFloat64Ceil |
827 MachineOperatorBuilder::kFloat64RoundTruncate; 887 MachineOperatorBuilder::kFloat64RoundTruncate;
828 } 888 }
829 return MachineOperatorBuilder::kNoFlags; 889 return MachineOperatorBuilder::kNoFlags;
830 } 890 }
831 891
832 } // namespace compiler 892 } // namespace compiler
833 } // namespace internal 893 } // namespace internal
834 } // namespace v8 894 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698