Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: src/compiler/ia32/instruction-selector-ia32.cc

Issue 931623002: [turbofan] Optimize certain chains of Branch into a Switch. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addrssed comments. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/ia32/code-generator-ia32.cc ('k') | src/compiler/instruction-codes.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 } // namespace 921 } // namespace
922 922
923 923
924 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, 924 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
925 BasicBlock* fbranch) { 925 BasicBlock* fbranch) {
926 FlagsContinuation cont(kNotEqual, tbranch, fbranch); 926 FlagsContinuation cont(kNotEqual, tbranch, fbranch);
927 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont); 927 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont);
928 } 928 }
929 929
930 930
931 void InstructionSelector::VisitSwitch(Node* node, BasicBlock* default_branch,
932 BasicBlock** case_branches,
933 int32_t* case_values, size_t case_count,
934 int32_t min_value, int32_t max_value) {
935 IA32OperandGenerator g(this);
936 InstructionOperand value_operand = g.UseRegister(node->InputAt(0));
937 InstructionOperand default_operand = g.Label(default_branch);
938
939 // Note that {value_range} can be 0 if {min_value} is -2^31 and {max_value}
940 // is 2^31-1, so don't assume that it's non-zero below.
941 size_t value_range =
942 1u + bit_cast<uint32_t>(max_value) - bit_cast<uint32_t>(min_value);
943
944 // Determine whether to issue an ArchTableSwitch or an ArchLookupSwitch
945 // instruction.
946 size_t table_space_cost = 4 + value_range;
947 size_t table_time_cost = 3;
948 size_t lookup_space_cost = 3 + 2 * case_count;
949 size_t lookup_time_cost = case_count;
950 if (case_count > 4 &&
951 table_space_cost + 3 * table_time_cost <=
952 lookup_space_cost + 3 * lookup_time_cost &&
953 min_value > std::numeric_limits<int32_t>::min()) {
954 InstructionOperand index_operand = value_operand;
955 if (min_value) {
956 index_operand = g.TempRegister();
957 Emit(kIA32Lea | AddressingModeField::encode(kMode_MRI), index_operand,
958 value_operand, g.TempImmediate(-min_value));
959 }
960 size_t input_count = 2 + value_range;
961 auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
962 inputs[0] = index_operand;
963 std::fill(&inputs[1], &inputs[input_count], default_operand);
964 for (size_t index = 0; index < case_count; ++index) {
965 size_t value = case_values[index] - min_value;
966 BasicBlock* branch = case_branches[index];
967 DCHECK_LE(0u, value);
968 DCHECK_LT(value + 2, input_count);
969 inputs[value + 2] = g.Label(branch);
970 }
971 Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr)
972 ->MarkAsControl();
973 return;
974 }
975
976 // Generate a sequence of conditional jumps.
977 size_t input_count = 2 + case_count * 2;
978 auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
979 inputs[0] = value_operand;
980 inputs[1] = default_operand;
981 for (size_t index = 0; index < case_count; ++index) {
982 int32_t value = case_values[index];
983 BasicBlock* branch = case_branches[index];
984 inputs[index * 2 + 2 + 0] = g.TempImmediate(value);
985 inputs[index * 2 + 2 + 1] = g.Label(branch);
986 }
987 Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr)
988 ->MarkAsControl();
989 }
990
991
931 void InstructionSelector::VisitWord32Equal(Node* const node) { 992 void InstructionSelector::VisitWord32Equal(Node* const node) {
932 FlagsContinuation cont(kEqual, node); 993 FlagsContinuation cont(kEqual, node);
933 Int32BinopMatcher m(node); 994 Int32BinopMatcher m(node);
934 if (m.right().Is(0)) { 995 if (m.right().Is(0)) {
935 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont); 996 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont);
936 } 997 }
937 VisitWordCompare(this, node, &cont); 998 VisitWordCompare(this, node, &cont);
938 } 999 }
939 1000
940 1001
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 MachineOperatorBuilder::kFloat64Ceil | 1069 MachineOperatorBuilder::kFloat64Ceil |
1009 MachineOperatorBuilder::kFloat64RoundTruncate | 1070 MachineOperatorBuilder::kFloat64RoundTruncate |
1010 MachineOperatorBuilder::kWord32ShiftIsSafe; 1071 MachineOperatorBuilder::kWord32ShiftIsSafe;
1011 } 1072 }
1012 return MachineOperatorBuilder::Flag::kNoFlags; 1073 return MachineOperatorBuilder::Flag::kNoFlags;
1013 } 1074 }
1014 1075
1015 } // namespace compiler 1076 } // namespace compiler
1016 } // namespace internal 1077 } // namespace internal
1017 } // namespace v8 1078 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/ia32/code-generator-ia32.cc ('k') | src/compiler/instruction-codes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698