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 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1167 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, | 1167 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
1168 Node* left, Node* right, FlagsContinuation* cont, | 1168 Node* left, Node* right, FlagsContinuation* cont, |
1169 bool commutative) { | 1169 bool commutative) { |
1170 X87OperandGenerator g(selector); | 1170 X87OperandGenerator g(selector); |
1171 if (commutative && g.CanBeBetterLeftOperand(right)) { | 1171 if (commutative && g.CanBeBetterLeftOperand(right)) { |
1172 std::swap(left, right); | 1172 std::swap(left, right); |
1173 } | 1173 } |
1174 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); | 1174 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); |
1175 } | 1175 } |
1176 | 1176 |
1177 bool InferMachineRepresentation(Node* node, | |
1178 MachineRepresentation* representation) { | |
1179 if (node->opcode() == IrOpcode::kLoad) { | |
1180 *representation = LoadRepresentationOf(node->op()).representation(); | |
1181 return true; | |
1182 } | |
1183 if (node->opcode() != IrOpcode::kInt32Constant) { | |
1184 return false; | |
1185 } | |
1186 int32_t value = OpParameter<int32_t>(node->op()); | |
1187 if (is_int8(value)) { | |
1188 *representation = MachineRepresentation::kWord8; | |
1189 } else if (is_int16(value)) { | |
1190 *representation = MachineRepresentation::kWord16; | |
1191 } else { | |
1192 *representation = MachineRepresentation::kWord32; | |
1193 } | |
1194 return true; | |
1195 } | |
1196 | |
1197 // Tries to match the size of the given opcode to that of the operands, if | 1177 // Tries to match the size of the given opcode to that of the operands, if |
1198 // possible. | 1178 // possible. |
1199 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, | 1179 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, |
1200 Node* right) { | 1180 Node* right) { |
1201 if (opcode != kX87Cmp && opcode != kX87Test) { | 1181 if (opcode != kX87Cmp && opcode != kX87Test) { |
1202 return opcode; | 1182 return opcode; |
1203 } | 1183 } |
1204 // We only do this if at least one of the two operands is a load. | 1184 // Currently, if one of the two operands is not a Load, we don't know what its |
1205 // TODO(epertoso): we can probably get some size information out of phi nodes. | 1185 // machine representation is, so we bail out. |
1206 if (left->opcode() != IrOpcode::kLoad && right->opcode() != IrOpcode::kLoad) { | 1186 // TODO(epertoso): we can probably get some size information out of immediates |
| 1187 // and phi nodes. |
| 1188 if (left->opcode() != IrOpcode::kLoad || right->opcode() != IrOpcode::kLoad) { |
1207 return opcode; | 1189 return opcode; |
1208 } | 1190 } |
1209 MachineRepresentation left_representation, right_representation; | 1191 // If the load representations don't match, both operands will be |
1210 if (!InferMachineRepresentation(left, &left_representation) || | 1192 // zero/sign-extended to 32bit. |
1211 !InferMachineRepresentation(right, &right_representation)) { | 1193 LoadRepresentation left_representation = LoadRepresentationOf(left->op()); |
| 1194 if (left_representation != LoadRepresentationOf(right->op())) { |
1212 return opcode; | 1195 return opcode; |
1213 } | 1196 } |
1214 // If the representations don't match, both operands will be | 1197 switch (left_representation.representation()) { |
1215 // zero/sign-extended to 32bit. | |
1216 if (left_representation != right_representation) { | |
1217 return opcode; | |
1218 } | |
1219 switch (left_representation) { | |
1220 case MachineRepresentation::kBit: | 1198 case MachineRepresentation::kBit: |
1221 case MachineRepresentation::kWord8: | 1199 case MachineRepresentation::kWord8: |
1222 return opcode == kX87Cmp ? kX87Cmp8 : kX87Test8; | 1200 return opcode == kX87Cmp ? kX87Cmp8 : kX87Test8; |
1223 case MachineRepresentation::kWord16: | 1201 case MachineRepresentation::kWord16: |
1224 return opcode == kX87Cmp ? kX87Cmp16 : kX87Test16; | 1202 return opcode == kX87Cmp ? kX87Cmp16 : kX87Test16; |
1225 default: | 1203 default: |
1226 return opcode; | 1204 return opcode; |
1227 } | 1205 } |
1228 } | 1206 } |
1229 | 1207 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1281 // if one of the two inputs is a memory operand, make sure it's on the left. | 1259 // if one of the two inputs is a memory operand, make sure it's on the left. |
1282 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || | 1260 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || |
1283 (g.CanBeMemoryOperand(narrowed_opcode, node, right) && | 1261 (g.CanBeMemoryOperand(narrowed_opcode, node, right) && |
1284 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) { | 1262 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) { |
1285 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1263 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
1286 std::swap(left, right); | 1264 std::swap(left, right); |
1287 } | 1265 } |
1288 | 1266 |
1289 // Match immediates on right side of comparison. | 1267 // Match immediates on right side of comparison. |
1290 if (g.CanBeImmediate(right)) { | 1268 if (g.CanBeImmediate(right)) { |
1291 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { | 1269 if (g.CanBeMemoryOperand(opcode, node, left)) { |
1292 // If we're truncating the immediate (32 bits to 16 or 8), comparison | 1270 // TODO(epertoso): we should use `narrowed_opcode' here once we match |
1293 // semantics should take the signedness/unsignedness of the op into | 1271 // immediates too. |
1294 // account. | 1272 return VisitCompareWithMemoryOperand(selector, opcode, left, |
1295 if (narrowed_opcode != opcode && | |
1296 LoadRepresentationOf(left->op()).IsUnsigned()) { | |
1297 switch (cont->condition()) { | |
1298 case FlagsCondition::kSignedLessThan: | |
1299 cont->OverwriteAndNegateIfEqual(FlagsCondition::kUnsignedLessThan); | |
1300 break; | |
1301 case FlagsCondition::kSignedGreaterThan: | |
1302 cont->OverwriteAndNegateIfEqual( | |
1303 FlagsCondition::kUnsignedGreaterThan); | |
1304 break; | |
1305 case FlagsCondition::kSignedLessThanOrEqual: | |
1306 cont->OverwriteAndNegateIfEqual( | |
1307 FlagsCondition::kUnsignedLessThanOrEqual); | |
1308 break; | |
1309 case FlagsCondition::kSignedGreaterThanOrEqual: | |
1310 cont->OverwriteAndNegateIfEqual( | |
1311 FlagsCondition::kUnsignedGreaterThanOrEqual); | |
1312 break; | |
1313 default: | |
1314 break; | |
1315 } | |
1316 } | |
1317 return VisitCompareWithMemoryOperand(selector, narrowed_opcode, left, | |
1318 g.UseImmediate(right), cont); | 1273 g.UseImmediate(right), cont); |
1319 } | 1274 } |
1320 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), | 1275 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), |
1321 cont); | 1276 cont); |
1322 } | 1277 } |
1323 | 1278 |
1324 // Match memory operands on left side of comparison. | 1279 // Match memory operands on left side of comparison. |
1325 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { | 1280 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { |
1326 bool needs_byte_register = | 1281 bool needs_byte_register = |
1327 narrowed_opcode == kX87Test8 || narrowed_opcode == kX87Cmp8; | 1282 narrowed_opcode == kX87Test8 || narrowed_opcode == kX87Cmp8; |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1701 MachineOperatorBuilder::kFloat32RoundTruncate | | 1656 MachineOperatorBuilder::kFloat32RoundTruncate | |
1702 MachineOperatorBuilder::kFloat64RoundTruncate | | 1657 MachineOperatorBuilder::kFloat64RoundTruncate | |
1703 MachineOperatorBuilder::kFloat32RoundTiesEven | | 1658 MachineOperatorBuilder::kFloat32RoundTiesEven | |
1704 MachineOperatorBuilder::kFloat64RoundTiesEven; | 1659 MachineOperatorBuilder::kFloat64RoundTiesEven; |
1705 return flags; | 1660 return flags; |
1706 } | 1661 } |
1707 | 1662 |
1708 } // namespace compiler | 1663 } // namespace compiler |
1709 } // namespace internal | 1664 } // namespace internal |
1710 } // namespace v8 | 1665 } // namespace v8 |
OLD | NEW |