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

Side by Side Diff: src/compiler/ppc/instruction-selector-ppc.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
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 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 #endif 1242 #endif
1243 1243
1244 1244
1245 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, 1245 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
1246 BasicBlock* fbranch) { 1246 BasicBlock* fbranch) {
1247 FlagsContinuation cont(kNotEqual, tbranch, fbranch); 1247 FlagsContinuation cont(kNotEqual, tbranch, fbranch);
1248 VisitWord32CompareZero(this, branch, branch->InputAt(0), &cont); 1248 VisitWord32CompareZero(this, branch, branch->InputAt(0), &cont);
1249 } 1249 }
1250 1250
1251 1251
1252 void InstructionSelector::VisitSwitch(Node* node, BasicBlock* default_branch, 1252 void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) {
1253 BasicBlock** case_branches,
1254 int32_t* case_values, size_t case_count,
1255 int32_t min_value, int32_t max_value) {
1256 PPCOperandGenerator g(this); 1253 PPCOperandGenerator g(this);
1257 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); 1254 InstructionOperand value_operand = g.UseRegister(node->InputAt(0));
1258 InstructionOperand default_operand = g.Label(default_branch);
1259 1255
1260 // Note that {value_range} can be 0 if {min_value} is -2^31 and {max_value} 1256 // Emit either ArchTableSwitch or ArchLookupSwitch.
1261 // is 2^31-1, so don't assume that it's non-zero below. 1257 size_t table_space_cost = 4 + sw.value_range;
1262 size_t value_range =
1263 1u + bit_cast<uint32_t>(max_value) - bit_cast<uint32_t>(min_value);
1264
1265 // Determine whether to issue an ArchTableSwitch or an ArchLookupSwitch
1266 // instruction.
1267 size_t table_space_cost = 4 + value_range;
1268 size_t table_time_cost = 3; 1258 size_t table_time_cost = 3;
1269 size_t lookup_space_cost = 3 + 2 * case_count; 1259 size_t lookup_space_cost = 3 + 2 * sw.case_count;
1270 size_t lookup_time_cost = case_count; 1260 size_t lookup_time_cost = sw.case_count;
1271 if (case_count > 0 && 1261 if (sw.case_count > 0 &&
1272 table_space_cost + 3 * table_time_cost <= 1262 table_space_cost + 3 * table_time_cost <=
1273 lookup_space_cost + 3 * lookup_time_cost && 1263 lookup_space_cost + 3 * lookup_time_cost &&
1274 min_value > std::numeric_limits<int32_t>::min()) { 1264 sw.min_value > std::numeric_limits<int32_t>::min()) {
1275 InstructionOperand index_operand = value_operand; 1265 InstructionOperand index_operand = value_operand;
1276 if (min_value) { 1266 if (sw.min_value) {
1277 index_operand = g.TempRegister(); 1267 index_operand = g.TempRegister();
1278 Emit(kPPC_Sub32, index_operand, value_operand, 1268 Emit(kPPC_Sub32, index_operand, value_operand,
1279 g.TempImmediate(min_value)); 1269 g.TempImmediate(sw.min_value));
1280 } 1270 }
1281 size_t input_count = 2 + value_range; 1271 // Generate a table lookup.
1282 auto* inputs = zone()->NewArray<InstructionOperand>(input_count); 1272 return EmitTableSwitch(sw, index_operand);
1283 inputs[0] = index_operand;
1284 std::fill(&inputs[1], &inputs[input_count], default_operand);
1285 for (size_t index = 0; index < case_count; ++index) {
1286 size_t value = case_values[index] - min_value;
1287 BasicBlock* branch = case_branches[index];
1288 DCHECK_LE(0u, value);
1289 DCHECK_LT(value + 2, input_count);
1290 inputs[value + 2] = g.Label(branch);
1291 }
1292 Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr);
1293 return;
1294 } 1273 }
1295 1274
1296 // Generate a sequence of conditional jumps. 1275 // Generate a sequence of conditional jumps.
1297 size_t input_count = 2 + case_count * 2; 1276 return EmitLookupSwitch(sw, value_operand);
1298 auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
1299 inputs[0] = value_operand;
1300 inputs[1] = default_operand;
1301 for (size_t index = 0; index < case_count; ++index) {
1302 int32_t value = case_values[index];
1303 BasicBlock* branch = case_branches[index];
1304 inputs[index * 2 + 2 + 0] = g.TempImmediate(value);
1305 inputs[index * 2 + 2 + 1] = g.Label(branch);
1306 }
1307 Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr);
1308 } 1277 }
1309 1278
1310 1279
1311 void InstructionSelector::VisitWord32Equal(Node* const node) { 1280 void InstructionSelector::VisitWord32Equal(Node* const node) {
1312 FlagsContinuation cont(kEqual, node); 1281 FlagsContinuation cont(kEqual, node);
1313 Int32BinopMatcher m(node); 1282 Int32BinopMatcher m(node);
1314 if (m.right().Is(0)) { 1283 if (m.right().Is(0)) {
1315 return VisitWord32CompareZero(this, m.node(), m.left().node(), &cont); 1284 return VisitWord32CompareZero(this, m.node(), m.left().node(), &cont);
1316 } 1285 }
1317 VisitWord32Compare(this, node, &cont); 1286 VisitWord32Compare(this, node, &cont);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 MachineOperatorBuilder::kFloat64Min | 1470 MachineOperatorBuilder::kFloat64Min |
1502 MachineOperatorBuilder::kFloat64RoundDown | 1471 MachineOperatorBuilder::kFloat64RoundDown |
1503 MachineOperatorBuilder::kFloat64RoundTruncate | 1472 MachineOperatorBuilder::kFloat64RoundTruncate |
1504 MachineOperatorBuilder::kFloat64RoundTiesAway; 1473 MachineOperatorBuilder::kFloat64RoundTiesAway;
1505 // We omit kWord32ShiftIsSafe as s[rl]w use 0x3f as a mask rather than 0x1f. 1474 // We omit kWord32ShiftIsSafe as s[rl]w use 0x3f as a mask rather than 0x1f.
1506 } 1475 }
1507 1476
1508 } // namespace compiler 1477 } // namespace compiler
1509 } // namespace internal 1478 } // namespace internal
1510 } // namespace v8 1479 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/mips64/instruction-selector-mips64.cc ('k') | src/compiler/x64/instruction-selector-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698