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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "src/base/adapters.h" | 7 #include "src/base/adapters.h" |
8 #include "src/compiler/instruction-selector-impl.h" | 8 #include "src/compiler/instruction-selector-impl.h" |
9 #include "src/compiler/node-matchers.h" | 9 #include "src/compiler/node-matchers.h" |
10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1331 } | 1331 } |
1332 } | 1332 } |
1333 } | 1333 } |
1334 | 1334 |
1335 | 1335 |
1336 bool InstructionSelector::IsTailCallAddressImmediate() { return true; } | 1336 bool InstructionSelector::IsTailCallAddressImmediate() { return true; } |
1337 | 1337 |
1338 | 1338 |
1339 namespace { | 1339 namespace { |
1340 | 1340 |
1341 void VisitCompareWithMemoryOperand(InstructionSelector* selector, | |
1342 InstructionCode opcode, Node* left, | |
1343 InstructionOperand right, | |
1344 FlagsContinuation* cont) { | |
1345 DCHECK(left_operands_count > 0 && left_operands_count <= 3); | |
epertoso
2016/02/18 13:31:35
Already deleted this.
| |
1346 X64OperandGenerator g(selector); | |
1347 size_t input_count = 0; | |
1348 InstructionOperand inputs[6]; | |
1349 AddressingMode addressing_mode = | |
1350 g.GetEffectiveAddressMemoryOperand(left, inputs, &input_count); | |
1351 opcode |= AddressingModeField::encode(addressing_mode); | |
1352 opcode = cont->Encode(opcode); | |
1353 | |
1354 if (cont->IsBranch()) { | |
1355 inputs[input_count++] = g.Label(cont->true_block()); | |
1356 inputs[input_count++] = g.Label(cont->false_block()); | |
1357 selector->Emit(opcode, 0, nullptr, input_count, inputs); | |
1358 } else { | |
1359 DCHECK(cont->IsSet()); | |
1360 InstructionOperand output = g.DefineAsRegister(cont->result()); | |
1361 selector->Emit(opcode, 1, &output, input_count, inputs); | |
1362 } | |
1363 } | |
1364 | |
1365 // Determines if {input} of {node} can be replaced by a memory operand. | |
1366 bool CanUseMemoryOperand(InstructionSelector* selector, InstructionCode opcode, | |
1367 Node* node, Node* input) { | |
1368 if (input->opcode() != IrOpcode::kLoad || !selector->CanCover(node, input)) { | |
1369 return false; | |
1370 } | |
1371 MachineRepresentation rep = | |
1372 LoadRepresentationOf(input->op()).representation(); | |
1373 if (rep == MachineRepresentation::kWord64 || | |
1374 rep == MachineRepresentation::kTagged) { | |
1375 return opcode == kX64Cmp || opcode == kX64Test; | |
1376 } else if (rep == MachineRepresentation::kWord32) { | |
1377 return opcode == kX64Cmp32 || opcode == kX64Test32; | |
1378 } | |
1379 return false; | |
1380 } | |
1381 | |
1341 // Shared routine for multiple compare operations. | 1382 // Shared routine for multiple compare operations. |
1342 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, | 1383 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
1343 InstructionOperand left, InstructionOperand right, | 1384 InstructionOperand left, InstructionOperand right, |
1344 FlagsContinuation* cont) { | 1385 FlagsContinuation* cont) { |
1345 X64OperandGenerator g(selector); | 1386 X64OperandGenerator g(selector); |
1346 opcode = cont->Encode(opcode); | 1387 opcode = cont->Encode(opcode); |
1347 if (cont->IsBranch()) { | 1388 if (cont->IsBranch()) { |
1348 selector->Emit(opcode, g.NoOutput(), left, right, | 1389 selector->Emit(opcode, g.NoOutput(), left, right, |
1349 g.Label(cont->true_block()), g.Label(cont->false_block())); | 1390 g.Label(cont->true_block()), g.Label(cont->false_block())); |
1350 } else { | 1391 } else { |
1351 DCHECK(cont->IsSet()); | 1392 DCHECK(cont->IsSet()); |
1352 selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right); | 1393 selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right); |
1353 } | 1394 } |
1354 } | 1395 } |
1355 | 1396 |
1356 | 1397 |
1357 // Shared routine for multiple compare operations. | 1398 // Shared routine for multiple compare operations. |
1358 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, | 1399 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
1359 Node* left, Node* right, FlagsContinuation* cont, | 1400 Node* left, Node* right, FlagsContinuation* cont, |
1360 bool commutative) { | 1401 bool commutative) { |
1361 X64OperandGenerator g(selector); | 1402 X64OperandGenerator g(selector); |
1362 if (commutative && g.CanBeBetterLeftOperand(right)) { | 1403 if (commutative && g.CanBeBetterLeftOperand(right)) { |
1363 std::swap(left, right); | 1404 std::swap(left, right); |
1364 } | 1405 } |
1365 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); | 1406 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); |
1366 } | 1407 } |
1367 | 1408 |
1368 | |
1369 // Shared routine for multiple word compare operations. | 1409 // Shared routine for multiple word compare operations. |
1370 void VisitWordCompare(InstructionSelector* selector, Node* node, | 1410 void VisitWordCompare(InstructionSelector* selector, Node* node, |
1371 InstructionCode opcode, FlagsContinuation* cont) { | 1411 InstructionCode opcode, FlagsContinuation* cont) { |
1372 X64OperandGenerator g(selector); | 1412 X64OperandGenerator g(selector); |
1373 Node* const left = node->InputAt(0); | 1413 Node* const left = node->InputAt(0); |
1374 Node* const right = node->InputAt(1); | 1414 Node* const right = node->InputAt(1); |
1375 | 1415 |
1376 // Match immediates on left or right side of comparison. | 1416 // Match immediates on left or right side of comparison. |
1377 if (g.CanBeImmediate(right)) { | 1417 if (g.CanBeImmediate(right)) { |
1378 VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), cont); | 1418 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), |
1419 cont); | |
1379 } else if (g.CanBeImmediate(left)) { | 1420 } else if (g.CanBeImmediate(left)) { |
1380 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1421 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
1381 VisitCompare(selector, opcode, g.Use(right), g.UseImmediate(left), cont); | 1422 return VisitCompare(selector, opcode, g.Use(right), g.UseImmediate(left), |
1382 } else { | 1423 cont); |
1383 VisitCompare(selector, opcode, left, right, cont, | |
1384 node->op()->HasProperty(Operator::kCommutative)); | |
1385 } | 1424 } |
1425 // TODO(epertoso): emit memory operands for comparisons againt immediates as | |
1426 // well. | |
1427 if (CanUseMemoryOperand(selector, opcode, node, left)) { | |
1428 return VisitCompareWithMemoryOperand(selector, opcode, left, | |
1429 g.UseRegister(right), cont); | |
1430 } | |
1431 return VisitCompare(selector, opcode, left, right, cont, | |
1432 node->op()->HasProperty(Operator::kCommutative)); | |
1386 } | 1433 } |
1387 | 1434 |
1388 | |
1389 // Shared routine for 64-bit word comparison operations. | 1435 // Shared routine for 64-bit word comparison operations. |
1390 void VisitWord64Compare(InstructionSelector* selector, Node* node, | 1436 void VisitWord64Compare(InstructionSelector* selector, Node* node, |
1391 FlagsContinuation* cont) { | 1437 FlagsContinuation* cont) { |
1392 X64OperandGenerator g(selector); | 1438 X64OperandGenerator g(selector); |
1393 Int64BinopMatcher m(node); | 1439 Int64BinopMatcher m(node); |
1394 if (m.left().IsLoad() && m.right().IsLoadStackPointer()) { | 1440 if (m.left().IsLoad() && m.right().IsLoadStackPointer()) { |
1395 LoadMatcher<ExternalReferenceMatcher> mleft(m.left().node()); | 1441 LoadMatcher<ExternalReferenceMatcher> mleft(m.left().node()); |
1396 ExternalReference js_stack_limit = | 1442 ExternalReference js_stack_limit = |
1397 ExternalReference::address_of_stack_limit(selector->isolate()); | 1443 ExternalReference::address_of_stack_limit(selector->isolate()); |
1398 if (mleft.object().Is(js_stack_limit) && mleft.index().Is(0)) { | 1444 if (mleft.object().Is(js_stack_limit) && mleft.index().Is(0)) { |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1836 MachineOperatorBuilder::kFloat64RoundTruncate | | 1882 MachineOperatorBuilder::kFloat64RoundTruncate | |
1837 MachineOperatorBuilder::kFloat32RoundTiesEven | | 1883 MachineOperatorBuilder::kFloat32RoundTiesEven | |
1838 MachineOperatorBuilder::kFloat64RoundTiesEven; | 1884 MachineOperatorBuilder::kFloat64RoundTiesEven; |
1839 } | 1885 } |
1840 return flags; | 1886 return flags; |
1841 } | 1887 } |
1842 | 1888 |
1843 } // namespace compiler | 1889 } // namespace compiler |
1844 } // namespace internal | 1890 } // namespace internal |
1845 } // namespace v8 | 1891 } // namespace v8 |
OLD | NEW |