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

Side by Side Diff: src/compiler/arm/instruction-selector-arm.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/arm/code-generator-arm.cc ('k') | src/compiler/arm64/code-generator-arm64.cc » ('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/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 1236 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 } // namespace 1247 } // namespace
1248 1248
1249 1249
1250 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, 1250 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch,
1251 BasicBlock* fbranch) { 1251 BasicBlock* fbranch) {
1252 FlagsContinuation cont(kNotEqual, tbranch, fbranch); 1252 FlagsContinuation cont(kNotEqual, tbranch, fbranch);
1253 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont); 1253 VisitWordCompareZero(this, branch, branch->InputAt(0), &cont);
1254 } 1254 }
1255 1255
1256 1256
1257 void InstructionSelector::VisitSwitch(Node* node, BasicBlock* default_branch,
1258 BasicBlock** case_branches,
1259 int32_t* case_values, size_t case_count,
1260 int32_t min_value, int32_t max_value) {
1261 ArmOperandGenerator g(this);
1262 InstructionOperand value_operand = g.UseRegister(node->InputAt(0));
1263 InstructionOperand default_operand = g.Label(default_branch);
1264
1265 // Note that {value_range} can be 0 if {min_value} is -2^31 and {max_value}
1266 // is 2^31-1, so don't assume that it's non-zero below.
1267 size_t value_range =
1268 1u + bit_cast<uint32_t>(max_value) - bit_cast<uint32_t>(min_value);
1269
1270 // Determine whether to issue an ArchTableSwitch or an ArchLookupSwitch
1271 // instruction.
1272 size_t table_space_cost = 4 + value_range;
1273 size_t table_time_cost = 3;
1274 size_t lookup_space_cost = 3 + 2 * case_count;
1275 size_t lookup_time_cost = case_count;
1276 if (case_count > 0 &&
1277 table_space_cost + 3 * table_time_cost <=
1278 lookup_space_cost + 3 * lookup_time_cost &&
1279 min_value > std::numeric_limits<int32_t>::min()) {
1280 InstructionOperand index_operand = value_operand;
1281 if (min_value) {
1282 index_operand = g.TempRegister();
1283 Emit(kArmSub | AddressingModeField::encode(kMode_Operand2_I),
1284 index_operand, value_operand, g.TempImmediate(min_value));
1285 }
1286 size_t input_count = 2 + value_range;
1287 auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
1288 inputs[0] = index_operand;
1289 std::fill(&inputs[1], &inputs[input_count], default_operand);
1290 for (size_t index = 0; index < case_count; ++index) {
1291 size_t value = case_values[index] - min_value;
1292 BasicBlock* branch = case_branches[index];
1293 DCHECK_LE(0u, value);
1294 DCHECK_LT(value + 2, input_count);
1295 inputs[value + 2] = g.Label(branch);
1296 }
1297 Emit(kArchTableSwitch, 0, nullptr, input_count, inputs, 0, nullptr)
1298 ->MarkAsControl();
1299 return;
1300 }
1301
1302 // Generate a sequence of conditional jumps.
1303 size_t input_count = 2 + case_count * 2;
1304 auto* inputs = zone()->NewArray<InstructionOperand>(input_count);
1305 inputs[0] = value_operand;
1306 inputs[1] = default_operand;
1307 for (size_t index = 0; index < case_count; ++index) {
1308 int32_t value = case_values[index];
1309 BasicBlock* branch = case_branches[index];
1310 inputs[index * 2 + 2 + 0] = g.TempImmediate(value);
1311 inputs[index * 2 + 2 + 1] = g.Label(branch);
1312 }
1313 Emit(kArchLookupSwitch, 0, nullptr, input_count, inputs, 0, nullptr)
1314 ->MarkAsControl();
1315 }
1316
1317
1257 void InstructionSelector::VisitWord32Equal(Node* const node) { 1318 void InstructionSelector::VisitWord32Equal(Node* const node) {
1258 FlagsContinuation cont(kEqual, node); 1319 FlagsContinuation cont(kEqual, node);
1259 Int32BinopMatcher m(node); 1320 Int32BinopMatcher m(node);
1260 if (m.right().Is(0)) { 1321 if (m.right().Is(0)) {
1261 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont); 1322 return VisitWordCompareZero(this, m.node(), m.left().node(), &cont);
1262 } 1323 }
1263 VisitWordCompare(this, node, &cont); 1324 VisitWordCompare(this, node, &cont);
1264 } 1325 }
1265 1326
1266 1327
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 MachineOperatorBuilder::kFloat64Ceil | 1399 MachineOperatorBuilder::kFloat64Ceil |
1339 MachineOperatorBuilder::kFloat64RoundTruncate | 1400 MachineOperatorBuilder::kFloat64RoundTruncate |
1340 MachineOperatorBuilder::kFloat64RoundTiesAway; 1401 MachineOperatorBuilder::kFloat64RoundTiesAway;
1341 } 1402 }
1342 return flags; 1403 return flags;
1343 } 1404 }
1344 1405
1345 } // namespace compiler 1406 } // namespace compiler
1346 } // namespace internal 1407 } // namespace internal
1347 } // namespace v8 1408 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/arm/code-generator-arm.cc ('k') | src/compiler/arm64/code-generator-arm64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698