OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM64. |
6 #if defined(TARGET_ARCH_ARM64) | 6 #if defined(TARGET_ARCH_ARM64) |
7 | 7 |
8 #include "vm/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
9 | 9 |
10 #include "vm/ast_printer.h" | 10 #include "vm/ast_printer.h" |
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 LocationSummary* locs) { | 1195 LocationSummary* locs) { |
1196 ASSERT(Array::Handle(zone(), ic_data.arguments_descriptor()).Length() > 0); | 1196 ASSERT(Array::Handle(zone(), ic_data.arguments_descriptor()).Length() > 0); |
1197 __ LoadUniqueObject(R5, ic_data); | 1197 __ LoadUniqueObject(R5, ic_data); |
1198 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall, | 1198 GenerateDartCall(deopt_id, token_pos, stub_entry, RawPcDescriptors::kIcCall, |
1199 locs); | 1199 locs); |
1200 __ Drop(argument_count); | 1200 __ Drop(argument_count); |
1201 } | 1201 } |
1202 | 1202 |
1203 | 1203 |
1204 void FlowGraphCompiler::EmitMegamorphicInstanceCall( | 1204 void FlowGraphCompiler::EmitMegamorphicInstanceCall( |
1205 const ICData& ic_data, | 1205 const String& name, |
| 1206 const Array& arguments_descriptor, |
1206 intptr_t argument_count, | 1207 intptr_t argument_count, |
1207 intptr_t deopt_id, | 1208 intptr_t deopt_id, |
1208 TokenPosition token_pos, | 1209 TokenPosition token_pos, |
1209 LocationSummary* locs, | 1210 LocationSummary* locs, |
1210 intptr_t try_index, | 1211 intptr_t try_index, |
1211 intptr_t slow_path_argument_count) { | 1212 intptr_t slow_path_argument_count) { |
1212 const String& name = String::Handle(zone(), ic_data.target_name()); | |
1213 const Array& arguments_descriptor = | |
1214 Array::ZoneHandle(zone(), ic_data.arguments_descriptor()); | |
1215 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); | 1213 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); |
1216 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle( | 1214 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle( |
1217 zone(), | 1215 zone(), |
1218 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); | 1216 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); |
1219 | 1217 |
1220 __ Comment("MegamorphicCall"); | 1218 __ Comment("MegamorphicCall"); |
1221 // Load receiver into R0. | 1219 // Load receiver into R0. |
1222 __ LoadFromOffset(R0, SP, (argument_count - 1) * kWordSize); | 1220 __ LoadFromOffset(R0, SP, (argument_count - 1) * kWordSize); |
1223 | 1221 |
1224 __ LoadObject(R5, cache); | 1222 __ LoadObject(R5, cache); |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1437 // TODO(zerny): clobber non-live temporary FPU registers. | 1435 // TODO(zerny): clobber non-live temporary FPU registers. |
1438 if (tmp.IsRegister() && | 1436 if (tmp.IsRegister() && |
1439 !locs->live_registers()->ContainsRegister(tmp.reg())) { | 1437 !locs->live_registers()->ContainsRegister(tmp.reg())) { |
1440 __ movz(tmp.reg(), Immediate(0xf7), 0); | 1438 __ movz(tmp.reg(), Immediate(0xf7), 0); |
1441 } | 1439 } |
1442 } | 1440 } |
1443 } | 1441 } |
1444 #endif | 1442 #endif |
1445 | 1443 |
1446 | 1444 |
1447 void FlowGraphCompiler::EmitTestAndCall(const ICData& ic_data, | 1445 void FlowGraphCompiler::EmitTestAndCall(const PolymorphicTargets& targets, |
| 1446 const String& function_name, |
1448 intptr_t argument_count, | 1447 intptr_t argument_count, |
1449 const Array& argument_names, | 1448 const Array& argument_names, |
1450 Label* failed, | 1449 Label* failed, |
1451 Label* match_found, | 1450 Label* match_found, |
1452 intptr_t deopt_id, | 1451 intptr_t deopt_id, |
1453 TokenPosition token_index, | 1452 TokenPosition token_index, |
1454 LocationSummary* locs, | 1453 LocationSummary* locs, |
1455 bool complete, | 1454 bool complete, |
1456 intptr_t total_ic_calls) { | 1455 intptr_t total_ic_calls) { |
1457 ASSERT(is_optimizing()); | 1456 ASSERT(is_optimizing()); |
| 1457 |
1458 __ Comment("EmitTestAndCall"); | 1458 __ Comment("EmitTestAndCall"); |
1459 const Array& arguments_descriptor = Array::ZoneHandle( | 1459 const Array& arguments_descriptor = Array::ZoneHandle( |
1460 zone(), ArgumentsDescriptor::New(argument_count, argument_names)); | 1460 zone(), ArgumentsDescriptor::New(argument_count, argument_names)); |
1461 | |
1462 // Load receiver into R0. | 1461 // Load receiver into R0. |
1463 __ LoadFromOffset(R0, SP, (argument_count - 1) * kWordSize); | 1462 __ LoadFromOffset(R0, SP, (argument_count - 1) * kWordSize); |
1464 __ LoadObject(R4, arguments_descriptor); | 1463 __ LoadObject(R4, arguments_descriptor); |
1465 | 1464 |
1466 const bool kFirstCheckIsSmi = ic_data.GetReceiverClassIdAt(0) == kSmiCid; | 1465 const int kNoCase = -1; |
1467 const intptr_t num_checks = ic_data.NumberOfChecks(); | 1466 int smi_case = kNoCase; |
| 1467 int which_case_to_skip = kNoCase; |
1468 | 1468 |
1469 ASSERT(!ic_data.IsNull() && (num_checks > 0)); | 1469 const int length = targets.length(); |
| 1470 int non_smi_length = length; |
1470 | 1471 |
1471 Label after_smi_test; | 1472 // Find out if one of the classes in one of the cases is the Smi class. We |
1472 if (kFirstCheckIsSmi) { | 1473 // will be handling that specially. |
| 1474 for (int i = 0; i < length; i++) { |
| 1475 const intptr_t start = targets[i].cid_start; |
| 1476 if (start > kSmiCid) continue; |
| 1477 const intptr_t end = targets[i].cid_end; |
| 1478 if (end >= kSmiCid) { |
| 1479 smi_case = i; |
| 1480 if (start == kSmiCid && end == kSmiCid) { |
| 1481 // If this case has only the Smi class then we won't need to emit it at |
| 1482 // all later. |
| 1483 which_case_to_skip = i; |
| 1484 non_smi_length--; |
| 1485 } |
| 1486 break; |
| 1487 } |
| 1488 } |
| 1489 |
| 1490 if (smi_case != kNoCase) { |
| 1491 Label after_smi_test; |
1473 __ tsti(R0, Immediate(kSmiTagMask)); | 1492 __ tsti(R0, Immediate(kSmiTagMask)); |
1474 // Jump if receiver is not Smi. | 1493 // Jump if receiver is not Smi. |
1475 if (num_checks == 1) { | 1494 __ b(non_smi_length == 0 ? failed : &after_smi_test, NE); |
1476 __ b(failed, NE); | |
1477 } else { | |
1478 __ b(&after_smi_test, NE); | |
1479 } | |
1480 // Do not use the code from the function, but let the code be patched so | 1495 // Do not use the code from the function, but let the code be patched so |
1481 // that we can record the outgoing edges to other code. | 1496 // that we can record the outgoing edges to other code. |
1482 const Function& function = | 1497 const Function& function = *targets[smi_case].target; |
1483 Function::ZoneHandle(zone(), ic_data.GetTargetAt(0)); | |
1484 GenerateStaticDartCall(deopt_id, token_index, | 1498 GenerateStaticDartCall(deopt_id, token_index, |
1485 *StubCode::CallStaticFunction_entry(), | 1499 *StubCode::CallStaticFunction_entry(), |
1486 RawPcDescriptors::kOther, locs, function); | 1500 RawPcDescriptors::kOther, locs, function); |
1487 __ Drop(argument_count); | 1501 __ Drop(argument_count); |
1488 if (num_checks > 1) { | 1502 if (non_smi_length > 0) { |
1489 __ b(match_found); | 1503 __ b(match_found); |
1490 } | 1504 } |
| 1505 __ Bind(&after_smi_test); |
1491 } else { | 1506 } else { |
1492 // Receiver is Smi, but Smi is not a valid class therefore fail. | 1507 // Receiver is Smi, but Smi is not a valid class therefore fail. |
1493 // (Smi class must be first in the list). | |
1494 if (!complete) { | 1508 if (!complete) { |
1495 __ tsti(R0, Immediate(kSmiTagMask)); | 1509 __ tsti(R0, Immediate(kSmiTagMask)); |
1496 __ b(failed, EQ); | 1510 __ b(failed, EQ); |
1497 } | 1511 } |
1498 } | 1512 } |
1499 __ Bind(&after_smi_test); | |
1500 | 1513 |
1501 ASSERT(!ic_data.IsNull() && (num_checks > 0)); | 1514 ASSERT(length > 0); |
1502 GrowableArray<CidRangeTarget> sorted(num_checks); | |
1503 SortICDataByCount(ic_data, &sorted, /* drop_smi = */ true); | |
1504 | 1515 |
1505 const intptr_t sorted_len = sorted.length(); | 1516 // If non_smi_length is 0 then only a Smi check was needed; the Smi check |
1506 // If sorted_len is 0 then only a Smi check was needed; the Smi check above | 1517 // above will fail if there was only one check and receiver is not Smi. |
1507 // will fail if there was only one check and receiver is not Smi. | 1518 if (non_smi_length == 0) return; |
1508 if (sorted_len == 0) return; | |
1509 | 1519 |
1510 // Value is not Smi, | 1520 // Value is not Smi, |
1511 __ LoadClassId(R2, R0); | 1521 __ LoadClassId(R2, R0); |
1512 | 1522 |
1513 bool add_megamorphic_call = false; | 1523 bool add_megamorphic_call = false; |
1514 const int kMaxImmediateInInstruction = 256; | 1524 const int kMaxImmediateInInstruction = 256; |
1515 int bias = | 1525 int bias = |
1516 ComputeGoodBiasForCidComparison(sorted, kMaxImmediateInInstruction); | 1526 ComputeGoodBiasForCidComparison(targets, kMaxImmediateInInstruction); |
1517 if (bias != 0) __ AddImmediate(R2, R2, -bias); | 1527 if (bias != 0) __ AddImmediate(R2, R2, -bias); |
1518 | 1528 |
1519 for (intptr_t i = 0; i < sorted_len; i++) { | 1529 int last_check = which_case_to_skip == length - 1 ? length - 2 : length - 1; |
1520 const bool is_last_check = (i == (sorted_len - 1)); | 1530 |
1521 int cid_start = sorted[i].cid_start; | 1531 for (intptr_t i = 0; i < length; i++) { |
1522 int cid_end = sorted[i].cid_end; | 1532 if (i == which_case_to_skip) continue; |
1523 int count = sorted[i].count; | 1533 const bool is_last_check = (i == last_check); |
| 1534 const int cid_start = targets[i].cid_start; |
| 1535 const int cid_end = targets[i].cid_end; |
| 1536 const int count = targets[i].count; |
1524 if (!is_last_check && !complete && count < (total_ic_calls >> 5)) { | 1537 if (!is_last_check && !complete && count < (total_ic_calls >> 5)) { |
1525 // This case is hit too rarely to be worth writing class-id checks inline | 1538 // This case is hit too rarely to be worth writing class-id checks inline |
1526 // for. | 1539 // for. Note that we can't do this for calls with only one target because |
| 1540 // the type propagator may have made use of that and expects a deopt if |
| 1541 // a new class is seen at this calls site. See HasSingleRecognizedCid. |
1527 add_megamorphic_call = true; | 1542 add_megamorphic_call = true; |
1528 break; | 1543 break; |
1529 } | 1544 } |
1530 ASSERT(cid_start > kSmiCid || cid_end < kSmiCid); | |
1531 Label next_test; | 1545 Label next_test; |
1532 if (!complete || !is_last_check) { | 1546 if (!complete || !is_last_check) { |
1533 Label* next_label = is_last_check ? failed : &next_test; | 1547 Label* next_label = is_last_check ? failed : &next_test; |
1534 if (cid_start == cid_end) { | 1548 if (cid_start == cid_end) { |
1535 __ CompareImmediate(R2, cid_start - bias); | 1549 __ CompareImmediate(R2, cid_start - bias); |
1536 __ b(next_label, NE); | 1550 __ b(next_label, NE); |
1537 } else { | 1551 } else { |
1538 __ AddImmediate(R2, R2, bias - cid_start); | 1552 __ AddImmediate(R2, R2, bias - cid_start); |
1539 bias = cid_start; | 1553 bias = cid_start; |
1540 __ CompareImmediate(R2, cid_end - cid_start); | 1554 __ CompareImmediate(R2, cid_end - cid_start); |
1541 __ b(next_label, HI); // Unsigned higher. | 1555 __ b(next_label, HI); // Unsigned higher. |
1542 } | 1556 } |
1543 } | 1557 } |
1544 // Do not use the code from the function, but let the code be patched so | 1558 // Do not use the code from the function, but let the code be patched so |
1545 // that we can record the outgoing edges to other code. | 1559 // that we can record the outgoing edges to other code. |
1546 const Function& function = *sorted[i].target; | 1560 const Function& function = *targets[i].target; |
1547 GenerateStaticDartCall(deopt_id, token_index, | 1561 GenerateStaticDartCall(deopt_id, token_index, |
1548 *StubCode::CallStaticFunction_entry(), | 1562 *StubCode::CallStaticFunction_entry(), |
1549 RawPcDescriptors::kOther, locs, function); | 1563 RawPcDescriptors::kOther, locs, function); |
1550 __ Drop(argument_count); | 1564 __ Drop(argument_count); |
1551 if (!is_last_check) { | 1565 if (!is_last_check || add_megamorphic_call) { |
1552 __ b(match_found); | 1566 __ b(match_found); |
1553 } | 1567 } |
1554 __ Bind(&next_test); | 1568 __ Bind(&next_test); |
1555 } | 1569 } |
1556 if (add_megamorphic_call) { | 1570 if (add_megamorphic_call) { |
1557 int try_index = CatchClauseNode::kInvalidTryIndex; | 1571 int try_index = CatchClauseNode::kInvalidTryIndex; |
1558 EmitMegamorphicInstanceCall(ic_data, argument_count, deopt_id, token_index, | 1572 EmitMegamorphicInstanceCall(function_name, arguments_descriptor, |
1559 locs, try_index, argument_count); | 1573 argument_count, deopt_id, token_index, locs, |
| 1574 try_index); |
1560 } | 1575 } |
1561 } | 1576 } |
1562 | 1577 |
1563 | 1578 |
1564 #undef __ | 1579 #undef __ |
1565 #define __ compiler_->assembler()-> | 1580 #define __ compiler_->assembler()-> |
1566 | 1581 |
1567 | 1582 |
1568 void ParallelMoveResolver::EmitMove(int index) { | 1583 void ParallelMoveResolver::EmitMove(int index) { |
1569 MoveOperands* move = moves_[index]; | 1584 MoveOperands* move = moves_[index]; |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1833 void ParallelMoveResolver::RestoreFpuScratch(FpuRegister reg) { | 1848 void ParallelMoveResolver::RestoreFpuScratch(FpuRegister reg) { |
1834 __ PopDouble(reg); | 1849 __ PopDouble(reg); |
1835 } | 1850 } |
1836 | 1851 |
1837 | 1852 |
1838 #undef __ | 1853 #undef __ |
1839 | 1854 |
1840 } // namespace dart | 1855 } // namespace dart |
1841 | 1856 |
1842 #endif // defined TARGET_ARCH_ARM64 | 1857 #endif // defined TARGET_ARCH_ARM64 |
OLD | NEW |