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 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1180 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, | 1180 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
1181 Node* left, Node* right, FlagsContinuation* cont, | 1181 Node* left, Node* right, FlagsContinuation* cont, |
1182 bool commutative) { | 1182 bool commutative) { |
1183 X87OperandGenerator g(selector); | 1183 X87OperandGenerator g(selector); |
1184 if (commutative && g.CanBeBetterLeftOperand(right)) { | 1184 if (commutative && g.CanBeBetterLeftOperand(right)) { |
1185 std::swap(left, right); | 1185 std::swap(left, right); |
1186 } | 1186 } |
1187 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); | 1187 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); |
1188 } | 1188 } |
1189 | 1189 |
1190 bool InferMachineRepresentation(Node* node, | |
1191 MachineRepresentation* representation) { | |
1192 if (node->opcode() == IrOpcode::kLoad) { | |
1193 *representation = LoadRepresentationOf(node->op()).representation(); | |
1194 return true; | |
1195 } | |
1196 if (node->opcode() != IrOpcode::kInt32Constant) { | |
1197 return false; | |
1198 } | |
1199 int32_t value = OpParameter<int32_t>(node->op()); | |
1200 if (is_int8(value)) { | |
1201 *representation = MachineRepresentation::kWord8; | |
1202 } else if (is_int16(value)) { | |
1203 *representation = MachineRepresentation::kWord16; | |
1204 } else { | |
1205 *representation = MachineRepresentation::kWord32; | |
1206 } | |
1207 return true; | |
1208 } | |
1209 | |
1210 // Tries to match the size of the given opcode to that of the operands, if | 1190 // Tries to match the size of the given opcode to that of the operands, if |
1211 // possible. | 1191 // possible. |
1212 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, | 1192 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, |
1213 Node* right) { | 1193 Node* right) { |
1214 if (opcode != kX87Cmp && opcode != kX87Test) { | 1194 if (opcode != kX87Cmp && opcode != kX87Test) { |
1215 return opcode; | 1195 return opcode; |
1216 } | 1196 } |
1217 // We only do this if at least one of the two operands is a load. | 1197 // Currently, if one of the two operands is not a Load, we don't know what its |
1218 // TODO(epertoso): we can probably get some size information out of phi nodes. | 1198 // machine representation is, so we bail out. |
1219 if (left->opcode() != IrOpcode::kLoad && right->opcode() != IrOpcode::kLoad) { | 1199 // TODO(epertoso): we can probably get some size information out of immediates |
| 1200 // and phi nodes. |
| 1201 if (left->opcode() != IrOpcode::kLoad || right->opcode() != IrOpcode::kLoad) { |
1220 return opcode; | 1202 return opcode; |
1221 } | 1203 } |
1222 MachineRepresentation left_representation, right_representation; | 1204 // If the load representations don't match, both operands will be |
1223 if (!InferMachineRepresentation(left, &left_representation) || | 1205 // zero/sign-extended to 32bit. |
1224 !InferMachineRepresentation(right, &right_representation)) { | 1206 LoadRepresentation left_representation = LoadRepresentationOf(left->op()); |
| 1207 if (left_representation != LoadRepresentationOf(right->op())) { |
1225 return opcode; | 1208 return opcode; |
1226 } | 1209 } |
1227 // If the representations don't match, both operands will be | 1210 switch (left_representation.representation()) { |
1228 // zero/sign-extended to 32bit. | |
1229 if (left_representation != right_representation) { | |
1230 return opcode; | |
1231 } | |
1232 switch (left_representation) { | |
1233 case MachineRepresentation::kBit: | 1211 case MachineRepresentation::kBit: |
1234 case MachineRepresentation::kWord8: | 1212 case MachineRepresentation::kWord8: |
1235 return opcode == kX87Cmp ? kX87Cmp8 : kX87Test8; | 1213 return opcode == kX87Cmp ? kX87Cmp8 : kX87Test8; |
1236 case MachineRepresentation::kWord16: | 1214 case MachineRepresentation::kWord16: |
1237 return opcode == kX87Cmp ? kX87Cmp16 : kX87Test16; | 1215 return opcode == kX87Cmp ? kX87Cmp16 : kX87Test16; |
1238 default: | 1216 default: |
1239 return opcode; | 1217 return opcode; |
1240 } | 1218 } |
1241 } | 1219 } |
1242 | 1220 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 // if one of the two inputs is a memory operand, make sure it's on the left. | 1272 // if one of the two inputs is a memory operand, make sure it's on the left. |
1295 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || | 1273 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || |
1296 (g.CanBeMemoryOperand(narrowed_opcode, node, right) && | 1274 (g.CanBeMemoryOperand(narrowed_opcode, node, right) && |
1297 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) { | 1275 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) { |
1298 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1276 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
1299 std::swap(left, right); | 1277 std::swap(left, right); |
1300 } | 1278 } |
1301 | 1279 |
1302 // Match immediates on right side of comparison. | 1280 // Match immediates on right side of comparison. |
1303 if (g.CanBeImmediate(right)) { | 1281 if (g.CanBeImmediate(right)) { |
1304 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { | 1282 if (g.CanBeMemoryOperand(opcode, node, left)) { |
1305 // If we're truncating the immediate (32 bits to 16 or 8), comparison | 1283 // TODO(epertoso): we should use `narrowed_opcode' here once we match |
1306 // semantics should take the signedness/unsignedness of the op into | 1284 // immediates too. |
1307 // account. | 1285 return VisitCompareWithMemoryOperand(selector, opcode, left, |
1308 if (narrowed_opcode != opcode && | |
1309 LoadRepresentationOf(left->op()).IsUnsigned()) { | |
1310 switch (cont->condition()) { | |
1311 case FlagsCondition::kSignedLessThan: | |
1312 cont->OverwriteAndNegateIfEqual(FlagsCondition::kUnsignedLessThan); | |
1313 break; | |
1314 case FlagsCondition::kSignedGreaterThan: | |
1315 cont->OverwriteAndNegateIfEqual( | |
1316 FlagsCondition::kUnsignedGreaterThan); | |
1317 break; | |
1318 case FlagsCondition::kSignedLessThanOrEqual: | |
1319 cont->OverwriteAndNegateIfEqual( | |
1320 FlagsCondition::kUnsignedLessThanOrEqual); | |
1321 break; | |
1322 case FlagsCondition::kSignedGreaterThanOrEqual: | |
1323 cont->OverwriteAndNegateIfEqual( | |
1324 FlagsCondition::kUnsignedGreaterThanOrEqual); | |
1325 break; | |
1326 default: | |
1327 break; | |
1328 } | |
1329 } | |
1330 return VisitCompareWithMemoryOperand(selector, narrowed_opcode, left, | |
1331 g.UseImmediate(right), cont); | 1286 g.UseImmediate(right), cont); |
1332 } | 1287 } |
1333 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), | 1288 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), |
1334 cont); | 1289 cont); |
1335 } | 1290 } |
1336 | 1291 |
1337 // Match memory operands on left side of comparison. | 1292 // Match memory operands on left side of comparison. |
1338 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { | 1293 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { |
1339 bool needs_byte_register = | 1294 bool needs_byte_register = |
1340 narrowed_opcode == kX87Test8 || narrowed_opcode == kX87Cmp8; | 1295 narrowed_opcode == kX87Test8 || narrowed_opcode == kX87Cmp8; |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1721 // static | 1676 // static |
1722 MachineOperatorBuilder::AlignmentRequirements | 1677 MachineOperatorBuilder::AlignmentRequirements |
1723 InstructionSelector::AlignmentRequirements() { | 1678 InstructionSelector::AlignmentRequirements() { |
1724 return MachineOperatorBuilder::AlignmentRequirements:: | 1679 return MachineOperatorBuilder::AlignmentRequirements:: |
1725 FullUnalignedAccessSupport(); | 1680 FullUnalignedAccessSupport(); |
1726 } | 1681 } |
1727 | 1682 |
1728 } // namespace compiler | 1683 } // namespace compiler |
1729 } // namespace internal | 1684 } // namespace internal |
1730 } // namespace v8 | 1685 } // namespace v8 |
OLD | NEW |