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/instruction-selector-impl.h" | 8 #include "src/compiler/instruction-selector-impl.h" |
9 #include "src/compiler/node-matchers.h" | 9 #include "src/compiler/node-matchers.h" |
10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 } | 1331 } |
1332 } | 1332 } |
1333 } | 1333 } |
1334 | 1334 |
1335 | 1335 |
1336 bool InstructionSelector::IsTailCallAddressImmediate() { return true; } | 1336 bool InstructionSelector::IsTailCallAddressImmediate() { return true; } |
1337 | 1337 |
1338 | 1338 |
1339 namespace { | 1339 namespace { |
1340 | 1340 |
| 1341 void VisitCompareWithMemoryOperand(InstructionSelector* selector, |
| 1342 InstructionCode opcode, Node* left, |
| 1343 InstructionOperand right, |
| 1344 FlagsContinuation* cont) { |
| 1345 DCHECK(left->opcode() == IrOpcode::kLoad); |
| 1346 X64OperandGenerator g(selector); |
| 1347 size_t input_count = 0; |
| 1348 InstructionOperand inputs[6]; |
| 1349 AddressingMode addressing_mode = |
| 1350 g.GetEffectiveAddressMemoryOperand(left, inputs, &input_count); |
| 1351 opcode |= AddressingModeField::encode(addressing_mode); |
| 1352 opcode = cont->Encode(opcode); |
| 1353 inputs[input_count++] = right; |
| 1354 |
| 1355 if (cont->IsBranch()) { |
| 1356 inputs[input_count++] = g.Label(cont->true_block()); |
| 1357 inputs[input_count++] = g.Label(cont->false_block()); |
| 1358 selector->Emit(opcode, 0, nullptr, input_count, inputs); |
| 1359 } else { |
| 1360 DCHECK(cont->IsSet()); |
| 1361 InstructionOperand output = g.DefineAsRegister(cont->result()); |
| 1362 selector->Emit(opcode, 1, &output, input_count, inputs); |
| 1363 } |
| 1364 } |
| 1365 |
| 1366 // Determines if {input} of {node} can be replaced by a memory operand. |
| 1367 bool CanUseMemoryOperand(InstructionSelector* selector, InstructionCode opcode, |
| 1368 Node* node, Node* input) { |
| 1369 if (input->opcode() != IrOpcode::kLoad || !selector->CanCover(node, input)) { |
| 1370 return false; |
| 1371 } |
| 1372 MachineRepresentation rep = |
| 1373 LoadRepresentationOf(input->op()).representation(); |
| 1374 if (rep == MachineRepresentation::kWord64 || |
| 1375 rep == MachineRepresentation::kTagged) { |
| 1376 return opcode == kX64Cmp || opcode == kX64Test; |
| 1377 } else if (rep == MachineRepresentation::kWord32) { |
| 1378 return opcode == kX64Cmp32 || opcode == kX64Test32; |
| 1379 } |
| 1380 return false; |
| 1381 } |
| 1382 |
1341 // Shared routine for multiple compare operations. | 1383 // Shared routine for multiple compare operations. |
1342 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, | 1384 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
1343 InstructionOperand left, InstructionOperand right, | 1385 InstructionOperand left, InstructionOperand right, |
1344 FlagsContinuation* cont) { | 1386 FlagsContinuation* cont) { |
1345 X64OperandGenerator g(selector); | 1387 X64OperandGenerator g(selector); |
1346 opcode = cont->Encode(opcode); | 1388 opcode = cont->Encode(opcode); |
1347 if (cont->IsBranch()) { | 1389 if (cont->IsBranch()) { |
1348 selector->Emit(opcode, g.NoOutput(), left, right, | 1390 selector->Emit(opcode, g.NoOutput(), left, right, |
1349 g.Label(cont->true_block()), g.Label(cont->false_block())); | 1391 g.Label(cont->true_block()), g.Label(cont->false_block())); |
1350 } else { | 1392 } else { |
1351 DCHECK(cont->IsSet()); | 1393 DCHECK(cont->IsSet()); |
1352 selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right); | 1394 selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right); |
1353 } | 1395 } |
1354 } | 1396 } |
1355 | 1397 |
1356 | 1398 |
1357 // Shared routine for multiple compare operations. | 1399 // Shared routine for multiple compare operations. |
1358 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, | 1400 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
1359 Node* left, Node* right, FlagsContinuation* cont, | 1401 Node* left, Node* right, FlagsContinuation* cont, |
1360 bool commutative) { | 1402 bool commutative) { |
1361 X64OperandGenerator g(selector); | 1403 X64OperandGenerator g(selector); |
1362 if (commutative && g.CanBeBetterLeftOperand(right)) { | 1404 if (commutative && g.CanBeBetterLeftOperand(right)) { |
1363 std::swap(left, right); | 1405 std::swap(left, right); |
1364 } | 1406 } |
1365 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); | 1407 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); |
1366 } | 1408 } |
1367 | 1409 |
1368 | |
1369 // Shared routine for multiple word compare operations. | 1410 // Shared routine for multiple word compare operations. |
1370 void VisitWordCompare(InstructionSelector* selector, Node* node, | 1411 void VisitWordCompare(InstructionSelector* selector, Node* node, |
1371 InstructionCode opcode, FlagsContinuation* cont) { | 1412 InstructionCode opcode, FlagsContinuation* cont) { |
1372 X64OperandGenerator g(selector); | 1413 X64OperandGenerator g(selector); |
1373 Node* const left = node->InputAt(0); | 1414 Node* left = node->InputAt(0); |
1374 Node* const right = node->InputAt(1); | 1415 Node* right = node->InputAt(1); |
1375 | 1416 |
1376 // Match immediates on left or right side of comparison. | 1417 // If one of the two inputs is an immediate, make sure it's on the right. |
| 1418 if (!g.CanBeImmediate(right) && g.CanBeImmediate(left)) { |
| 1419 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
| 1420 std::swap(left, right); |
| 1421 } |
| 1422 |
| 1423 // Match immediates on right side of comparison. |
1377 if (g.CanBeImmediate(right)) { | 1424 if (g.CanBeImmediate(right)) { |
1378 VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), cont); | 1425 if (CanUseMemoryOperand(selector, opcode, node, left)) { |
1379 } else if (g.CanBeImmediate(left)) { | 1426 return VisitCompareWithMemoryOperand(selector, opcode, left, |
| 1427 g.UseImmediate(right), cont); |
| 1428 } |
| 1429 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), |
| 1430 cont); |
| 1431 } |
| 1432 |
| 1433 if (g.CanBeBetterLeftOperand(right)) { |
1380 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1434 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
1381 VisitCompare(selector, opcode, g.Use(right), g.UseImmediate(left), cont); | 1435 std::swap(left, right); |
1382 } else { | |
1383 VisitCompare(selector, opcode, left, right, cont, | |
1384 node->op()->HasProperty(Operator::kCommutative)); | |
1385 } | 1436 } |
| 1437 |
| 1438 if (CanUseMemoryOperand(selector, opcode, node, left)) { |
| 1439 return VisitCompareWithMemoryOperand(selector, opcode, left, |
| 1440 g.UseRegister(right), cont); |
| 1441 } |
| 1442 return VisitCompare(selector, opcode, left, right, cont, |
| 1443 node->op()->HasProperty(Operator::kCommutative)); |
1386 } | 1444 } |
1387 | 1445 |
1388 | |
1389 // Shared routine for 64-bit word comparison operations. | 1446 // Shared routine for 64-bit word comparison operations. |
1390 void VisitWord64Compare(InstructionSelector* selector, Node* node, | 1447 void VisitWord64Compare(InstructionSelector* selector, Node* node, |
1391 FlagsContinuation* cont) { | 1448 FlagsContinuation* cont) { |
1392 X64OperandGenerator g(selector); | 1449 X64OperandGenerator g(selector); |
1393 Int64BinopMatcher m(node); | 1450 Int64BinopMatcher m(node); |
1394 if (m.left().IsLoad() && m.right().IsLoadStackPointer()) { | 1451 if (m.left().IsLoad() && m.right().IsLoadStackPointer()) { |
1395 LoadMatcher<ExternalReferenceMatcher> mleft(m.left().node()); | 1452 LoadMatcher<ExternalReferenceMatcher> mleft(m.left().node()); |
1396 ExternalReference js_stack_limit = | 1453 ExternalReference js_stack_limit = |
1397 ExternalReference::address_of_stack_limit(selector->isolate()); | 1454 ExternalReference::address_of_stack_limit(selector->isolate()); |
1398 if (mleft.object().Is(js_stack_limit) && mleft.index().Is(0)) { | 1455 if (mleft.object().Is(js_stack_limit) && mleft.index().Is(0)) { |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1836 MachineOperatorBuilder::kFloat64RoundTruncate | | 1893 MachineOperatorBuilder::kFloat64RoundTruncate | |
1837 MachineOperatorBuilder::kFloat32RoundTiesEven | | 1894 MachineOperatorBuilder::kFloat32RoundTiesEven | |
1838 MachineOperatorBuilder::kFloat64RoundTiesEven; | 1895 MachineOperatorBuilder::kFloat64RoundTiesEven; |
1839 } | 1896 } |
1840 return flags; | 1897 return flags; |
1841 } | 1898 } |
1842 | 1899 |
1843 } // namespace compiler | 1900 } // namespace compiler |
1844 } // namespace internal | 1901 } // namespace internal |
1845 } // namespace v8 | 1902 } // namespace v8 |
OLD | NEW |