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 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
948 } | 948 } |
949 | 949 |
950 | 950 |
951 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, | 951 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, |
952 BasicBlock* fbranch) { | 952 BasicBlock* fbranch) { |
953 FlagsContinuation cont(kNotEqual, tbranch, fbranch); | 953 FlagsContinuation cont(kNotEqual, tbranch, fbranch); |
954 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont); | 954 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont); |
955 } | 955 } |
956 | 956 |
957 | 957 |
958 void InstructionSelector::VisitSwitch(Node* node, BasicBlock* default_branch, | 958 void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) { |
959 BasicBlock** case_branches, | |
960 int32_t* case_values, size_t case_count, | |
961 int32_t min_value, int32_t max_value) { | |
962 Mips64OperandGenerator g(this); | 959 Mips64OperandGenerator g(this); |
963 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); | 960 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); |
964 InstructionOperand default_operand = g.Label(default_branch); | |
965 | 961 |
966 // Note that {value_range} can be 0 if {min_value} is -2^31 and {max_value} | 962 // Emit either ArchTableSwitch or ArchLookupSwitch. |
967 // is 2^31-1, so don't assume that it's non-zero below. | 963 size_t table_space_cost = 10 + 2 * sw.value_range; |
968 size_t value_range = | |
969 1u + bit_cast<uint32_t>(max_value) - bit_cast<uint32_t>(min_value); | |
970 | |
971 // Determine whether to issue an ArchTableSwitch or an ArchLookupSwitch | |
972 // instruction. | |
973 size_t table_space_cost = 10 + 2 * value_range; | |
974 size_t table_time_cost = 3; | 964 size_t table_time_cost = 3; |
975 size_t lookup_space_cost = 2 + 2 * case_count; | 965 size_t lookup_space_cost = 2 + 2 * sw.case_count; |
976 size_t lookup_time_cost = case_count; | 966 size_t lookup_time_cost = sw.case_count; |
977 if (case_count > 0 && | 967 if (sw.case_count > 0 && |
978 table_space_cost + 3 * table_time_cost <= | 968 table_space_cost + 3 * table_time_cost <= |
979 lookup_space_cost + 3 * lookup_time_cost && | 969 lookup_space_cost + 3 * lookup_time_cost && |
980 min_value > std::numeric_limits<int32_t>::min()) { | 970 sw.min_value > std::numeric_limits<int32_t>::min()) { |
981 InstructionOperand index_operand = value_operand; | 971 InstructionOperand index_operand = value_operand; |
982 if (min_value) { | 972 if (sw.min_value) { |
983 index_operand = g.TempRegister(); | 973 index_operand = g.TempRegister(); |
984 Emit(kMips64Sub, index_operand, value_operand, | 974 Emit(kMips64Sub, index_operand, value_operand, |
985 g.TempImmediate(min_value)); | 975 g.TempImmediate(sw.min_value)); |
986 } | 976 } |
987 size_t input_count = 2 + value_range; | 977 // Generate a table lookup. |
988 auto* inputs = zone()->NewArray<InstructionOperand>(input_count); | 978 return EmitTableSwitch(sw, index_operand); |
989 inputs[0] = index_operand; | |
990 std::fill(&inputs[1], &inputs[input_count], default_operand); | |
991 for (size_t index = 0; index < case_count; ++index) { | |
992 size_t value = case_values[index] - min_value; | |
993 BasicBlock* branch = case_branches[index]; | |
994 DCHECK_LE(0u, value); | |
995 DCHECK_LT(value + 2, input_count); | |
996 inputs[value + 2] = g.Label(branch); | |
997 } | |
998 Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr); | |
999 return; | |
1000 } | 979 } |
1001 | 980 |
1002 // Generate a sequence of conditional jumps. | 981 // Generate a sequence of conditional jumps. |
1003 size_t input_count = 2 + case_count * 2; | 982 return EmitLookupSwitch(sw, value_operand); |
1004 auto* inputs = zone()->NewArray<InstructionOperand>(input_count); | |
1005 inputs[0] = value_operand; | |
1006 inputs[1] = default_operand; | |
1007 for (size_t index = 0; index < case_count; ++index) { | |
1008 int32_t value = case_values[index]; | |
1009 BasicBlock* branch = case_branches[index]; | |
1010 inputs[index * 2 + 2 + 0] = g.TempImmediate(value); | |
1011 inputs[index * 2 + 2 + 1] = g.Label(branch); | |
1012 } | |
1013 Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr); | |
1014 } | 983 } |
1015 | 984 |
1016 | 985 |
1017 void InstructionSelector::VisitWord32Equal(Node* const node) { | 986 void InstructionSelector::VisitWord32Equal(Node* const node) { |
1018 FlagsContinuation cont(kEqual, node); | 987 FlagsContinuation cont(kEqual, node); |
1019 Int32BinopMatcher m(node); | 988 Int32BinopMatcher m(node); |
1020 if (m.right().Is(0)) { | 989 if (m.right().Is(0)) { |
1021 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont); | 990 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont); |
1022 } | 991 } |
1023 | 992 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1151 // static | 1120 // static |
1152 MachineOperatorBuilder::Flags | 1121 MachineOperatorBuilder::Flags |
1153 InstructionSelector::SupportedMachineOperatorFlags() { | 1122 InstructionSelector::SupportedMachineOperatorFlags() { |
1154 return MachineOperatorBuilder::kFloat64RoundDown | | 1123 return MachineOperatorBuilder::kFloat64RoundDown | |
1155 MachineOperatorBuilder::kFloat64RoundTruncate; | 1124 MachineOperatorBuilder::kFloat64RoundTruncate; |
1156 } | 1125 } |
1157 | 1126 |
1158 } // namespace compiler | 1127 } // namespace compiler |
1159 } // namespace internal | 1128 } // namespace internal |
1160 } // namespace v8 | 1129 } // namespace v8 |
OLD | NEW |