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

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

Issue 2042263002: Version 5.2.361.17 (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') | src/compiler/instruction-selector.cc » ('j') | 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 IA32-specific methods for generating operands. 14 // Adds IA32-specific methods for generating operands.
15 class IA32OperandGenerator final : public OperandGenerator { 15 class IA32OperandGenerator final : public OperandGenerator {
16 public: 16 public:
17 explicit IA32OperandGenerator(InstructionSelector* selector) 17 explicit IA32OperandGenerator(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 kIA32Cmp: 42 case kIA32Cmp:
39 case kIA32Test: 43 case kIA32Test:
40 return rep == MachineRepresentation::kWord32 || 44 return rep == MachineRepresentation::kWord32 ||
41 rep == MachineRepresentation::kTagged; 45 rep == MachineRepresentation::kTagged;
42 case kIA32Cmp16: 46 case kIA32Cmp16:
43 case kIA32Test16: 47 case kIA32Test16:
44 return rep == MachineRepresentation::kWord16; 48 return rep == MachineRepresentation::kWord16;
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, 1175 void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
1172 Node* left, Node* right, FlagsContinuation* cont, 1176 Node* left, Node* right, FlagsContinuation* cont,
1173 bool commutative) { 1177 bool commutative) {
1174 IA32OperandGenerator g(selector); 1178 IA32OperandGenerator g(selector);
1175 if (commutative && g.CanBeBetterLeftOperand(right)) { 1179 if (commutative && g.CanBeBetterLeftOperand(right)) {
1176 std::swap(left, right); 1180 std::swap(left, right);
1177 } 1181 }
1178 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); 1182 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont);
1179 } 1183 }
1180 1184
1181 bool InferMachineRepresentation(Node* node,
1182 MachineRepresentation* representation) {
1183 if (node->opcode() == IrOpcode::kLoad) {
1184 *representation = LoadRepresentationOf(node->op()).representation();
1185 return true;
1186 }
1187 if (node->opcode() != IrOpcode::kInt32Constant) {
1188 return false;
1189 }
1190 int32_t value = OpParameter<int32_t>(node->op());
1191 if (is_int8(value)) {
1192 *representation = MachineRepresentation::kWord8;
1193 } else if (is_int16(value)) {
1194 *representation = MachineRepresentation::kWord16;
1195 } else {
1196 *representation = MachineRepresentation::kWord32;
1197 }
1198 return true;
1199 }
1200
1201 // Tries to match the size of the given opcode to that of the operands, if 1185 // Tries to match the size of the given opcode to that of the operands, if
1202 // possible. 1186 // possible.
1203 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, 1187 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left,
1204 Node* right) { 1188 Node* right) {
1205 if (opcode != kIA32Cmp && opcode != kIA32Test) { 1189 if (opcode != kIA32Cmp && opcode != kIA32Test) {
1206 return opcode; 1190 return opcode;
1207 } 1191 }
1208 // We only do this if at least one of the two operands is a load. 1192 // Currently, if one of the two operands is not a Load, we don't know what its
1209 // TODO(epertoso): we can probably get some size information out of phi nodes. 1193 // machine representation is, so we bail out.
1210 if (left->opcode() != IrOpcode::kLoad && right->opcode() != IrOpcode::kLoad) { 1194 // TODO(epertoso): we can probably get some size information out of immediates
1195 // and phi nodes.
1196 if (left->opcode() != IrOpcode::kLoad || right->opcode() != IrOpcode::kLoad) {
1211 return opcode; 1197 return opcode;
1212 } 1198 }
1213 MachineRepresentation left_representation, right_representation; 1199 // If the load representations don't match, both operands will be
1214 if (!InferMachineRepresentation(left, &left_representation) || 1200 // zero/sign-extended to 32bit.
1215 !InferMachineRepresentation(right, &right_representation)) { 1201 LoadRepresentation left_representation = LoadRepresentationOf(left->op());
1202 if (left_representation != LoadRepresentationOf(right->op())) {
1216 return opcode; 1203 return opcode;
1217 } 1204 }
1218 // If the representations don't match, both operands will be 1205 switch (left_representation.representation()) {
1219 // zero/sign-extended to 32bit.
1220 if (left_representation != right_representation) {
1221 return opcode;
1222 }
1223 switch (left_representation) {
1224 case MachineRepresentation::kBit: 1206 case MachineRepresentation::kBit:
1225 case MachineRepresentation::kWord8: 1207 case MachineRepresentation::kWord8:
1226 return opcode == kIA32Cmp ? kIA32Cmp8 : kIA32Test8; 1208 return opcode == kIA32Cmp ? kIA32Cmp8 : kIA32Test8;
1227 case MachineRepresentation::kWord16: 1209 case MachineRepresentation::kWord16:
1228 return opcode == kIA32Cmp ? kIA32Cmp16 : kIA32Test16; 1210 return opcode == kIA32Cmp ? kIA32Cmp16 : kIA32Test16;
1229 default: 1211 default:
1230 return opcode; 1212 return opcode;
1231 } 1213 }
1232 } 1214 }
1233 1215
(...skipping 16 matching lines...) Expand all
1250 1232
1251 // Shared routine for multiple word compare operations. 1233 // Shared routine for multiple word compare operations.
1252 void VisitWordCompare(InstructionSelector* selector, Node* node, 1234 void VisitWordCompare(InstructionSelector* selector, Node* node,
1253 InstructionCode opcode, FlagsContinuation* cont) { 1235 InstructionCode opcode, FlagsContinuation* cont) {
1254 IA32OperandGenerator g(selector); 1236 IA32OperandGenerator g(selector);
1255 Node* left = node->InputAt(0); 1237 Node* left = node->InputAt(0);
1256 Node* right = node->InputAt(1); 1238 Node* right = node->InputAt(1);
1257 1239
1258 InstructionCode narrowed_opcode = TryNarrowOpcodeSize(opcode, left, right); 1240 InstructionCode narrowed_opcode = TryNarrowOpcodeSize(opcode, left, right);
1259 1241
1242 int effect_level = selector->GetEffectLevel(node);
1243 if (cont->IsBranch()) {
1244 effect_level = selector->GetEffectLevel(
1245 cont->true_block()->PredecessorAt(0)->control_input());
1246 }
1247
1260 // If one of the two inputs is an immediate, make sure it's on the right, or 1248 // If one of the two inputs is an immediate, make sure it's on the right, or
1261 // if one of the two inputs is a memory operand, make sure it's on the left. 1249 // if one of the two inputs is a memory operand, make sure it's on the left.
1262 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || 1250 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) ||
1263 (g.CanBeMemoryOperand(narrowed_opcode, node, right) && 1251 (g.CanBeMemoryOperand(narrowed_opcode, node, right, effect_level) &&
1264 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) { 1252 !g.CanBeMemoryOperand(narrowed_opcode, node, left, effect_level))) {
1265 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); 1253 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute();
1266 std::swap(left, right); 1254 std::swap(left, right);
1267 } 1255 }
1268 1256
1269 // Match immediates on right side of comparison. 1257 // Match immediates on right side of comparison.
1270 if (g.CanBeImmediate(right)) { 1258 if (g.CanBeImmediate(right)) {
1271 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { 1259 if (g.CanBeMemoryOperand(opcode, node, left, effect_level)) {
1272 // If we're truncating the immediate (32 bits to 16 or 8), comparison 1260 // TODO(epertoso): we should use `narrowed_opcode' here once we match
1273 // semantics should take the signedness/unsignedness of the op into 1261 // immediates too.
1274 // account. 1262 return VisitCompareWithMemoryOperand(selector, opcode, left,
1275 if (narrowed_opcode != opcode &&
1276 LoadRepresentationOf(left->op()).IsUnsigned()) {
1277 switch (cont->condition()) {
1278 case FlagsCondition::kSignedLessThan:
1279 cont->OverwriteAndNegateIfEqual(FlagsCondition::kUnsignedLessThan);
1280 break;
1281 case FlagsCondition::kSignedGreaterThan:
1282 cont->OverwriteAndNegateIfEqual(
1283 FlagsCondition::kUnsignedGreaterThan);
1284 break;
1285 case FlagsCondition::kSignedLessThanOrEqual:
1286 cont->OverwriteAndNegateIfEqual(
1287 FlagsCondition::kUnsignedLessThanOrEqual);
1288 break;
1289 case FlagsCondition::kSignedGreaterThanOrEqual:
1290 cont->OverwriteAndNegateIfEqual(
1291 FlagsCondition::kUnsignedGreaterThanOrEqual);
1292 break;
1293 default:
1294 break;
1295 }
1296 }
1297 return VisitCompareWithMemoryOperand(selector, narrowed_opcode, left,
1298 g.UseImmediate(right), cont); 1263 g.UseImmediate(right), cont);
1299 } 1264 }
1300 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), 1265 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right),
1301 cont); 1266 cont);
1302 } 1267 }
1303 1268
1304 // Match memory operands on left side of comparison. 1269 // Match memory operands on left side of comparison.
1305 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { 1270 if (g.CanBeMemoryOperand(narrowed_opcode, node, left, effect_level)) {
1306 bool needs_byte_register = 1271 bool needs_byte_register =
1307 narrowed_opcode == kIA32Test8 || narrowed_opcode == kIA32Cmp8; 1272 narrowed_opcode == kIA32Test8 || narrowed_opcode == kIA32Cmp8;
1308 return VisitCompareWithMemoryOperand( 1273 return VisitCompareWithMemoryOperand(
1309 selector, narrowed_opcode, left, 1274 selector, narrowed_opcode, left,
1310 needs_byte_register ? g.UseByteRegister(right) : g.UseRegister(right), 1275 needs_byte_register ? g.UseByteRegister(right) : g.UseRegister(right),
1311 cont); 1276 cont);
1312 } 1277 }
1313 1278
1314 if (g.CanBeBetterLeftOperand(right)) { 1279 if (g.CanBeBetterLeftOperand(right)) {
1315 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); 1280 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute();
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 MachineOperatorBuilder::kFloat64RoundTruncate | 1652 MachineOperatorBuilder::kFloat64RoundTruncate |
1688 MachineOperatorBuilder::kFloat32RoundTiesEven | 1653 MachineOperatorBuilder::kFloat32RoundTiesEven |
1689 MachineOperatorBuilder::kFloat64RoundTiesEven; 1654 MachineOperatorBuilder::kFloat64RoundTiesEven;
1690 } 1655 }
1691 return flags; 1656 return flags;
1692 } 1657 }
1693 1658
1694 } // namespace compiler 1659 } // namespace compiler
1695 } // namespace internal 1660 } // namespace internal
1696 } // namespace v8 1661 } // namespace v8
OLDNEW
« no previous file with comments | « include/v8-version.h ('k') | src/compiler/instruction-selector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698