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 { |
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 1183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 | 1232 |
1229 // Shared routine for multiple word compare operations. | 1233 // Shared routine for multiple word compare operations. |
1230 void VisitWordCompare(InstructionSelector* selector, Node* node, | 1234 void VisitWordCompare(InstructionSelector* selector, Node* node, |
1231 InstructionCode opcode, FlagsContinuation* cont) { | 1235 InstructionCode opcode, FlagsContinuation* cont) { |
1232 IA32OperandGenerator g(selector); | 1236 IA32OperandGenerator g(selector); |
1233 Node* left = node->InputAt(0); | 1237 Node* left = node->InputAt(0); |
1234 Node* right = node->InputAt(1); | 1238 Node* right = node->InputAt(1); |
1235 | 1239 |
1236 InstructionCode narrowed_opcode = TryNarrowOpcodeSize(opcode, left, right); | 1240 InstructionCode narrowed_opcode = TryNarrowOpcodeSize(opcode, left, right); |
1237 | 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 |
1238 // 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 |
1239 // 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. |
1240 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || | 1250 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || |
1241 (g.CanBeMemoryOperand(narrowed_opcode, node, right) && | 1251 (g.CanBeMemoryOperand(narrowed_opcode, node, right, effect_level) && |
1242 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) { | 1252 !g.CanBeMemoryOperand(narrowed_opcode, node, left, effect_level))) { |
1243 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1253 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
1244 std::swap(left, right); | 1254 std::swap(left, right); |
1245 } | 1255 } |
1246 | 1256 |
1247 // Match immediates on right side of comparison. | 1257 // Match immediates on right side of comparison. |
1248 if (g.CanBeImmediate(right)) { | 1258 if (g.CanBeImmediate(right)) { |
1249 if (g.CanBeMemoryOperand(opcode, node, left)) { | 1259 if (g.CanBeMemoryOperand(opcode, node, left, effect_level)) { |
1250 // TODO(epertoso): we should use `narrowed_opcode' here once we match | 1260 // TODO(epertoso): we should use `narrowed_opcode' here once we match |
1251 // immediates too. | 1261 // immediates too. |
1252 return VisitCompareWithMemoryOperand(selector, opcode, left, | 1262 return VisitCompareWithMemoryOperand(selector, opcode, left, |
1253 g.UseImmediate(right), cont); | 1263 g.UseImmediate(right), cont); |
1254 } | 1264 } |
1255 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), | 1265 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), |
1256 cont); | 1266 cont); |
1257 } | 1267 } |
1258 | 1268 |
1259 // Match memory operands on left side of comparison. | 1269 // Match memory operands on left side of comparison. |
1260 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { | 1270 if (g.CanBeMemoryOperand(narrowed_opcode, node, left, effect_level)) { |
1261 bool needs_byte_register = | 1271 bool needs_byte_register = |
1262 narrowed_opcode == kIA32Test8 || narrowed_opcode == kIA32Cmp8; | 1272 narrowed_opcode == kIA32Test8 || narrowed_opcode == kIA32Cmp8; |
1263 return VisitCompareWithMemoryOperand( | 1273 return VisitCompareWithMemoryOperand( |
1264 selector, narrowed_opcode, left, | 1274 selector, narrowed_opcode, left, |
1265 needs_byte_register ? g.UseByteRegister(right) : g.UseRegister(right), | 1275 needs_byte_register ? g.UseByteRegister(right) : g.UseRegister(right), |
1266 cont); | 1276 cont); |
1267 } | 1277 } |
1268 | 1278 |
1269 if (g.CanBeBetterLeftOperand(right)) { | 1279 if (g.CanBeBetterLeftOperand(right)) { |
1270 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1280 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1649 // static | 1659 // static |
1650 MachineOperatorBuilder::AlignmentRequirements | 1660 MachineOperatorBuilder::AlignmentRequirements |
1651 InstructionSelector::AlignmentRequirements() { | 1661 InstructionSelector::AlignmentRequirements() { |
1652 return MachineOperatorBuilder::AlignmentRequirements:: | 1662 return MachineOperatorBuilder::AlignmentRequirements:: |
1653 FullUnalignedAccessSupport(); | 1663 FullUnalignedAccessSupport(); |
1654 } | 1664 } |
1655 | 1665 |
1656 } // namespace compiler | 1666 } // namespace compiler |
1657 } // namespace internal | 1667 } // namespace internal |
1658 } // namespace v8 | 1668 } // namespace v8 |
OLD | NEW |