| 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 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1218 | 1222 |
| 1219 // Shared routine for multiple word compare operations. | 1223 // Shared routine for multiple word compare operations. |
| 1220 void VisitWordCompare(InstructionSelector* selector, Node* node, | 1224 void VisitWordCompare(InstructionSelector* selector, Node* node, |
| 1221 InstructionCode opcode, FlagsContinuation* cont) { | 1225 InstructionCode opcode, FlagsContinuation* cont) { |
| 1222 IA32OperandGenerator g(selector); | 1226 IA32OperandGenerator g(selector); |
| 1223 Node* left = node->InputAt(0); | 1227 Node* left = node->InputAt(0); |
| 1224 Node* right = node->InputAt(1); | 1228 Node* right = node->InputAt(1); |
| 1225 | 1229 |
| 1226 InstructionCode narrowed_opcode = TryNarrowOpcodeSize(opcode, left, right); | 1230 InstructionCode narrowed_opcode = TryNarrowOpcodeSize(opcode, left, right); |
| 1227 | 1231 |
| 1232 int effect_level = selector->GetEffectLevel(node); |
| 1233 if (cont->IsBranch()) { |
| 1234 effect_level = selector->GetEffectLevel( |
| 1235 cont->true_block()->PredecessorAt(0)->control_input()); |
| 1236 } |
| 1237 |
| 1228 // If one of the two inputs is an immediate, make sure it's on the right, or | 1238 // If one of the two inputs is an immediate, make sure it's on the right, or |
| 1229 // if one of the two inputs is a memory operand, make sure it's on the left. | 1239 // if one of the two inputs is a memory operand, make sure it's on the left. |
| 1230 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || | 1240 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || |
| 1231 (g.CanBeMemoryOperand(narrowed_opcode, node, right) && | 1241 (g.CanBeMemoryOperand(narrowed_opcode, node, right, effect_level) && |
| 1232 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) { | 1242 !g.CanBeMemoryOperand(narrowed_opcode, node, left, effect_level))) { |
| 1233 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1243 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
| 1234 std::swap(left, right); | 1244 std::swap(left, right); |
| 1235 } | 1245 } |
| 1236 | 1246 |
| 1237 // Match immediates on right side of comparison. | 1247 // Match immediates on right side of comparison. |
| 1238 if (g.CanBeImmediate(right)) { | 1248 if (g.CanBeImmediate(right)) { |
| 1239 if (g.CanBeMemoryOperand(opcode, node, left)) { | 1249 if (g.CanBeMemoryOperand(opcode, node, left, effect_level)) { |
| 1240 // TODO(epertoso): we should use `narrowed_opcode' here once we match | 1250 // TODO(epertoso): we should use `narrowed_opcode' here once we match |
| 1241 // immediates too. | 1251 // immediates too. |
| 1242 return VisitCompareWithMemoryOperand(selector, opcode, left, | 1252 return VisitCompareWithMemoryOperand(selector, opcode, left, |
| 1243 g.UseImmediate(right), cont); | 1253 g.UseImmediate(right), cont); |
| 1244 } | 1254 } |
| 1245 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), | 1255 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), |
| 1246 cont); | 1256 cont); |
| 1247 } | 1257 } |
| 1248 | 1258 |
| 1249 // Match memory operands on left side of comparison. | 1259 // Match memory operands on left side of comparison. |
| 1250 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { | 1260 if (g.CanBeMemoryOperand(narrowed_opcode, node, left, effect_level)) { |
| 1251 bool needs_byte_register = | 1261 bool needs_byte_register = |
| 1252 narrowed_opcode == kIA32Test8 || narrowed_opcode == kIA32Cmp8; | 1262 narrowed_opcode == kIA32Test8 || narrowed_opcode == kIA32Cmp8; |
| 1253 return VisitCompareWithMemoryOperand( | 1263 return VisitCompareWithMemoryOperand( |
| 1254 selector, narrowed_opcode, left, | 1264 selector, narrowed_opcode, left, |
| 1255 needs_byte_register ? g.UseByteRegister(right) : g.UseRegister(right), | 1265 needs_byte_register ? g.UseByteRegister(right) : g.UseRegister(right), |
| 1256 cont); | 1266 cont); |
| 1257 } | 1267 } |
| 1258 | 1268 |
| 1259 if (g.CanBeBetterLeftOperand(right)) { | 1269 if (g.CanBeBetterLeftOperand(right)) { |
| 1260 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1270 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1586 MachineOperatorBuilder::kFloat64RoundTruncate | | 1596 MachineOperatorBuilder::kFloat64RoundTruncate | |
| 1587 MachineOperatorBuilder::kFloat32RoundTiesEven | | 1597 MachineOperatorBuilder::kFloat32RoundTiesEven | |
| 1588 MachineOperatorBuilder::kFloat64RoundTiesEven; | 1598 MachineOperatorBuilder::kFloat64RoundTiesEven; |
| 1589 } | 1599 } |
| 1590 return flags; | 1600 return flags; |
| 1591 } | 1601 } |
| 1592 | 1602 |
| 1593 } // namespace compiler | 1603 } // namespace compiler |
| 1594 } // namespace internal | 1604 } // namespace internal |
| 1595 } // namespace v8 | 1605 } // namespace v8 |
| OLD | NEW |