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 25 matching lines...) Expand all Loading... |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 bool CanBeMemoryOperand(InstructionCode opcode, Node* node, Node* input) { | 39 bool CanBeMemoryOperand(InstructionCode opcode, Node* node, Node* input) { |
40 if (input->opcode() != IrOpcode::kLoad || | 40 if (input->opcode() != IrOpcode::kLoad || |
41 !selector()->CanCover(node, input)) { | 41 !selector()->CanCover(node, input)) { |
42 return false; | 42 return false; |
43 } | 43 } |
44 MachineRepresentation rep = | 44 MachineRepresentation rep = |
45 LoadRepresentationOf(input->op()).representation(); | 45 LoadRepresentationOf(input->op()).representation(); |
46 if (rep == MachineRepresentation::kWord64 || | 46 switch (opcode) { |
47 rep == MachineRepresentation::kTagged) { | 47 case kX64Cmp: |
48 return opcode == kX64Cmp || opcode == kX64Test; | 48 case kX64Test: |
49 } else if (rep == MachineRepresentation::kWord32) { | 49 return rep == MachineRepresentation::kWord64 || |
50 return opcode == kX64Cmp32 || opcode == kX64Test32; | 50 rep == MachineRepresentation::kTagged; |
| 51 case kX64Cmp32: |
| 52 case kX64Test32: |
| 53 return rep == MachineRepresentation::kWord32; |
| 54 case kX64Cmp16: |
| 55 case kX64Test16: |
| 56 return rep == MachineRepresentation::kWord16; |
| 57 case kX64Cmp8: |
| 58 case kX64Test8: |
| 59 return rep == MachineRepresentation::kWord8; |
| 60 default: |
| 61 break; |
51 } | 62 } |
52 return false; | 63 return false; |
53 } | 64 } |
54 | 65 |
55 AddressingMode GenerateMemoryOperandInputs(Node* index, int scale_exponent, | 66 AddressingMode GenerateMemoryOperandInputs(Node* index, int scale_exponent, |
56 Node* base, Node* displacement, | 67 Node* base, Node* displacement, |
57 InstructionOperand inputs[], | 68 InstructionOperand inputs[], |
58 size_t* input_count) { | 69 size_t* input_count) { |
59 AddressingMode mode = kMode_MRI; | 70 AddressingMode mode = kMode_MRI; |
60 if (base != nullptr) { | 71 if (base != nullptr) { |
(...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1409 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, | 1420 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
1410 Node* left, Node* right, FlagsContinuation* cont, | 1421 Node* left, Node* right, FlagsContinuation* cont, |
1411 bool commutative) { | 1422 bool commutative) { |
1412 X64OperandGenerator g(selector); | 1423 X64OperandGenerator g(selector); |
1413 if (commutative && g.CanBeBetterLeftOperand(right)) { | 1424 if (commutative && g.CanBeBetterLeftOperand(right)) { |
1414 std::swap(left, right); | 1425 std::swap(left, right); |
1415 } | 1426 } |
1416 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); | 1427 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); |
1417 } | 1428 } |
1418 | 1429 |
| 1430 // Tries to match the size of the given opcode to that of the operands, if |
| 1431 // possible. |
| 1432 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, |
| 1433 Node* right) { |
| 1434 if (opcode != kX64Cmp32 && opcode != kX64Test32) { |
| 1435 return opcode; |
| 1436 } |
| 1437 // Currently, if one of the two operands is not a Load, we don't know what its |
| 1438 // machine representation is, so we bail out. |
| 1439 // TODO(epertoso): we can probably get some size information out of immediates |
| 1440 // and phi nodes. |
| 1441 if (left->opcode() != IrOpcode::kLoad || right->opcode() != IrOpcode::kLoad) { |
| 1442 return opcode; |
| 1443 } |
| 1444 // If the load representations don't match, both operands will be |
| 1445 // zero/sign-extended to 32bit. |
| 1446 LoadRepresentation left_representation = LoadRepresentationOf(left->op()); |
| 1447 if (left_representation != LoadRepresentationOf(right->op())) { |
| 1448 return opcode; |
| 1449 } |
| 1450 switch (left_representation.representation()) { |
| 1451 case MachineRepresentation::kBit: |
| 1452 case MachineRepresentation::kWord8: |
| 1453 return opcode == kX64Cmp32 ? kX64Cmp8 : kX64Test8; |
| 1454 case MachineRepresentation::kWord16: |
| 1455 return opcode == kX64Cmp32 ? kX64Cmp16 : kX64Test16; |
| 1456 default: |
| 1457 return opcode; |
| 1458 } |
| 1459 } |
| 1460 |
1419 // Shared routine for multiple word compare operations. | 1461 // Shared routine for multiple word compare operations. |
1420 void VisitWordCompare(InstructionSelector* selector, Node* node, | 1462 void VisitWordCompare(InstructionSelector* selector, Node* node, |
1421 InstructionCode opcode, FlagsContinuation* cont) { | 1463 InstructionCode opcode, FlagsContinuation* cont) { |
1422 X64OperandGenerator g(selector); | 1464 X64OperandGenerator g(selector); |
1423 Node* left = node->InputAt(0); | 1465 Node* left = node->InputAt(0); |
1424 Node* right = node->InputAt(1); | 1466 Node* right = node->InputAt(1); |
1425 | 1467 |
| 1468 opcode = TryNarrowOpcodeSize(opcode, left, right); |
| 1469 |
1426 // If one of the two inputs is an immediate, make sure it's on the right, or | 1470 // If one of the two inputs is an immediate, make sure it's on the right, or |
1427 // if one of the two inputs is a memory operand, make sure it's on the left. | 1471 // if one of the two inputs is a memory operand, make sure it's on the left. |
1428 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || | 1472 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || |
1429 (g.CanBeMemoryOperand(opcode, node, right) && | 1473 (g.CanBeMemoryOperand(opcode, node, right) && |
1430 !g.CanBeMemoryOperand(opcode, node, left))) { | 1474 !g.CanBeMemoryOperand(opcode, node, left))) { |
1431 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1475 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
1432 std::swap(left, right); | 1476 std::swap(left, right); |
1433 } | 1477 } |
1434 | 1478 |
1435 // Match immediates on right side of comparison. | 1479 // Match immediates on right side of comparison. |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1927 MachineOperatorBuilder::kFloat64RoundTruncate | | 1971 MachineOperatorBuilder::kFloat64RoundTruncate | |
1928 MachineOperatorBuilder::kFloat32RoundTiesEven | | 1972 MachineOperatorBuilder::kFloat32RoundTiesEven | |
1929 MachineOperatorBuilder::kFloat64RoundTiesEven; | 1973 MachineOperatorBuilder::kFloat64RoundTiesEven; |
1930 } | 1974 } |
1931 return flags; | 1975 return flags; |
1932 } | 1976 } |
1933 | 1977 |
1934 } // namespace compiler | 1978 } // namespace compiler |
1935 } // namespace internal | 1979 } // namespace internal |
1936 } // namespace v8 | 1980 } // namespace v8 |
OLD | NEW |