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

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

Issue 1019803005: [turbofan] Factor out common switch-related code in instruction selectors. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « src/compiler/arm64/instruction-selector-arm64.cc ('k') | src/compiler/instruction-selector.h » ('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/instruction-selector-impl.h" 5 #include "src/compiler/instruction-selector-impl.h"
6 #include "src/compiler/node-matchers.h" 6 #include "src/compiler/node-matchers.h"
7 #include "src/compiler/node-properties.h" 7 #include "src/compiler/node-properties.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 } // namespace 984 } // namespace
985 985
986 986
987 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, 987 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
988 BasicBlock* fbranch) { 988 BasicBlock* fbranch) {
989 FlagsContinuation cont(kNotEqual, tbranch, fbranch); 989 FlagsContinuation cont(kNotEqual, tbranch, fbranch);
990 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont); 990 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont);
991 } 991 }
992 992
993 993
994 void InstructionSelector::VisitSwitch(Node* node, BasicBlock* default_branch, 994 void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) {
995 BasicBlock** case_branches,
996 int32_t* case_values, size_t case_count,
997 int32_t min_value, int32_t max_value) {
998 IA32OperandGenerator g(this); 995 IA32OperandGenerator g(this);
999 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); 996 InstructionOperand value_operand = g.UseRegister(node->InputAt(0));
1000 InstructionOperand default_operand = g.Label(default_branch);
1001 997
1002 // Note that {value_range} can be 0 if {min_value} is -2^31 and {max_value} 998 // Emit either ArchTableSwitch or ArchLookupSwitch.
1003 // is 2^31-1, so don't assume that it's non-zero below. 999 size_t table_space_cost = 4 + sw.value_range;
1004 size_t value_range =
1005 1u + bit_cast<uint32_t>(max_value) - bit_cast<uint32_t>(min_value);
1006
1007 // Determine whether to issue an ArchTableSwitch or an ArchLookupSwitch
1008 // instruction.
1009 size_t table_space_cost = 4 + value_range;
1010 size_t table_time_cost = 3; 1000 size_t table_time_cost = 3;
1011 size_t lookup_space_cost = 3 + 2 * case_count; 1001 size_t lookup_space_cost = 3 + 2 * sw.case_count;
1012 size_t lookup_time_cost = case_count; 1002 size_t lookup_time_cost = sw.case_count;
1013 if (case_count > 4 && 1003 if (sw.case_count > 4 &&
1014 table_space_cost + 3 * table_time_cost <= 1004 table_space_cost + 3 * table_time_cost <=
1015 lookup_space_cost + 3 * lookup_time_cost && 1005 lookup_space_cost + 3 * lookup_time_cost &&
1016 min_value > std::numeric_limits<int32_t>::min()) { 1006 sw.min_value > std::numeric_limits<int32_t>::min()) {
1017 InstructionOperand index_operand = value_operand; 1007 InstructionOperand index_operand = value_operand;
1018 if (min_value) { 1008 if (sw.min_value) {
1019 index_operand = g.TempRegister(); 1009 index_operand = g.TempRegister();
1020 Emit(kIA32Lea | AddressingModeField::encode(kMode_MRI), index_operand, 1010 Emit(kIA32Lea | AddressingModeField::encode(kMode_MRI), index_operand,
1021 value_operand, g.TempImmediate(-min_value)); 1011 value_operand, g.TempImmediate(-sw.min_value));
1022 } 1012 }
1023 size_t input_count = 2 + value_range; 1013 // Generate a table lookup.
1024 auto* inputs = zone()->NewArray<InstructionOperand>(input_count); 1014 return EmitTableSwitch(sw, index_operand);
1025 inputs[0] = index_operand;
1026 std::fill(&inputs[1], &inputs[input_count], default_operand);
1027 for (size_t index = 0; index < case_count; ++index) {
1028 size_t value = case_values[index] - min_value;
1029 BasicBlock* branch = case_branches[index];
1030 DCHECK_LE(0u, value);
1031 DCHECK_LT(value + 2, input_count);
1032 inputs[value + 2] = g.Label(branch);
1033 }
1034 Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr);
1035 return;
1036 } 1015 }
1037 1016
1038 // Generate a sequence of conditional jumps. 1017 // Generate a sequence of conditional jumps.
1039 size_t input_count = 2 + case_count * 2; 1018 return EmitLookupSwitch(sw, value_operand);
1040 auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
1041 inputs[0] = value_operand;
1042 inputs[1] = default_operand;
1043 for (size_t index = 0; index < case_count; ++index) {
1044 int32_t value = case_values[index];
1045 BasicBlock* branch = case_branches[index];
1046 inputs[index * 2 + 2 + 0] = g.TempImmediate(value);
1047 inputs[index * 2 + 2 + 1] = g.Label(branch);
1048 }
1049 Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr);
1050 } 1019 }
1051 1020
1052 1021
1053 void InstructionSelector::VisitWord32Equal(Node* const node) { 1022 void InstructionSelector::VisitWord32Equal(Node* const node) {
1054 FlagsContinuation cont(kEqual, node); 1023 FlagsContinuation cont(kEqual, node);
1055 Int32BinopMatcher m(node); 1024 Int32BinopMatcher m(node);
1056 if (m.right().Is(0)) { 1025 if (m.right().Is(0)) {
1057 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont); 1026 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont);
1058 } 1027 }
1059 VisitWordCompare(this, node, &cont); 1028 VisitWordCompare(this, node, &cont);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 if (CpuFeatures::IsSupported(SSE4_1)) { 1138 if (CpuFeatures::IsSupported(SSE4_1)) {
1170 flags |= MachineOperatorBuilder::kFloat64RoundDown | 1139 flags |= MachineOperatorBuilder::kFloat64RoundDown |
1171 MachineOperatorBuilder::kFloat64RoundTruncate; 1140 MachineOperatorBuilder::kFloat64RoundTruncate;
1172 } 1141 }
1173 return flags; 1142 return flags;
1174 } 1143 }
1175 1144
1176 } // namespace compiler 1145 } // namespace compiler
1177 } // namespace internal 1146 } // namespace internal
1178 } // namespace v8 1147 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/arm64/instruction-selector-arm64.cc ('k') | src/compiler/instruction-selector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698