Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: src/compiler/x87/instruction-selector-x87.cc

Issue 2049643002: Version 5.2.361.18 (cherry-pick) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@5.2
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/v8-version.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 {
11 namespace internal { 11 namespace internal {
12 namespace compiler { 12 namespace compiler {
13 13
14 // Adds X87-specific methods for generating operands. 14 // Adds X87-specific methods for generating operands.
15 class X87OperandGenerator final : public OperandGenerator { 15 class X87OperandGenerator final : public OperandGenerator {
16 public: 16 public:
17 explicit X87OperandGenerator(InstructionSelector* selector) 17 explicit X87OperandGenerator(InstructionSelector* selector)
18 : OperandGenerator(selector) {} 18 : OperandGenerator(selector) {}
19 19
20 InstructionOperand UseByteRegister(Node* node) { 20 InstructionOperand UseByteRegister(Node* node) {
21 // TODO(titzer): encode byte register use constraints. 21 // TODO(titzer): encode byte register use constraints.
22 return UseFixed(node, edx); 22 return UseFixed(node, edx);
23 } 23 }
24 24
25 InstructionOperand DefineAsByteRegister(Node* node) { 25 InstructionOperand DefineAsByteRegister(Node* node) {
26 // TODO(titzer): encode byte register def constraints. 26 // TODO(titzer): encode byte register def constraints.
27 return DefineAsRegister(node); 27 return DefineAsRegister(node);
28 } 28 }
29 29
30 bool CanBeMemoryOperand(InstructionCode opcode, Node* node, Node* input) { 30 bool CanBeMemoryOperand(InstructionCode opcode, Node* node, Node* input,
31 int effect_level) {
31 if (input->opcode() != IrOpcode::kLoad || 32 if (input->opcode() != IrOpcode::kLoad ||
32 !selector()->CanCover(node, input)) { 33 !selector()->CanCover(node, input)) {
33 return false; 34 return false;
34 } 35 }
36 if (effect_level != selector()->GetEffectLevel(input)) {
37 return false;
38 }
35 MachineRepresentation rep = 39 MachineRepresentation rep =
36 LoadRepresentationOf(input->op()).representation(); 40 LoadRepresentationOf(input->op()).representation();
37 switch (opcode) { 41 switch (opcode) {
38 case kX87Cmp: 42 case kX87Cmp:
39 case kX87Test: 43 case kX87Test:
40 return rep == MachineRepresentation::kWord32 || 44 return rep == MachineRepresentation::kWord32 ||
41 rep == MachineRepresentation::kTagged; 45 rep == MachineRepresentation::kTagged;
42 case kX87Cmp16: 46 case kX87Cmp16:
43 case kX87Test16: 47 case kX87Test16:
44 return rep == MachineRepresentation::kWord16; 48 return rep == MachineRepresentation::kWord16;
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, 1184 void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
1181 Node* left, Node* right, FlagsContinuation* cont, 1185 Node* left, Node* right, FlagsContinuation* cont,
1182 bool commutative) { 1186 bool commutative) {
1183 X87OperandGenerator g(selector); 1187 X87OperandGenerator g(selector);
1184 if (commutative && g.CanBeBetterLeftOperand(right)) { 1188 if (commutative && g.CanBeBetterLeftOperand(right)) {
1185 std::swap(left, right); 1189 std::swap(left, right);
1186 } 1190 }
1187 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); 1191 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont);
1188 } 1192 }
1189 1193
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 1194 // Tries to match the size of the given opcode to that of the operands, if
1211 // possible. 1195 // possible.
1212 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, 1196 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left,
1213 Node* right) { 1197 Node* right) {
1214 if (opcode != kX87Cmp && opcode != kX87Test) { 1198 if (opcode != kX87Cmp && opcode != kX87Test) {
1215 return opcode; 1199 return opcode;
1216 } 1200 }
1217 // We only do this if at least one of the two operands is a load. 1201 // 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. 1202 // machine representation is, so we bail out.
1219 if (left->opcode() != IrOpcode::kLoad && right->opcode() != IrOpcode::kLoad) { 1203 // TODO(epertoso): we can probably get some size information out of immediates
1204 // and phi nodes.
1205 if (left->opcode() != IrOpcode::kLoad || right->opcode() != IrOpcode::kLoad) {
1220 return opcode; 1206 return opcode;
1221 } 1207 }
1222 MachineRepresentation left_representation, right_representation; 1208 // If the load representations don't match, both operands will be
1223 if (!InferMachineRepresentation(left, &left_representation) || 1209 // zero/sign-extended to 32bit.
1224 !InferMachineRepresentation(right, &right_representation)) { 1210 LoadRepresentation left_representation = LoadRepresentationOf(left->op());
1211 if (left_representation != LoadRepresentationOf(right->op())) {
1225 return opcode; 1212 return opcode;
1226 } 1213 }
1227 // If the representations don't match, both operands will be 1214 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: 1215 case MachineRepresentation::kBit:
1234 case MachineRepresentation::kWord8: 1216 case MachineRepresentation::kWord8:
1235 return opcode == kX87Cmp ? kX87Cmp8 : kX87Test8; 1217 return opcode == kX87Cmp ? kX87Cmp8 : kX87Test8;
1236 case MachineRepresentation::kWord16: 1218 case MachineRepresentation::kWord16:
1237 return opcode == kX87Cmp ? kX87Cmp16 : kX87Test16; 1219 return opcode == kX87Cmp ? kX87Cmp16 : kX87Test16;
1238 default: 1220 default:
1239 return opcode; 1221 return opcode;
1240 } 1222 }
1241 } 1223 }
1242 1224
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 1265
1284 // Shared routine for multiple word compare operations. 1266 // Shared routine for multiple word compare operations.
1285 void VisitWordCompare(InstructionSelector* selector, Node* node, 1267 void VisitWordCompare(InstructionSelector* selector, Node* node,
1286 InstructionCode opcode, FlagsContinuation* cont) { 1268 InstructionCode opcode, FlagsContinuation* cont) {
1287 X87OperandGenerator g(selector); 1269 X87OperandGenerator g(selector);
1288 Node* left = node->InputAt(0); 1270 Node* left = node->InputAt(0);
1289 Node* right = node->InputAt(1); 1271 Node* right = node->InputAt(1);
1290 1272
1291 InstructionCode narrowed_opcode = TryNarrowOpcodeSize(opcode, left, right); 1273 InstructionCode narrowed_opcode = TryNarrowOpcodeSize(opcode, left, right);
1292 1274
1275 int effect_level = selector->GetEffectLevel(node);
1276 if (cont->IsBranch()) {
1277 effect_level = selector->GetEffectLevel(
1278 cont->true_block()->PredecessorAt(0)->control_input());
1279 }
1280
1293 // If one of the two inputs is an immediate, make sure it's on the right, or 1281 // If one of the two inputs is an immediate, make sure it's on the right, or
1294 // if one of the two inputs is a memory operand, make sure it's on the left. 1282 // 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)) || 1283 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) ||
1296 (g.CanBeMemoryOperand(narrowed_opcode, node, right) && 1284 (g.CanBeMemoryOperand(narrowed_opcode, node, right, effect_level) &&
1297 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) { 1285 !g.CanBeMemoryOperand(narrowed_opcode, node, left, effect_level))) {
1298 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); 1286 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute();
1299 std::swap(left, right); 1287 std::swap(left, right);
1300 } 1288 }
1301 1289
1302 // Match immediates on right side of comparison. 1290 // Match immediates on right side of comparison.
1303 if (g.CanBeImmediate(right)) { 1291 if (g.CanBeImmediate(right)) {
1304 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { 1292 if (g.CanBeMemoryOperand(opcode, node, left, effect_level)) {
1305 // If we're truncating the immediate (32 bits to 16 or 8), comparison 1293 // TODO(epertoso): we should use `narrowed_opcode' here once we match
1306 // semantics should take the signedness/unsignedness of the op into 1294 // immediates too.
1307 // account. 1295 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); 1296 g.UseImmediate(right), cont);
1332 } 1297 }
1333 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), 1298 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right),
1334 cont); 1299 cont);
1335 } 1300 }
1336 1301
1337 // Match memory operands on left side of comparison. 1302 // Match memory operands on left side of comparison.
1338 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { 1303 if (g.CanBeMemoryOperand(narrowed_opcode, node, left, effect_level)) {
1339 bool needs_byte_register = 1304 bool needs_byte_register =
1340 narrowed_opcode == kX87Test8 || narrowed_opcode == kX87Cmp8; 1305 narrowed_opcode == kX87Test8 || narrowed_opcode == kX87Cmp8;
1341 return VisitCompareWithMemoryOperand( 1306 return VisitCompareWithMemoryOperand(
1342 selector, narrowed_opcode, left, 1307 selector, narrowed_opcode, left,
1343 needs_byte_register ? g.UseByteRegister(right) : g.UseRegister(right), 1308 needs_byte_register ? g.UseByteRegister(right) : g.UseRegister(right),
1344 cont); 1309 cont);
1345 } 1310 }
1346 1311
1347 if (g.CanBeBetterLeftOperand(right)) { 1312 if (g.CanBeBetterLeftOperand(right)) {
1348 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); 1313 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute();
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 MachineOperatorBuilder::kFloat32RoundTruncate | 1679 MachineOperatorBuilder::kFloat32RoundTruncate |
1715 MachineOperatorBuilder::kFloat64RoundTruncate | 1680 MachineOperatorBuilder::kFloat64RoundTruncate |
1716 MachineOperatorBuilder::kFloat32RoundTiesEven | 1681 MachineOperatorBuilder::kFloat32RoundTiesEven |
1717 MachineOperatorBuilder::kFloat64RoundTiesEven; 1682 MachineOperatorBuilder::kFloat64RoundTiesEven;
1718 return flags; 1683 return flags;
1719 } 1684 }
1720 1685
1721 } // namespace compiler 1686 } // namespace compiler
1722 } // namespace internal 1687 } // namespace internal
1723 } // namespace v8 1688 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8-version.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698