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/adapters.h" | 5 #include "src/base/adapters.h" |
6 #include "src/base/bits.h" | 6 #include "src/base/bits.h" |
7 #include "src/compiler/instruction-selector-impl.h" | 7 #include "src/compiler/instruction-selector-impl.h" |
8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 | 10 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 DCHECK_NE(0u, input_count); | 260 DCHECK_NE(0u, input_count); |
261 DCHECK_NE(0u, output_count); | 261 DCHECK_NE(0u, output_count); |
262 DCHECK_GE(arraysize(inputs), input_count); | 262 DCHECK_GE(arraysize(inputs), input_count); |
263 DCHECK_GE(arraysize(outputs), output_count); | 263 DCHECK_GE(arraysize(outputs), output_count); |
264 DCHECK_NE(kMode_None, AddressingModeField::decode(opcode)); | 264 DCHECK_NE(kMode_None, AddressingModeField::decode(opcode)); |
265 | 265 |
266 opcode = cont->Encode(opcode); | 266 opcode = cont->Encode(opcode); |
267 if (cont->IsDeoptimize()) { | 267 if (cont->IsDeoptimize()) { |
268 selector->EmitDeoptimize(opcode, output_count, outputs, input_count, inputs, | 268 selector->EmitDeoptimize(opcode, output_count, outputs, input_count, inputs, |
269 cont->reason(), cont->frame_state()); | 269 cont->reason(), cont->frame_state()); |
| 270 } else if (cont->IsTrap()) { |
| 271 inputs[input_count++] = g.UseImmediate(cont->trap_id()); |
| 272 selector->Emit(opcode, output_count, outputs, input_count, inputs); |
270 } else { | 273 } else { |
271 selector->Emit(opcode, output_count, outputs, input_count, inputs); | 274 selector->Emit(opcode, output_count, outputs, input_count, inputs); |
272 } | 275 } |
273 } | 276 } |
274 | 277 |
275 | 278 |
276 void VisitBinop(InstructionSelector* selector, Node* node, | 279 void VisitBinop(InstructionSelector* selector, Node* node, |
277 InstructionCode opcode, InstructionCode reverse_opcode) { | 280 InstructionCode opcode, InstructionCode reverse_opcode) { |
278 FlagsContinuation cont; | 281 FlagsContinuation cont; |
279 VisitBinop(selector, node, opcode, reverse_opcode, &cont); | 282 VisitBinop(selector, node, opcode, reverse_opcode, &cont); |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 DCHECK_NE(0u, input_count); | 886 DCHECK_NE(0u, input_count); |
884 DCHECK_NE(0u, output_count); | 887 DCHECK_NE(0u, output_count); |
885 DCHECK_GE(arraysize(inputs), input_count); | 888 DCHECK_GE(arraysize(inputs), input_count); |
886 DCHECK_GE(arraysize(outputs), output_count); | 889 DCHECK_GE(arraysize(outputs), output_count); |
887 DCHECK_NE(kMode_None, AddressingModeField::decode(opcode)); | 890 DCHECK_NE(kMode_None, AddressingModeField::decode(opcode)); |
888 | 891 |
889 opcode = cont->Encode(opcode); | 892 opcode = cont->Encode(opcode); |
890 if (cont->IsDeoptimize()) { | 893 if (cont->IsDeoptimize()) { |
891 selector->EmitDeoptimize(opcode, output_count, outputs, input_count, inputs, | 894 selector->EmitDeoptimize(opcode, output_count, outputs, input_count, inputs, |
892 cont->reason(), cont->frame_state()); | 895 cont->reason(), cont->frame_state()); |
| 896 } else if (cont->IsTrap()) { |
| 897 inputs[input_count++] = g.UseImmediate(cont->trap_id()); |
| 898 selector->Emit(opcode, output_count, outputs, input_count, inputs); |
893 } else { | 899 } else { |
894 selector->Emit(opcode, output_count, outputs, input_count, inputs); | 900 selector->Emit(opcode, output_count, outputs, input_count, inputs); |
895 } | 901 } |
896 } | 902 } |
897 | 903 |
898 | 904 |
899 template <typename TryMatchShift> | 905 template <typename TryMatchShift> |
900 void VisitShift(InstructionSelector* selector, Node* node, | 906 void VisitShift(InstructionSelector* selector, Node* node, |
901 TryMatchShift try_match_shift) { | 907 TryMatchShift try_match_shift) { |
902 FlagsContinuation cont; | 908 FlagsContinuation cont; |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1250 InstructionOperand shift_31 = g.UseImmediate(31); | 1256 InstructionOperand shift_31 = g.UseImmediate(31); |
1251 InstructionCode opcode = cont->Encode(kArmCmp) | | 1257 InstructionCode opcode = cont->Encode(kArmCmp) | |
1252 AddressingModeField::encode(kMode_Operand2_R_ASR_I); | 1258 AddressingModeField::encode(kMode_Operand2_R_ASR_I); |
1253 if (cont->IsBranch()) { | 1259 if (cont->IsBranch()) { |
1254 selector->Emit(opcode, g.NoOutput(), temp_operand, result_operand, shift_31, | 1260 selector->Emit(opcode, g.NoOutput(), temp_operand, result_operand, shift_31, |
1255 g.Label(cont->true_block()), g.Label(cont->false_block())); | 1261 g.Label(cont->true_block()), g.Label(cont->false_block())); |
1256 } else if (cont->IsDeoptimize()) { | 1262 } else if (cont->IsDeoptimize()) { |
1257 InstructionOperand in[] = {temp_operand, result_operand, shift_31}; | 1263 InstructionOperand in[] = {temp_operand, result_operand, shift_31}; |
1258 selector->EmitDeoptimize(opcode, 0, nullptr, 3, in, cont->reason(), | 1264 selector->EmitDeoptimize(opcode, 0, nullptr, 3, in, cont->reason(), |
1259 cont->frame_state()); | 1265 cont->frame_state()); |
1260 } else { | 1266 } else if (cont->IsSet()) { |
1261 DCHECK(cont->IsSet()); | |
1262 selector->Emit(opcode, g.DefineAsRegister(cont->result()), temp_operand, | 1267 selector->Emit(opcode, g.DefineAsRegister(cont->result()), temp_operand, |
1263 result_operand, shift_31); | 1268 result_operand, shift_31); |
| 1269 } else { |
| 1270 DCHECK(cont->IsTrap()); |
| 1271 InstructionOperand in[] = {temp_operand, result_operand, shift_31, |
| 1272 g.UseImmediate(cont->trap_id())}; |
| 1273 selector->Emit(opcode, 0, nullptr, 4, in); |
1264 } | 1274 } |
1265 } | 1275 } |
1266 | 1276 |
1267 } // namespace | 1277 } // namespace |
1268 | 1278 |
1269 void InstructionSelector::VisitInt32Mul(Node* node) { | 1279 void InstructionSelector::VisitInt32Mul(Node* node) { |
1270 ArmOperandGenerator g(this); | 1280 ArmOperandGenerator g(this); |
1271 Int32BinopMatcher m(node); | 1281 Int32BinopMatcher m(node); |
1272 if (m.right().HasValue() && m.right().Value() > 0) { | 1282 if (m.right().HasValue() && m.right().Value() > 0) { |
1273 int32_t value = m.right().Value(); | 1283 int32_t value = m.right().Value(); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 InstructionOperand left, InstructionOperand right, | 1651 InstructionOperand left, InstructionOperand right, |
1642 FlagsContinuation* cont) { | 1652 FlagsContinuation* cont) { |
1643 ArmOperandGenerator g(selector); | 1653 ArmOperandGenerator g(selector); |
1644 opcode = cont->Encode(opcode); | 1654 opcode = cont->Encode(opcode); |
1645 if (cont->IsBranch()) { | 1655 if (cont->IsBranch()) { |
1646 selector->Emit(opcode, g.NoOutput(), left, right, | 1656 selector->Emit(opcode, g.NoOutput(), left, right, |
1647 g.Label(cont->true_block()), g.Label(cont->false_block())); | 1657 g.Label(cont->true_block()), g.Label(cont->false_block())); |
1648 } else if (cont->IsDeoptimize()) { | 1658 } else if (cont->IsDeoptimize()) { |
1649 selector->EmitDeoptimize(opcode, g.NoOutput(), left, right, cont->reason(), | 1659 selector->EmitDeoptimize(opcode, g.NoOutput(), left, right, cont->reason(), |
1650 cont->frame_state()); | 1660 cont->frame_state()); |
| 1661 } else if (cont->IsSet()) { |
| 1662 selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right); |
1651 } else { | 1663 } else { |
1652 DCHECK(cont->IsSet()); | 1664 DCHECK(cont->IsTrap()); |
1653 selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right); | 1665 selector->Emit(opcode, g.NoOutput(), left, right, |
| 1666 g.UseImmediate(cont->trap_id())); |
1654 } | 1667 } |
1655 } | 1668 } |
1656 | 1669 |
1657 | 1670 |
1658 // Shared routine for multiple float32 compare operations. | 1671 // Shared routine for multiple float32 compare operations. |
1659 void VisitFloat32Compare(InstructionSelector* selector, Node* node, | 1672 void VisitFloat32Compare(InstructionSelector* selector, Node* node, |
1660 FlagsContinuation* cont) { | 1673 FlagsContinuation* cont) { |
1661 ArmOperandGenerator g(selector); | 1674 ArmOperandGenerator g(selector); |
1662 Float32BinopMatcher m(node); | 1675 Float32BinopMatcher m(node); |
1663 if (m.right().Is(0.0f)) { | 1676 if (m.right().Is(0.0f)) { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1834 } | 1847 } |
1835 | 1848 |
1836 DCHECK_NE(0u, input_count); | 1849 DCHECK_NE(0u, input_count); |
1837 DCHECK_GE(arraysize(inputs), input_count); | 1850 DCHECK_GE(arraysize(inputs), input_count); |
1838 DCHECK_GE(arraysize(outputs), output_count); | 1851 DCHECK_GE(arraysize(outputs), output_count); |
1839 | 1852 |
1840 opcode = cont->Encode(opcode); | 1853 opcode = cont->Encode(opcode); |
1841 if (cont->IsDeoptimize()) { | 1854 if (cont->IsDeoptimize()) { |
1842 selector->EmitDeoptimize(opcode, output_count, outputs, input_count, inputs, | 1855 selector->EmitDeoptimize(opcode, output_count, outputs, input_count, inputs, |
1843 cont->reason(), cont->frame_state()); | 1856 cont->reason(), cont->frame_state()); |
| 1857 } else if (cont->IsTrap()) { |
| 1858 inputs[input_count++] = g.UseImmediate(cont->trap_id()); |
| 1859 selector->Emit(opcode, output_count, outputs, input_count, inputs); |
1844 } else { | 1860 } else { |
1845 selector->Emit(opcode, output_count, outputs, input_count, inputs); | 1861 selector->Emit(opcode, output_count, outputs, input_count, inputs); |
1846 } | 1862 } |
1847 } | 1863 } |
1848 | 1864 |
1849 | 1865 |
1850 void VisitWordCompare(InstructionSelector* selector, Node* node, | 1866 void VisitWordCompare(InstructionSelector* selector, Node* node, |
1851 FlagsContinuation* cont) { | 1867 FlagsContinuation* cont) { |
1852 InstructionCode opcode = kArmCmp; | 1868 InstructionCode opcode = kArmCmp; |
1853 Int32BinopMatcher m(node); | 1869 Int32BinopMatcher m(node); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1990 ArmOperandGenerator g(selector); | 2006 ArmOperandGenerator g(selector); |
1991 InstructionCode const opcode = | 2007 InstructionCode const opcode = |
1992 cont->Encode(kArmTst) | AddressingModeField::encode(kMode_Operand2_R); | 2008 cont->Encode(kArmTst) | AddressingModeField::encode(kMode_Operand2_R); |
1993 InstructionOperand const value_operand = g.UseRegister(value); | 2009 InstructionOperand const value_operand = g.UseRegister(value); |
1994 if (cont->IsBranch()) { | 2010 if (cont->IsBranch()) { |
1995 selector->Emit(opcode, g.NoOutput(), value_operand, value_operand, | 2011 selector->Emit(opcode, g.NoOutput(), value_operand, value_operand, |
1996 g.Label(cont->true_block()), g.Label(cont->false_block())); | 2012 g.Label(cont->true_block()), g.Label(cont->false_block())); |
1997 } else if (cont->IsDeoptimize()) { | 2013 } else if (cont->IsDeoptimize()) { |
1998 selector->EmitDeoptimize(opcode, g.NoOutput(), value_operand, value_operand, | 2014 selector->EmitDeoptimize(opcode, g.NoOutput(), value_operand, value_operand, |
1999 cont->reason(), cont->frame_state()); | 2015 cont->reason(), cont->frame_state()); |
2000 } else { | 2016 } else if (cont->IsSet()) { |
2001 DCHECK(cont->IsSet()); | |
2002 selector->Emit(opcode, g.DefineAsRegister(cont->result()), value_operand, | 2017 selector->Emit(opcode, g.DefineAsRegister(cont->result()), value_operand, |
2003 value_operand); | 2018 value_operand); |
| 2019 } else { |
| 2020 DCHECK(cont->IsTrap()); |
| 2021 selector->Emit(opcode, g.NoOutput(), value_operand, value_operand, |
| 2022 g.UseImmediate(cont->trap_id())); |
2004 } | 2023 } |
2005 } | 2024 } |
2006 | 2025 |
2007 } // namespace | 2026 } // namespace |
2008 | 2027 |
2009 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, | 2028 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, |
2010 BasicBlock* fbranch) { | 2029 BasicBlock* fbranch) { |
2011 FlagsContinuation cont(kNotEqual, tbranch, fbranch); | 2030 FlagsContinuation cont(kNotEqual, tbranch, fbranch); |
2012 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont); | 2031 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont); |
2013 } | 2032 } |
2014 | 2033 |
2015 void InstructionSelector::VisitDeoptimizeIf(Node* node) { | 2034 void InstructionSelector::VisitDeoptimizeIf(Node* node) { |
2016 FlagsContinuation cont = FlagsContinuation::ForDeoptimize( | 2035 FlagsContinuation cont = FlagsContinuation::ForDeoptimize( |
2017 kNotEqual, DeoptimizeReasonOf(node->op()), node->InputAt(1)); | 2036 kNotEqual, DeoptimizeReasonOf(node->op()), node->InputAt(1)); |
2018 VisitWordCompareZero(this, node, node->InputAt(0), &cont); | 2037 VisitWordCompareZero(this, node, node->InputAt(0), &cont); |
2019 } | 2038 } |
2020 | 2039 |
2021 void InstructionSelector::VisitDeoptimizeUnless(Node* node) { | 2040 void InstructionSelector::VisitDeoptimizeUnless(Node* node) { |
2022 FlagsContinuation cont = FlagsContinuation::ForDeoptimize( | 2041 FlagsContinuation cont = FlagsContinuation::ForDeoptimize( |
2023 kEqual, DeoptimizeReasonOf(node->op()), node->InputAt(1)); | 2042 kEqual, DeoptimizeReasonOf(node->op()), node->InputAt(1)); |
2024 VisitWordCompareZero(this, node, node->InputAt(0), &cont); | 2043 VisitWordCompareZero(this, node, node->InputAt(0), &cont); |
2025 } | 2044 } |
2026 | 2045 |
2027 void InstructionSelector::VisitTrapIf(Node* node) { UNREACHABLE(); } | 2046 void InstructionSelector::VisitTrapIf(Node* node) { |
| 2047 FlagsContinuation cont = FlagsContinuation::ForTrap( |
| 2048 kNotEqual, OpParameter<Runtime::FunctionId>(node->op()), |
| 2049 node->InputAt(1)); |
| 2050 VisitWordCompareZero(this, node, node->InputAt(0), &cont); |
| 2051 } |
2028 | 2052 |
2029 void InstructionSelector::VisitTrapUnless(Node* node) { UNREACHABLE(); } | 2053 void InstructionSelector::VisitTrapUnless(Node* node) { |
| 2054 FlagsContinuation cont = FlagsContinuation::ForTrap( |
| 2055 kEqual, OpParameter<Runtime::FunctionId>(node->op()), node->InputAt(1)); |
| 2056 VisitWordCompareZero(this, node, node->InputAt(0), &cont); |
| 2057 } |
2030 | 2058 |
2031 void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) { | 2059 void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) { |
2032 ArmOperandGenerator g(this); | 2060 ArmOperandGenerator g(this); |
2033 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); | 2061 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); |
2034 | 2062 |
2035 // Emit either ArchTableSwitch or ArchLookupSwitch. | 2063 // Emit either ArchTableSwitch or ArchLookupSwitch. |
2036 size_t table_space_cost = 4 + sw.value_range; | 2064 size_t table_space_cost = 4 + sw.value_range; |
2037 size_t table_time_cost = 3; | 2065 size_t table_time_cost = 3; |
2038 size_t lookup_space_cost = 3 + 2 * sw.case_count; | 2066 size_t lookup_space_cost = 3 + 2 * sw.case_count; |
2039 size_t lookup_time_cost = sw.case_count; | 2067 size_t lookup_time_cost = sw.case_count; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2291 Vector<MachineType> req_aligned = Vector<MachineType>::New(2); | 2319 Vector<MachineType> req_aligned = Vector<MachineType>::New(2); |
2292 req_aligned[0] = MachineType::Float32(); | 2320 req_aligned[0] = MachineType::Float32(); |
2293 req_aligned[1] = MachineType::Float64(); | 2321 req_aligned[1] = MachineType::Float64(); |
2294 return MachineOperatorBuilder::AlignmentRequirements:: | 2322 return MachineOperatorBuilder::AlignmentRequirements:: |
2295 SomeUnalignedAccessUnsupported(req_aligned, req_aligned); | 2323 SomeUnalignedAccessUnsupported(req_aligned, req_aligned); |
2296 } | 2324 } |
2297 | 2325 |
2298 } // namespace compiler | 2326 } // namespace compiler |
2299 } // namespace internal | 2327 } // namespace internal |
2300 } // namespace v8 | 2328 } // namespace v8 |
OLD | NEW |