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 "src/base/adapters.h" | 5 #include "src/base/adapters.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 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 } | 982 } |
983 } | 983 } |
984 } | 984 } |
985 | 985 |
986 | 986 |
987 bool InstructionSelector::IsTailCallAddressImmediate() { return true; } | 987 bool InstructionSelector::IsTailCallAddressImmediate() { return true; } |
988 | 988 |
989 | 989 |
990 namespace { | 990 namespace { |
991 | 991 |
| 992 void VisitCompareWithMemoryOperand(InstructionSelector* selector, |
| 993 InstructionCode opcode, Node* left, |
| 994 InstructionOperand right, |
| 995 FlagsContinuation* cont) { |
| 996 DCHECK(left->opcode() == IrOpcode::kLoad); |
| 997 IA32OperandGenerator g(selector); |
| 998 size_t input_count = 0; |
| 999 InstructionOperand inputs[6]; |
| 1000 AddressingMode addressing_mode = |
| 1001 g.GetEffectiveAddressMemoryOperand(left, inputs, &input_count); |
| 1002 opcode |= AddressingModeField::encode(addressing_mode); |
| 1003 opcode = cont->Encode(opcode); |
| 1004 inputs[input_count++] = right; |
| 1005 |
| 1006 if (cont->IsBranch()) { |
| 1007 inputs[input_count++] = g.Label(cont->true_block()); |
| 1008 inputs[input_count++] = g.Label(cont->false_block()); |
| 1009 selector->Emit(opcode, 0, nullptr, input_count, inputs); |
| 1010 } else { |
| 1011 DCHECK(cont->IsSet()); |
| 1012 InstructionOperand output = g.DefineAsRegister(cont->result()); |
| 1013 selector->Emit(opcode, 1, &output, input_count, inputs); |
| 1014 } |
| 1015 } |
| 1016 |
| 1017 // Determines if {input} of {node} can be replaced by a memory operand. |
| 1018 bool CanUseMemoryOperand(InstructionSelector* selector, InstructionCode opcode, |
| 1019 Node* node, Node* input) { |
| 1020 if (input->opcode() != IrOpcode::kLoad || !selector->CanCover(node, input)) { |
| 1021 return false; |
| 1022 } |
| 1023 MachineRepresentation load_representation = |
| 1024 LoadRepresentationOf(input->op()).representation(); |
| 1025 if (load_representation == MachineRepresentation::kWord32 || |
| 1026 load_representation == MachineRepresentation::kTagged) { |
| 1027 return opcode == kIA32Cmp || opcode == kIA32Test; |
| 1028 } |
| 1029 return false; |
| 1030 } |
| 1031 |
992 // Shared routine for multiple compare operations. | 1032 // Shared routine for multiple compare operations. |
993 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, | 1033 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
994 InstructionOperand left, InstructionOperand right, | 1034 InstructionOperand left, InstructionOperand right, |
995 FlagsContinuation* cont) { | 1035 FlagsContinuation* cont) { |
996 IA32OperandGenerator g(selector); | 1036 IA32OperandGenerator g(selector); |
997 if (cont->IsBranch()) { | 1037 if (cont->IsBranch()) { |
998 selector->Emit(cont->Encode(opcode), g.NoOutput(), left, right, | 1038 selector->Emit(cont->Encode(opcode), g.NoOutput(), left, right, |
999 g.Label(cont->true_block()), g.Label(cont->false_block())); | 1039 g.Label(cont->true_block()), g.Label(cont->false_block())); |
1000 } else { | 1040 } else { |
1001 DCHECK(cont->IsSet()); | 1041 DCHECK(cont->IsSet()); |
(...skipping 25 matching lines...) Expand all Loading... |
1027 | 1067 |
1028 | 1068 |
1029 // Shared routine for multiple float64 compare operations (inputs commuted). | 1069 // Shared routine for multiple float64 compare operations (inputs commuted). |
1030 void VisitFloat64Compare(InstructionSelector* selector, Node* node, | 1070 void VisitFloat64Compare(InstructionSelector* selector, Node* node, |
1031 FlagsContinuation* cont) { | 1071 FlagsContinuation* cont) { |
1032 Node* const left = node->InputAt(0); | 1072 Node* const left = node->InputAt(0); |
1033 Node* const right = node->InputAt(1); | 1073 Node* const right = node->InputAt(1); |
1034 VisitCompare(selector, kSSEFloat64Cmp, right, left, cont, false); | 1074 VisitCompare(selector, kSSEFloat64Cmp, right, left, cont, false); |
1035 } | 1075 } |
1036 | 1076 |
1037 | |
1038 // Shared routine for multiple word compare operations. | 1077 // Shared routine for multiple word compare operations. |
1039 void VisitWordCompare(InstructionSelector* selector, Node* node, | 1078 void VisitWordCompare(InstructionSelector* selector, Node* node, |
1040 InstructionCode opcode, FlagsContinuation* cont) { | 1079 InstructionCode opcode, FlagsContinuation* cont) { |
1041 IA32OperandGenerator g(selector); | 1080 IA32OperandGenerator g(selector); |
1042 Node* const left = node->InputAt(0); | 1081 Node* left = node->InputAt(0); |
1043 Node* const right = node->InputAt(1); | 1082 Node* right = node->InputAt(1); |
1044 | 1083 |
1045 // Match immediates on left or right side of comparison. | 1084 // If one of the two inputs is an immediate, make sure it's on the right. |
| 1085 if (!g.CanBeImmediate(right) && g.CanBeImmediate(left)) { |
| 1086 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
| 1087 std::swap(left, right); |
| 1088 } |
| 1089 |
| 1090 // Match immediates on right side of comparison. |
1046 if (g.CanBeImmediate(right)) { | 1091 if (g.CanBeImmediate(right)) { |
1047 VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), cont); | 1092 if (CanUseMemoryOperand(selector, opcode, node, left)) { |
1048 } else if (g.CanBeImmediate(left)) { | 1093 return VisitCompareWithMemoryOperand(selector, opcode, left, |
| 1094 g.UseImmediate(right), cont); |
| 1095 } |
| 1096 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), |
| 1097 cont); |
| 1098 } |
| 1099 |
| 1100 if (g.CanBeBetterLeftOperand(right)) { |
1049 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1101 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
1050 VisitCompare(selector, opcode, g.Use(right), g.UseImmediate(left), cont); | 1102 std::swap(left, right); |
1051 } else { | |
1052 VisitCompare(selector, opcode, left, right, cont, | |
1053 node->op()->HasProperty(Operator::kCommutative)); | |
1054 } | 1103 } |
| 1104 |
| 1105 if (CanUseMemoryOperand(selector, opcode, node, left)) { |
| 1106 return VisitCompareWithMemoryOperand(selector, opcode, left, |
| 1107 g.UseRegister(right), cont); |
| 1108 } |
| 1109 return VisitCompare(selector, opcode, left, right, cont, |
| 1110 node->op()->HasProperty(Operator::kCommutative)); |
1055 } | 1111 } |
1056 | 1112 |
1057 | |
1058 void VisitWordCompare(InstructionSelector* selector, Node* node, | 1113 void VisitWordCompare(InstructionSelector* selector, Node* node, |
1059 FlagsContinuation* cont) { | 1114 FlagsContinuation* cont) { |
1060 IA32OperandGenerator g(selector); | 1115 IA32OperandGenerator g(selector); |
1061 Int32BinopMatcher m(node); | 1116 Int32BinopMatcher m(node); |
1062 if (m.left().IsLoad() && m.right().IsLoadStackPointer()) { | 1117 if (m.left().IsLoad() && m.right().IsLoadStackPointer()) { |
1063 LoadMatcher<ExternalReferenceMatcher> mleft(m.left().node()); | 1118 LoadMatcher<ExternalReferenceMatcher> mleft(m.left().node()); |
1064 ExternalReference js_stack_limit = | 1119 ExternalReference js_stack_limit = |
1065 ExternalReference::address_of_stack_limit(selector->isolate()); | 1120 ExternalReference::address_of_stack_limit(selector->isolate()); |
1066 if (mleft.object().Is(js_stack_limit) && mleft.index().Is(0)) { | 1121 if (mleft.object().Is(js_stack_limit) && mleft.index().Is(0)) { |
1067 // Compare(Load(js_stack_limit), LoadStackPointer) | 1122 // Compare(Load(js_stack_limit), LoadStackPointer) |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1357 MachineOperatorBuilder::kFloat64RoundTruncate | | 1412 MachineOperatorBuilder::kFloat64RoundTruncate | |
1358 MachineOperatorBuilder::kFloat32RoundTiesEven | | 1413 MachineOperatorBuilder::kFloat32RoundTiesEven | |
1359 MachineOperatorBuilder::kFloat64RoundTiesEven; | 1414 MachineOperatorBuilder::kFloat64RoundTiesEven; |
1360 } | 1415 } |
1361 return flags; | 1416 return flags; |
1362 } | 1417 } |
1363 | 1418 |
1364 } // namespace compiler | 1419 } // namespace compiler |
1365 } // namespace internal | 1420 } // namespace internal |
1366 } // namespace v8 | 1421 } // namespace v8 |
OLD | NEW |