| 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/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 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1436 } | 1436 } |
| 1437 } | 1437 } |
| 1438 | 1438 |
| 1439 // Branch could not be combined with a compare, compare against 0 and branch. | 1439 // Branch could not be combined with a compare, compare against 0 and branch. |
| 1440 Emit(cont.Encode(kArm64CompareAndBranch32), g.NoOutput(), | 1440 Emit(cont.Encode(kArm64CompareAndBranch32), g.NoOutput(), |
| 1441 g.UseRegister(value), g.Label(cont.true_block()), | 1441 g.UseRegister(value), g.Label(cont.true_block()), |
| 1442 g.Label(cont.false_block())); | 1442 g.Label(cont.false_block())); |
| 1443 } | 1443 } |
| 1444 | 1444 |
| 1445 | 1445 |
| 1446 void InstructionSelector::VisitSwitch(Node* node, BasicBlock* default_branch, | 1446 void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) { |
| 1447 BasicBlock** case_branches, | |
| 1448 int32_t* case_values, size_t case_count, | |
| 1449 int32_t min_value, int32_t max_value) { | |
| 1450 Arm64OperandGenerator g(this); | 1447 Arm64OperandGenerator g(this); |
| 1451 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); | 1448 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); |
| 1452 InstructionOperand default_operand = g.Label(default_branch); | |
| 1453 | 1449 |
| 1454 // Note that {value_range} can be 0 if {min_value} is -2^31 and {max_value} | 1450 // Emit either ArchTableSwitch or ArchLookupSwitch. |
| 1455 // is 2^31-1, so don't assume that it's non-zero below. | 1451 size_t table_space_cost = 4 + sw.value_range; |
| 1456 size_t value_range = | |
| 1457 1u + bit_cast<uint32_t>(max_value) - bit_cast<uint32_t>(min_value); | |
| 1458 | |
| 1459 // Determine whether to issue an ArchTableSwitch or an ArchLookupSwitch | |
| 1460 // instruction. | |
| 1461 size_t table_space_cost = 4 + value_range; | |
| 1462 size_t table_time_cost = 3; | 1452 size_t table_time_cost = 3; |
| 1463 size_t lookup_space_cost = 3 + 2 * case_count; | 1453 size_t lookup_space_cost = 3 + 2 * sw.case_count; |
| 1464 size_t lookup_time_cost = case_count; | 1454 size_t lookup_time_cost = sw.case_count; |
| 1465 if (case_count > 0 && | 1455 if (sw.case_count > 0 && |
| 1466 table_space_cost + 3 * table_time_cost <= | 1456 table_space_cost + 3 * table_time_cost <= |
| 1467 lookup_space_cost + 3 * lookup_time_cost && | 1457 lookup_space_cost + 3 * lookup_time_cost && |
| 1468 min_value > std::numeric_limits<int32_t>::min()) { | 1458 sw.min_value > std::numeric_limits<int32_t>::min()) { |
| 1469 InstructionOperand index_operand = value_operand; | 1459 InstructionOperand index_operand = value_operand; |
| 1470 if (min_value) { | 1460 if (sw.min_value) { |
| 1471 index_operand = g.TempRegister(); | 1461 index_operand = g.TempRegister(); |
| 1472 Emit(kArm64Sub32, index_operand, value_operand, | 1462 Emit(kArm64Sub32, index_operand, value_operand, |
| 1473 g.TempImmediate(min_value)); | 1463 g.TempImmediate(sw.min_value)); |
| 1474 } | 1464 } |
| 1475 size_t input_count = 2 + value_range; | 1465 // Generate a table lookup. |
| 1476 auto* inputs = zone()->NewArray<InstructionOperand>(input_count); | 1466 return EmitTableSwitch(sw, index_operand); |
| 1477 inputs[0] = index_operand; | |
| 1478 std::fill(&inputs[1], &inputs[input_count], default_operand); | |
| 1479 for (size_t index = 0; index < case_count; ++index) { | |
| 1480 size_t value = case_values[index] - min_value; | |
| 1481 BasicBlock* branch = case_branches[index]; | |
| 1482 DCHECK_LE(0u, value); | |
| 1483 DCHECK_LT(value + 2, input_count); | |
| 1484 inputs[value + 2] = g.Label(branch); | |
| 1485 } | |
| 1486 Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr); | |
| 1487 return; | |
| 1488 } | 1467 } |
| 1489 | 1468 |
| 1490 // Generate a sequence of conditional jumps. | 1469 // Generate a sequence of conditional jumps. |
| 1491 size_t input_count = 2 + case_count * 2; | 1470 return EmitLookupSwitch(sw, value_operand); |
| 1492 auto* inputs = zone()->NewArray<InstructionOperand>(input_count); | |
| 1493 inputs[0] = value_operand; | |
| 1494 inputs[1] = default_operand; | |
| 1495 for (size_t index = 0; index < case_count; ++index) { | |
| 1496 int32_t value = case_values[index]; | |
| 1497 BasicBlock* branch = case_branches[index]; | |
| 1498 inputs[index * 2 + 2 + 0] = g.TempImmediate(value); | |
| 1499 inputs[index * 2 + 2 + 1] = g.Label(branch); | |
| 1500 } | |
| 1501 Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr); | |
| 1502 } | 1471 } |
| 1503 | 1472 |
| 1504 | 1473 |
| 1505 void InstructionSelector::VisitWord32Equal(Node* const node) { | 1474 void InstructionSelector::VisitWord32Equal(Node* const node) { |
| 1506 Node* const user = node; | 1475 Node* const user = node; |
| 1507 FlagsContinuation cont(kEqual, node); | 1476 FlagsContinuation cont(kEqual, node); |
| 1508 Int32BinopMatcher m(user); | 1477 Int32BinopMatcher m(user); |
| 1509 if (m.right().Is(0)) { | 1478 if (m.right().Is(0)) { |
| 1510 Node* const value = m.left().node(); | 1479 Node* const value = m.left().node(); |
| 1511 if (CanCover(user, value)) { | 1480 if (CanCover(user, value)) { |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1690 MachineOperatorBuilder::kFloat64Max | | 1659 MachineOperatorBuilder::kFloat64Max | |
| 1691 MachineOperatorBuilder::kFloat64Min | | 1660 MachineOperatorBuilder::kFloat64Min | |
| 1692 MachineOperatorBuilder::kWord32ShiftIsSafe | | 1661 MachineOperatorBuilder::kWord32ShiftIsSafe | |
| 1693 MachineOperatorBuilder::kInt32DivIsSafe | | 1662 MachineOperatorBuilder::kInt32DivIsSafe | |
| 1694 MachineOperatorBuilder::kUint32DivIsSafe; | 1663 MachineOperatorBuilder::kUint32DivIsSafe; |
| 1695 } | 1664 } |
| 1696 | 1665 |
| 1697 } // namespace compiler | 1666 } // namespace compiler |
| 1698 } // namespace internal | 1667 } // namespace internal |
| 1699 } // namespace v8 | 1668 } // namespace v8 |
| OLD | NEW |