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 if (left->opcode() != IrOpcode::kLoad || right->opcode() != IrOpcode::kLoad) { | |
Jarin
2016/03/14 14:54:08
Could you add a comment explaining why you only co
epertoso
2016/03/15 14:38:46
Done.
| |
1438 return opcode; | |
1439 } | |
1440 // If the load representations don't match, both operands will be | |
1441 // zero/sign-extended to 32bit. | |
1442 LoadRepresentation left_representation = LoadRepresentationOf(left->op()); | |
1443 if (left_representation != LoadRepresentationOf(right->op())) { | |
1444 return opcode; | |
1445 } | |
1446 switch (left_representation.representation()) { | |
1447 case MachineRepresentation::kBit: | |
1448 case MachineRepresentation::kWord8: | |
1449 return opcode == kX64Cmp32 ? kX64Cmp8 : kX64Test8; | |
1450 case MachineRepresentation::kWord16: | |
1451 return opcode == kX64Cmp32 ? kX64Cmp16 : kX64Test16; | |
1452 default: | |
1453 return opcode; | |
1454 } | |
1455 } | |
1456 | |
1419 // Shared routine for multiple word compare operations. | 1457 // Shared routine for multiple word compare operations. |
1420 void VisitWordCompare(InstructionSelector* selector, Node* node, | 1458 void VisitWordCompare(InstructionSelector* selector, Node* node, |
1421 InstructionCode opcode, FlagsContinuation* cont) { | 1459 InstructionCode opcode, FlagsContinuation* cont) { |
1422 X64OperandGenerator g(selector); | 1460 X64OperandGenerator g(selector); |
1423 Node* left = node->InputAt(0); | 1461 Node* left = node->InputAt(0); |
1424 Node* right = node->InputAt(1); | 1462 Node* right = node->InputAt(1); |
1425 | 1463 |
1464 opcode = TryNarrowOpcodeSize(opcode, left, right); | |
1465 | |
1426 // If one of the two inputs is an immediate, make sure it's on the right, or | 1466 // 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. | 1467 // 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)) || | 1468 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || |
1429 (g.CanBeMemoryOperand(opcode, node, right) && | 1469 (g.CanBeMemoryOperand(opcode, node, right) && |
1430 !g.CanBeMemoryOperand(opcode, node, left))) { | 1470 !g.CanBeMemoryOperand(opcode, node, left))) { |
1431 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1471 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
1432 std::swap(left, right); | 1472 std::swap(left, right); |
1433 } | 1473 } |
1434 | 1474 |
1435 // Match immediates on right side of comparison. | 1475 // Match immediates on right side of comparison. |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1927 MachineOperatorBuilder::kFloat64RoundTruncate | | 1967 MachineOperatorBuilder::kFloat64RoundTruncate | |
1928 MachineOperatorBuilder::kFloat32RoundTiesEven | | 1968 MachineOperatorBuilder::kFloat32RoundTiesEven | |
1929 MachineOperatorBuilder::kFloat64RoundTiesEven; | 1969 MachineOperatorBuilder::kFloat64RoundTiesEven; |
1930 } | 1970 } |
1931 return flags; | 1971 return flags; |
1932 } | 1972 } |
1933 | 1973 |
1934 } // namespace compiler | 1974 } // namespace compiler |
1935 } // namespace internal | 1975 } // namespace internal |
1936 } // namespace v8 | 1976 } // namespace v8 |
OLD | NEW |