| OLD | NEW |
| 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 1253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1264 } // namespace | 1264 } // namespace |
| 1265 | 1265 |
| 1266 | 1266 |
| 1267 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, | 1267 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, |
| 1268 BasicBlock* fbranch) { | 1268 BasicBlock* fbranch) { |
| 1269 FlagsContinuation cont(kNotEqual, tbranch, fbranch); | 1269 FlagsContinuation cont(kNotEqual, tbranch, fbranch); |
| 1270 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont); | 1270 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont); |
| 1271 } | 1271 } |
| 1272 | 1272 |
| 1273 | 1273 |
| 1274 void InstructionSelector::VisitSwitch(Node* node, BasicBlock* default_branch, | 1274 void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) { |
| 1275 BasicBlock** case_branches, | |
| 1276 int32_t* case_values, size_t case_count, | |
| 1277 int32_t min_value, int32_t max_value) { | |
| 1278 ArmOperandGenerator g(this); | 1275 ArmOperandGenerator g(this); |
| 1279 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); | 1276 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); |
| 1280 InstructionOperand default_operand = g.Label(default_branch); | |
| 1281 | 1277 |
| 1282 // Note that {value_range} can be 0 if {min_value} is -2^31 and {max_value} | 1278 // Emit either ArchTableSwitch or ArchLookupSwitch. |
| 1283 // is 2^31-1, so don't assume that it's non-zero below. | 1279 size_t table_space_cost = 4 + sw.value_range; |
| 1284 size_t value_range = | |
| 1285 1u + bit_cast<uint32_t>(max_value) - bit_cast<uint32_t>(min_value); | |
| 1286 | |
| 1287 // Determine whether to issue an ArchTableSwitch or an ArchLookupSwitch | |
| 1288 // instruction. | |
| 1289 size_t table_space_cost = 4 + value_range; | |
| 1290 size_t table_time_cost = 3; | 1280 size_t table_time_cost = 3; |
| 1291 size_t lookup_space_cost = 3 + 2 * case_count; | 1281 size_t lookup_space_cost = 3 + 2 * sw.case_count; |
| 1292 size_t lookup_time_cost = case_count; | 1282 size_t lookup_time_cost = sw.case_count; |
| 1293 if (case_count > 0 && | 1283 if (sw.case_count > 0 && |
| 1294 table_space_cost + 3 * table_time_cost <= | 1284 table_space_cost + 3 * table_time_cost <= |
| 1295 lookup_space_cost + 3 * lookup_time_cost && | 1285 lookup_space_cost + 3 * lookup_time_cost && |
| 1296 min_value > std::numeric_limits<int32_t>::min()) { | 1286 sw.min_value > std::numeric_limits<int32_t>::min()) { |
| 1297 InstructionOperand index_operand = value_operand; | 1287 InstructionOperand index_operand = value_operand; |
| 1298 if (min_value) { | 1288 if (sw.min_value) { |
| 1299 index_operand = g.TempRegister(); | 1289 index_operand = g.TempRegister(); |
| 1300 Emit(kArmSub | AddressingModeField::encode(kMode_Operand2_I), | 1290 Emit(kArmSub | AddressingModeField::encode(kMode_Operand2_I), |
| 1301 index_operand, value_operand, g.TempImmediate(min_value)); | 1291 index_operand, value_operand, g.TempImmediate(sw.min_value)); |
| 1302 } | 1292 } |
| 1303 size_t input_count = 2 + value_range; | 1293 // Generate a table lookup. |
| 1304 auto* inputs = zone()->NewArray<InstructionOperand>(input_count); | 1294 return EmitTableSwitch(sw, index_operand); |
| 1305 inputs[0] = index_operand; | |
| 1306 std::fill(&inputs[1], &inputs[input_count], default_operand); | |
| 1307 for (size_t index = 0; index < case_count; ++index) { | |
| 1308 size_t value = case_values[index] - min_value; | |
| 1309 BasicBlock* branch = case_branches[index]; | |
| 1310 DCHECK_LE(0u, value); | |
| 1311 DCHECK_LT(value + 2, input_count); | |
| 1312 inputs[value + 2] = g.Label(branch); | |
| 1313 } | |
| 1314 Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr); | |
| 1315 return; | |
| 1316 } | 1295 } |
| 1317 | 1296 |
| 1318 // Generate a sequence of conditional jumps. | 1297 // Generate a sequence of conditional jumps. |
| 1319 size_t input_count = 2 + case_count * 2; | 1298 return EmitLookupSwitch(sw, value_operand); |
| 1320 auto* inputs = zone()->NewArray<InstructionOperand>(input_count); | |
| 1321 inputs[0] = value_operand; | |
| 1322 inputs[1] = default_operand; | |
| 1323 for (size_t index = 0; index < case_count; ++index) { | |
| 1324 int32_t value = case_values[index]; | |
| 1325 BasicBlock* branch = case_branches[index]; | |
| 1326 inputs[index * 2 + 2 + 0] = g.TempImmediate(value); | |
| 1327 inputs[index * 2 + 2 + 1] = g.Label(branch); | |
| 1328 } | |
| 1329 Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr); | |
| 1330 } | 1299 } |
| 1331 | 1300 |
| 1332 | 1301 |
| 1333 void InstructionSelector::VisitWord32Equal(Node* const node) { | 1302 void InstructionSelector::VisitWord32Equal(Node* const node) { |
| 1334 FlagsContinuation cont(kEqual, node); | 1303 FlagsContinuation cont(kEqual, node); |
| 1335 Int32BinopMatcher m(node); | 1304 Int32BinopMatcher m(node); |
| 1336 if (m.right().Is(0)) { | 1305 if (m.right().Is(0)) { |
| 1337 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont); | 1306 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont); |
| 1338 } | 1307 } |
| 1339 VisitWordCompare(this, node, &cont); | 1308 VisitWordCompare(this, node, &cont); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 flags |= MachineOperatorBuilder::kFloat64RoundDown | | 1428 flags |= MachineOperatorBuilder::kFloat64RoundDown | |
| 1460 MachineOperatorBuilder::kFloat64RoundTruncate | | 1429 MachineOperatorBuilder::kFloat64RoundTruncate | |
| 1461 MachineOperatorBuilder::kFloat64RoundTiesAway; | 1430 MachineOperatorBuilder::kFloat64RoundTiesAway; |
| 1462 } | 1431 } |
| 1463 return flags; | 1432 return flags; |
| 1464 } | 1433 } |
| 1465 | 1434 |
| 1466 } // namespace compiler | 1435 } // namespace compiler |
| 1467 } // namespace internal | 1436 } // namespace internal |
| 1468 } // namespace v8 | 1437 } // namespace v8 |
| OLD | NEW |