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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "src/base/adapters.h" | 7 #include "src/base/adapters.h" |
| 8 #include "src/compiler/compiler-source-position-table.h" |
8 #include "src/compiler/instruction-selector-impl.h" | 9 #include "src/compiler/instruction-selector-impl.h" |
9 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
10 #include "src/compiler/node-properties.h" | 11 #include "src/compiler/node-properties.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 namespace compiler { | 15 namespace compiler { |
15 | 16 |
16 // Adds X64-specific methods for generating operands. | 17 // Adds X64-specific methods for generating operands. |
17 class X64OperandGenerator final : public OperandGenerator { | 18 class X64OperandGenerator final : public OperandGenerator { |
(...skipping 1662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1680 opcode = cont->Encode(opcode); | 1681 opcode = cont->Encode(opcode); |
1681 inputs[input_count++] = right; | 1682 inputs[input_count++] = right; |
1682 | 1683 |
1683 if (cont->IsBranch()) { | 1684 if (cont->IsBranch()) { |
1684 inputs[input_count++] = g.Label(cont->true_block()); | 1685 inputs[input_count++] = g.Label(cont->true_block()); |
1685 inputs[input_count++] = g.Label(cont->false_block()); | 1686 inputs[input_count++] = g.Label(cont->false_block()); |
1686 selector->Emit(opcode, 0, nullptr, input_count, inputs); | 1687 selector->Emit(opcode, 0, nullptr, input_count, inputs); |
1687 } else if (cont->IsDeoptimize()) { | 1688 } else if (cont->IsDeoptimize()) { |
1688 selector->EmitDeoptimize(opcode, 0, nullptr, input_count, inputs, | 1689 selector->EmitDeoptimize(opcode, 0, nullptr, input_count, inputs, |
1689 cont->reason(), cont->frame_state()); | 1690 cont->reason(), cont->frame_state()); |
1690 } else { | 1691 } else if (cont->IsSet()) { |
1691 DCHECK(cont->IsSet()); | |
1692 InstructionOperand output = g.DefineAsRegister(cont->result()); | 1692 InstructionOperand output = g.DefineAsRegister(cont->result()); |
1693 selector->Emit(opcode, 1, &output, input_count, inputs); | 1693 selector->Emit(opcode, 1, &output, input_count, inputs); |
| 1694 } else { |
| 1695 DCHECK(cont->IsTrap()); |
| 1696 inputs[input_count++] = g.UseImmediate(cont->trap_id()); |
| 1697 Instruction* instr = |
| 1698 selector->Emit(opcode, 0, nullptr, input_count, inputs); |
| 1699 selector->SetSourcePosition(instr, *cont->source_position()); |
1694 } | 1700 } |
1695 } | 1701 } |
1696 | 1702 |
1697 // Shared routine for multiple compare operations. | 1703 // Shared routine for multiple compare operations. |
1698 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, | 1704 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
1699 InstructionOperand left, InstructionOperand right, | 1705 InstructionOperand left, InstructionOperand right, |
1700 FlagsContinuation* cont) { | 1706 FlagsContinuation* cont) { |
1701 X64OperandGenerator g(selector); | 1707 X64OperandGenerator g(selector); |
1702 opcode = cont->Encode(opcode); | 1708 opcode = cont->Encode(opcode); |
1703 if (cont->IsBranch()) { | 1709 if (cont->IsBranch()) { |
1704 selector->Emit(opcode, g.NoOutput(), left, right, | 1710 selector->Emit(opcode, g.NoOutput(), left, right, |
1705 g.Label(cont->true_block()), g.Label(cont->false_block())); | 1711 g.Label(cont->true_block()), g.Label(cont->false_block())); |
1706 } else if (cont->IsDeoptimize()) { | 1712 } else if (cont->IsDeoptimize()) { |
1707 selector->EmitDeoptimize(opcode, g.NoOutput(), left, right, cont->reason(), | 1713 selector->EmitDeoptimize(opcode, g.NoOutput(), left, right, cont->reason(), |
1708 cont->frame_state()); | 1714 cont->frame_state()); |
| 1715 } else if (cont->IsSet()) { |
| 1716 selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right); |
1709 } else { | 1717 } else { |
1710 DCHECK(cont->IsSet()); | 1718 DCHECK(cont->IsTrap()); |
1711 selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right); | 1719 Instruction* instr = selector->Emit(opcode, g.NoOutput(), left, right, |
| 1720 g.UseImmediate(cont->trap_id())); |
| 1721 selector->SetSourcePosition(instr, *cont->source_position()); |
1712 } | 1722 } |
1713 } | 1723 } |
1714 | 1724 |
1715 | 1725 |
1716 // Shared routine for multiple compare operations. | 1726 // Shared routine for multiple compare operations. |
1717 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, | 1727 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
1718 Node* left, Node* right, FlagsContinuation* cont, | 1728 Node* left, Node* right, FlagsContinuation* cont, |
1719 bool commutative) { | 1729 bool commutative) { |
1720 X64OperandGenerator g(selector); | 1730 X64OperandGenerator g(selector); |
1721 if (commutative && g.CanBeBetterLeftOperand(right)) { | 1731 if (commutative && g.CanBeBetterLeftOperand(right)) { |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1851 if (mleft.object().Is(js_stack_limit) && mleft.index().Is(0)) { | 1861 if (mleft.object().Is(js_stack_limit) && mleft.index().Is(0)) { |
1852 // Compare(Load(js_stack_limit), LoadStackPointer) | 1862 // Compare(Load(js_stack_limit), LoadStackPointer) |
1853 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1863 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
1854 InstructionCode opcode = cont->Encode(kX64StackCheck); | 1864 InstructionCode opcode = cont->Encode(kX64StackCheck); |
1855 if (cont->IsBranch()) { | 1865 if (cont->IsBranch()) { |
1856 selector->Emit(opcode, g.NoOutput(), g.Label(cont->true_block()), | 1866 selector->Emit(opcode, g.NoOutput(), g.Label(cont->true_block()), |
1857 g.Label(cont->false_block())); | 1867 g.Label(cont->false_block())); |
1858 } else if (cont->IsDeoptimize()) { | 1868 } else if (cont->IsDeoptimize()) { |
1859 selector->EmitDeoptimize(opcode, 0, nullptr, 0, nullptr, cont->reason(), | 1869 selector->EmitDeoptimize(opcode, 0, nullptr, 0, nullptr, cont->reason(), |
1860 cont->frame_state()); | 1870 cont->frame_state()); |
| 1871 } else if (cont->IsSet()) { |
| 1872 selector->Emit(opcode, g.DefineAsRegister(cont->result())); |
1861 } else { | 1873 } else { |
1862 DCHECK(cont->IsSet()); | 1874 DCHECK(cont->IsTrap()); |
1863 selector->Emit(opcode, g.DefineAsRegister(cont->result())); | 1875 Instruction* instr = selector->Emit(opcode, g.NoOutput(), |
| 1876 g.UseImmediate(cont->trap_id())); |
| 1877 selector->SetSourcePosition(instr, *cont->source_position()); |
1864 } | 1878 } |
1865 return; | 1879 return; |
1866 } | 1880 } |
1867 } | 1881 } |
1868 VisitWordCompare(selector, node, kX64Cmp, cont); | 1882 VisitWordCompare(selector, node, kX64Cmp, cont); |
1869 } | 1883 } |
1870 | 1884 |
1871 | 1885 |
1872 // Shared routine for comparison with zero. | 1886 // Shared routine for comparison with zero. |
1873 void VisitCompareZero(InstructionSelector* selector, Node* node, | 1887 void VisitCompareZero(InstructionSelector* selector, Node* node, |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2061 kNotEqual, DeoptimizeReasonOf(node->op()), node->InputAt(1)); | 2075 kNotEqual, DeoptimizeReasonOf(node->op()), node->InputAt(1)); |
2062 VisitWordCompareZero(this, node, node->InputAt(0), &cont); | 2076 VisitWordCompareZero(this, node, node->InputAt(0), &cont); |
2063 } | 2077 } |
2064 | 2078 |
2065 void InstructionSelector::VisitDeoptimizeUnless(Node* node) { | 2079 void InstructionSelector::VisitDeoptimizeUnless(Node* node) { |
2066 FlagsContinuation cont = FlagsContinuation::ForDeoptimize( | 2080 FlagsContinuation cont = FlagsContinuation::ForDeoptimize( |
2067 kEqual, DeoptimizeReasonOf(node->op()), node->InputAt(1)); | 2081 kEqual, DeoptimizeReasonOf(node->op()), node->InputAt(1)); |
2068 VisitWordCompareZero(this, node, node->InputAt(0), &cont); | 2082 VisitWordCompareZero(this, node, node->InputAt(0), &cont); |
2069 } | 2083 } |
2070 | 2084 |
| 2085 void InstructionSelector::VisitTrapIf(Node* node) { |
| 2086 SourcePosition pos = source_positions_->GetSourcePosition(node); |
| 2087 FlagsContinuation cont = FlagsContinuation::ForTrap( |
| 2088 kNotEqual, OpParameter<Runtime::FunctionId>(node->op()), &pos, |
| 2089 node->InputAt(1)); |
| 2090 VisitWordCompareZero(this, node, node->InputAt(0), &cont); |
| 2091 } |
| 2092 |
| 2093 void InstructionSelector::VisitTrapUnless(Node* node) { |
| 2094 SourcePosition pos = source_positions_->GetSourcePosition(node); |
| 2095 FlagsContinuation cont = FlagsContinuation::ForTrap( |
| 2096 kEqual, OpParameter<Runtime::FunctionId>(node->op()), &pos, |
| 2097 node->InputAt(1)); |
| 2098 VisitWordCompareZero(this, node, node->InputAt(0), &cont); |
| 2099 } |
| 2100 |
2071 void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) { | 2101 void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) { |
2072 X64OperandGenerator g(this); | 2102 X64OperandGenerator g(this); |
2073 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); | 2103 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); |
2074 | 2104 |
2075 // Emit either ArchTableSwitch or ArchLookupSwitch. | 2105 // Emit either ArchTableSwitch or ArchLookupSwitch. |
2076 size_t table_space_cost = 4 + sw.value_range; | 2106 size_t table_space_cost = 4 + sw.value_range; |
2077 size_t table_time_cost = 3; | 2107 size_t table_time_cost = 3; |
2078 size_t lookup_space_cost = 3 + 2 * sw.case_count; | 2108 size_t lookup_space_cost = 3 + 2 * sw.case_count; |
2079 size_t lookup_time_cost = sw.case_count; | 2109 size_t lookup_time_cost = sw.case_count; |
2080 if (sw.case_count > 4 && | 2110 if (sw.case_count > 4 && |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2430 // static | 2460 // static |
2431 MachineOperatorBuilder::AlignmentRequirements | 2461 MachineOperatorBuilder::AlignmentRequirements |
2432 InstructionSelector::AlignmentRequirements() { | 2462 InstructionSelector::AlignmentRequirements() { |
2433 return MachineOperatorBuilder::AlignmentRequirements:: | 2463 return MachineOperatorBuilder::AlignmentRequirements:: |
2434 FullUnalignedAccessSupport(); | 2464 FullUnalignedAccessSupport(); |
2435 } | 2465 } |
2436 | 2466 |
2437 } // namespace compiler | 2467 } // namespace compiler |
2438 } // namespace internal | 2468 } // namespace internal |
2439 } // namespace v8 | 2469 } // namespace v8 |
OLD | NEW |