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

Side by Side Diff: src/compiler/mips64/instruction-selector-mips64.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 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 } 960 }
961 961
962 962
963 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, 963 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
964 BasicBlock* fbranch) { 964 BasicBlock* fbranch) {
965 FlagsContinuation cont(kNotEqual, tbranch, fbranch); 965 FlagsContinuation cont(kNotEqual, tbranch, fbranch);
966 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont); 966 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont);
967 } 967 }
968 968
969 969
970 void InstructionSelector::VisitSwitch(Node* node, BasicBlock* default_branch,
971 BasicBlock** case_branches,
972 int32_t* case_values, size_t case_count,
973 int32_t min_value, int32_t max_value) {
974 Mips64OperandGenerator g(this);
975 InstructionOperand value_operand = g.UseRegister(node->InputAt(0));
976 InstructionOperand default_operand = g.Label(default_branch);
977
978 // Note that {value_range} can be 0 if {min_value} is -2^31 and {max_value}
979 // is 2^31-1, so don't assume that it's non-zero below.
980 size_t value_range =
981 1u + bit_cast<uint32_t>(max_value) - bit_cast<uint32_t>(min_value);
982
983 // Determine whether to issue an ArchTableSwitch or an ArchLookupSwitch
984 // instruction.
985 size_t table_space_cost = 4 + value_range;
986 size_t table_time_cost = 3;
paul.l... 2015/02/17 19:33:59 as in mips32 port, the costs must be calculated co
987 size_t lookup_space_cost = 3 + 2 * case_count;
988 size_t lookup_time_cost = case_count;
989 if (case_count > 0 &&
990 table_space_cost + 3 * table_time_cost <=
991 lookup_space_cost + 3 * lookup_time_cost &&
992 min_value > std::numeric_limits<int32_t>::min()) {
993 InstructionOperand index_operand = value_operand;
994 if (min_value) {
995 index_operand = g.TempRegister();
996 Emit(kMips64Sub, index_operand, value_operand,
997 g.TempImmediate(min_value));
998 }
999 size_t input_count = 2 + value_range;
1000 auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
1001 inputs[0] = index_operand;
1002 std::fill(&inputs[1], &inputs[input_count], default_operand);
1003 for (size_t index = 0; index < case_count; ++index) {
1004 size_t value = case_values[index] - min_value;
1005 BasicBlock* branch = case_branches[index];
1006 DCHECK_LE(0u, value);
1007 DCHECK_LT(value + 2, input_count);
1008 inputs[value + 2] = g.Label(branch);
1009 }
1010 Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr)
1011 ->MarkAsControl();
1012 return;
1013 }
1014
1015 // Generate a sequence of conditional jumps.
1016 size_t input_count = 2 + case_count * 2;
1017 auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
1018 inputs[0] = value_operand;
1019 inputs[1] = default_operand;
1020 for (size_t index = 0; index < case_count; ++index) {
1021 int32_t value = case_values[index];
1022 BasicBlock* branch = case_branches[index];
1023 inputs[index * 2 + 2 + 0] = g.TempImmediate(value);
1024 inputs[index * 2 + 2 + 1] = g.Label(branch);
1025 }
1026 Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr)
1027 ->MarkAsControl();
1028 }
1029
1030
970 void InstructionSelector::VisitWord32Equal(Node* const node) { 1031 void InstructionSelector::VisitWord32Equal(Node* const node) {
971 FlagsContinuation cont(kEqual, node); 1032 FlagsContinuation cont(kEqual, node);
972 Int32BinopMatcher m(node); 1033 Int32BinopMatcher m(node);
973 if (m.right().Is(0)) { 1034 if (m.right().Is(0)) {
974 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont); 1035 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont);
975 } 1036 }
976 1037
977 VisitWord32Compare(this, node, &cont); 1038 VisitWord32Compare(this, node, &cont);
978 } 1039 }
979 1040
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 MachineOperatorBuilder::Flags 1134 MachineOperatorBuilder::Flags
1074 InstructionSelector::SupportedMachineOperatorFlags() { 1135 InstructionSelector::SupportedMachineOperatorFlags() {
1075 return MachineOperatorBuilder::kFloat64Floor | 1136 return MachineOperatorBuilder::kFloat64Floor |
1076 MachineOperatorBuilder::kFloat64Ceil | 1137 MachineOperatorBuilder::kFloat64Ceil |
1077 MachineOperatorBuilder::kFloat64RoundTruncate; 1138 MachineOperatorBuilder::kFloat64RoundTruncate;
1078 } 1139 }
1079 1140
1080 } // namespace compiler 1141 } // namespace compiler
1081 } // namespace internal 1142 } // namespace internal
1082 } // namespace v8 1143 } // namespace v8
OLDNEW
« src/compiler/mips64/code-generator-mips64.cc ('K') | « src/compiler/mips64/code-generator-mips64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698